For coursework of group 3 in SOFT564Z

Dependencies:   Motordriver ros_lib_kinetic

Revision:
8:e406c6f728bd
Parent:
7:2796f0b5228d
Parent:
6:3872858b7844
--- a/Debug.cpp	Thu Dec 05 13:02:10 2019 +0000
+++ b/Debug.cpp	Tue Dec 17 13:12:24 2019 +0000
@@ -18,6 +18,9 @@
 Terminal PC(SERIAL_TX, SERIAL_RX);
 /* Terminal object defined in Debug.hpp */
 
+DigitalOut debugLED(LED2);
+DigitalOut debugLED_temp(LED3);
+
 /*------------------------------------------------------------------------------
  Thread for handiling the terminal
 ------------------------------------------------------------------------------*/
@@ -25,7 +28,7 @@
 {
     // Initialise the terminal printing the table.
     PC.init();
-
+    
     // Enter Forever loop
     while(1) {
         // loop forever dispatching any function called to the queue
@@ -41,7 +44,9 @@
 {
     CurrentIDX = 0;
     col = false;
-    
+
+    debugLED_temp = 0;
+
     // Set baud rate for serial object pc
     pc.baud (115200);
 
@@ -51,9 +56,9 @@
     Colour(ColourGREEN);
 
     // Print DATA table to present data
-    pc.printf("|      PROJ515      :      DEBUG MENU    |                                                      |\n\r"
+    pc.printf("|      PROJ515          :      DEBUG MENU       |                                               |\n\r"
               "|***********************************************************************************************|\n\r"
-              "|      Error Code       |      Time Stamp       |                 Error MSG                     |\n\r"
+              "|      Error Type       |      Time Stamp       |                 Error MSG                     |\n\r"
               "|-----------------------|-----------------------|-----------------------------------------------|\n\r");
     for(char idx = 0; idx < Rows; idx++) {
         pc.printf("|                       |                       |                                               |\n\r");
@@ -93,8 +98,8 @@
 ------------------------------------------------------------------------------*/
 void Terminal::PrintDATA(char* STRING, char IDX)
 {
-    char Y = (IDX/4)+5;
-    char X = ((IDX%4)*23)+3;
+    char Y = (IDX/3)+5;
+    char X = ((IDX%3)*24)+3;
     Cursor(X,Y);
     pc.printf("%s",STRING);
 }
@@ -170,7 +175,7 @@
         }
 
         // debug break loop if too big
-        if(commandSize > 8) {
+        if(commandSize > 4) {
             break;
         }
     }
@@ -182,10 +187,38 @@
         }
 
         // debug break loop if too big
-        if(dataSIZE > 8) {
+        if(dataSIZE > 3) {
             break;
         }
     }
+
+    if(commandSize == 4) {
+        // Action for input of MOVE command
+        if((Terminal_buffer[0] == 'M') && (Terminal_buffer[1] == 'O') && (Terminal_buffer[2] == 'V') && (Terminal_buffer[3] == 'E')) {
+            if(dataSIZE != 3) {
+                Error msgs;
+                msgs.ErrorCode = warning;
+                msgs.TimeStamp = "TimeStamp";
+                msgs.ErrorMSGS = "input Value is not valid for command \"MOVE\"";
+                ERROR_MSGS(msgs);
+            } else if((Terminal_buffer[4] != ' ') || (Terminal_buffer[6] != '.')) {
+                Error msgs;
+                msgs.ErrorCode = warning;
+                msgs.TimeStamp = "TimeStamp";
+                msgs.ErrorMSGS = "Value input is incorrect format for command \"READ\"";
+                ERROR_MSGS(msgs);
+            } else {
+                float inputVAL;
+                BYTE tempARRAY[4] = {'0', Terminal_buffer[5], Terminal_buffer[6], Terminal_buffer[7]};
+                inputVAL = strTOflt(tempARRAY);
+                
+                char buffer_Temp[20];
+                sprintf(buffer_Temp, "%1.1f", inputVAL);
+                printDEBUG(buffer_Temp);
+                
+            }
+        }
+    }
 }
 
 /*------------------------------------------------------------------------------
@@ -193,12 +226,21 @@
  to check which charecteter has been entered and add it to a buffer.
 ------------------------------------------------------------------------------*/
 void Terminal::Input_Handler(void)
-{
+{    
+    char gotkey; 
+    pc.attach(0);
+    gotkey=pc.getc();
+    // remove the interupt from the serial input flag
+    //pc.attach(NULL,pc.RxIrq);
+    debugLED_temp = 1;
     // if data is in the buffer call function to check which key has been entered
-    if(pc.readable()!= 0) {
-        // remove the interupt from the serial input flag
-        pc.attach(NULL,pc.RxIrq);
+    if(pc.readable()!= 0)
+    {
         TerminalQueue.call(&PC, &Terminal::checkKEY);
+        
+    // if no data present in the buffer re attach the interupt
+    } else {
+        pc.attach(this, &Terminal::Input_Handler,pc.RxIrq);
     }
 }
 
@@ -225,49 +267,49 @@
     Cursor(3,(Rows+8));
     pc.printf("                                                                                              ");
     Cursor(3,(Rows+8));
-    
-    char buffer[20];
-    sprintf(buffer, "%d", msgs.ErrorCode);
 
     // Print diferent messages dependent on the Error code attached in the struct Error
     switch(msgs.ErrorCode) {
         case warning :
             Colour(ColourYELLOW);
-            PrintDATA(buffer , CurrentIDX);
-            PrintDATA(msgs.TimeStamp , CurrentIDX+1);
-            PrintDATA(msgs.ErrorMSGS , CurrentIDX+2);
-            CurrentIDX += 4;
+            PrintDATA("Warning", CurrentIDX);
+            PrintDATA(msgs.TimeStamp, CurrentIDX+1);
+            PrintDATA(msgs.ErrorMSGS, CurrentIDX+2);
             break;
 
         case fault :
             Colour(ColourAMBER);
-            PrintDATA(buffer , CurrentIDX);
-            PrintDATA(msgs.TimeStamp , CurrentIDX+1);
-            PrintDATA(msgs.ErrorMSGS , CurrentIDX+2);
-            CurrentIDX += 4;
+            PrintDATA("Fault", CurrentIDX);
+            PrintDATA(msgs.TimeStamp, CurrentIDX+1);
+            PrintDATA(msgs.ErrorMSGS, CurrentIDX+2);
             break;
 
         case criticalERROR :
             Colour(ColourRED);
-            PrintDATA(buffer , CurrentIDX);
-            PrintDATA(msgs.TimeStamp , CurrentIDX+1);
-            PrintDATA(msgs.ErrorMSGS , CurrentIDX+2);
-            CurrentIDX += 4;
+            PrintDATA("Critical ERROR", CurrentIDX);
+            PrintDATA(msgs.TimeStamp, CurrentIDX+1);
+            PrintDATA(msgs.ErrorMSGS, CurrentIDX+2);
             break;
 
         case criticalFAILURE :
             Colour(ColourRED);
-            PrintDATA(buffer , CurrentIDX);
-            PrintDATA(msgs.TimeStamp , CurrentIDX+1);
-            PrintDATA(msgs.ErrorMSGS , CurrentIDX+2);
-            CurrentIDX += 4;
+            PrintDATA("Critical FAILURE", CurrentIDX);
+            PrintDATA(msgs.TimeStamp, CurrentIDX+1);
+            PrintDATA(msgs.ErrorMSGS, CurrentIDX+2);
             break;
-            
-        default :            
+
+        default :
             // This point should never be reached as it would indicate a full
             // failure which would cause the watchdog to reset the system
             break;
     }
+    
+    if(CurrentIDX > MaxDATA-6)
+    {
+        CurrentIDX = 0;
+    } else {
+        CurrentIDX += 3;
+    }
 }
 
 /*------------------------------------------------------------------------------
@@ -326,12 +368,12 @@
 ------------------------------------------------------------------------------*/
 void Flag_Error(int ErrorCode, char* ErrorMSG)
 {
-    BYTE SampleTimeTag [20];   
+    //BYTE SampleTimeTag [20];
     //strcpy(SampleTimeTag, getSystemDateTime());
-    
+
     Error msgs;
     msgs.ErrorCode = ErrorCode;
     msgs.TimeStamp = "Temp";
     msgs.ErrorMSGS = ErrorMSG;
     TerminalQueue.call(&PC, &Terminal::ERROR_MSGS, msgs);
-}
\ No newline at end of file
+}