published command line interface

Dependencies:   mbed

Committer:
attila0970
Date:
Fri May 27 10:11:19 2022 +0000
Revision:
0:fe9e3f3e16e2
asd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
attila0970 0:fe9e3f3e16e2 1 #include "mbed.h"
attila0970 0:fe9e3f3e16e2 2 #include "cli.h"
attila0970 0:fe9e3f3e16e2 3
attila0970 0:fe9e3f3e16e2 4
attila0970 0:fe9e3f3e16e2 5 DigitalOut led(PA_5);
attila0970 0:fe9e3f3e16e2 6
attila0970 0:fe9e3f3e16e2 7 Serial pc(USBTX, USBRX);
attila0970 0:fe9e3f3e16e2 8
attila0970 0:fe9e3f3e16e2 9 fdgh
attila0970 0:fe9e3f3e16e2 10
attila0970 0:fe9e3f3e16e2 11 void serialInterrupt();
attila0970 0:fe9e3f3e16e2 12 void writeToSerial();
attila0970 0:fe9e3f3e16e2 13 void clearBuffer();
attila0970 0:fe9e3f3e16e2 14 void analizis();
attila0970 0:fe9e3f3e16e2 15 void charAnalizis();
attila0970 0:fe9e3f3e16e2 16 void start();
attila0970 0:fe9e3f3e16e2 17
attila0970 0:fe9e3f3e16e2 18 int main()
attila0970 0:fe9e3f3e16e2 19 {
attila0970 0:fe9e3f3e16e2 20 pc.baud(115200);
attila0970 0:fe9e3f3e16e2 21 pc.printf("sajt\n");
attila0970 0:fe9e3f3e16e2 22 start();
attila0970 0:fe9e3f3e16e2 23 while(1)
attila0970 0:fe9e3f3e16e2 24 {
attila0970 0:fe9e3f3e16e2 25 pc.attach(&serialInterrupt, Serial::RxIrq);
attila0970 0:fe9e3f3e16e2 26 if(cliFlag == 1)
attila0970 0:fe9e3f3e16e2 27 {
attila0970 0:fe9e3f3e16e2 28
attila0970 0:fe9e3f3e16e2 29 writeToSerial();
attila0970 0:fe9e3f3e16e2 30 analizis();
attila0970 0:fe9e3f3e16e2 31 charAnalizis();
attila0970 0:fe9e3f3e16e2 32 clearBuffer();
attila0970 0:fe9e3f3e16e2 33 i = 0;
attila0970 0:fe9e3f3e16e2 34 cliFlag = 0;
attila0970 0:fe9e3f3e16e2 35 run = true;
attila0970 0:fe9e3f3e16e2 36
attila0970 0:fe9e3f3e16e2 37
attila0970 0:fe9e3f3e16e2 38 }
attila0970 0:fe9e3f3e16e2 39 while(run)
attila0970 0:fe9e3f3e16e2 40 {
attila0970 0:fe9e3f3e16e2 41 led = !led;
attila0970 0:fe9e3f3e16e2 42 wait(1);
attila0970 0:fe9e3f3e16e2 43 }
attila0970 0:fe9e3f3e16e2 44 }
attila0970 0:fe9e3f3e16e2 45
attila0970 0:fe9e3f3e16e2 46 }
attila0970 0:fe9e3f3e16e2 47
attila0970 0:fe9e3f3e16e2 48
attila0970 0:fe9e3f3e16e2 49 //====================================================================
attila0970 0:fe9e3f3e16e2 50 //=========================functions==================================
attila0970 0:fe9e3f3e16e2 51 //====================================================================
attila0970 0:fe9e3f3e16e2 52 void start()
attila0970 0:fe9e3f3e16e2 53 {
attila0970 0:fe9e3f3e16e2 54 pc.printf("\nBeirt szoveg: ");
attila0970 0:fe9e3f3e16e2 55 }
attila0970 0:fe9e3f3e16e2 56
attila0970 0:fe9e3f3e16e2 57 void serialInterrupt()
attila0970 0:fe9e3f3e16e2 58 {
attila0970 0:fe9e3f3e16e2 59 run = false;
attila0970 0:fe9e3f3e16e2 60 while( pc.readable() && ((i + 1) < bufferSize) )
attila0970 0:fe9e3f3e16e2 61 {
attila0970 0:fe9e3f3e16e2 62 data[i] = pc.getc();
attila0970 0:fe9e3f3e16e2 63 if ( data[i] == '\n' || data[i] == '\r')
attila0970 0:fe9e3f3e16e2 64 {
attila0970 0:fe9e3f3e16e2 65 cliFlag = 1;
attila0970 0:fe9e3f3e16e2 66 }
attila0970 0:fe9e3f3e16e2 67 else if ( data[i] == 0x08 && i > 0)
attila0970 0:fe9e3f3e16e2 68 {
attila0970 0:fe9e3f3e16e2 69 i--;
attila0970 0:fe9e3f3e16e2 70 pc.putc(0x08);
attila0970 0:fe9e3f3e16e2 71 }
attila0970 0:fe9e3f3e16e2 72 else
attila0970 0:fe9e3f3e16e2 73 {
attila0970 0:fe9e3f3e16e2 74 pc.putc(data[i]);
attila0970 0:fe9e3f3e16e2 75 i++;
attila0970 0:fe9e3f3e16e2 76 }
attila0970 0:fe9e3f3e16e2 77 }
attila0970 0:fe9e3f3e16e2 78 return;
attila0970 0:fe9e3f3e16e2 79 }
attila0970 0:fe9e3f3e16e2 80
attila0970 0:fe9e3f3e16e2 81
attila0970 0:fe9e3f3e16e2 82
attila0970 0:fe9e3f3e16e2 83 void clearBuffer()
attila0970 0:fe9e3f3e16e2 84 {
attila0970 0:fe9e3f3e16e2 85 for ( int k = 0; k < bufferSize; k++)
attila0970 0:fe9e3f3e16e2 86 {
attila0970 0:fe9e3f3e16e2 87 data[k]='\0'; // '\0'
attila0970 0:fe9e3f3e16e2 88 intBuff[k]='\0';
attila0970 0:fe9e3f3e16e2 89 bigStrBuff[k]='\0';
attila0970 0:fe9e3f3e16e2 90 smallStrBuff[k]='\0';
attila0970 0:fe9e3f3e16e2 91 elseBuff[k]='\0';
attila0970 0:fe9e3f3e16e2 92 intIndex = 0;
attila0970 0:fe9e3f3e16e2 93 bigStrIndex = 0;
attila0970 0:fe9e3f3e16e2 94 smallStrIndex = 0;
attila0970 0:fe9e3f3e16e2 95 elseIndex = 0;
attila0970 0:fe9e3f3e16e2 96 }
attila0970 0:fe9e3f3e16e2 97 }
attila0970 0:fe9e3f3e16e2 98
attila0970 0:fe9e3f3e16e2 99 void writeToSerial()
attila0970 0:fe9e3f3e16e2 100 {
attila0970 0:fe9e3f3e16e2 101 pc.printf("\n");
attila0970 0:fe9e3f3e16e2 102 for ( j = 0; j < bufferSize; j++)
attila0970 0:fe9e3f3e16e2 103 {
attila0970 0:fe9e3f3e16e2 104 if ( data[j] != '\0')
attila0970 0:fe9e3f3e16e2 105 {
attila0970 0:fe9e3f3e16e2 106 pc.printf("%c", data[j]);
attila0970 0:fe9e3f3e16e2 107 }
attila0970 0:fe9e3f3e16e2 108 }
attila0970 0:fe9e3f3e16e2 109 }
attila0970 0:fe9e3f3e16e2 110
attila0970 0:fe9e3f3e16e2 111 void analizis()
attila0970 0:fe9e3f3e16e2 112 {
attila0970 0:fe9e3f3e16e2 113 pc.printf("\nValasz: ");
attila0970 0:fe9e3f3e16e2 114 if ( data[i-5] == 'h' && data[i-4] == 'e' && data[i-3] == 'l' && data[i-2] == 'l' && data[i-1] == 'o')
attila0970 0:fe9e3f3e16e2 115 {
attila0970 0:fe9e3f3e16e2 116 pc.printf("szia!");
attila0970 0:fe9e3f3e16e2 117 }
attila0970 0:fe9e3f3e16e2 118 if ( data[i-5] == 'm' && data[i-4] == 'i' && data[i-3] == 'z' && data[i-2] == 'u' && data[i-1] == '?')
attila0970 0:fe9e3f3e16e2 119 {
attila0970 0:fe9e3f3e16e2 120 pc.printf("semmi, veled?");
attila0970 0:fe9e3f3e16e2 121 }
attila0970 0:fe9e3f3e16e2 122 pc.printf("\n");
attila0970 0:fe9e3f3e16e2 123 run = true;
attila0970 0:fe9e3f3e16e2 124 }
attila0970 0:fe9e3f3e16e2 125
attila0970 0:fe9e3f3e16e2 126 void charAnalizis()
attila0970 0:fe9e3f3e16e2 127 {
attila0970 0:fe9e3f3e16e2 128
attila0970 0:fe9e3f3e16e2 129 for ( a = 0; a < bufferSize; a++)
attila0970 0:fe9e3f3e16e2 130 {
attila0970 0:fe9e3f3e16e2 131 if ( data[a] > 47 && data[a] < 58 )
attila0970 0:fe9e3f3e16e2 132 {
attila0970 0:fe9e3f3e16e2 133 intBuff[intIndex] = data[a];
attila0970 0:fe9e3f3e16e2 134 intIndex++;
attila0970 0:fe9e3f3e16e2 135 }
attila0970 0:fe9e3f3e16e2 136 if ( (data[a] > 64 && data[a] < 91) || (data[a] > 191 && data[a] < 221) )
attila0970 0:fe9e3f3e16e2 137 {
attila0970 0:fe9e3f3e16e2 138 bigStrBuff[bigStrIndex] = data[a];
attila0970 0:fe9e3f3e16e2 139 bigStrIndex++;
attila0970 0:fe9e3f3e16e2 140 }
attila0970 0:fe9e3f3e16e2 141 if ( (data[a] > 96 && data[a] < 123) || (data[a] > 223 && data[a] < 255) )
attila0970 0:fe9e3f3e16e2 142 {
attila0970 0:fe9e3f3e16e2 143 smallStrBuff[smallStrIndex] = data[a];
attila0970 0:fe9e3f3e16e2 144 smallStrIndex++;
attila0970 0:fe9e3f3e16e2 145 }
attila0970 0:fe9e3f3e16e2 146 if ( (data[a] > 32 && data[a] < 48) || (data[a] > 57 && data[a] < 65) || (data[a] > 90 && data[a] < 97))
attila0970 0:fe9e3f3e16e2 147 {
attila0970 0:fe9e3f3e16e2 148 elseBuff[elseIndex] = data[a];
attila0970 0:fe9e3f3e16e2 149 elseIndex++;
attila0970 0:fe9e3f3e16e2 150 }
attila0970 0:fe9e3f3e16e2 151 }
attila0970 0:fe9e3f3e16e2 152
attila0970 0:fe9e3f3e16e2 153 pc.printf("Szamok: ");
attila0970 0:fe9e3f3e16e2 154 for ( b = 0; b < intIndex; b++)
attila0970 0:fe9e3f3e16e2 155 {
attila0970 0:fe9e3f3e16e2 156 pc.printf("%c", intBuff[b]);
attila0970 0:fe9e3f3e16e2 157 }
attila0970 0:fe9e3f3e16e2 158 pc.printf("\n");
attila0970 0:fe9e3f3e16e2 159
attila0970 0:fe9e3f3e16e2 160 pc.printf("Nagy betuk: ");
attila0970 0:fe9e3f3e16e2 161 for ( b = 0; b < bigStrIndex; b++)
attila0970 0:fe9e3f3e16e2 162 {
attila0970 0:fe9e3f3e16e2 163 pc.printf("%c", bigStrBuff[b]);
attila0970 0:fe9e3f3e16e2 164 }
attila0970 0:fe9e3f3e16e2 165 pc.printf("\n");
attila0970 0:fe9e3f3e16e2 166
attila0970 0:fe9e3f3e16e2 167 pc.printf("Kis betuk: ");
attila0970 0:fe9e3f3e16e2 168 for ( b = 0; b < smallStrIndex; b++)
attila0970 0:fe9e3f3e16e2 169 {
attila0970 0:fe9e3f3e16e2 170 pc.printf("%c", smallStrBuff[b]);
attila0970 0:fe9e3f3e16e2 171 }
attila0970 0:fe9e3f3e16e2 172 pc.printf("\n");
attila0970 0:fe9e3f3e16e2 173
attila0970 0:fe9e3f3e16e2 174 pc.printf("Minden mas: ");
attila0970 0:fe9e3f3e16e2 175 for ( b = 0; b < elseIndex; b++)
attila0970 0:fe9e3f3e16e2 176 {
attila0970 0:fe9e3f3e16e2 177 pc.printf("%c", elseBuff[b]);
attila0970 0:fe9e3f3e16e2 178 }
attila0970 0:fe9e3f3e16e2 179 pc.printf("\n\n");
attila0970 0:fe9e3f3e16e2 180 pc.printf("\nBeirt szoveg: ");
attila0970 0:fe9e3f3e16e2 181 }