last version

Dependencies:   LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI

Committer:
bolko
Date:
Tue Jun 09 11:23:48 2020 +0000
Revision:
2:e23243b26a23
look;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bolko 2:e23243b26a23 1 #ifndef COMMAND_DECODER_H
bolko 2:e23243b26a23 2 #define COMMAND_DECODER_H
bolko 2:e23243b26a23 3 #include "mbed.h"
bolko 2:e23243b26a23 4 #include <string>
bolko 2:e23243b26a23 5
bolko 2:e23243b26a23 6 #define MAX_TOKEN_NR 2
bolko 2:e23243b26a23 7 #define MAX_KEYWORD_STRING_LTH 6
bolko 2:e23243b26a23 8 #define MAX_KEYWORD_NR 4
bolko 2:e23243b26a23 9 #define DELIMITER_CHAR 0x20
bolko 2:e23243b26a23 10
bolko 2:e23243b26a23 11 enum TokenType { KEYWORD, NUMBER, STRING};
bolko 2:e23243b26a23 12 enum KeywordCode {ID,CALLIB,GOTO,STEP};
bolko 2:e23243b26a23 13 enum Result { OK, FAIL };
bolko 2:e23243b26a23 14
bolko 2:e23243b26a23 15
bolko 2:e23243b26a23 16 union TokenValue {
bolko 2:e23243b26a23 17 enum KeywordCode eKeyword;
bolko 2:e23243b26a23 18 unsigned int uiNumber;
bolko 2:e23243b26a23 19 char *pcString;
bolko 2:e23243b26a23 20 };
bolko 2:e23243b26a23 21
bolko 2:e23243b26a23 22 struct Token {
bolko 2:e23243b26a23 23 enum TokenType eType;
bolko 2:e23243b26a23 24 union TokenValue uValue;
bolko 2:e23243b26a23 25 };
bolko 2:e23243b26a23 26
bolko 2:e23243b26a23 27 struct Keyword {
bolko 2:e23243b26a23 28 enum KeywordCode eCode;
bolko 2:e23243b26a23 29 char cString[MAX_KEYWORD_STRING_LTH + 1];
bolko 2:e23243b26a23 30 };
bolko 2:e23243b26a23 31
bolko 2:e23243b26a23 32 class CommandDecoder {
bolko 2:e23243b26a23 33 public:
bolko 2:e23243b26a23 34 void DecodeMsg(char *pcString);
bolko 2:e23243b26a23 35 struct Token asToken[MAX_TOKEN_NR];
bolko 2:e23243b26a23 36 unsigned char ucTokenNr;
bolko 2:e23243b26a23 37 private:
bolko 2:e23243b26a23 38 enum Result eHexStringToUInt(char pcStr[],unsigned int *puiValue);
bolko 2:e23243b26a23 39 void ReplaceCharactersInString(char pcString[], char cOldChar,char cNewChar);
bolko 2:e23243b26a23 40 void TokenizeString(char *pcString);
bolko 2:e23243b26a23 41 unsigned char ucFindTokensInString(char *pcString);
bolko 2:e23243b26a23 42 enum Result eStringToKeyword(char pcStr[],enum KeywordCode *peKeywordCode);
bolko 2:e23243b26a23 43 enum Result DecodeTokens();
bolko 2:e23243b26a23 44
bolko 2:e23243b26a23 45 };
bolko 2:e23243b26a23 46
bolko 2:e23243b26a23 47 #endif