Files
DLD154Pro/BLE/DLD154Pro_Peripheral_28K/APP/include/rs485_700bs.h
T
wangfq e974fd7814 fix(rs485): 修正心跳周期 — mstick() 单位是 5ms/tick
RS485_HEARTBEAT_MS: 5000→1000 (5s / 5ms = 1000 tick)
RS485_FAULT_MS:     1000→200  (1s / 5ms = 200 tick)
2026-07-24 17:48:18 +08:00

54 lines
1.8 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);
/* 主循环轮询 — 处理接收的 3 字节命令帧, 驱动心跳上报 */
void rs485_poll(void);
/* 有车/无车事件触发立即上报 (由检测算法调用) */
void rs485_event_notify(void);
/* 线圈状态变化触发 (连接/断开, 由 cjq_srv 调用) */
void rs485_loop_notify(void);
/* 重置心跳计时 (复位后调用, 触发首次 A1 上报) */
void rs485_reset_heartbeat(void);
#endif /* __RS485_700BS_H__ */