Files
wangfq d1fde88dd1 feat(DLD154Pro): RS485 省 Flash 减配 + 固件 V3.05
为节省 Flash 资源,注释掉 RS485 侧一批低频/非核心协议分支与调试打印:
- Modbus: FC 0x03(读保持寄存器)/0x10(批量写)/0x11(Report Slave ID)分发禁用;
  IR 0x0006/0x0007(Variation)/0x000A/0x000B/0x000C 读禁用(Variation 走全数据块
  0x010A/0x010B);HR 0x0000–0x0004/0x0009/0x000A 写禁用(FC 0x06 仅剩
  0x0010/0x0011/0x0012 有效)
- 700BS: 0x3D DIP 查询禁用 + 4 处调试 PRINT 移除
- MB_MAX_READ_REGS 125→40(40×2=80B 与 MB_MAX_DATA_BYTES 匹配,原 60 会越界 40B)
- 呼吸灯光耦加速步长 32→64;OTA 跳转前 mDelaymS(5) 移除
- cmcng.h 版本 V3.04 → V3.05(字符串 + SUB 宏同步)

协议文档已同步标注未实现(rs485-modbus V1.8 / rs485-700bs),见 docs commit。
2026-08-27 08:55:20 +08:00

58 lines
2.5 KiB
C
Raw Permalink 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_modbus.h
* DLD154Pro RS485 Modbus RTU 从机协议 — V1.6 私有扩展
*
* 物理层: RS485 半双工 (共享 UART0, 与 700BS 互斥)
* 帧格式: ADDR(1) + FC(1) + DATA(N) + CRC16(2)
* 主动上报: 3 级速率 (事件立即 / 活动 150ms / 空闲 800ms), FC 0x04 响应格式
*
* 2026-07-30 初始实现
*/
#ifndef __RS485_MODBUS_H__
#define __RS485_MODBUS_H__
#include <stdint.h>
/*===========================================================================
* 协议常量
*===========================================================================*/
/* 寄存器地址范围 */
#define MB_IR_FULL_BLOCK_START 0x0100 /* 全数据块起始地址 */
#define MB_IR_FULL_BLOCK_COUNT 19 /* 全数据块寄存器数 (0x01000x0112) */
#define MB_HR_AUTO_RPT_ENABLE 0x0010 /* 主动上报使能 (0=关, 1=开) */
#define MB_HR_ACTIVE_THRESHOLD 0x0011 /* 活动状态阈值 (|Variation|≥N) */
#define MB_HR_SYSTEM_CMD 0x0012 /* 系统指令: 写 0x2C2C 复位 MCU */
#define MB_CMD_RESET_MCU 0x2C2C /* 复位 MCU 指令值 */
/* 主动上报间隔 (mstick() 5ms/tick) */
#define MB_RPT_IDLE_MS 160 /* 空闲: 800ms / 5ms = 160 tick */
#define MB_RPT_ACTIVE_MS 30 /* 活动: 150ms / 5ms = 30 tick */
#define MB_RPT_ACTIVE_HYST 2 /* 降速迟滞: 连续 N 次低于阈值 */
/* 帧超时: t3.5 = 3.5 × 11 / 9600 ≈ 4.0ms, 取 2 tick (10ms) */
#define MB_FRAME_TIMEOUT_TICK 2
/* 全数据块 CRC 后的帧总长:
* addr(1) + fc(1) + byte_cnt(1) + data(38) + crc(2) = 43 */
#define MB_FULL_DATA_FRAME_LEN 43
/* FC 0x03/0x04 读寄存器缓冲 (Modbus 标准: max qty = 0x007D = 125) */
/* ⚠ 40/80 匹配: 40 寄存器 × 2B = 80B 缓冲 (2026-08-27 省 Flash 减配, 原 60 会越界 40B) */
#define MB_MAX_READ_REGS 40 //125 /* 单次读取最大寄存器数 */
#define MB_MAX_DATA_BYTES 80 //250 /* 40 × 2 字节 */
#define MB_RESP_BUF_SIZE (5 + MB_MAX_DATA_BYTES) /* addr+fc+bc+data+crc */
/*===========================================================================
* API
*===========================================================================*/
/* 初始化 Modbus 协议 (UART0 已在 rs485_init 中配置, 此处仅做协议状态初始化) */
void modbus_init(void);
/* 主循环轮询 — 帧接收 & 主动上报调度 (替代 rs485_poll) */
void modbus_poll(void);
#endif /* __RS485_MODBUS_H__ */