feat: Modbus RTU V1.6 私有协议编码实现
新增:
- rs485_modbus.h/c — 完整 Modbus RTU 从机实现 (516行)
· FC 0x02 读离散输入 (9-bit 位图: car_state/线圈/光耦/继电器)
· FC 0x03 读保持寄存器 (含 HR 0x0010/0x0011)
· FC 0x04 读输入寄存器 (基础 IR + 全数据块 0x0100-0x0112)
· FC 0x06/0x10 写寄存器 (含值域校验+只读拦截)
· FC 0x11 Report Slave ID
· CRC16 查表 (poly=0xA001)
· 全数据块组装 (19 reg = 38B big-endian)
· 主动上报 3 级速率调度 (事件立即/活动150ms/空闲800ms)
· 车间距/通过时间测量 (mstick/2=10ms单位, relay边沿触发)
· 光耦状态实时读取 (GPIOB_ReadPortPin)
· Holding Register 写穿透: Fusion Mode 同步 direction_mode,
Hold Time 同步 g_hold_time, Freq Level 同步 g_loop_cng_unit
改造:
- rs485_700bs.h/c: 暴露 rs485_send() + rx缓冲(_rx_buf/_rx_len/_rx_last_tick) 供Modbus共用
- peripheral_main.c: g_fm_700bs_disable 分派 700BS/Modbus; modbus_init() 随 rs485_init 调用
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#include "dbn_ble_srv.h"
|
||||
#include "CH59x_pwm.h"
|
||||
#include "rs485_700bs.h"
|
||||
#include "rs485_modbus.h"
|
||||
|
||||
|
||||
uint8_t g_flag_bt_state = 0; // 0 蓝牙没有连接,1 有蓝牙连接
|
||||
@@ -394,6 +395,7 @@ void gpio_uart_init(void)
|
||||
{
|
||||
/*--- RS485 通信 (PA14=TX, PA15=RX, PA13=RE) ---*/
|
||||
rs485_init(); /* 初始化 UART0 + GPIO + 中断 */
|
||||
modbus_init(); /* 初始化 Modbus 协议状态 */
|
||||
|
||||
/*--- 光耦输入 (PB10=IN_1) ---*/
|
||||
R32_PIN_CONFIG2 &= ~(1UL << 26); // 使能 PB10 数字输入 (默认关闭省电)
|
||||
@@ -1038,7 +1040,11 @@ void Main_Circulation()
|
||||
|
||||
opt_input_poll(); // 光耦输入处理 (复位 / 雷达)
|
||||
|
||||
rs485_poll(); // RS485 700BS 协议: 命令处理 + 心跳上报
|
||||
if (g_fm_700bs_disable) {
|
||||
modbus_poll(); // RS485 Modbus RTU 协议
|
||||
} else {
|
||||
rs485_poll(); // RS485 700BS 协议: 命令处理 + 心跳上报
|
||||
}
|
||||
|
||||
if(g_flag_bt_state == 0){
|
||||
// 如果蓝牙断开,主动上报需要禁用
|
||||
|
||||
Reference in New Issue
Block a user