last version

Dependencies:   LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI

Committer:
bolko
Date:
Tue Jun 09 11:23:48 2020 +0000
Revision:
2:e23243b26a23
Parent:
1:d562d46c33b7
look;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bolko 0:f4c2a4d3c318 1 #include "mbed.h"
bolko 2:e23243b26a23 2 #include "command_decoder.h"
bolko 2:e23243b26a23 3 #include "servo_gui.h"
bolko 2:e23243b26a23 4
bolko 2:e23243b26a23 5 #define CR '\r'
bolko 2:e23243b26a23 6
bolko 2:e23243b26a23 7 Serial MyUART(USBTX, USBRX,9600);
bolko 2:e23243b26a23 8 ServoGui MyServoGui;
bolko 2:e23243b26a23 9 CommandDecoder MyCommandDecoder;
bolko 0:f4c2a4d3c318 10
bolko 2:e23243b26a23 11 uint8_t puts(char *cBufferTransmit, unsigned char ucBufferSize){
bolko 2:e23243b26a23 12 unsigned char ucCharacterCounter;
bolko 2:e23243b26a23 13
bolko 2:e23243b26a23 14 for(ucCharacterCounter = 0; ucCharacterCounter <= ucBufferSize; ucCharacterCounter++){
bolko 2:e23243b26a23 15 if(cBufferTransmit[ucBufferSize] == NULL){
bolko 2:e23243b26a23 16 break;
bolko 2:e23243b26a23 17 }
bolko 2:e23243b26a23 18 }
bolko 2:e23243b26a23 19 if(ucCharacterCounter == ucBufferSize){
bolko 2:e23243b26a23 20 return 1;
bolko 2:e23243b26a23 21 }
bolko 2:e23243b26a23 22
bolko 2:e23243b26a23 23 for(unsigned char ucCharacterCounter = 0; cBufferTransmit[ucCharacterCounter] != NULL; ucCharacterCounter++){
bolko 2:e23243b26a23 24 MyUART.putc(cBufferTransmit[ucCharacterCounter]);
bolko 2:e23243b26a23 25 }
bolko 2:e23243b26a23 26 MyUART.putc(CR);
bolko 2:e23243b26a23 27 return 0;
bolko 2:e23243b26a23 28 }
bolko 0:f4c2a4d3c318 29
bolko 2:e23243b26a23 30 uint8_t gets(char *cBufferReceived, unsigned char ucBufferSize){
bolko 2:e23243b26a23 31 unsigned char ucCharacterCounter = 0;
bolko 2:e23243b26a23 32
bolko 2:e23243b26a23 33 while(ucCharacterCounter < ucBufferSize){
bolko 2:e23243b26a23 34 cBufferReceived[ucCharacterCounter] = MyUART.getc();
bolko 2:e23243b26a23 35 if(cBufferReceived[ucCharacterCounter] == CR){
bolko 2:e23243b26a23 36 cBufferReceived[ucCharacterCounter] = NULL;
bolko 2:e23243b26a23 37 return 0;
bolko 2:e23243b26a23 38 }
bolko 2:e23243b26a23 39 ucCharacterCounter++;
bolko 2:e23243b26a23 40 }
bolko 2:e23243b26a23 41 return 1;
bolko 2:e23243b26a23 42 }
bolko 2:e23243b26a23 43
bolko 2:e23243b26a23 44 void TokenHandling(){
bolko 2:e23243b26a23 45 char cID[] = "id_0x777";
bolko 2:e23243b26a23 46 char cUnkownCommand[] = "unknowncommand";
bolko 2:e23243b26a23 47 char cOK[] = "ok";
bolko 2:e23243b26a23 48
bolko 2:e23243b26a23 49 if((MyCommandDecoder.ucTokenNr>0) && (MyCommandDecoder.asToken[0].eType == KEYWORD)){
bolko 2:e23243b26a23 50 switch(MyCommandDecoder.asToken[0].uValue.eKeyword){
bolko 2:e23243b26a23 51 case ID:
bolko 2:e23243b26a23 52 puts(cID);
bolko 1:d562d46c33b7 53 break;
bolko 2:e23243b26a23 54 case CALLIB:
bolko 2:e23243b26a23 55 MyServoGui.ServoCallib();
bolko 2:e23243b26a23 56 puts(cOK);
bolko 2:e23243b26a23 57 break;
bolko 2:e23243b26a23 58 case GOTO:
bolko 2:e23243b26a23 59 if(MyCommandDecoder.asToken[1].eType == NUMBER){
bolko 2:e23243b26a23 60 MyServoGui.ServoGoTo(MyCommandDecoder.asToken[1].uValue.uiNumber);
bolko 2:e23243b26a23 61 MyServoGui.sServo.uiPreviousPosition = MyCommandDecoder.asToken[1].uValue.uiNumber;
bolko 2:e23243b26a23 62 puts(cOK);
bolko 2:e23243b26a23 63 }
bolko 2:e23243b26a23 64 else{
bolko 2:e23243b26a23 65 puts(cUnkownCommand);
bolko 2:e23243b26a23 66 }
bolko 1:d562d46c33b7 67 break;
bolko 2:e23243b26a23 68 case STEP:
bolko 2:e23243b26a23 69 if(MyCommandDecoder.asToken[1].eType == NUMBER){
bolko 2:e23243b26a23 70 MyServoGui.ServoGoTo(MyServoGui.sServo.uiPreviousPosition + MyCommandDecoder.asToken[1].uValue.uiNumber);
bolko 2:e23243b26a23 71 MyServoGui.sServo.uiPreviousPosition = MyServoGui.sServo.uiPreviousPosition + MyCommandDecoder.asToken[1].uValue.uiNumber;
bolko 2:e23243b26a23 72 puts(cOK);
bolko 2:e23243b26a23 73 }
bolko 2:e23243b26a23 74 else{
bolko 2:e23243b26a23 75 puts(cUnkownCommand);
bolko 2:e23243b26a23 76 }
bolko 2:e23243b26a23 77 break;
bolko 1:d562d46c33b7 78 default:
bolko 2:e23243b26a23 79 puts(cUnkownCommand);
bolko 2:e23243b26a23 80 break;
bolko 1:d562d46c33b7 81 }
bolko 2:e23243b26a23 82 }
bolko 2:e23243b26a23 83 else {
bolko 2:e23243b26a23 84 puts(cUnkownCommand,sizeof(cUnkownCommand));
bolko 2:e23243b26a23 85 }
bolko 2:e23243b26a23 86 }
bolko 2:e23243b26a23 87
bolko 2:e23243b26a23 88 int main(){
bolko 2:e23243b26a23 89 char cUnkownCommand[] = "unkowncommand";
bolko 2:e23243b26a23 90 char cBufferReceived[10];
bolko 2:e23243b26a23 91
bolko 2:e23243b26a23 92 while(1){
bolko 2:e23243b26a23 93
bolko 2:e23243b26a23 94 if(gets(cBufferReceived,sizeof(cBufferReceived)) == 0){
bolko 2:e23243b26a23 95 MyCommandDecoder.DecodeMsg(cBufferReceived);
bolko 2:e23243b26a23 96 TokenHandling();
bolko 2:e23243b26a23 97
bolko 2:e23243b26a23 98 }
bolko 2:e23243b26a23 99 else{
bolko 2:e23243b26a23 100 puts(cUnkownCommand,sizeof(cUnkownCommand));
bolko 2:e23243b26a23 101 }
bolko 2:e23243b26a23 102
bolko 2:e23243b26a23 103 }
bolko 0:f4c2a4d3c318 104 }
bolko 0:f4c2a4d3c318 105
bolko 2:e23243b26a23 106