feat: complete assembly mesh relay control path
- synchronize STM8 application and external flash layout updates\n- add assembly bootloader and assembly application test projects\n- add UART1 interrupt receive ring buffer\n- parse JDY-28M Mesh outer frames and source addresses\n- add CRC-16/MODBUS validation\n- implement relay control command 0x01 and response 0x81\n- support unicast and broadcast relay control frames\n- update host protocol, OTA documents, and serial tools
This commit is contained in:
+4
-3
@@ -3,8 +3,9 @@
|
||||
* @brief 蓝牙 Mesh 继电器硬件板级接口定义。
|
||||
*
|
||||
* 本阶段先提供稳定的硬件抽象接口,不在业务层直接操作 GPIO 寄存器。
|
||||
* PA1 的有效电平已经确认:高电平吸合、低电平断开;PB5 为低电平点亮的
|
||||
* 蓝牙组网/故障指示灯,PD3 为高电平点亮的继电器状态灯。
|
||||
* PA1 的有效电平已经确认:高电平吸合、低电平断开;PB4 为低电平点亮的
|
||||
* 蓝牙组网/故障指示灯,PB5 为低电平点亮的程序运行/OTA状态灯,PD3 为
|
||||
* 高电平点亮的继电器状态灯。
|
||||
*/
|
||||
#ifndef BOARD_H
|
||||
#define BOARD_H
|
||||
@@ -29,7 +30,7 @@ void Board_SetLed3(uint8_t on);
|
||||
/** 设置继电器状态灯,1表示点亮,0表示熄灭;硬件高电平点亮。 */
|
||||
void Board_SetRelayLed(uint8_t on);
|
||||
|
||||
/** 周期驱动PB4程序状态灯;正常运行500ms翻转,OTA期间100ms翻转。 */
|
||||
/** 周期驱动PB5程序状态灯;硬件低电平点亮,正常运行500ms翻转,OTA期间100ms翻转。 */
|
||||
void Board_StatusLedTask(uint8_t ota_active);
|
||||
|
||||
/** 设置 PWRC:1 表示拉低进入 AT 窗口,0 表示恢复高电平通信。 */
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
* @file business_protocol.h
|
||||
* @brief STM8 业务帧协议接口。
|
||||
*
|
||||
* 业务帧格式:SRC_H SRC_L | CMD | LEN | DATA | CRC16_H CRC16_L。
|
||||
* SRC 为发送方的 Mesh 短地址;CRC 使用 CRC-16/MODBUS,计算范围为
|
||||
* SRC、CMD、LEN 和 DATA,线上高字节在前。
|
||||
* 业务帧格式:CMD | LEN | DATA | CRC16_H CRC16_L。
|
||||
* 发送方和接收方短地址由JDY-28M外层提供;CRC计算范围为CMD、LEN和DATA。
|
||||
*/
|
||||
#ifndef BUSINESS_PROTOCOL_H
|
||||
#define BUSINESS_PROTOCOL_H
|
||||
@@ -14,9 +13,6 @@
|
||||
/** 业务帧最大 DATA 长度,需为 JDY-28M 外层 20 字节限制预留空间。 */
|
||||
#define BUSINESS_MAX_DATA_LENGTH 4u
|
||||
|
||||
/** 发送方短地址字段长度。 */
|
||||
#define BUSINESS_SOURCE_ADDRESS_LENGTH 2u
|
||||
|
||||
/** 业务命令:继电器控制。 */
|
||||
#define CMD_RELAY_CONTROL 0x01u
|
||||
|
||||
@@ -89,7 +85,7 @@ void BusinessProtocol_QueueDelayedResponse(uint16_t address,
|
||||
* 向解析器输入一个字节。
|
||||
*
|
||||
* 该接口只负责解析内层业务帧,不执行继电器动作,也不负责 JDY-28M
|
||||
* 外层 Mesh 封装。外层模块应在确认 `F1 DD 09 00 0A ... 0D 0A` 后,
|
||||
* 外层 Mesh 封装。外层模块应在确认 `F1 DD 09 SRC DST ... 0A` 后,
|
||||
* 将其中的业务数据逐字节送入本接口。
|
||||
*
|
||||
* @param value 输入字节。
|
||||
@@ -97,19 +93,13 @@ void BusinessProtocol_QueueDelayedResponse(uint16_t address,
|
||||
*/
|
||||
uint8_t BusinessProtocol_InputByte(uint8_t value);
|
||||
|
||||
/** 读取最近一帧合法业务帧的命令字。 */
|
||||
uint8_t BusinessProtocol_GetCommand(void);
|
||||
|
||||
/** 读取最近一帧合法业务帧的数据长度。 */
|
||||
uint8_t BusinessProtocol_GetDataLength(void);
|
||||
|
||||
/** 读取最近一帧合法业务帧携带的发送方 Mesh 短地址。 */
|
||||
uint16_t BusinessProtocol_GetSourceAddress(void);
|
||||
/** 设置当前外层接收帧携带的发送方地址,供业务应答使用。 */
|
||||
void BusinessProtocol_SetSourceAddress(uint16_t address);
|
||||
|
||||
/** 执行最近一帧已经通过校验的业务命令,并向源地址返回应答。 */
|
||||
void BusinessProtocol_HandleFrame(void);
|
||||
|
||||
/** CRC-16/MODBUS 计算函数,输入范围包含发送方地址字段。 */
|
||||
/** CRC-16/MODBUS计算函数,输入范围为CMD、LEN和DATA。 */
|
||||
uint16_t BusinessProtocol_Crc16Modbus(const uint8_t *data, uint16_t length);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,6 +12,5 @@
|
||||
void Interrupts_Enable(void);
|
||||
|
||||
/** 关闭 STM8 全局中断,用于极短的不可打断临界区。 */
|
||||
void Interrupts_Disable(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/** JDY-28M 外层完整帧最大长度,包含帧头、地址、数据和 0D 0A。 */
|
||||
/** JDY-28M 外层完整帧最大长度,包含帧头、双地址、数据和结束符。 */
|
||||
#define JDY_MESH_FRAME_MAX_LENGTH 20u
|
||||
|
||||
/** 初始化 JDY-28M 外层帧状态机。 */
|
||||
|
||||
@@ -27,7 +27,6 @@ uint8_t OtaManager_GetExpectedOffset(uint16_t *offset);
|
||||
* 读取Bootloader写入的升级结果并准备由主程序主动上报。
|
||||
* @return 0表示没有待上报结果,非0表示升级结果码。
|
||||
*/
|
||||
uint8_t OtaManager_GetBootloaderResult(void);
|
||||
/** 主机确认升级结果后清除待上报状态。 */
|
||||
void OtaManager_AcknowledgeBootloaderResult(void);
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
/* GPIO 端口寄存器布局:ODR、IDR、DDR、CR1、CR2。 */
|
||||
#define GPIOA_ODR_ADDR 0x5000u
|
||||
#define CLK_CKDIVR_ADDR 0x50C6u
|
||||
#define GPIOA_IDR_ADDR 0x5001u
|
||||
#define GPIOA_DDR_ADDR 0x5002u
|
||||
#define GPIOA_CR1_ADDR 0x5003u
|
||||
|
||||
@@ -15,5 +15,7 @@ uint32_t SystemTick_NowMs(void);
|
||||
|
||||
/** 在定时器中断服务程序中递增系统节拍。 */
|
||||
void SystemTick_InterruptHandler(void);
|
||||
/** TIM4中断处理函数主体,由主程序固定中断向量入口调用。 */
|
||||
void SystemTick_TIM4_Handler(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
void Uart1_Init(void);
|
||||
|
||||
/** UART任务入口;接收硬件由中断处理,此接口保留为空操作。 */
|
||||
void Uart1_Task(void);
|
||||
|
||||
/** 向 UART1 发送一个字节。 */
|
||||
void Uart1_WriteByte(uint8_t value);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#ifndef W25Q64_APP_H
|
||||
#define W25Q64_APP_H
|
||||
#include <stdint.h>
|
||||
void W25Q64App_Init(void);
|
||||
uint8_t W25Q64App_Init(void);
|
||||
uint8_t W25Q64App_ReadByte(uint32_t address, uint8_t *value);
|
||||
uint8_t W25Q64App_Read(uint32_t address, uint8_t *buffer, uint16_t length);
|
||||
uint8_t W25Q64App_EraseSector(uint32_t address);
|
||||
|
||||
Reference in New Issue
Block a user