xrocusOS_ADXL355 version

Dependencies:   mbed SDFileSystem

Committer:
APS_Lab
Date:
Fri Jul 05 02:09:06 2019 +0000
Revision:
20:2f2687580ecb
Parent:
19:36072b9b79f3
Ver0.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Inscape_ao 0:c347f602596d 1 #ifndef _COMMANDPARSER_H_
Inscape_ao 0:c347f602596d 2 #define _COMMANDPARSER_H_
Inscape_ao 0:c347f602596d 3
Inscape_ao 0:c347f602596d 4 #include "UartReceiver.h"
Inscape_ao 0:c347f602596d 5
Inscape_ao 1:71c9c97c9f3d 6 class CommandParser;
Inscape_ao 1:71c9c97c9f3d 7
Inscape_ao 2:a694440145e9 8 /**
Inscape_ao 2:a694440145e9 9 * Parsing Rules
Inscape_ao 2:a694440145e9 10 * if (cmdName) CALL func with exarg.
Inscape_ao 2:a694440145e9 11 */
Inscape_ao 0:c347f602596d 12 typedef struct _command_parser_rule_s {
Inscape_ao 0:c347f602596d 13 char* cmdName;
Inscape_ao 2:a694440145e9 14 int(*func)(CommandParser*, char*, int);
Inscape_ao 2:a694440145e9 15 int exarg;
Inscape_ao 0:c347f602596d 16 } CmdParseRule;
Inscape_ao 0:c347f602596d 17
Inscape_ao 2:a694440145e9 18 /* CommandParser */
Inscape_ao 0:c347f602596d 19 class CommandParser
Inscape_ao 0:c347f602596d 20 {
Inscape_ao 0:c347f602596d 21 public:
Inscape_ao 2:a694440145e9 22 /* CMD length */
Inscape_ao 0:c347f602596d 23 const static int CmdNameLen = 3;
Inscape_ao 2:a694440145e9 24 /* CMD total length */
Inscape_ao 0:c347f602596d 25 const static int CmdLen = sizeof(":0 CMD 0000") - 1 /* EOL */;
Inscape_ao 2:a694440145e9 26 /* reply code (for ACK/NAK) */
Inscape_ao 19:36072b9b79f3 27 class NakCode
Inscape_ao 1:71c9c97c9f3d 28 {
Inscape_ao 1:71c9c97c9f3d 29 public:
Inscape_ao 19:36072b9b79f3 30 const static int NAK_UNDEFINED = 0000;
Inscape_ao 19:36072b9b79f3 31 const static int NAK_INVAL_CMD = 1000;
Inscape_ao 19:36072b9b79f3 32 const static int NAK_INVAL_LEN = 1001;
Inscape_ao 19:36072b9b79f3 33 const static int NAK_INVAL_FMT = 1002;
Inscape_ao 19:36072b9b79f3 34 const static int NAK_INVAL_PARAM = 1003;
Inscape_ao 19:36072b9b79f3 35 const static int NAK_INVAL_SEQ = 1004;
Inscape_ao 19:36072b9b79f3 36 const static int NAK_IN_RUNNING = 2000;
Inscape_ao 19:36072b9b79f3 37 const static int NAK_IN_STOPPED = 2010;
Inscape_ao 19:36072b9b79f3 38 const static int NAK_INTERNAL_ERR = 4000;
Inscape_ao 1:71c9c97c9f3d 39 };
Inscape_ao 0:c347f602596d 40 private:
Inscape_ao 0:c347f602596d 41 int deviceID;
Inscape_ao 0:c347f602596d 42 UartReceiver *pR;
Inscape_ao 0:c347f602596d 43 Serial *pUart;
Inscape_ao 0:c347f602596d 44 CmdParseRule *ruleTable;
Inscape_ao 0:c347f602596d 45 int ruleTableLen;
Inscape_ao 0:c347f602596d 46 private:
Inscape_ao 2:a694440145e9 47 /* (INVALIDED) constructor */
Inscape_ao 0:c347f602596d 48 CommandParser(void);
Inscape_ao 0:c347f602596d 49 public:
Inscape_ao 2:a694440145e9 50 /* constructor */
Inscape_ao 0:c347f602596d 51 CommandParser(UartReceiver *setUartReceiver, int setDeviceID,
Inscape_ao 0:c347f602596d 52 CmdParseRule *setRuleTable, int setRuleTableLen);
Inscape_ao 2:a694440145e9 53 /* start parsing */
Inscape_ao 0:c347f602596d 54 void run(void);
Inscape_ao 2:a694440145e9 55 /* process parsing */
Inscape_ao 0:c347f602596d 56 int parse(char *pStr);
Inscape_ao 2:a694440145e9 57 /* get my Device ID */
Inscape_ao 1:71c9c97c9f3d 58 int getDeviceID(void);
Inscape_ao 2:a694440145e9 59 /* generate ACK/NAK with int code */
Inscape_ao 1:71c9c97c9f3d 60 void reply(bool ack = true, int replyCode = 0);
Inscape_ao 2:a694440145e9 61 /* generate ACK/NAK with String */
Inscape_ao 1:71c9c97c9f3d 62 void reply(bool ack, char *replyStr);
Inscape_ao 2:a694440145e9 63 /* get currentUart */
Inscape_ao 2:a694440145e9 64 Serial *getCurrentUart(void);
Inscape_ao 0:c347f602596d 65 };
Inscape_ao 0:c347f602596d 66 #endif /* _COMMANDPARSER_H_ */