AGH UST MBED part 2

Dependencies:   LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI

Committer:
matis755
Date:
Thu May 21 11:03:32 2020 +0000
Revision:
4:e48aee3e8d09
Child:
5:3c19c3ae6286
Ready without GUI;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
matis755 4:e48aee3e8d09 1 #ifndef DECODER
matis755 4:e48aee3e8d09 2 #define DECODER
matis755 4:e48aee3e8d09 3
matis755 4:e48aee3e8d09 4 #include "mbed.h"
matis755 4:e48aee3e8d09 5
matis755 4:e48aee3e8d09 6 #define NULL 0
matis755 4:e48aee3e8d09 7 #define TERMINATOR '\r'
matis755 4:e48aee3e8d09 8 #define DELIMITER_CHAR 0x20
matis755 4:e48aee3e8d09 9
matis755 4:e48aee3e8d09 10 #define HEX_bm 0x000F
matis755 4:e48aee3e8d09 11 #define MAX_TOKEN_NR 2
matis755 4:e48aee3e8d09 12 #define MAX_KEYWORD_STRING_LTH 6
matis755 4:e48aee3e8d09 13 #define MAX_KEYWORD_NR 4
matis755 4:e48aee3e8d09 14
matis755 4:e48aee3e8d09 15
matis755 4:e48aee3e8d09 16 typedef enum TokenType
matis755 4:e48aee3e8d09 17 {KEYWORD, NUMBER, STRING} TokenType;
matis755 4:e48aee3e8d09 18
matis755 4:e48aee3e8d09 19 typedef enum KeywordCode
matis755 4:e48aee3e8d09 20 { ID, CLB, GT, ST } KeywordCode;
matis755 4:e48aee3e8d09 21
matis755 4:e48aee3e8d09 22 typedef union TokenValue
matis755 4:e48aee3e8d09 23 {
matis755 4:e48aee3e8d09 24 enum KeywordCode eKeyword;
matis755 4:e48aee3e8d09 25 unsigned int uiNumber;
matis755 4:e48aee3e8d09 26 char *pcString;
matis755 4:e48aee3e8d09 27 } TokenValue;
matis755 4:e48aee3e8d09 28
matis755 4:e48aee3e8d09 29 typedef struct Token
matis755 4:e48aee3e8d09 30 {
matis755 4:e48aee3e8d09 31 enum TokenType eType;
matis755 4:e48aee3e8d09 32 union TokenValue uValue;
matis755 4:e48aee3e8d09 33 } Token;
matis755 4:e48aee3e8d09 34
matis755 4:e48aee3e8d09 35
matis755 4:e48aee3e8d09 36 typedef struct Keyword
matis755 4:e48aee3e8d09 37 {
matis755 4:e48aee3e8d09 38 enum KeywordCode eCode;
matis755 4:e48aee3e8d09 39 char cString[MAX_KEYWORD_STRING_LTH + 1];
matis755 4:e48aee3e8d09 40 } Keyword;
matis755 4:e48aee3e8d09 41
matis755 4:e48aee3e8d09 42
matis755 4:e48aee3e8d09 43
matis755 4:e48aee3e8d09 44
matis755 4:e48aee3e8d09 45 class Decoder {
matis755 4:e48aee3e8d09 46 private:
matis755 4:e48aee3e8d09 47 struct Token asToken[MAX_TOKEN_NR];
matis755 4:e48aee3e8d09 48 unsigned char ucTokenCnt;
matis755 4:e48aee3e8d09 49 void ReplaceCharactersInString(char pcString[],char cOldChar,char cNewChar);
matis755 4:e48aee3e8d09 50 enum Result eHexStringToUInt(char pcStr[],unsigned int *puiValue);
matis755 4:e48aee3e8d09 51 unsigned char ucFindTokensInString(char *pcString);
matis755 4:e48aee3e8d09 52 enum Result eStringToKeyword (char pcStr[],enum KeywordCode *peKeywordCode);
matis755 4:e48aee3e8d09 53 void DecodeTokens(unsigned char ucTokenCnt);
matis755 4:e48aee3e8d09 54 public:
matis755 4:e48aee3e8d09 55 void DecodeMsg(char *pcString);
matis755 4:e48aee3e8d09 56 enum TokenType eGetTokenType(unsigned char ucIdx);
matis755 4:e48aee3e8d09 57 enum KeywordCode eGetKeyword(unsigned char ucIdx);
matis755 4:e48aee3e8d09 58 unsigned char GetTokenCnt(void);
matis755 4:e48aee3e8d09 59 };
matis755 4:e48aee3e8d09 60
matis755 4:e48aee3e8d09 61
matis755 4:e48aee3e8d09 62 #endif