Attila Fazekas
/
cli
published command line interface
Revision 0:fe9e3f3e16e2, committed 2022-05-27
- Comitter:
- attila0970
- Date:
- Fri May 27 10:11:19 2022 +0000
- Commit message:
- asd
Changed in this revision
diff -r 000000000000 -r fe9e3f3e16e2 cli.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cli.h Fri May 27 10:11:19 2022 +0000 @@ -0,0 +1,31 @@ +#include "mbed.h" + + +#define bufferSize 32 + +//global variables +bool run = true; +int i = 0; +int j = 0; +int a = 0; +int b = 0; +int cliFlag = 0; + +int intIndex = 0; +int bigStrIndex = 0; +int smallStrIndex = 0; +int elseIndex = 0; +unsigned char data[bufferSize]; +unsigned char intBuff[bufferSize]; +unsigned char bigStrBuff[bufferSize]; +unsigned char smallStrBuff[bufferSize]; +unsigned char elseBuff[bufferSize]; + + + + + + + + +
diff -r 000000000000 -r fe9e3f3e16e2 cli_main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cli_main.cpp Fri May 27 10:11:19 2022 +0000 @@ -0,0 +1,181 @@ +#include "mbed.h" +#include "cli.h" + + +DigitalOut led(PA_5); + +Serial pc(USBTX, USBRX); + +fdgh + +void serialInterrupt(); +void writeToSerial(); +void clearBuffer(); +void analizis(); +void charAnalizis(); +void start(); + +int main() +{ + pc.baud(115200); + pc.printf("sajt\n"); + start(); + while(1) + { + pc.attach(&serialInterrupt, Serial::RxIrq); + if(cliFlag == 1) + { + + writeToSerial(); + analizis(); + charAnalizis(); + clearBuffer(); + i = 0; + cliFlag = 0; + run = true; + + + } + while(run) + { + led = !led; + wait(1); + } + } + +} + + +//==================================================================== +//=========================functions================================== +//==================================================================== +void start() +{ + pc.printf("\nBeirt szoveg: "); +} + +void serialInterrupt() +{ + run = false; + while( pc.readable() && ((i + 1) < bufferSize) ) + { + data[i] = pc.getc(); + if ( data[i] == '\n' || data[i] == '\r') + { + cliFlag = 1; + } + else if ( data[i] == 0x08 && i > 0) + { + i--; + pc.putc(0x08); + } + else + { + pc.putc(data[i]); + i++; + } + } + return; +} + + + +void clearBuffer() +{ + for ( int k = 0; k < bufferSize; k++) + { + data[k]='\0'; // '\0' + intBuff[k]='\0'; + bigStrBuff[k]='\0'; + smallStrBuff[k]='\0'; + elseBuff[k]='\0'; + intIndex = 0; + bigStrIndex = 0; + smallStrIndex = 0; + elseIndex = 0; + } +} + +void writeToSerial() +{ + pc.printf("\n"); + for ( j = 0; j < bufferSize; j++) + { + if ( data[j] != '\0') + { + pc.printf("%c", data[j]); + } + } +} + +void analizis() +{ + pc.printf("\nValasz: "); + if ( data[i-5] == 'h' && data[i-4] == 'e' && data[i-3] == 'l' && data[i-2] == 'l' && data[i-1] == 'o') + { + pc.printf("szia!"); + } + if ( data[i-5] == 'm' && data[i-4] == 'i' && data[i-3] == 'z' && data[i-2] == 'u' && data[i-1] == '?') + { + pc.printf("semmi, veled?"); + } + pc.printf("\n"); + run = true; +} + +void charAnalizis() +{ + + for ( a = 0; a < bufferSize; a++) + { + if ( data[a] > 47 && data[a] < 58 ) + { + intBuff[intIndex] = data[a]; + intIndex++; + } + if ( (data[a] > 64 && data[a] < 91) || (data[a] > 191 && data[a] < 221) ) + { + bigStrBuff[bigStrIndex] = data[a]; + bigStrIndex++; + } + if ( (data[a] > 96 && data[a] < 123) || (data[a] > 223 && data[a] < 255) ) + { + smallStrBuff[smallStrIndex] = data[a]; + smallStrIndex++; + } + if ( (data[a] > 32 && data[a] < 48) || (data[a] > 57 && data[a] < 65) || (data[a] > 90 && data[a] < 97)) + { + elseBuff[elseIndex] = data[a]; + elseIndex++; + } + } + + pc.printf("Szamok: "); + for ( b = 0; b < intIndex; b++) + { + pc.printf("%c", intBuff[b]); + } + pc.printf("\n"); + + pc.printf("Nagy betuk: "); + for ( b = 0; b < bigStrIndex; b++) + { + pc.printf("%c", bigStrBuff[b]); + } + pc.printf("\n"); + + pc.printf("Kis betuk: "); + for ( b = 0; b < smallStrIndex; b++) + { + pc.printf("%c", smallStrBuff[b]); + } + pc.printf("\n"); + + pc.printf("Minden mas: "); + for ( b = 0; b < elseIndex; b++) + { + pc.printf("%c", elseBuff[b]); + } + pc.printf("\n\n"); + pc.printf("\nBeirt szoveg: "); +}
diff -r 000000000000 -r fe9e3f3e16e2 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri May 27 10:11:19 2022 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/aa5281ff4a02 \ No newline at end of file