diff --git a/BLE/DLD154Pro_Peripheral_28K/APP/include/rs485_modbus.h b/BLE/DLD154Pro_Peripheral_28K/APP/include/rs485_modbus.h index 5848e9f..bfe01d4 100644 --- a/BLE/DLD154Pro_Peripheral_28K/APP/include/rs485_modbus.h +++ b/BLE/DLD154Pro_Peripheral_28K/APP/include/rs485_modbus.h @@ -23,6 +23,8 @@ #define MB_HR_AUTO_RPT_ENABLE 0x0010 /* 主动上报使能 (0=关, 1=开) */ #define MB_HR_ACTIVE_THRESHOLD 0x0011 /* 活动状态阈值 (|Variation|≥N) */ +#define MB_HR_SYSTEM_CMD 0x0012 /* 系统指令: 写 0x2C2C 复位 MCU */ +#define MB_CMD_RESET_MCU 0x2C2C /* 复位 MCU 指令值 */ /* 主动上报间隔 (mstick() 5ms/tick) */ #define MB_RPT_IDLE_MS 160 /* 空闲: 800ms / 5ms = 160 tick */ diff --git a/BLE/DLD154Pro_Peripheral_28K/APP/rs485_700bs.c b/BLE/DLD154Pro_Peripheral_28K/APP/rs485_700bs.c index 9fc8267..ca7340a 100644 --- a/BLE/DLD154Pro_Peripheral_28K/APP/rs485_700bs.c +++ b/BLE/DLD154Pro_Peripheral_28K/APP/rs485_700bs.c @@ -125,25 +125,7 @@ static void handle_query_freq(uint8_t addr) /* 0x2C — 复位初始化线圈 */ static void handle_reset_init(uint8_t addr) { - (void)addr; - extern uint8_t g_loop_stable; - extern uint8_t loop1_LOOP_OK0; - extern uint8_t loop1_LC_Reset; - extern uint8_t loop1_INI_LOOP; - extern uint16_t loop1_stable_cnt; - extern uint16_t LC_Hold_CNT; - extern uint32_t loop1_ORG_CNT, loop1_ORG_SUM; - - loop1_LC_Reset = 1; - loop1_INI_LOOP = 1; - loop1_LOOP_OK0 = 0; - g_loop_stable = 0; - loop1_stable_cnt = 0; - LC_Hold_CNT = 0; - loop1_ORG_CNT = 0; - loop1_ORG_SUM = 0; - _hb_need_init = 1; - _last_car_state = (_last_car_state ^ 1); + SYS_ResetExecute(); PRINT("RS485: coil reset init\n"); } diff --git a/BLE/DLD154Pro_Peripheral_28K/APP/rs485_modbus.c b/BLE/DLD154Pro_Peripheral_28K/APP/rs485_modbus.c index d777097..cda5e3b 100644 --- a/BLE/DLD154Pro_Peripheral_28K/APP/rs485_modbus.c +++ b/BLE/DLD154Pro_Peripheral_28K/APP/rs485_modbus.c @@ -550,6 +550,8 @@ static uint8_t read_hr_register(uint16_t addr, uint8_t *hi, uint8_t *lo) *hi = 0; *lo = _auto_rpt_enable; return 1; case 0x0011: /* Active Threshold */ *hi = (uint8_t)(_active_threshold >> 8); *lo = (uint8_t)(_active_threshold); return 1; + case 0x0012: /* System Cmd (只读, 恒为 0) */ + *hi = 0; *lo = 0; return 1; default: return 0; } @@ -653,6 +655,12 @@ static void handle_write_single_reg(const uint8_t *rx, uint8_t rx_len) case 0x0011: /* Active Threshold: 0-65535 */ _active_threshold = reg_val; break; + case 0x0012: /* System Cmd: 写 0x2C2C 复位 MCU */ + if (reg_val == MB_CMD_RESET_MCU) { + SYS_ResetExecute(); + } + /* 非法值: 忽略, 不响应异常 (对齐 700BS 0x2C 行为) */ + return; default: send_exception(0x06, 0x02); /* Illegal Data Address */ return; @@ -723,6 +731,13 @@ static void handle_write_multiple_regs(const uint8_t *rx, uint8_t rx_len) if (_auto_rpt_enable) { _rpt_last_ms = mstick(); _rpt_active = 0; _rpt_hyst_cnt = 0; } break; case 0x0011: _active_threshold = reg_val; break; + case 0x0012: /* System Cmd: 写 0x2C2C 复位 MCU */ + if (reg_val == MB_CMD_RESET_MCU) { + SYS_ResetExecute(); + return; /* 不复位则忽略非法值 */ + } + /* 非法值: 忽略, 继续后续寄存器 */ + break; default: send_exception(0x10, 0x02); return; } }