3.27_433:实现并验证RF433模块接收相应指令:新增UART路由核心模块,使程序能响应RF433/RS485指令,并向UART2输出LOG(RS485由于硬件原因未验证)
This commit is contained in:
@ -3,13 +3,16 @@
|
||||
* @file cmd_parser.h
|
||||
* @brief ASCII指令解析模块头文件
|
||||
* @author Application Layer
|
||||
* @version 1.0
|
||||
* @version 1.2
|
||||
******************************************************************************
|
||||
* @attention
|
||||
* 本模块实现ASCII文本指令的解析和处理
|
||||
* 指令格式: $CMD,param1,param2*CS\r\n
|
||||
* 支持异或校验,FF为调试特权后门
|
||||
* 包含完善的安全防护机制
|
||||
*
|
||||
* 修订历史:
|
||||
* v1.2 - 增加响应回调机制,支持多端口路由
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
@ -41,67 +44,31 @@ typedef struct {
|
||||
char param2[PARAM_MAX_LEN];
|
||||
uint8_t received_cs;
|
||||
uint8_t calculated_cs;
|
||||
uint8_t source_port;
|
||||
bool valid;
|
||||
bool skip_checksum;
|
||||
} cmd_frame_t;
|
||||
|
||||
/**
|
||||
* @brief 初始化指令解析模块
|
||||
* @note 重置解析状态机,清空缓冲区
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
typedef void (*cmd_response_callback_t)(uint8_t source_port, const char *response);
|
||||
|
||||
void CmdParser_Init(void);
|
||||
|
||||
/**
|
||||
* @brief 指令解析任务处理函数
|
||||
* @note 在主循环中调用,处理已接收的完整指令帧
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
void CmdParser_Task(void);
|
||||
|
||||
/**
|
||||
* @brief 喂入单字节数据到解析器
|
||||
* @note 通常在UART接收中断中调用
|
||||
* @param byte: 接收到的字节数据
|
||||
* @param current_tick: 当前系统tick(用于超时检测)
|
||||
* @retval 无
|
||||
*/
|
||||
void CmdParser_FeedByte(uint8_t byte, uint32_t current_tick);
|
||||
|
||||
/**
|
||||
* @brief 检查是否有完整的指令帧
|
||||
* @note 用于查询解析状态
|
||||
* @param frame: 输出参数,存储解析结果
|
||||
* @retval true: 有完整帧, false: 无
|
||||
*/
|
||||
bool CmdParser_HasCompleteFrame(cmd_frame_t *frame);
|
||||
|
||||
/**
|
||||
* @brief 确认指令已处理
|
||||
* @note 处理完指令后调用,重置解析器
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
void CmdParser_Acknowledge(void);
|
||||
|
||||
/**
|
||||
* @brief 获取解析错误计数
|
||||
* @note 用于调试和诊断
|
||||
* @param 无
|
||||
* @retval 错误计数
|
||||
*/
|
||||
uint32_t CmdParser_GetErrorCount(void);
|
||||
|
||||
/**
|
||||
* @brief 获取接收到的有效指令计数
|
||||
* @note 用于调试和诊断
|
||||
* @param 无
|
||||
* @retval 有效指令计数
|
||||
*/
|
||||
uint32_t CmdParser_GetValidCount(void);
|
||||
|
||||
void CmdParser_SetResponseCallback(cmd_response_callback_t callback);
|
||||
|
||||
void CmdParser_SetSourcePort(uint8_t port_id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user