Files
433_STM32/Core/Inc/cmd_parser.h

110 lines
2.5 KiB
C
Raw Normal View History

/**
******************************************************************************
* @file cmd_parser.h
* @brief ASCII指令解析模块头文件
* @author Application Layer
* @version 1.0
******************************************************************************
* @attention
* ASCII文本指令的解析和处理
* : $CMD,param1,param2*CS\r\n
* FF为调试特权后门
*
******************************************************************************
*/
#ifndef __CMD_PARSER_H
#define __CMD_PARSER_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdbool.h>
#define CMD_MAX_LEN 8
#define PARAM_MAX_LEN 32
#define PARSE_TIMEOUT_MS 1000
typedef enum {
CMD_CODE_UNKNOWN = 0,
CMD_CODE_RL = 1,
CMD_CODE_DI = 2,
CMD_CODE_ECHO = 3,
CMD_CODE_FWD = 4
} cmd_code_t;
typedef struct {
char cmd[CMD_MAX_LEN];
char param1[PARAM_MAX_LEN];
char param2[PARAM_MAX_LEN];
uint8_t received_cs;
uint8_t calculated_cs;
bool valid;
bool skip_checksum;
} cmd_frame_t;
/**
* @brief
* @note
* @param
* @retval
*/
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);
#ifdef __cplusplus
}
#endif
#endif