Files
DLD154Pro/BLE/DLD154Pro_Peripheral_28K/APP/include/rs485_700bs.h
T
wangfq e32f3892fe 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 调用
2026-07-30 12:02:24 +08:00

66 lines
2.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* rs485_700bs.h
* DLD154Pro RS485 700BS 协议 — 车检器从机实现
* 协议版本: V1.15 | 2022-08-19
* 波特率: 9600 8N1, 半双工 RS485, XOR 校验
*/
#ifndef __RS485_700BS_H__
#define __RS485_700BS_H__
#include <stdint.h>
/* 协议常量 */
#define RS485_BAUD 9600
#define RS485_HEARTBEAT_MS 1000 // 空闲心跳 5s (1000 tick × 5ms/tick)
#define RS485_FAULT_MS 200 // 故障心跳 1s (200 tick × 5ms/tick)
#define RS485_MAX_FRAME 10 // 最大帧长
/* 命令码 (主机→从机) */
#define CMD_QUERY_STATUS 0xFA // 查询有车状态 + 线圈好坏
#define CMD_QUERY_FREQ 0x1B // 查询线圈频率
#define CMD_RESET_INIT 0x2C // 复位初始化线圈
#define CMD_QUERY_DIP 0x3D // 查询拨码 DIP1-5 (灵敏度/输出/延时)
/* 回复码 (从机→主机) */
#define RSP_STATUS 0xF5 // 状态回复
#define RSP_FREQ 0x14 // 频率回复
#define RSP_DIP 0x32 // 拨码回复
/* 心跳 (从机主动) */
#define HB_PREAMBLE 0xAA
#define HB_INIT_FIRST 0xA1 // 设备复位后首次
#define HB_INIT_NORMAL 0xA0 // 正常心跳
/*===========================================================================
* API
*===========================================================================*/
/* 初始化 RS485 通信 (UART0 9600 8N1 + 中断接收) */
void rs485_init(void);
/* 发送一帧 — 切 RE=TX, 发完等 1ms, 切回 RE=RX (供 700BS / Modbus 模块复用) */
void rs485_send(const uint8_t *data, uint8_t len);
/* 主循环轮询 — 处理接收的 3 字节命令帧, 驱动心跳上报 (仅 700BS 模式) */
void rs485_poll(void);
/* 有车/无车事件触发立即上报 (由检测算法调用) */
void rs485_event_notify(void);
/* 线圈状态变化触发 (连接/断开, 由 cjq_srv 调用) */
void rs485_loop_notify(void);
/* 重置心跳计时 (复位后调用, 触发首次 A1 上报) */
void rs485_reset_heartbeat(void);
/*===========================================================================
* 共享 UART 接收缓冲 (Modbus 模块共用)
*===========================================================================*/
/* UART0 ISR (rs485_700bs.c) 填充的接收缓冲 */
extern uint8_t _rx_buf[16];
extern uint8_t _rx_len;
extern uint32_t _rx_last_tick;
#endif /* __RS485_700BS_H__ */