Repo. for the ELEC351 Coursework - Oliver Thompson

Dependencies:   BMP280 ELEC350-Practicals-FZ429- TextLCD watchdog_RTOS BME280 ntp-client

Revision:
17:da78a552339d
Parent:
16:73af0e3ddcaa
Child:
18:a036c2e5ff89
--- a/SerialComms.hpp	Fri Dec 07 17:46:12 2018 +0000
+++ b/SerialComms.hpp	Sat Dec 08 00:59:10 2018 +0000
@@ -16,7 +16,7 @@
 #define cmdCol 37
 Serial pc(USBTX, USBRX);   // USB Tx and Rx Connections 
 
-const int buffer_size = 20;
+const int buffer_size = 30;
 char rx_buffer[buffer_size+1];
 
 struct Timestamp
@@ -42,14 +42,11 @@
          int rxInputFlag;
          char RxIn[buffer_size+1];
          char clearingArray[buffer_size+1];
-
+         char timestampArray[buffer_size+1];
    public:
-       
         EventQueue SERIAL_Queue;                    //Initialise the EventQueue
-
         void displayFrame()
         { 
-      
             printf("\033[2J"); // Clear screen
             printf("\033[0;0H"); // Home Positon Reset
             printf("*********************************************************************************\n"
@@ -104,10 +101,11 @@
             fTemp = 0;
             fPressure = 0;
             fLDR = 0;
-            char rx_buffer[buffer_size+1] = {0};
             for (int i = 0; i < buffer_size+1; i++)
             {
                 clearingArray[i] = ' ';
+                timestampArray[i] = 0;
+                rx_buffer[i] = 0;
             }
             displayFrame();
             SERIAL_Queue.call_every(1000, callback(this, &Serialcomms::updateTerminal));
@@ -136,7 +134,8 @@
         }
         
         void updateTerminal()                   // Print internal values of sensors
-        {            
+        {          
+            printf("\033[6;16f%s", timestampArray);  
             printf("\033[7;16f%5.2f", fTemp);
             printf("\033[8;16f%5.2f", fPressure);
             printf("\033[9;16f%5.2f", fLDR);
@@ -170,7 +169,7 @@
         int searchInput(char stream[], char command[])
         {
             int match = 0;
-            const int commandLength = strlen(command);
+            const int commandLength = strlen(command); 
             for (int i = 0; i < commandLength; i++)
             {
                 if  (stream[i] == command[i])
@@ -179,14 +178,10 @@
                 }
                 else
                 {
-                    if(match != (commandLength-1))
-                    {
-                        match = 0;
-                    }
-                    break;
+                    match = 0;
+                    i = commandLength-1;
                 }
-            }
-            
+            }           
             return match;
         }
         
@@ -205,25 +200,42 @@
             }           
             else if(int read = searchInput(RxIn, "READ") > 0)
             {
-                printintegertoTerminal(read);
-
+                read = searchInput(RxIn, "READ");
                 char count[buffer_size] = {0};
-                // Extract number of requested samples
                 for (int i = read; i < strlen(RxIn); i++)
                 {
-                    count[i-read] = RxIn[i];
+                    count[i-read] = RxIn[i+1];
                 }
-                printstringtoTerminal(count);   
-            } 
+            }
             else if(int del = searchInput(RxIn, "DELETE") > 0)
             {
+                del = searchInput(RxIn, "DELETE");
+                char count[buffer_size] = {0};
+                for (int i = del; i < strlen(RxIn); i++)
+                {
+                    count[i-del] = RxIn[i+1];
+                }
             }         
             else if(int setdate = searchInput(RxIn, "SETDATE") > 0) //<dd> <mm> <yyyy>
-            {                
+            {
+                setdate = searchInput(RxIn, "SETDATE");
+                char count[buffer_size] = {0};
+                for (int i = setdate; i < strlen(RxIn); i++)
+                {
+                    count[i-setdate] = RxIn[i+1];
+                    timestampArray[i-setdate] = RxIn[i+1];
+                }
             }     
             else if(int settime = searchInput(RxIn, "SETTIME") > 0) //<hh> <mm> <ss>
             {
-            }       
+                settime = searchInput(RxIn, "SETTIME");
+                char count[buffer_size] = {0};
+                for (int i = settime; i < strlen(RxIn); i++)
+                {
+                    count[i-settime] = RxIn[i+1];
+                    timestampArray[i-settime+6] = RxIn[i+1];
+                }           
+            }        
             else if(int sett = searchInput(RxIn, "SETT") > 0)
             {
             }           
@@ -235,6 +247,12 @@
             }
             else if(int clearall = searchInput(RxIn, "CLEAR ALL") > 0)
             {
+                cmdCount = 0;
+                for (int i = 0; i < 22; i++)
+                {
+                    printstringtoTerminal(clearingArray);
+                }
+                cmdCount = 0;
             }
             else
             {