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.
command_decoder.cpp
00001 #include "string.h" 00002 #include "command_decoder.h" 00003 00004 struct Keyword asKeywordList[MAX_KEYWORD_NR]= 00005 { 00006 {CALLIB, "callib"}, 00007 {GOTO, "goto"}, 00008 {STEP, "step"}, 00009 {ID, "id"} 00010 }; 00011 struct Token asToken[MAX_TOKEN_NR]; 00012 00013 unsigned char ucTokenNr; 00014 00015 unsigned char ucFindTokensInString(char *pcString){ 00016 00017 enum LedState { TOKEN, DELIMITER}; 00018 enum LedState eState = DELIMITER; 00019 00020 unsigned char ucLicznikTokenu = 0; 00021 unsigned char ucLicznikZnaku = 0; 00022 char cAktualnyZnak; 00023 00024 for(ucLicznikZnaku=0; pcString[ucLicznikZnaku] != NULL; ucLicznikZnaku++){ 00025 cAktualnyZnak = pcString[ucLicznikZnaku]; 00026 switch(eState){ 00027 case DELIMITER: 00028 if(cAktualnyZnak == DELIMITER_CHAR){ 00029 eState = DELIMITER; 00030 }else if(ucLicznikTokenu < MAX_TOKEN_NR){ 00031 eState = TOKEN; 00032 asToken[ucLicznikTokenu].uValue.pcString = pcString + ucLicznikZnaku; 00033 ucLicznikTokenu++; 00034 }else{ 00035 return(ucLicznikTokenu); 00036 } 00037 break; 00038 case TOKEN: 00039 if(cAktualnyZnak!= DELIMITER_CHAR){ 00040 eState = TOKEN; 00041 }else{ 00042 eState = DELIMITER; 00043 } 00044 break; 00045 } 00046 } 00047 return(ucLicznikTokenu); 00048 } 00049 00050 enum Result eStringToKeyword(char pcStr[], enum KeywordCode *peKeywordCode){ 00051 00052 unsigned char ucKeywordIndex; 00053 00054 for(ucKeywordIndex=0; ucKeywordIndex < MAX_KEYWORD_NR; ucKeywordIndex++){ 00055 if(eCompareString(pcStr, asKeywordList[ucKeywordIndex].cString) == EQUAL){ 00056 *peKeywordCode = asKeywordList[ucKeywordIndex].eCode; 00057 return(OK); 00058 } 00059 } 00060 return(ERROR); 00061 } 00062 00063 void DecodeTokens(void){ 00064 00065 unsigned int uiNumber; 00066 unsigned char ucTokenIndex; 00067 enum KeywordCode eKeyword; 00068 00069 for(ucTokenIndex=0; ucTokenIndex < ucTokenNr; ucTokenIndex++){ 00070 if((eStringToKeyword (asToken[ucTokenIndex].uValue.pcString, &eKeyword))== OK){ 00071 asToken[ucTokenIndex].eType = KEYWORD; 00072 asToken[ucTokenIndex].uValue.eKeyword=eKeyword; 00073 }else if((eHexStringToUInt(asToken[ucTokenIndex].uValue.pcString,&uiNumber))== OK){ 00074 asToken[ucTokenIndex].eType = NUMBER; 00075 asToken[ucTokenIndex].uValue.uiNumber = uiNumber; 00076 }else{ 00077 asToken[ucTokenIndex].eType = STRING; 00078 } 00079 } 00080 } 00081 00082 void DecodeMsg(char *pcString){ 00083 00084 ucTokenNr = ucFindTokensInString (pcString); 00085 ReplaceCharactersInString(pcString,' ',NULL); 00086 DecodeTokens(); 00087 }
Generated on Tue Aug 16 2022 02:15:48 by
 1.7.2