SEND

Dependencies:   BMP280 LGLCD2

Fork of 0NicksCoursework_copywithserialtime by Liam Grazier

Committer:
liam_grazier
Date:
Tue Jan 09 11:33:14 2018 +0000
Revision:
10:098c2fa0a1a6
Parent:
8:582ac4c5a524
fin commented

Who changed what in which revision?

UserRevisionLine numberNew contents of line
liam_grazier 10:098c2fa0a1a6 1 /* ELEC351 COURSEWORK 2018
liam_grazier 10:098c2fa0a1a6 2 DESIGNED USING MBED ONLINE COMPILER IMPORTED TO KEIL
liam_grazier 10:098c2fa0a1a6 3 LIAM GRAZIER // DOUG TILLEY // ALEX BARON
liam_grazier 10:098c2fa0a1a6 4 */
liam_grazier 8:582ac4c5a524 5 #include "mbed.h"
liam_grazier 8:582ac4c5a524 6 #include "stx.hpp"
liam_grazier 8:582ac4c5a524 7 #include "components.hpp"
liam_grazier 10:098c2fa0a1a6 8 Mutex Sx; //mutex lock for serial tx (Sx) Thread
liam_grazier 10:098c2fa0a1a6 9 char buffer[255]; //buffer used for storing scanf data from serial rx
liam_grazier 10:098c2fa0a1a6 10 int empty = 0; //empty flag
liam_grazier 10:098c2fa0a1a6 11 void welcomemsg(void) //function for welcome msg for the main.
liam_grazier 10:098c2fa0a1a6 12 {
liam_grazier 10:098c2fa0a1a6 13 printf("WELCOME TO ELEC351 ENVIRONMENTAL SERIAL INTERFACE\n\rFOR ASSISTANCE TYPE HELP\n\r"); //msg that is printed
liam_grazier 8:582ac4c5a524 14 }
liam_grazier 10:098c2fa0a1a6 15 void datain(void) //function for scaning the serial rx input and writing to the Char Buffer
liam_grazier 10:098c2fa0a1a6 16 {
liam_grazier 10:098c2fa0a1a6 17 if(empty == 0)
liam_grazier 10:098c2fa0a1a6 18 {
liam_grazier 10:098c2fa0a1a6 19 Sx.lock(); //locks to protect the scan
liam_grazier 10:098c2fa0a1a6 20 scanf("%s", &buffer);
liam_grazier 10:098c2fa0a1a6 21 Sx.unlock();
liam_grazier 8:582ac4c5a524 22 }
liam_grazier 10:098c2fa0a1a6 23 }
liam_grazier 10:098c2fa0a1a6 24 void printcommandlist() //function for printing the command list to the terminal
liam_grazier 10:098c2fa0a1a6 25 {
liam_grazier 8:582ac4c5a524 26 Sx.lock();
liam_grazier 8:582ac4c5a524 27 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" );
liam_grazier 8:582ac4c5a524 28 Sx.unlock();
liam_grazier 10:098c2fa0a1a6 29 }
liam_grazier 10:098c2fa0a1a6 30 void readdata() //function for deciding what to do with the data in the buffer
liam_grazier 10:098c2fa0a1a6 31 {
liam_grazier 10:098c2fa0a1a6 32 if (buffer != "")
liam_grazier 10:098c2fa0a1a6 33 {
liam_grazier 10:098c2fa0a1a6 34 if (strstr(buffer, "READALL"))
liam_grazier 10:098c2fa0a1a6 35 {
liam_grazier 10:098c2fa0a1a6 36 printf("COMMAND NOT AVAILABLE\n\r");//command not coded yet
liam_grazier 8:582ac4c5a524 37 }
liam_grazier 10:098c2fa0a1a6 38 else if(strstr(buffer, "COMMANDLIST")) //prints command list to terminal
liam_grazier 10:098c2fa0a1a6 39 {
liam_grazier 10:098c2fa0a1a6 40 printcommandlist();
liam_grazier 10:098c2fa0a1a6 41 }
liam_grazier 10:098c2fa0a1a6 42 else if(strstr(buffer, "DISPLAYTIME")) //displays current RTC time via command
liam_grazier 10:098c2fa0a1a6 43 {
liam_grazier 10:098c2fa0a1a6 44 DispTime();
liam_grazier 8:582ac4c5a524 45 }
liam_grazier 10:098c2fa0a1a6 46 else if(strstr(buffer, "HELP")) //calls help command
liam_grazier 10:098c2fa0a1a6 47 {
liam_grazier 10:098c2fa0a1a6 48 help();
liam_grazier 8:582ac4c5a524 49 }
liam_grazier 10:098c2fa0a1a6 50 else if(strstr(buffer, "DELETEALL"))//calls delete all records (working)
liam_grazier 10:098c2fa0a1a6 51 {
liam_grazier 10:098c2fa0a1a6 52 deletealldata();
liam_grazier 8:582ac4c5a524 53 }
liam_grazier 10:098c2fa0a1a6 54 else if(strstr(buffer, "SETDATE")) //calls set date function (working)
liam_grazier 10:098c2fa0a1a6 55 {
liam_grazier 10:098c2fa0a1a6 56 rundate();
liam_grazier 8:582ac4c5a524 57 }
liam_grazier 10:098c2fa0a1a6 58 else if(strstr(buffer, "SETTIME")) //calls set time function (WORKING)
liam_grazier 10:098c2fa0a1a6 59 {
liam_grazier 10:098c2fa0a1a6 60 runtime();
liam_grazier 8:582ac4c5a524 61 }
liam_grazier 10:098c2fa0a1a6 62 else if(strstr(buffer, "SETT"))
liam_grazier 10:098c2fa0a1a6 63 {
liam_grazier 10:098c2fa0a1a6 64 printf("ENTER SAMPLING RATE RANGLE 0.1<T<60\n\r");
liam_grazier 10:098c2fa0a1a6 65 printf("COMMAND NOT AVAILABLE\n\r"); //command not coded yet
liam_grazier 8:582ac4c5a524 66 }
liam_grazier 10:098c2fa0a1a6 67 else if(strstr(buffer, "STATEON"))
liam_grazier 10:098c2fa0a1a6 68 {
liam_grazier 10:098c2fa0a1a6 69 printf("COMMAND NOT AVAILABLE\n\r"); //command not coded yet
liam_grazier 8:582ac4c5a524 70 }
liam_grazier 10:098c2fa0a1a6 71 else if(strstr(buffer, "STATEOFF"))
liam_grazier 10:098c2fa0a1a6 72 {
liam_grazier 10:098c2fa0a1a6 73 printf("COMMAND NOT AVAILABLE\n\r"); //command not coded yet
liam_grazier 8:582ac4c5a524 74 }
liam_grazier 10:098c2fa0a1a6 75 else if(strstr(buffer, "LOGGINGON"))
liam_grazier 10:098c2fa0a1a6 76 {
liam_grazier 10:098c2fa0a1a6 77 printf("IF YOU ARE SEEING THIS, NO ISSUES"); //command not coded yet, just a bit of a joke
liam_grazier 8:582ac4c5a524 78 }
liam_grazier 10:098c2fa0a1a6 79 else if(strstr(buffer, "LOGGINGOFF"))
liam_grazier 10:098c2fa0a1a6 80 {
liam_grazier 10:098c2fa0a1a6 81 printf("COMMAND NOT AVAILABLE\n\r"); //command not coded yet
liam_grazier 8:582ac4c5a524 82 }
liam_grazier 8:582ac4c5a524 83 else
liam_grazier 8:582ac4c5a524 84 {
liam_grazier 10:098c2fa0a1a6 85 printf("UNRECOGNISED\n\r"); //returns unrecognised for all comments not matching criteria above
liam_grazier 8:582ac4c5a524 86 }
liam_grazier 10:098c2fa0a1a6 87 }
liam_grazier 10:098c2fa0a1a6 88 }
liam_grazier 10:098c2fa0a1a6 89 void help() //help command
liam_grazier 10:098c2fa0a1a6 90 {
liam_grazier 10:098c2fa0a1a6 91 printf("HELP: \n\rFOR COMMAND LIST, type COMMANDLIST\n\r"); //prints this statement when HELP is typed
liam_grazier 10:098c2fa0a1a6 92 }
liam_grazier 10:098c2fa0a1a6 93 void readalldata() //command not coded (placeholder for code to be called from
liam_grazier 10:098c2fa0a1a6 94 {
liam_grazier 8:582ac4c5a524 95 printf("read all data\n\r");
liam_grazier 10:098c2fa0a1a6 96 }
liam_grazier 10:098c2fa0a1a6 97 void deletealldata()//commadn for wiping the SD (WORKING)
liam_grazier 10:098c2fa0a1a6 98 {
liam_grazier 10:098c2fa0a1a6 99 sdwipe();
liam_grazier 10:098c2fa0a1a6 100 }
liam_grazier 10:098c2fa0a1a6 101 void setT()//command not coded (placeholder for code to be called from
liam_grazier 8:582ac4c5a524 102 {
liam_grazier 8:582ac4c5a524 103 printf("Set Sampling Period 'T'\n\r");
liam_grazier 10:098c2fa0a1a6 104 }
liam_grazier 10:098c2fa0a1a6 105 void stateon()//command not coded (placeholder for code to be called from
liam_grazier 10:098c2fa0a1a6 106 {
liam_grazier 8:582ac4c5a524 107 printf("Set Sampling ON\n\r");
liam_grazier 10:098c2fa0a1a6 108 }
liam_grazier 10:098c2fa0a1a6 109 void stateoff()//command not coded (placeholder for code to be called from
liam_grazier 10:098c2fa0a1a6 110 {
liam_grazier 8:582ac4c5a524 111 printf("Set Sampling OFF\n\r");
liam_grazier 10:098c2fa0a1a6 112 }
liam_grazier 10:098c2fa0a1a6 113 void loggingon()//command not coded (placeholder for code to be called from
liam_grazier 10:098c2fa0a1a6 114 {
liam_grazier 10:098c2fa0a1a6 115 printf("Logging On\n\r");
liam_grazier 10:098c2fa0a1a6 116 }
liam_grazier 10:098c2fa0a1a6 117 void loggingoff() //command not coded (placeholder for code to be called from
liam_grazier 10:098c2fa0a1a6 118 {
liam_grazier 10:098c2fa0a1a6 119 printf("Logging Off\n\r");
liam_grazier 10:098c2fa0a1a6 120 }
liam_grazier 10:098c2fa0a1a6 121 void useseriel()
liam_grazier 10:098c2fa0a1a6 122 {
liam_grazier 10:098c2fa0a1a6 123 help(); //prints the help command when serial init. (this prints in terminal)
liam_grazier 10:098c2fa0a1a6 124 while(true)
liam_grazier 10:098c2fa0a1a6 125 {
liam_grazier 10:098c2fa0a1a6 126 Thread::signal_wait(SIG_SX); //this signal triggers on ticker from main
liam_grazier 10:098c2fa0a1a6 127 datain(); //getdata
liam_grazier 10:098c2fa0a1a6 128 readdata(); //readata and decide what to do with it
liam_grazier 10:098c2fa0a1a6 129 }
liam_grazier 10:098c2fa0a1a6 130 }