Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI
string.h@3:6fc7976cc5bf, 2020-05-20 (annotated)
- Committer:
- matis755
- Date:
- Wed May 20 16:37:25 2020 +0000
- Revision:
- 3:6fc7976cc5bf
- Parent:
- 2:8788d711db7e
Create class for decoding strings
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| matis755 | 3:6fc7976cc5bf | 1 | #include "mbed.h" |
| matis755 | 3:6fc7976cc5bf | 2 | |
| matis755 | 2:8788d711db7e | 3 | #define NULL 0 |
| matis755 | 2:8788d711db7e | 4 | #define TERMINATOR '\r' |
| matis755 | 2:8788d711db7e | 5 | #define DELIMITER_CHAR 0x20 |
| matis755 | 2:8788d711db7e | 6 | |
| matis755 | 2:8788d711db7e | 7 | #define HEX_bm 0x000F |
| matis755 | 2:8788d711db7e | 8 | #define MAX_TOKEN_NR 2 |
| matis755 | 2:8788d711db7e | 9 | #define MAX_KEYWORD_STRING_LTH 6 |
| matis755 | 2:8788d711db7e | 10 | #define MAX_KEYWORD_NR 2 |
| matis755 | 2:8788d711db7e | 11 | |
| matis755 | 2:8788d711db7e | 12 | |
| matis755 | 2:8788d711db7e | 13 | typedef enum TokenType |
| matis755 | 2:8788d711db7e | 14 | {KEYWORD, NUMBER, STRING} TokenType; |
| matis755 | 2:8788d711db7e | 15 | |
| matis755 | 2:8788d711db7e | 16 | typedef enum KeywordCode |
| matis755 | 2:8788d711db7e | 17 | { CLB, GT} KeywordCode; |
| matis755 | 2:8788d711db7e | 18 | |
| matis755 | 2:8788d711db7e | 19 | typedef union TokenValue |
| matis755 | 2:8788d711db7e | 20 | { |
| matis755 | 2:8788d711db7e | 21 | enum KeywordCode eKeyword; |
| matis755 | 2:8788d711db7e | 22 | unsigned int uiNumber; |
| matis755 | 2:8788d711db7e | 23 | char *pcString; |
| matis755 | 2:8788d711db7e | 24 | } TokenValue; |
| matis755 | 2:8788d711db7e | 25 | |
| matis755 | 2:8788d711db7e | 26 | typedef struct Token |
| matis755 | 2:8788d711db7e | 27 | { |
| matis755 | 2:8788d711db7e | 28 | enum TokenType eType; |
| matis755 | 2:8788d711db7e | 29 | union TokenValue uValue; |
| matis755 | 2:8788d711db7e | 30 | } Token; |
| matis755 | 2:8788d711db7e | 31 | |
| matis755 | 2:8788d711db7e | 32 | |
| matis755 | 2:8788d711db7e | 33 | typedef struct Keyword |
| matis755 | 2:8788d711db7e | 34 | { |
| matis755 | 2:8788d711db7e | 35 | enum KeywordCode eCode; |
| matis755 | 2:8788d711db7e | 36 | char cString[MAX_KEYWORD_STRING_LTH + 1]; |
| matis755 | 2:8788d711db7e | 37 | } Keyword; |
| matis755 | 2:8788d711db7e | 38 | |
| matis755 | 2:8788d711db7e | 39 | |
| matis755 | 3:6fc7976cc5bf | 40 | |
| matis755 | 3:6fc7976cc5bf | 41 | |
| matis755 | 3:6fc7976cc5bf | 42 | class Tokenizer { |
| matis755 | 3:6fc7976cc5bf | 43 | private: |
| matis755 | 3:6fc7976cc5bf | 44 | struct Token asToken[MAX_TOKEN_NR]; |
| matis755 | 3:6fc7976cc5bf | 45 | unsigned char ucTokenCnt; |
| matis755 | 3:6fc7976cc5bf | 46 | void ReplaceCharactersInString(char pcString[],char cOldChar,char cNewChar); |
| matis755 | 3:6fc7976cc5bf | 47 | enum Result eHexStringToUInt(char pcStr[],unsigned int *puiValue); |
| matis755 | 3:6fc7976cc5bf | 48 | unsigned char ucFindTokensInString(char *pcString); |
| matis755 | 3:6fc7976cc5bf | 49 | enum Result eStringToKeyword (char pcStr[],enum KeywordCode *peKeywordCode); |
| matis755 | 3:6fc7976cc5bf | 50 | void DecodeTokens(unsigned char ucTokenCnt); |
| matis755 | 3:6fc7976cc5bf | 51 | public: |
| matis755 | 3:6fc7976cc5bf | 52 | void DecodeMsg(char *pcString); |
| matis755 | 3:6fc7976cc5bf | 53 | enum TokenType eGetTokenType(unsigned char ucIdx); |
| matis755 | 3:6fc7976cc5bf | 54 | enum KeywordCode eGetKeyword(unsigned char ucIdx); |
| matis755 | 3:6fc7976cc5bf | 55 | unsigned char GetTokenCnt(void); |
| matis755 | 3:6fc7976cc5bf | 56 | }; |
| matis755 | 3:6fc7976cc5bf | 57 | |
| matis755 | 3:6fc7976cc5bf | 58 | |
| matis755 | 3:6fc7976cc5bf | 59 | |
| matis755 | 3:6fc7976cc5bf | 60 |