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.
handler.cpp
00001 #include "handler.h" 00002 #include "com.h" 00003 00004 00005 00006 Handler::Handler(char *nm) { 00007 name = nm; 00008 init(); 00009 stringState=NOTREADY; 00010 } 00011 00012 00013 void Handler::init() { 00014 #ifdef DEBUGHAND 00015 com.printf("INIT HANDLER\r\n"); 00016 #endif 00017 state = WAITINGON_S; 00018 resetMatch(); 00019 } 00020 00021 void Handler::resetMatch() { 00022 #ifdef DEBUGHAND 00023 com.printf("RESET MATCH STRING\r\n"); 00024 #endif 00025 matchString[0]='\0'; 00026 pmatchString = matchString; 00027 } 00028 00029 00030 void Handler::run() { 00031 int c; 00032 if (!com.readable()) { 00033 return; 00034 } 00035 c = com.getc(); 00036 00037 #ifdef DEBUGHAND 00038 com.printf("READ CHAR, %c\r\n", c); 00039 #endif 00040 00041 switch (state) { 00042 case WAITINGON_S: 00043 recievedStart(c); 00044 break; 00045 case RECIEVING_MATCH: 00046 processChar(c); 00047 break; 00048 default: 00049 //should not get here 00050 hostError(); 00051 break; 00052 00053 } 00054 } 00055 00056 void Handler::processChar(char c) { 00057 switch (c) { 00058 case ONECHR: 00059 case ZEROCHR: 00060 recieveMatchString(c); 00061 #ifdef DEBUGHAND 00062 com.printf("REC 1 or 0\r\n"); 00063 #endif 00064 break; 00065 case '\r': 00066 case ' ': 00067 case '\n': 00068 //do nothing 00069 break; 00070 case ENDCHAR: 00071 #ifdef DEBUGHAND 00072 com.printf("REC E\r\n"); 00073 #endif 00074 matchStringRecieved(); 00075 break; 00076 default: 00077 hostError(); 00078 } 00079 } 00080 00081 00082 void Handler::hostError() { 00083 com.printf(HOSTERROR); 00084 init(); 00085 } 00086 00087 void Handler::recieveMatchString(char c) { 00088 *pmatchString = c; 00089 pmatchString++; 00090 } 00091 00092 void Handler::recievedStart(char c) { 00093 if (c==STARTCHAR) { 00094 #ifdef DEBUGHAND 00095 com.printf("REC S\r\n"); 00096 #endif 00097 state = RECIEVING_MATCH; 00098 stringState = NOTREADY; 00099 resetMatch(); 00100 } 00101 } 00102 00103 void Handler::matchStringRecieved() { 00104 #ifdef DEBUGHAND 00105 com.printf("COMPLETE\r\n"); 00106 #endif 00107 *pmatchString=NULL; 00108 strcpy(completeMatchString, matchString); 00109 com.printf("ARMED-%s\r\n",matchString); 00110 init(); 00111 stringState=READY; 00112 } 00113 00114 00115 00116 bool Handler::isReady() { 00117 if (stringState==READY) { 00118 return true; 00119 } else { 00120 return false; 00121 } 00122 } 00123 00124 char *Handler::getMatchString() { 00125 return completeMatchString; 00126 }
Generated on Wed Jul 13 2022 17:38:20 by
1.7.2