Repo. for the ELEC351 Coursework - Oliver Thompson

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

Files at this revision

API Documentation at this revision

Comitter:
O_Thom
Date:
Wed Jan 02 12:12:30 2019 +0000
Parent:
19:c3b396b65f2a
Commit message:
Serial Messaging Complete - SD Class need to handle commands. LCD and Networking Time and Date Update Needs Testing.

Changed in this revision

LCD.hpp Show annotated file Show diff for this revision Revisions of this file
Network.hpp Show annotated file Show diff for this revision Revisions of this file
SDCard.hpp Show annotated file Show diff for this revision Revisions of this file
Sampler.hpp Show annotated file Show diff for this revision Revisions of this file
SerialComms.hpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
messageStruct.hpp Show annotated file Show diff for this revision Revisions of this file
--- a/LCD.hpp	Thu Dec 13 16:09:54 2018 +0000
+++ b/LCD.hpp	Wed Jan 02 12:12:30 2019 +0000
@@ -7,7 +7,7 @@
 #include <stdio.h>
 #include <string.h>
 
-
+Mail<time_and_date,5> Serial2LCD;           // Serial -> LCD Mailbox 5 Elements Wide Time&Date
 
 class LCD_Data
     {
@@ -49,7 +49,26 @@
     EventQueue LCD_Queue;  //create an event queue for main
     time_t timestamp; //current time in format of unix time, can be converted to DAY_OF_WEEK MONTH DAY HOUR:MINUTE:SECOND YEAR using ctime(&timestamp);
     
-    
+ 
+        void getSerial2LCD()    // Queue Consumer
+        {
+            if (!Serial2LCD.empty())
+            {
+                osEvent evt = Serial2LCD.get(); 
+        switch (evt.status) 
+                {
+                    case osEventMail:
+                //Normal status
+                                time_and_date *time_copy = (time_and_date*)evt.value.p; 
+                                time = time_copy->current_time; // Update the internal clock
+                                Serial2Net.free(time_copy); // Free up the space in the memory Pool
+                    default:
+                //All other errors (see cmsis_os.h for meaning of error code)
+                //printf("Serial2Net->get() returned %02x status\n\r", evt.status);
+                }               
+            }
+        }
+   
     
     LCD_Data(){ //constructor, initializes the FLIP variable for use in toggling the bottom line of the LCD
         flip = 1;
@@ -117,9 +136,9 @@
      
      
      //printf("current day is: %s\n", day);
-       // printf("current year is: %s\n", year);
-      // printf("current time is: %s\n", time);
-       // printf("current date is: %s\n", date);
+     // printf("current year is: %s\n", year);
+     // printf("current time is: %s\n", time);
+     // printf("current date is: %s\n", date);
      // printf("current month is: %s\n", month);
      
  
@@ -127,12 +146,12 @@
        m_oNet.Network_Queue.call(&m_oNet, &Network::update_Time, current_time);
        
        time_and_date Timemsg; // Define instance of message structure
-        Timemsg.day = day;
-        Timemsg.month = month;
-        Timemsg.date = date;
-        Timemsg.time = time;
-        Timemsg.year = year;
-        Timemsg.current_time = current_time;
+                Timemsg.day = day;
+                Timemsg.month = month;
+                Timemsg.date = date;
+                Timemsg.time = time;
+                Timemsg.year = year;
+                Timemsg.current_time = current_time;
         
        flip = 3; //will tell the user that the time has been updated on next FLIP instance with the LCD
        
@@ -143,8 +162,8 @@
        
     };  //end of LCD class
     
-    
-    
 // Define the member object for the LCD
 LCD_Data m_oDisplay;
-#endif
\ No newline at end of file
+#endif
+        
+        
\ No newline at end of file
--- a/Network.hpp	Thu Dec 13 16:09:54 2018 +0000
+++ b/Network.hpp	Wed Jan 02 12:12:30 2019 +0000
@@ -3,32 +3,17 @@
 #define _NETWORK_ 
 
 #include "mbed.h" 
-
 #include "FATFileSystem.h" 
-
 #include "sample_hardware.hpp" 
-
 #include "EthernetInterface.h" 
-
 #include "TCPServer.h" 
-
 //#include "messageStruct.hpp" 
-
 //#include "LCD.hpp"
-
 #include "TCPSocket.h" 
-
 #include <iostream> 
-
 #include <string>  
-
 #include "ntp-client/NTPClient.h"
 
-
-
-
- 
-
 #define HTTP_STATUS_LINE "HTTP/1.0 200 OK" 
 #define HTTP_HEADER_FIELDS "Content-Type: text/html; charset=utf-8" 
 #define HTTP_MESSAGE_BODY1 ""                                    \
@@ -72,39 +57,36 @@
   
 
 #define IP        "10.0.0.10"
-
 #define NETMASK   "255.0.0.0"
-
 #define GATEWAY   "10.0.0.2"
+EthernetInterface eth; 
+NTPClient ntp(&eth);   
 
-EthernetInterface eth; 
 
-NTPClient ntp(&eth);   
+Mail<time_and_date,5> Serial2Net;           // Serial -> Net Mailbox 5 Elements Wide Time&Date
+
 
 class Network 
 { 
 //friend class LCD_Data;
     private: 
-     float temp;       //current temperature of sensor 
-     float pressure;  //current pressure of sensor 
-     float fLDR;      //current light level from LDR 
+     double temp;       //current temperature of sensor 
+     double pressure;  //current pressure of sensor 
+     double fLDR;      //current light level from LDR 
      string time;
-
-      void update_temp(double t) //use this function to update the current temperature value 
-            { 
-                temp = 5; 
-            }  
-
-        void update_pressure(double p) //use this function to update the current pressure value 
-            { 
-                pressure = 4;     
-            }  
-
-        void update_LDR(double L) 
-            { 
-                fLDR = 3;    
-            } 
-
+        
+         void update_temp(double t) //use this function to update the current temperature value
+                {
+                        temp = t;
+                } 
+        void update_pressure(double p) //use this function to update the current pressure value
+                {
+                        pressure = p;    
+                } 
+        void update_LDR(double L)
+                {
+                        fLDR = L;   
+                }
              
     public: 
     EventQueue Network_Queue; 
@@ -116,16 +98,34 @@
     //Configure an ethernet connection 
     eth.set_network(IP, NETMASK, GATEWAY); 
     eth.connect(); 
-           
+      
     } 
   
 
     ~Network(){     //deconstructor  
-
     } 
 
-      void update_sensor_info(sample_message msg) //updates all current sensor information, this is called by a ticker every 5 seconds to read from the mailbox 
+        void getSerial2Net()    // Queue Consumer
+        {
+            if (!Serial2Net.empty())
+            {
+                osEvent evt = Serial2Net.get(); 
+        switch (evt.status) 
+                {
+                    case osEventMail:
+                //Normal status
+                                time_and_date *time_copy = (time_and_date*)evt.value.p; 
+                                time = time_copy->current_time; // Update the internal clock
+                                Serial2Net.free(time_copy); // Free up the space in the memory Pool
+                    default:
+                //All other errors (see cmsis_os.h for meaning of error code)
+                //printf("Serial2Net->get() returned %02x status\n\r", evt.status);
+                }               
+            }
+        }
 
+
+    void update_sensor_info(sample_message msg) //updates all current sensor information, this is called by a ticker every 5 seconds to read from the mailbox
     { 
          update_temp(msg.temp);                  // Include message class passing of data 
          update_pressure(msg.pressure); 
@@ -140,8 +140,6 @@
      
 
     void NetPush(){ 
-     
-
   //Now setup a web server 
 
     TCPServer srv;           //TCP/IP Server 
@@ -166,7 +164,7 @@
 
         srv.accept(&clt_sock, &clt_addr); 
 
-        printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port()); 
+        //printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port()); 
 
              
 
@@ -218,20 +216,10 @@
         response += time;
         
         response += HTTP_MESSAGE_BODY5; 
- 
-
-         
-
-         
 
         //Send static HTML response (as a C string) 
 
-        clt_sock.send(response.c_str(), response.size()+6);  
-
-               
-
-         
-
+        clt_sock.send(response.c_str(), response.size());  
         } 
 
 }; 
@@ -243,4 +231,4 @@
 Network m_oNet; 
 
 #endif
-            
\ No newline at end of file
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDCard.hpp	Wed Jan 02 12:12:30 2019 +0000
@@ -0,0 +1,119 @@
+#ifndef _SDCARD_ 
+#define _SDCARD_  
+#include "mbed.h" 
+#include "SDBlockDevice.h" 
+#include "FATFileSystem.h" 
+#include "sample_hardware.hpp" 
+
+  
+
+class SDcard 
+
+{     
+
+    private: 
+     float temp;       //current temperature of sensor 
+     float pressure;  //current pressure of sensor 
+     float fLDR;      //current light level from LDR 
+
+      void update_temp(double t) //use this function to update the current temperature value 
+            { 
+                temp = t; 
+            }  
+
+        void update_pressure(double p) //use this function to update the current pressure value 
+            { 
+                pressure = p;     
+            }  
+
+        void update_LDR(double L) 
+            { 
+                fLDR = L;    
+            } 
+
+        
+
+    public: 
+    EventQueue SDcard_Queue; 
+    
+    SDcard()
+        {                      //constructor, 
+  
+    }    
+
+   
+
+      ~SDcard(){                      //Deconstructor,  
+
+    }
+
+
+        void getSerial2SD() // Queue Consumer
+        {
+            if (!Serial2SD.empty())
+            {
+                osEvent evt = Serial2SD.get(); 
+        switch (evt.status) 
+                {
+                    case osEventMail:
+                //Normal status
+                                SD_message *mail = (SD_message*)evt.value.p;
+                                // Pass onto a decoder/ handler
+                                // i.e. InputHandler(message) // Will inspect the difference parameters in the structure and proceed accordingly
+                                Serial2SD.free(mail);   // Free up the space in the memory Pool
+                    default:
+                //All other errors (see cmsis_os.h for meaning of error code)
+                //printf("Serial2Net->get() returned %02x status\n\r", evt.status);
+                }               
+            }
+        }
+
+      void update_sensor_info(sample_message msg) //updates all current sensor information, this is called by a ticker every 5 seconds to read from the mailbox 
+    { 
+         update_temp(msg.temp);                  // Include message class passing of data 
+         update_pressure(msg.pressure); 
+         update_LDR(msg.ldr); 
+    } 
+    
+
+
+
+    void Save_Data() {          
+    //Create a filing system for SD Card 
+
+                        // initalising the SD card 
+            if ( sd.init() != 0) {
+                    printf("Init failed \n");
+                    //errorCode(FATAL);
+            }  
+            
+    FATFileSystem fs("sd", &sd);
+        
+    FILE* fp = fopen("/sd/SensorData.csv","a");
+
+    if (fp == NULL) {
+        error("Could not open file for write\n");
+        //errorCode(FATAL);
+    } 
+
+    //Storing sensor data in csv file 
+
+    fprintf(fp, " Temperature(C) , %4.2f , Pressure(mbar) , %4.2f , Lux , %4.2f \n", temp , pressure , fLDR );
+
+    //Close the file
+    fclose(fp); 
+
+   //Close down SD card 
+    sd.deinit(); 
+    
+    //errorCode(OK);
+  
+        
+   } 
+}; 
+// creating the instance SD of the class SDcard 
+
+
+SDcard m_oSD; 
+
+#endif
\ No newline at end of file
--- a/Sampler.hpp	Thu Dec 13 16:09:54 2018 +0000
+++ b/Sampler.hpp	Wed Jan 02 12:12:30 2019 +0000
@@ -1,48 +1,59 @@
 #ifndef _SAMPLER_
 #define _SAMPLER_
+
 #include "mbed.h"
 #include "LCD.hpp"
 #include "SerialComms.hpp"
+#include "SDcard.hpp"
 #include "sample_hardware.hpp"
 #include <vector>
-
-
 #define Activate_Flag 1
 
-LCD_Data m_oDisplay;
-Serialcomms m_oSerial(m_oDisplay);
+Serialcomms m_oSerial;
 
 class Sampler
 {
 private:
-
+    int SampleEN;
+    sample_message message;
+   
 public: 
     EventQueue SAMP_Queue;                  //Initialise the EventQueue
-    sample_message message;
-    int SampleEN = 1;
+
     Sampler()   //Constructor 
     {
         SampleEN = 0;
     }
     ~Sampler() //Destructor - should the instance go out of scope, this is called
     {
+            
     }
-    
-    void publishSample()
-    {
-        if (SampleEN)
+ 
+        void getSerial2Sampler()    // Queue Consumer
         {
-             sample_message message = getData();
-             m_oDisplay.LCD_Queue.call(&m_oDisplay, &LCD_Data::update_sensor_info, message);
-             m_oSerial.SERIAL_Queue.call(&m_oSerial, &Serialcomms::setsampledata, message);
-            //SD_Queue.call(this, &SD_Queue::update_sensor_info, sample_data, sample_data);
+            if (!Serial2Sampler.empty())
+            {
+                osEvent evt = Serial2Sampler.get();     //With timeout
+        switch (evt.status) 
+                {
+            case osEventMessage:
+                //Normal status
+                                if ((evt.value.v == 0) || (evt.value.v == 1))   // Update the enable pin if the value co-responds to allowed cases
+                                {
+                                    SampleEN = evt.value.v;             
+                                }
+                greenLED = !greenLED;
+            case osEventTimeout:
+                //Timeout
+                //printf("Serial2Sampler->get() returned %02x status (timeout)\n\r", evt.status);
+            default:
+                //All other errors (see cmsis_os.h for meaning of error code)
+                //printf("Serial2Sampler->get() returned %02x status\n\r", evt.status);
+                }               
+            }
         }
-    }
-    
-    void updateSampleEN(int EN)
-    {
-        SampleEN = EN;
-    }
+
+
     void getData()
     {
         float temp = sensor.getTemperature();
@@ -55,12 +66,27 @@
         msg.temp = temp;
         msg.pressure = pressure;
         msg.ldr = LDR;
-        redLED != redLED;
         message = msg;  // Write to the private 'global' variable
+    }
+        
+    void publishSample()
+    {
+       if (SampleEN == 1)
+       {
+          getData();
+          m_oDisplay.LCD_Queue.call(&m_oDisplay, &LCD_Data::update_sensor_info, message);
+                  m_oNet.Network_Queue.call(&m_oNet, &Network::update_sensor_info, message);
+          m_oSerial.SERIAL_Queue.call(&m_oSerial, &Serialcomms::setsampledata, message);
+                  //m_oSD.SDcard_Queue.call(&m_oSD, &SDcard::update_sensor_info, message);
         }
-    
+    }
+   
+
     void updateTimeData();
+};
+
+#endif
 
 
-};
-#endif
\ No newline at end of file
+Sampler m_oSample;
+
--- a/SerialComms.hpp	Thu Dec 13 16:09:54 2018 +0000
+++ b/SerialComms.hpp	Wed Jan 02 12:12:30 2019 +0000
@@ -1,6 +1,6 @@
 #include "mbed.h"
 #include "mbed_events.h"
-#include<string> 
+#include <string> 
 #include <iostream>
 #include <vector>
 
@@ -9,7 +9,6 @@
 #define ERROR_SD_EXIT 3
 #define ERROR_NET_EXIT 4
 #define ERROR_SAMPLER_EXIT 5
-
 #define cmdRow 36
 #define cmdCol 37
 
@@ -18,41 +17,61 @@
 const int buffer_size = 30;
 char rx_buffer[buffer_size+1];
 
-struct Timestamp
-{
- int Day;
- int Month;
- int Year;
- int Second;
- int Minute;
- int Hour;
-};
-
-class Sampler;  // Forward Declaration
-
-Sampler SampleRef; // Reference initialisation
+Queue<uint32_t,5> Serial2Sampler;           // Serial -> Sampler Message Queue. 5 Elements Wide
+Mail<SD_message, 5> Serial2SD;                  // Serial -> SD Mailbox  Time&Date + Sample Management
 
 class Serialcomms
-{  
-
+{
    private:
          float fTemp;               //current temperature of sensor
          float fPressure;           //current pressure of sensor
          float fLDR;                //current light level from LDR
+                 bool Logging;
+                 bool SampleEN;
          vector<int> ErrorCodes;
          int rx_in; 
-         //char rx_buffer[buffer_size + 1];
          int cmdCount;
          int rxInputFlag;
          char RxIn[buffer_size+1];
          char clearingArray[buffer_size+1];
-         char timestampArray[buffer_size+1];
-         Sampler& SampleRef;
+         char timestampArray[15+1];
          
    public:
         EventQueue SERIAL_Queue;                    //Initialise the EventQueue
+     
+                void addtoSerial2Sampler(uint32_t Data)         // Producer for the Queue
+                {
+                    osStatus Stat = Serial2Sampler.put((uint32_t*)Data);    // Put the data into the message queue
+                    if (Stat == osErrorResource)    // Try catch & Error Handling
+                    {
+                        printf("Serial2Sampler->put() Error code: %4Xh, Resource not available\r\n", Stat);
+                    }
+                }    
+
+                void addtoSerial2Net()          // Producer for the Mailbox
+                {
+            time_and_date *mail = Serial2Net.alloc();       // Allocatte space in the memory pool
+                    mail -> current_time = timestampArray;
+                    osStatus Stat = Serial2Net.put(mail);               // Pointer to teh data package
+                    if (Stat == osErrorResource)                                // Try catch & Error Handling
+                    {
+                        printf("Serial2Net->put() Error code: %4Xh, Resource not available\r\n", Stat);
+                    }
+                }    
+
+                void addtoSerial2LCD()          // Producer for the Mailbox
+                {
+                    time_and_date *mail = Serial2Net.alloc();
+                    mail -> current_time = timestampArray;
+                    osStatus Stat = Serial2LCD.put(mail);   // Put the data into the message queue
+                    if (Stat == osErrorResource)    // Try catch & Error Handling
+                    {
+                        printf("Serial2LCD->put() Error code: %4Xh, Resource not available\r\n", Stat);
+                    }
+                }    
+                
         void displayFrame()
-        { 
+        {
             printf("\033[2J"); // Clear screen
             printf("\033[0;0H"); // Home Positon Reset
             printf("*********************************************************************************\n"
@@ -65,7 +84,7 @@
                    "* Pressure:                     *                                               *\n" // Col 7 Row 12
                    "* Light Level:                  *                                               *\n" // Col 8 Row15
                    "*********************************                                               *\n"
-                   "*         Error Codes           *                                               *\n" //Col 10                  
+                   "*         Error Codes           *                                               *\n" // Col 10                  
                    "*********************************                                               *\n" // Col 11 Row 2
                    "*                               *                                               *\n" 
                    "*                               *                                               *\n" 
@@ -96,29 +115,32 @@
                    "*********************************************************************************\n\n"    
                    );          
             printf("\033[%d;%dfcmd: ", cmdRow, cmdCol);
-
         }  
         
-        //Serialcomms(Sampler& m_oSampler) : m_oSampleRef(m_oSampler) // Take the reference to the sampler object and state in m_oSamplerRef
         Serialcomms() // Take the reference of the sampler object and state in m_oSamplerRef
         {
-            //m_oSampleRef = m_oSampler;
-            //SampleQueueRef = m_oQueue;
             pc.baud(9600);
             rx_in = 0;
             cmdCount = 0;
             fTemp = 0;
             fPressure = 0;
             fLDR = 0;
+                      Logging = 0;
+                      SampleEN = 0;
             for (int i = 0; i < buffer_size+1; i++)
             {
                 clearingArray[i] = ' ';
-                timestampArray[i] = 0;
                 rx_buffer[i] = 0;
+                                if (i < 16)
+                                {
+                                    timestampArray[i] = ' ';
+                                }
+
             }
+                        timestampArray[8] = ':';
             displayFrame();
             SERIAL_Queue.call_every(1000, callback(this, &Serialcomms::updateTerminal));
-            SERIAL_Queue.call_every(50, callback(this, &Serialcomms::ReadData));           // Start the periodic event to check the buffer
+            SERIAL_Queue.call_every(50, callback(this, &Serialcomms::ReadData));           // Start the periodic event to check the serial buffer
         }
         
         ~Serialcomms()
@@ -128,9 +150,9 @@
         
         void setsampledata(sample_message msg)      // Update internal values
         {
-            fTemp = msg.temp;
-            fPressure = msg.pressure;
-            fLDR = msg.ldr;   
+                    fTemp = msg.temp;
+                    fPressure = msg.pressure;
+                    fLDR = msg.ldr;   
         }
         
         sample_message getsampledata()              // Retrieves the data
@@ -174,7 +196,6 @@
             cmdCount++;              
         }
         
-              
         int searchInput(char stream[], char command[])
         {
             int match = 0;
@@ -199,8 +220,9 @@
         {   
             if (int readall = searchInput(RxIn, "READ ALL") > 0)     
             {
-                printstringtoTerminal("READING ALL");
+              printstringtoTerminal("READING ALL");                         
             }
+                        
             else if(int readall = searchInput(RxIn, "DELETE ALL") > 0)
             {
                 printf("\033[%d;%df%s", (cmdRow-(cmdCount+1)),(cmdCol+5), "DELETING ALL");  // Confirmation of Command
@@ -226,42 +248,86 @@
             }         
             else if(int setdate = searchInput(RxIn, "SETDATE") > 0) //<dd> <mm> <yyyy>
             {
-                setdate = searchInput(RxIn, "SETDATE");
+                setdate = searchInput(RxIn, "SETDATE"); // Returns the index of the last character
                 char count[buffer_size] = {0};
                 for (int i = setdate; i < strlen(RxIn); i++)
                 {
+                                    if (RxIn[i+1] != ' ')
+                                    {
                     count[i-setdate] = RxIn[i+1];
-                    timestampArray[i-setdate] = RxIn[i+1];
+                    timestampArray[i-setdate] = RxIn[i+1];                                      
+                                    }
                 }
+                                addtoSerial2LCD();      // Update the DATE on the LCD
+                                addtoSerial2Net();      // Update the DATE on the Webpage
             }     
             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++)
-                {
+                                {
+                                    if (RxIn[i+1] != ' ')
+                                    {
                     count[i-settime] = RxIn[i+1];
-                    timestampArray[i-settime+6] = RxIn[i+1];
-                }           
+                    timestampArray[i-settime+9] = RxIn[i+1];
+                                    }
+                }
+                                addtoSerial2LCD();      // Update the TIME on the LCD
+                                addtoSerial2Net();      // Update the TIME on the Webpage                               
             }        
-            else if(int sett = searchInput(RxIn, "SETT") > 0)
+            else if(int sett = searchInput(RxIn, "STATE") > 0)
             {
-                SampleRef.SAMP_Queue.call(&m_oSampleRef, &Sampler::updateSampleEN, 1) // Call the update function for the enable pin within the sampler class
-                //SampleQueueRef.call(&m_oSampleRef, &m_oSampleRef::updateSampleEN, 1) // Call the update function for the enable pin within the sampler class           
-            }           
-            else if(int state = searchInput(RxIn, "STATE") > 0)       
+                            SampleEN = !SampleEN;
+                            if (SampleEN)
+                            {
+                                printstringtoTerminal("SAMPLING");                          
+                            }
+                            else
+                            {
+                                printstringtoTerminal("SAMPLING DISABLED");                         
+                            }
+                            addtoSerial2Sampler(SampleEN);
+//                          uint32_t bit = (uint32_t)(RxIn[5] - '0');   // Take the last character after the "SETT" string and push it onto the queue
+//                          if ((bit == 1) || (bit == 0))
+//                          {
+//                              addtoSerial2Sampler(bit);
+//                          }
+//                          else
+//                          {
+//                              printf("Invalid STATE Entry");
+//                          }
+            }
+            else if(int state = searchInput(RxIn, "SETT") > 0)     // PENDING WORK -> Set the time period of sampling  
             {
-            }      
+                            uint32_t bit = 0;   // Re-init
+                            bit += (uint32_t)(RxIn[4] - '0');   // Take the last character after the "SETT" string and push it onto the queue
+                            // Modify the enable sampling bit
+                            if (bit > 0)
+                            {
+                                addtoSerial2Sampler(bit);
+                            }
+            }     
             else if(int logging = searchInput(RxIn, "LOGGING") > 0)     // Verbose logging
             {
+                            Logging = !Logging; // Toggle the private Logging Bool Variable
+                            if (Logging)
+                            {
+                                printstringtoTerminal("LOGGING");                           
+                            }
+                            else
+                            {
+                                printstringtoTerminal("LOGGING DISABLED");                          
+                            }
             }
-            else if(int clearall = searchInput(RxIn, "CLEAR ALL") > 0)
+            else if(int clearall = searchInput(RxIn, "CLEARALL") > 0)   // Reset the terminal
             {
                 cmdCount = 0;
                 for (int i = 0; i < 22; i++)
                 {
                     printstringtoTerminal(clearingArray);
                 }
+                                displayFrame();
                 cmdCount = 0;
             }
             else
@@ -272,8 +338,9 @@
             for (int i = 0; i < (buffer_size+1); i++)   // Init
             {
                 RxIn[i] = 0;   
+                              rx_buffer[i] = ' ';
             }
-            printf("\033[%d;%dfcmd: ", cmdRow, cmdCol);  // Reset to cmd location      
+            printf("\033[%d;%dfcmd: %s", cmdRow, cmdCol, rx_buffer);  // Reset to cmd location      
         }
  
 
@@ -322,10 +389,7 @@
             }
         }
         void updateTimeDate()
-        {
-            
-        }
-        
-
+        {   
+        }   
 };
 
--- a/main.cpp	Thu Dec 13 16:09:54 2018 +0000
+++ b/main.cpp	Wed Jan 02 12:12:30 2019 +0000
@@ -1,14 +1,8 @@
 #include "mbed.h"
 #include "sample_hardware.hpp"
 #include "Sampler.hpp"
-//#include <watchdog_RTOS.h>
 #define WatchDogTimeout 2000
 #define SerialRxFlag 1
-void LCD_Thread(void);
-void SAMP_Thread(void);
-void SERIAL_Thread(void);
-void SERIAL_IRQ(void);
-void Network_Thread(void);
 
 Thread tLCD, tSAMP, tSERIAL, tSD, tNET;
 
@@ -19,13 +13,73 @@
 //Watchdog_RTOS SDWatch;
 //Watchdog_RTOS NetWatch;
 
-Serial m_oSerial(m_oSampler);  // Pass a reference to the Sampler object
+void LCD_Thread()
+{   
+    vector<int> ErrorCodes;
+   // LCDWatch.kick(WatchDogTimeout);
+    while(1)
+    {
+     //   m_oDisplay.LCD_Queue.call_every(1500, LCDWatch.kick);
+        m_oDisplay.LCD_Queue.call_every(1000, &m_oDisplay, &LCD_Data::display_LCD);         //Displays the current sensor information onto the LCD screen every x miliseconds
+        m_oDisplay.LCD_Queue.call_every(1000, &m_oDisplay, &LCD_Data::getSerial2LCD);       //Displays the current sensor information onto the LCD screen every x miliseconds
+                m_oDisplay.LCD_Queue.dispatch();                                                    // Enters WAITING state when blocking 
+        ErrorCodes.push_back(ERROR_LCD_EXIT);                                               // Update Error Vector
+        m_oSerial.SERIAL_Queue.call(&m_oSerial, &Serialcomms::updateErrors, ErrorCodes);    // Pass error vector to the serial thread
+    }
+}
+
+void SAMP_Thread()
+{
+     vector<int> ErrorCodes;
+     //SamplerWatch.kick(WatchDogTimeout);
+     while(1)
+     {
+                //m_oSample.SAMP_Queue.call_every(1500, SamplerWatch.kick);
+        m_oSample.SAMP_Queue.call_every(500, &m_oSample, &Sampler::publishSample);                      // Publish sample default (0.5 Second Tp)
+        m_oSample.SAMP_Queue.call_every(500, &m_oSample, &Sampler::getSerial2Sampler);           // Start the periodic event to check the serial buffer
+              m_oSample.SAMP_Queue.dispatch();                                                                // Enters WAITING state when blocking 
+        ErrorCodes.push_back(ERROR_SAMPLER_EXIT);                                                            // Update Error Vector
+        m_oSerial.SERIAL_Queue.call(&m_oSerial, &Serialcomms::updateErrors, ErrorCodes);     // Pass error vector to the serial thread
+     }
+}
+
+void SERIAL_Thread()
+{
+    vector<int> ErrorCodes;
+        //SerialWatch.kick(WatchDogTimeout);
+     while(1)
+     {
+        //m_oSerial.SERIAL_Queue.call_every(1500, SerialWatch.kick);
+        m_oSerial.SERIAL_Queue.dispatch();                                                               // Enters WAITING state when blocking 
+        ErrorCodes.push_back(ERROR_SERIAL_EXIT);                                                            // Update Error Vector
+     }   
+}
 
 
-// Define member object
-// LCD Defined in Cpp due to use in Sampler.hpp
+void Network_Thread() 
+{ 
+    vector<int> ErrorCodes;
+    while(1) 
+    {
+            
+        m_oNet.Network_Queue.call_every(5000, &m_oNet, &Network::NetPush); 
+        m_oNet.Network_Queue.call_every(1000, &m_oNet, &Network::getSerial2Net);        // Poll the mailbox for an update in time and date
+        m_oNet.Network_Queue.dispatch(); 
+        ErrorCodes.push_back(ERROR_NET_EXIT);                                                            // Update Error Vector
+//        m_oNet.Network_Queue.call(&m_oNet, &Network::updateErrors, ErrorCodes);     // Pass error vector to the serial thread
+    }    
+} 
 
+void SD_Thread() 
+{ 
+    while(1) 
+    { 
+         m_oSD.SDcard_Queue.call_every(5000, &m_oSD, &SDcard::Save_Data); 
+         m_oSD.SDcard_Queue.dispatch(); 
+    } 
+}    
 
+     
 int main()
 {  
     tLCD.start(LCD_Thread);
@@ -36,64 +90,3 @@
     Thread::wait(osWaitForever);
 }
 
-void LCD_Thread()
-{   
-    vector<int> ErrorCodes;
-   // LCDWatch.kick(WatchDogTimeout);
-    while(1)
-    {
-     //   m_oDisplay.LCD_Queue.call_every(1500, LCDWatch.kick);
-        m_oDisplay.LCD_Queue.call_every(1000, &m_oDisplay, &LCD_Data::display_LCD);                     //Displays the current sensor information onto the LCD screen every x miliseconds
-        m_oDisplay.LCD_Queue.dispatch();                                                                // Enters WAITING state when blocking 
-        ErrorCodes.push_back(ERROR_LCD_EXIT);                                                            // Update Error Vector
-        m_oSerial.SERIAL_Queue.call(&m_oSerial, &Serialcomms::updateErrors, ErrorCodes);    // Pass error vector to the serial thread
-    }
-}
-
-void SAMP_Thread()
-{
-     vector<int> ErrorCodes;
-    // SamplerWatch.kick(WatchDogTimeout);
-
-     while(1)
-     {
-     //  m_oSample.SAMP_Queue.call_every(1500, SamplerWatch.kick);
-        m_oSample.SAMP_Queue.call_every(500, &m_oSample, &Sampler::publishSample);                      // Publish sample 
-        m_oSample.SAMP_Queue.dispatch();                                                                // Enters WAITING state when blocking 
-        ErrorCodes.push_back(ERROR_SAMPLER_EXIT);                                                            // Update Error Vector
-        m_oSerial.SERIAL_Queue.call(&m_oSerial, &Serialcomms::updateErrors, ErrorCodes);     // Pass error vector to the serial thread
-
-     }
-}
-
-void SERIAL_Thread()
-{
-    vector<int> ErrorCodes;
-   //  SerialWatch.kick(WatchDogTimeout);
-     while(1)
-     {
-        //m_oSerial.SERIAL_Queue.call_every(1500, SerialWatch.kick);
-        m_oSerial.SERIAL_Queue.dispatch();                                                               // Enters WAITING state when blocking 
-        ErrorCodes.push_back(ERROR_SERIAL_EXIT);                                                            // Update Error Vector
-
-     }   
-}
-
-
-void Network_Thread() 
-{ 
-    while(1) 
-    { 
-         m_oNet.Network_Queue.call_every(10, &m_oNet, &Network::NetPush); 
-         m_oNet.Network_Queue.dispatch(); 
-
-          while(true)  
-        {   // Flash if the event queue is exited. 
-            greenLED = 1; 
-            wait(0.5); 
-            greenLED = 0; 
-            wait(0.1);     
-
-        } 
-    }    
-} 
--- a/messageStruct.hpp	Thu Dec 13 16:09:54 2018 +0000
+++ b/messageStruct.hpp	Wed Jan 02 12:12:30 2019 +0000
@@ -14,14 +14,24 @@
 
 typedef struct
 {
-   string day; //current day, mon - sun
-   string month; //current month, jan - dec
-   string date; //current date, 1-31
-   string time; //current time SS:MM:HH
-   string year; //current year 1970 - 2035?
+   string day;              //current day, mon - sun
+   string month;            //current month, jan - dec
+   string date;             //current date, 1-31
+   string time;             //current time SS:MM:HH
+   string year;             //current year 1970 - 2035?
    
    string current_time; //all of the above in one string, day month  date time year
     
 } time_and_date;
 
-extern time_and_date Timemsg;
\ No newline at end of file
+
+typedef struct
+{
+    time_and_date timestamp;    
+    bool ReadDelete;                    //Read/Write (1/0)
+    signed int numberSamples; // -1 for all else interger
+} SD_message;
+
+
+
+extern time_and_date Timemsg;