Oddanie
Diff: DECODER.h
- Revision:
- 0:f6e7c3ad5a58
- Child:
- 1:288ebe73ba81
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DECODER.h Mon May 18 17:08:10 2020 +0000 @@ -0,0 +1,54 @@ +#ifndef DECODER_H +#define DECODER_H + +#define HEX_bm 0x000F +#define MAX_TOKEN_NR 2 +#define MAX_KEYWORD_STRING_LTH 6 +#define MAX_KEYWORD_NR 4 + +typedef enum CompResult +{ DIFFERENT , EQUAL } CompResult; + +typedef enum TokeType +{KEYWORD, NUMBER, EMPTY} TokeType; + +typedef enum Result +{ OK, ERR } Resul; + +typedef enum KeywordCode +{ID, CALLIB, GOTO, STEP} KeywordCode; + +typedef union TokenValue +{ +enum KeywordCode eKeyword; +unsigned int uiNumber; +char *pcString; +} TokenValue; + +typedef struct Token +{ +enum TokeType eType; +union TokenValue uValue; +} Token; + +typedef struct Keyword +{ +enum KeywordCode eCode; +char cString[MAX_KEYWORD_STRING_LTH + 1]; +} Keyword; + +class Decoder +{ + public: + enum Result DecodeMsg(char *pcString); + struct Token asToken[MAX_TOKEN_NR]; + private: + enum CompResult eCompareString(char pcStr1[], char pcStr2[]); + void ReplaceCharactersInString(char pcString[],char cOldChar,char cNewChar); + enum Result eHexStringToUInt(char pcStr[],unsigned int *puiValue); + unsigned char ucFindTokensInString(char *pcString); + enum Result eStringToKeyword (char pcStr[],enum KeywordCode *peKeywordCode); + enum Result DecodeTokens(); +}; + +#endif // DECODER_H