diff --git a/BLE/DLD154Pro_Peripheral_28K/APP/rs485_modbus.c b/BLE/DLD154Pro_Peripheral_28K/APP/rs485_modbus.c index 3a290ee..d777097 100644 --- a/BLE/DLD154Pro_Peripheral_28K/APP/rs485_modbus.c +++ b/BLE/DLD154Pro_Peripheral_28K/APP/rs485_modbus.c @@ -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;