fix: Modbus 主动上报缺少线圈断开/重连事件触发
根因: modbus_report_schedule() 只检测继电器翻转, 没有检测 loop1_LOOP_OK 变化。线圈断开时依赖 150ms/800ms 周期上报, 若断开-重连-再断开在一个周期内完成, 中间事件被吞掉。 修复: - +extern loop1_LOOP_OK - +_last_loop_ok 状态追踪器 - +线圈断开/重连边沿检测 (对齐 700BS rs485_poll 行为) - +modbus_init 初始化 _last_loop_ok
This commit is contained in:
@@ -78,6 +78,7 @@ static uint16_t crc16(const uint8_t *data, uint8_t len)
|
||||
extern uint8_t _rx_buf[16];
|
||||
extern uint8_t _rx_len;
|
||||
extern uint32_t _rx_last_tick;
|
||||
extern uint8_t loop1_LOOP_OK; /* 线圈连接状态 (1=正常, 0=断开) */
|
||||
|
||||
/*===========================================================================
|
||||
* Modbus 协议状态
|
||||
@@ -100,6 +101,9 @@ static uint32_t _misc_time_value = 0; /* 时间值 (10ms 单位) */
|
||||
/* 计数器 (上电清零) */
|
||||
static uint32_t _relay_engage_cnt = 0; /* 继电器吸合累计次数 */
|
||||
|
||||
/* 线圈状态追踪 (断开/重连 事件触发) */
|
||||
static uint8_t _last_loop_ok = 0; /* 线圈连接状态快照 (边沿检测) */
|
||||
|
||||
/*===========================================================================
|
||||
* 主动上报 — 全数据块组装 & 发送
|
||||
*===========================================================================*/
|
||||
@@ -282,6 +286,20 @@ static void modbus_report_schedule(void)
|
||||
}
|
||||
}
|
||||
|
||||
/* 线圈断开/重连 → 立即上报 (对齐 700BS 行为) */
|
||||
{
|
||||
uint8_t loop_ok = loop1_LOOP_OK;
|
||||
if (loop_ok != _last_loop_ok) {
|
||||
_last_loop_ok = loop_ok;
|
||||
update_misc_time();
|
||||
send_full_data();
|
||||
_rpt_last_ms = mstick();
|
||||
_rpt_hyst_cnt = 0;
|
||||
_rpt_active = is_active();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t now = mstick();
|
||||
uint32_t elapsed = now - _rpt_last_ms;
|
||||
|
||||
@@ -770,6 +788,7 @@ void modbus_init(void)
|
||||
_rpt_active = 0;
|
||||
_rpt_hyst_cnt = 0;
|
||||
_last_relay_state = g_loop_acs_info.relay1_state;
|
||||
_last_loop_ok = loop1_LOOP_OK;
|
||||
_last_relay_off_10ms = 0;
|
||||
_last_relay_on_10ms = 0;
|
||||
_misc_time_type = 0xFFFF;
|
||||
|
||||
Reference in New Issue
Block a user