xrocusOS_ADXL355 version
Dependencies: mbed SDFileSystem
CommandParser.h
00001 #ifndef _COMMANDPARSER_H_ 00002 #define _COMMANDPARSER_H_ 00003 00004 #include "UartReceiver.h" 00005 00006 class CommandParser; 00007 00008 /** 00009 * Parsing Rules 00010 * if (cmdName) CALL func with exarg. 00011 */ 00012 typedef struct _command_parser_rule_s { 00013 char* cmdName; 00014 int(*func)(CommandParser*, char*, int); 00015 int exarg; 00016 } CmdParseRule; 00017 00018 /* CommandParser */ 00019 class CommandParser 00020 { 00021 public: 00022 /* CMD length */ 00023 const static int CmdNameLen = 3; 00024 /* CMD total length */ 00025 const static int CmdLen = sizeof(":0 CMD 0000") - 1 /* EOL */; 00026 /* reply code (for ACK/NAK) */ 00027 class NakCode 00028 { 00029 public: 00030 const static int NAK_UNDEFINED = 0000; 00031 const static int NAK_INVAL_CMD = 1000; 00032 const static int NAK_INVAL_LEN = 1001; 00033 const static int NAK_INVAL_FMT = 1002; 00034 const static int NAK_INVAL_PARAM = 1003; 00035 const static int NAK_INVAL_SEQ = 1004; 00036 const static int NAK_IN_RUNNING = 2000; 00037 const static int NAK_IN_STOPPED = 2010; 00038 const static int NAK_INTERNAL_ERR = 4000; 00039 }; 00040 private: 00041 int deviceID; 00042 UartReceiver *pR; 00043 Serial *pUart; 00044 CmdParseRule *ruleTable; 00045 int ruleTableLen; 00046 private: 00047 /* (INVALIDED) constructor */ 00048 CommandParser(void); 00049 public: 00050 /* constructor */ 00051 CommandParser(UartReceiver *setUartReceiver, int setDeviceID, 00052 CmdParseRule *setRuleTable, int setRuleTableLen); 00053 /* start parsing */ 00054 void run(void); 00055 /* process parsing */ 00056 int parse(char *pStr); 00057 /* get my Device ID */ 00058 int getDeviceID(void); 00059 /* generate ACK/NAK with int code */ 00060 void reply(bool ack = true, int replyCode = 0); 00061 /* generate ACK/NAK with String */ 00062 void reply(bool ack, char *replyStr); 00063 /* get currentUart */ 00064 Serial *getCurrentUart(void); 00065 }; 00066 #endif /* _COMMANDPARSER_H_ */
Generated on Sun Jul 17 2022 15:09:45 by 1.7.2