Liam Grazier / Mbed OS Final351CWfolderonly

Fork of Final351CW_FINAL by Liam Grazier

Revision:
10:098c2fa0a1a6
Parent:
8:582ac4c5a524
--- a/serialtx/stx.cpp	Tue Jan 09 06:14:41 2018 +0000
+++ b/serialtx/stx.cpp	Tue Jan 09 11:33:14 2018 +0000
@@ -1,109 +1,130 @@
+/*   ELEC351 COURSEWORK 2018 
+DESIGNED USING MBED ONLINE COMPILER IMPORTED TO KEIL
+LIAM GRAZIER // DOUG TILLEY // ALEX BARON 
+ */
 #include "mbed.h"
 #include "stx.hpp"
 #include "components.hpp"
-Mutex Sx;
-char buffer[255];
-int empty = 0; 
-void welcomemsg(void){
-printf("WELCOME TO ELEC351 ENVIRONMENTAL SERIAL INTERFACE\n\rFOR ASSISTANCE TYPE HELP\n\r");
+Mutex Sx; //mutex lock for serial tx (Sx) Thread
+char buffer[255]; //buffer used for storing scanf data from serial rx
+int empty = 0; //empty flag
+void welcomemsg(void) //function for welcome msg for the main.
+{
+    printf("WELCOME TO ELEC351 ENVIRONMENTAL SERIAL INTERFACE\n\rFOR ASSISTANCE TYPE HELP\n\r"); //msg that is printed
 }
-void datain(void){
-    if(empty == 0){
-     Sx.lock();
-     scanf("%s", &buffer);
-     Sx.unlock();
-     }
+void datain(void) //function for scaning the serial rx input and writing to the Char Buffer 
+{
+    if(empty == 0)
+    {
+        Sx.lock(); //locks to protect the scan
+        scanf("%s", &buffer);
+        Sx.unlock();
     }
-void printcommandlist(){
+}
+void printcommandlist() //function for printing the command list to the terminal
+{
     Sx.lock();
     printf("Command List:\n\r READALL\n\r DELETEALL\n\r SETDATE\n\r DISPLAYTIME\n\r SETTIME\n\r SETT\n\r STATEON(Sampling State)\n\r STATEOFF(Sampling State)\n\r LOGGINGON\n\r LOGGINGOFF\n\r COMMANDLIST\n\r" );
     Sx.unlock();
-    }
-void readdata(){
-    if (buffer != ""){
-     if (strstr(buffer, "READALL")){
-        readalldata();
-        }
-        else if(strstr(buffer, "COMMANDLIST")){
-        printcommandlist();   
+}
+void readdata() //function for deciding what to do with the data in the buffer
+{
+    if (buffer != "")
+    {
+        if (strstr(buffer, "READALL"))
+        {
+            printf("COMMAND NOT AVAILABLE\n\r");//command not coded yet
         }
-        else if(strstr(buffer, "DISPLAYTIME")){
-        printcommandlist();   
+        else if(strstr(buffer, "COMMANDLIST")) //prints command list to terminal
+        {
+            printcommandlist();   
+        }
+        else if(strstr(buffer, "DISPLAYTIME")) //displays current RTC time via command 
+        {
+            DispTime();  
         }
-        else if(strstr(buffer, "HELP")){
-        help();   
+        else if(strstr(buffer, "HELP")) //calls help command 
+        {
+            help();   
         }
-        else if(strstr(buffer, "DELETEALL")){
-        deletealldata();
+        else if(strstr(buffer, "DELETEALL"))//calls delete all records (working)
+        {
+            deletealldata();
         }
-        else if(strstr(buffer, "SETDATE")){////////COME BACK HERE LATE
-        rundate();
+        else if(strstr(buffer, "SETDATE")) //calls set date function (working)
+        {
+            rundate();
         }
-        else if(strstr(buffer, "SETTIME")){////////COME BACK HERE LATE
-        runtime();
+        else if(strstr(buffer, "SETTIME")) //calls set time function (WORKING)
+        {
+            runtime();
         }
-        else if(strstr(buffer, "SETT")){////////COME BACK HERE LATE
-        setT();
+        else if(strstr(buffer, "SETT"))
+        {
+            printf("ENTER SAMPLING RATE RANGLE 0.1<T<60\n\r");
+            printf("COMMAND NOT AVAILABLE\n\r"); //command not coded yet
         }
-        else if(strstr(buffer, "STATEON")){
-        stateon();
+        else if(strstr(buffer, "STATEON"))
+        {
+            printf("COMMAND NOT AVAILABLE\n\r"); //command not coded yet
         }
-        else if(strstr(buffer, "STATEOFF")){
-        stateoff();
+            else if(strstr(buffer, "STATEOFF"))
+        {
+            printf("COMMAND NOT AVAILABLE\n\r"); //command not coded yet
         }
-        else if(strstr(buffer, "LOGGINGON")){
-        loggingon();
+        else if(strstr(buffer, "LOGGINGON"))
+        {
+            printf("IF YOU ARE SEEING THIS, NO ISSUES"); //command not coded yet, just a bit of a joke
         }
-        else if(strstr(buffer, "LOGGINGOFF")){
-        loggingoff();
+        else if(strstr(buffer, "LOGGINGOFF"))
+        {
+            printf("COMMAND NOT AVAILABLE\n\r"); //command not coded yet
         }
         else
         {
-        printf("UNRECOGNISED\n\r");
+            printf("UNRECOGNISED\n\r"); //returns unrecognised for all comments not matching criteria above
         }
-       }
-       }
-void help(){
-    printf("HELP: \n\rFOR COMMAND LIST, type COMMANDLIST\n\r");
-    }    
-void readalldata(){
+    }
+}
+void help() //help command 
+{
+    printf("HELP: \n\rFOR COMMAND LIST, type COMMANDLIST\n\r"); //prints this statement when HELP is typed
+}    
+void readalldata() //command not coded (placeholder for code to be called from
+{
     printf("read all data\n\r");
-    } //displays date, tim, temperature, presure, ligt
-void deletealldata(){
-    printf("delete all data \n\r");
-    } //deletes all memory from th iternal memory
-void setdate(){
-    printf("Set Date\n\r");
-    } //sets the day month and year
-void settime(){
-printf("Set Time\n\r");
-} //sets the clock hours, minutes, seconds
-void setT()
+} 
+void deletealldata()//commadn for wiping the SD (WORKING)
+{
+    sdwipe();
+}
+void setT()//command not coded (placeholder for code to be called from
 {
     printf("Set Sampling Period 'T'\n\r");
-    } //sets the sampling period to <T> seconds
-void stateon(){
+} 
+void stateon()//command not coded (placeholder for code to be called from
+{
     printf("Set Sampling ON\n\r");
-    } //turns ampling ON and OFF
-void stateoff(){
+} 
+void stateoff()//command not coded (placeholder for code to be called from
+{
     printf("Set Sampling OFF\n\r");
-    } 
-void loggingon(){
-    
-    printf("Logging On\n\r");
-    } 
-void loggingoff(){
-    
-    printf("Logging Off\n\r");
-    }    
-    //turns diagnostic logging ON and OFF
-void useseriel(){
-  
-    help();
-    while(true){
-     Thread::signal_wait(SIG_SX);
-     datain();
-     readdata();
-                }
-        }   
-           
\ No newline at end of file
+} 
+void loggingon()//command not coded (placeholder for code to be called from
+{
+printf("Logging On\n\r");
+} 
+void loggingoff() //command not coded (placeholder for code to be called from
+{
+printf("Logging Off\n\r");
+}    
+void useseriel()
+{
+    help(); //prints the help command when serial init. (this prints in terminal)
+    while(true)
+    {
+        Thread::signal_wait(SIG_SX); //this signal triggers on ticker from main
+        datain(); //getdata
+        readdata(); //readata and decide what to do with it 
+    }
+}