feat: Modbus 新增 0x0012 系统指令寄存器,写 0x2C2C 复位 MCU (对齐 700BS 0x2C)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user