AGH UST MBED part 2

Dependencies:   LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI

Revision:
4:e48aee3e8d09
Parent:
3:6fc7976cc5bf
Child:
5:3c19c3ae6286
--- a/main.cpp	Wed May 20 16:37:25 2020 +0000
+++ b/main.cpp	Thu May 21 11:03:32 2020 +0000
@@ -1,65 +1,52 @@
 #include "mbed.h"
-#include "string.h"
+#include "decoder.h"
+#include "uart.h"
+#include "stepper.h"
 
-#define BUFFER_SIZE 100
 
-Serial MySerial(USBTX, USBRX);
 DigitalOut led_green(LED1);
 DigitalOut led_red(LED2);
 
-char gets(char *pStr, unsigned char ucSize){
-    unsigned char ucStrPtr = 0;
-    while(ucStrPtr < ucSize) {
-        pStr[ucStrPtr] = MySerial.getc();
-        if(pStr[ucStrPtr] == '\r') {
-            pStr[ucStrPtr] = NULL;
-            return 0;
-        }
-        ucStrPtr ++;    
-    }
-    return 1;
-}
-
-char puts(char *pStr, unsigned char ucSize){   
-    unsigned char ucNullPtr;
-    for(ucNullPtr = 0; ucNullPtr <= ucSize; ucNullPtr++){
-        if(pStr[ucNullPtr] == NULL) {
-            break;
-        }
-        else {}
-    }
-    if (ucNullPtr == ucSize) {
-        return 1;
-    }
-
-    for(unsigned char ucIdx = 0; ucIdx < ucNullPtr; ucIdx ++) {
-        MySerial.putc(pStr[ucIdx]);
-    }
-    MySerial.putc('\r');
-    return 0;
-}
-
 
 int main() {
-    Tokenizer MyTokenizer;
+    Decoder MyDecoder;
+    Uart MyUart;
+    Stepper MyStepper;
+    
     char cTablica[BUFFER_SIZE];
-
+    char cCorrectResponse[] = "ok\n";
+    char cUnknownKeyword[] = "unknowncommand\n";
+    char cIdentifier[] = "id anyidentyfier\n";
    
     while(1){
-        if(!gets(cTablica, BUFFER_SIZE)){        
-            MyTokenizer.DecodeMsg(cTablica);
-            if ((MyTokenizer.eGetTokenType(0) == KEYWORD) & (MyTokenizer.GetTokenCnt() != 0)){
-                switch (MyTokenizer.eGetKeyword(0)){
+        if(!MyUart.gets(cTablica, BUFFER_SIZE)){        
+            MyDecoder.DecodeMsg(cTablica);
+            if ((MyDecoder.eGetTokenType(0) == KEYWORD) & (MyDecoder.GetTokenCnt() != 0)){
+                switch (MyDecoder.eGetKeyword(0)){
+                    case (ID):
+                        MyUart.puts(cIdentifier, BUFFER_SIZE);
+                        break;
                     case (CLB):
                         led_green = !led_green;
+                        MyStepper.Callib();
+                        MyUart.puts(cCorrectResponse, BUFFER_SIZE);
                         break;
                     case (GT):
                         led_red = !led_red;
+                        MyStepper.Goto(4);
+                        MyUart.puts(cCorrectResponse, BUFFER_SIZE);
+                        break;
+                    case (ST):
+                        MyStepper.Step(5);
+                        MyUart.puts(cCorrectResponse, BUFFER_SIZE);
                         break;
                     default:
                         break;
                 }
             }
+            else {
+                MyUart.puts(cUnknownKeyword, BUFFER_SIZE);
+            }
         }
     }
 }