Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of 0NicksCoursework_copywithserialtime by
stx.cpp
00001 /* ELEC351 COURSEWORK 2018 00002 DESIGNED USING MBED ONLINE COMPILER IMPORTED TO KEIL 00003 LIAM GRAZIER // DOUG TILLEY // ALEX BARON 00004 */ 00005 #include "mbed.h" 00006 #include "stx.hpp" 00007 #include "components.hpp" 00008 Mutex Sx; //mutex lock for serial tx (Sx) Thread 00009 char buffer[255]; //buffer used for storing scanf data from serial rx 00010 int empty = 0; //empty flag 00011 void welcomemsg(void) //function for welcome msg for the main. 00012 { 00013 printf("WELCOME TO ELEC351 ENVIRONMENTAL SERIAL INTERFACE\n\rFOR ASSISTANCE TYPE HELP\n\r"); //msg that is printed 00014 } 00015 void datain(void) //function for scaning the serial rx input and writing to the Char Buffer 00016 { 00017 if(empty == 0) 00018 { 00019 Sx.lock(); //locks to protect the scan 00020 scanf("%s", &buffer); 00021 Sx.unlock(); 00022 } 00023 } 00024 void printcommandlist() //function for printing the command list to the terminal 00025 { 00026 Sx.lock(); 00027 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" ); 00028 Sx.unlock(); 00029 } 00030 void readdata() //function for deciding what to do with the data in the buffer 00031 { 00032 if (buffer != "") 00033 { 00034 if (strstr(buffer, "READALL")) 00035 { 00036 printf("COMMAND NOT AVAILABLE\n\r");//command not coded yet 00037 } 00038 else if(strstr(buffer, "COMMANDLIST")) //prints command list to terminal 00039 { 00040 printcommandlist(); 00041 } 00042 else if(strstr(buffer, "DISPLAYTIME")) //displays current RTC time via command 00043 { 00044 DispTime(); 00045 } 00046 else if(strstr(buffer, "HELP")) //calls help command 00047 { 00048 help(); 00049 } 00050 else if(strstr(buffer, "DELETEALL"))//calls delete all records (working) 00051 { 00052 deletealldata(); 00053 } 00054 else if(strstr(buffer, "SETDATE")) //calls set date function (working) 00055 { 00056 rundate(); 00057 } 00058 else if(strstr(buffer, "SETTIME")) //calls set time function (WORKING) 00059 { 00060 runtime(); 00061 } 00062 else if(strstr(buffer, "SETT")) 00063 { 00064 printf("ENTER SAMPLING RATE RANGLE 0.1<T<60\n\r"); 00065 printf("COMMAND NOT AVAILABLE\n\r"); //command not coded yet 00066 } 00067 else if(strstr(buffer, "STATEON")) 00068 { 00069 printf("COMMAND NOT AVAILABLE\n\r"); //command not coded yet 00070 } 00071 else if(strstr(buffer, "STATEOFF")) 00072 { 00073 printf("COMMAND NOT AVAILABLE\n\r"); //command not coded yet 00074 } 00075 else if(strstr(buffer, "LOGGINGON")) 00076 { 00077 printf("IF YOU ARE SEEING THIS, NO ISSUES"); //command not coded yet, just a bit of a joke 00078 } 00079 else if(strstr(buffer, "LOGGINGOFF")) 00080 { 00081 printf("COMMAND NOT AVAILABLE\n\r"); //command not coded yet 00082 } 00083 else 00084 { 00085 printf("UNRECOGNISED\n\r"); //returns unrecognised for all comments not matching criteria above 00086 } 00087 } 00088 } 00089 void help() //help command 00090 { 00091 printf("HELP: \n\rFOR COMMAND LIST, type COMMANDLIST\n\r"); //prints this statement when HELP is typed 00092 } 00093 void readalldata() //command not coded (placeholder for code to be called from 00094 { 00095 printf("read all data\n\r"); 00096 } 00097 void deletealldata()//commadn for wiping the SD (WORKING) 00098 { 00099 sdwipe(); 00100 } 00101 void setT()//command not coded (placeholder for code to be called from 00102 { 00103 printf("Set Sampling Period 'T'\n\r"); 00104 } 00105 void stateon()//command not coded (placeholder for code to be called from 00106 { 00107 printf("Set Sampling ON\n\r"); 00108 } 00109 void stateoff()//command not coded (placeholder for code to be called from 00110 { 00111 printf("Set Sampling OFF\n\r"); 00112 } 00113 void loggingon()//command not coded (placeholder for code to be called from 00114 { 00115 printf("Logging On\n\r"); 00116 } 00117 void loggingoff() //command not coded (placeholder for code to be called from 00118 { 00119 printf("Logging Off\n\r"); 00120 } 00121 void useseriel() 00122 { 00123 help(); //prints the help command when serial init. (this prints in terminal) 00124 while(true) 00125 { 00126 Thread::signal_wait(SIG_SX); //this signal triggers on ticker from main 00127 datain(); //getdata 00128 readdata(); //readata and decide what to do with it 00129 } 00130 }
Generated on Sun Jul 17 2022 05:50:34 by
 1.7.2
 1.7.2 
    