xrocusOS_ADXL355 version

Dependencies:   mbed SDFileSystem

Committer:
Inscape_ao
Date:
Tue Apr 23 08:47:11 2019 +0000
Revision:
2:a694440145e9
Parent:
1:71c9c97c9f3d
Child:
19:36072b9b79f3
add TimeManager

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 1:71c9c97c9f3d 27 class CmdReply
Inscape_ao 1:71c9c97c9f3d 28 {
Inscape_ao 1:71c9c97c9f3d 29 public:
Inscape_ao 1:71c9c97c9f3d 30 const static int Success = 0;
Inscape_ao 1:71c9c97c9f3d 31 const static int InvalidFmt = 1;
Inscape_ao 1:71c9c97c9f3d 32 const static int InvalidCmd = 2;
Inscape_ao 1:71c9c97c9f3d 33 const static int InvalidLen = 3;
Inscape_ao 1:71c9c97c9f3d 34 };
Inscape_ao 0:c347f602596d 35 private:
Inscape_ao 0:c347f602596d 36 int deviceID;
Inscape_ao 0:c347f602596d 37 UartReceiver *pR;
Inscape_ao 0:c347f602596d 38 Serial *pUart;
Inscape_ao 0:c347f602596d 39 CmdParseRule *ruleTable;
Inscape_ao 0:c347f602596d 40 int ruleTableLen;
Inscape_ao 0:c347f602596d 41 private:
Inscape_ao 2:a694440145e9 42 /* (INVALIDED) constructor */
Inscape_ao 0:c347f602596d 43 CommandParser(void);
Inscape_ao 0:c347f602596d 44 public:
Inscape_ao 2:a694440145e9 45 /* constructor */
Inscape_ao 0:c347f602596d 46 CommandParser(UartReceiver *setUartReceiver, int setDeviceID,
Inscape_ao 0:c347f602596d 47 CmdParseRule *setRuleTable, int setRuleTableLen);
Inscape_ao 2:a694440145e9 48 /* start parsing */
Inscape_ao 0:c347f602596d 49 void run(void);
Inscape_ao 2:a694440145e9 50 /* process parsing */
Inscape_ao 0:c347f602596d 51 int parse(char *pStr);
Inscape_ao 2:a694440145e9 52 /* get my Device ID */
Inscape_ao 1:71c9c97c9f3d 53 int getDeviceID(void);
Inscape_ao 2:a694440145e9 54 /* generate ACK/NAK with int code */
Inscape_ao 1:71c9c97c9f3d 55 void reply(bool ack = true, int replyCode = 0);
Inscape_ao 2:a694440145e9 56 /* generate ACK/NAK with String */
Inscape_ao 1:71c9c97c9f3d 57 void reply(bool ack, char *replyStr);
Inscape_ao 2:a694440145e9 58 /* get currentUart */
Inscape_ao 2:a694440145e9 59 Serial *getCurrentUart(void);
Inscape_ao 0:c347f602596d 60 };
Inscape_ao 0:c347f602596d 61 #endif /* _COMMANDPARSER_H_ */