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.
cli_main.cpp
00001 #include "mbed.h" 00002 #include "cli.h" 00003 00004 00005 DigitalOut led(PA_5); 00006 00007 Serial pc(USBTX, USBRX); 00008 00009 fdgh 00010 00011 void serialInterrupt(); 00012 void writeToSerial(); 00013 void clearBuffer(); 00014 void analizis(); 00015 void charAnalizis(); 00016 void start(); 00017 00018 int main() 00019 { 00020 pc.baud(115200); 00021 pc.printf("sajt\n"); 00022 start(); 00023 while(1) 00024 { 00025 pc.attach(&serialInterrupt, Serial::RxIrq); 00026 if(cliFlag == 1) 00027 { 00028 00029 writeToSerial(); 00030 analizis(); 00031 charAnalizis(); 00032 clearBuffer(); 00033 i = 0; 00034 cliFlag = 0; 00035 run = true; 00036 00037 00038 } 00039 while(run) 00040 { 00041 led = !led; 00042 wait(1); 00043 } 00044 } 00045 00046 } 00047 00048 00049 //==================================================================== 00050 //=========================functions================================== 00051 //==================================================================== 00052 void start() 00053 { 00054 pc.printf("\nBeirt szoveg: "); 00055 } 00056 00057 void serialInterrupt() 00058 { 00059 run = false; 00060 while( pc.readable() && ((i + 1) < bufferSize) ) 00061 { 00062 data[i] = pc.getc(); 00063 if ( data[i] == '\n' || data[i] == '\r') 00064 { 00065 cliFlag = 1; 00066 } 00067 else if ( data[i] == 0x08 && i > 0) 00068 { 00069 i--; 00070 pc.putc(0x08); 00071 } 00072 else 00073 { 00074 pc.putc(data[i]); 00075 i++; 00076 } 00077 } 00078 return; 00079 } 00080 00081 00082 00083 void clearBuffer() 00084 { 00085 for ( int k = 0; k < bufferSize; k++) 00086 { 00087 data[k]='\0'; // '\0' 00088 intBuff[k]='\0'; 00089 bigStrBuff[k]='\0'; 00090 smallStrBuff[k]='\0'; 00091 elseBuff[k]='\0'; 00092 intIndex = 0; 00093 bigStrIndex = 0; 00094 smallStrIndex = 0; 00095 elseIndex = 0; 00096 } 00097 } 00098 00099 void writeToSerial() 00100 { 00101 pc.printf("\n"); 00102 for ( j = 0; j < bufferSize; j++) 00103 { 00104 if ( data[j] != '\0') 00105 { 00106 pc.printf("%c", data[j]); 00107 } 00108 } 00109 } 00110 00111 void analizis() 00112 { 00113 pc.printf("\nValasz: "); 00114 if ( data[i-5] == 'h' && data[i-4] == 'e' && data[i-3] == 'l' && data[i-2] == 'l' && data[i-1] == 'o') 00115 { 00116 pc.printf("szia!"); 00117 } 00118 if ( data[i-5] == 'm' && data[i-4] == 'i' && data[i-3] == 'z' && data[i-2] == 'u' && data[i-1] == '?') 00119 { 00120 pc.printf("semmi, veled?"); 00121 } 00122 pc.printf("\n"); 00123 run = true; 00124 } 00125 00126 void charAnalizis() 00127 { 00128 00129 for ( a = 0; a < bufferSize; a++) 00130 { 00131 if ( data[a] > 47 && data[a] < 58 ) 00132 { 00133 intBuff[intIndex] = data[a]; 00134 intIndex++; 00135 } 00136 if ( (data[a] > 64 && data[a] < 91) || (data[a] > 191 && data[a] < 221) ) 00137 { 00138 bigStrBuff[bigStrIndex] = data[a]; 00139 bigStrIndex++; 00140 } 00141 if ( (data[a] > 96 && data[a] < 123) || (data[a] > 223 && data[a] < 255) ) 00142 { 00143 smallStrBuff[smallStrIndex] = data[a]; 00144 smallStrIndex++; 00145 } 00146 if ( (data[a] > 32 && data[a] < 48) || (data[a] > 57 && data[a] < 65) || (data[a] > 90 && data[a] < 97)) 00147 { 00148 elseBuff[elseIndex] = data[a]; 00149 elseIndex++; 00150 } 00151 } 00152 00153 pc.printf("Szamok: "); 00154 for ( b = 0; b < intIndex; b++) 00155 { 00156 pc.printf("%c", intBuff[b]); 00157 } 00158 pc.printf("\n"); 00159 00160 pc.printf("Nagy betuk: "); 00161 for ( b = 0; b < bigStrIndex; b++) 00162 { 00163 pc.printf("%c", bigStrBuff[b]); 00164 } 00165 pc.printf("\n"); 00166 00167 pc.printf("Kis betuk: "); 00168 for ( b = 0; b < smallStrIndex; b++) 00169 { 00170 pc.printf("%c", smallStrBuff[b]); 00171 } 00172 pc.printf("\n"); 00173 00174 pc.printf("Minden mas: "); 00175 for ( b = 0; b < elseIndex; b++) 00176 { 00177 pc.printf("%c", elseBuff[b]); 00178 } 00179 pc.printf("\n\n"); 00180 pc.printf("\nBeirt szoveg: "); 00181 }
Generated on Thu Jul 14 2022 16:20:12 by
1.7.2