Network, SD card, Serial, LCD and sensors all work! :) ** Don't Press the User Button without an SD Card inserted!! **

Dependencies:   BMP280

Fork of Thread_Communication_V2 by BDG

Committer:
GeorgeJourneaux
Date:
Tue Dec 26 21:54:41 2017 +0000
Revision:
6:64d346936f0e
Parent:
5:ea3ec65cbf5f
Child:
7:f017a37bcf1b
READ<n>, DELETE ALL

Who changed what in which revision?

UserRevisionLine numberNew contents of line
benparkes 0:cb3a5c15b01e 1 #include "mbed.h"
benparkes 0:cb3a5c15b01e 2 #include "main.h"
benparkes 0:cb3a5c15b01e 3
GeorgeJourneaux 4:93d6d13d4de3 4 #define ENTER_KEY 1
GeorgeJourneaux 6:64d346936f0e 5 #define MAX_SAMPLES 4
GeorgeJourneaux 4:93d6d13d4de3 6
GeorgeJourneaux 3:73497379c0cb 7 LCD lcd(PD_15, PF_12, PF_13, PE_9, PF_14, PF_15);
GeorgeJourneaux 3:73497379c0cb 8 BMP280 Sensor(D14, D15);
benparkes 0:cb3a5c15b01e 9
GeorgeJourneaux 5:ea3ec65cbf5f 10 //Define Functions
benparkes 0:cb3a5c15b01e 11 void PrintLCD ();
GeorgeJourneaux 2:28d12a3db239 12 void Rx_interrupt();
GeorgeJourneaux 2:28d12a3db239 13 void Serial_CMD();
GeorgeJourneaux 2:28d12a3db239 14
GeorgeJourneaux 5:ea3ec65cbf5f 15 //data FIFO buffer
GeorgeJourneaux 6:64d346936f0e 16 char data_buffer[MAX_SAMPLES][64];
GeorgeJourneaux 6:64d346936f0e 17 int sample_h = 0;
GeorgeJourneaux 6:64d346936f0e 18 int sample_t = 0;
GeorgeJourneaux 5:ea3ec65cbf5f 19 int data_h = 0;
GeorgeJourneaux 5:ea3ec65cbf5f 20 int data_t = 0;
GeorgeJourneaux 5:ea3ec65cbf5f 21 struct tm * sample_epoch;
GeorgeJourneaux 6:64d346936f0e 22 Mutex DataBuffer;
GeorgeJourneaux 5:ea3ec65cbf5f 23
GeorgeJourneaux 3:73497379c0cb 24 //Serial_CMD
GeorgeJourneaux 2:28d12a3db239 25 volatile int rx_in=0;
GeorgeJourneaux 5:ea3ec65cbf5f 26 char rx_buffer[32];
GeorgeJourneaux 3:73497379c0cb 27 time_t raw_time = time(NULL);
GeorgeJourneaux 5:ea3ec65cbf5f 28 char serial_buffer[80];
GeorgeJourneaux 3:73497379c0cb 29
benparkes 1:bca9993a0df3 30 /* Mail */
benparkes 1:bca9993a0df3 31 typedef struct {
benparkes 1:bca9993a0df3 32 float LDR_Value;
benparkes 1:bca9993a0df3 33 float temp_Value;
benparkes 1:bca9993a0df3 34 float press_Value;
benparkes 1:bca9993a0df3 35 } mail_t;
benparkes 1:bca9993a0df3 36
benparkes 1:bca9993a0df3 37 Mail<mail_t, 16> mail_box;
benparkes 0:cb3a5c15b01e 38
GeorgeJourneaux 3:73497379c0cb 39 //Threads
benparkes 0:cb3a5c15b01e 40 Thread t1;
benparkes 0:cb3a5c15b01e 41 Thread t2;
GeorgeJourneaux 2:28d12a3db239 42 Thread S_CMD;
GeorgeJourneaux 3:73497379c0cb 43
GeorgeJourneaux 3:73497379c0cb 44 /*--------------------------------MAIN--------------------------------*/
GeorgeJourneaux 3:73497379c0cb 45 int main() {
benparkes 0:cb3a5c15b01e 46
GeorgeJourneaux 3:73497379c0cb 47 t1.start(PrintLCD);
GeorgeJourneaux 3:73497379c0cb 48
GeorgeJourneaux 3:73497379c0cb 49 pc.baud(9600);
GeorgeJourneaux 3:73497379c0cb 50 pc.attach(&Rx_interrupt, Serial::RxIrq);
GeorgeJourneaux 3:73497379c0cb 51 S_CMD.start(Serial_CMD);
GeorgeJourneaux 5:ea3ec65cbf5f 52
GeorgeJourneaux 3:73497379c0cb 53 while(1) {
GeorgeJourneaux 3:73497379c0cb 54 Green_int = !Green_int;
GeorgeJourneaux 5:ea3ec65cbf5f 55
GeorgeJourneaux 6:64d346936f0e 56 //Read sensors, send to mail-queue
GeorgeJourneaux 3:73497379c0cb 57 mail_t *mail = mail_box.alloc();
GeorgeJourneaux 3:73497379c0cb 58 mail->LDR_Value = LDR_In.read();
GeorgeJourneaux 3:73497379c0cb 59 mail->temp_Value = Sensor.getTemperature();
GeorgeJourneaux 3:73497379c0cb 60 mail->press_Value = Sensor.getPressure();
GeorgeJourneaux 5:ea3ec65cbf5f 61 mail_box.put(mail);
GeorgeJourneaux 6:64d346936f0e 62
GeorgeJourneaux 6:64d346936f0e 63 //Lock data buffer
GeorgeJourneaux 6:64d346936f0e 64 DataBuffer.lock();
GeorgeJourneaux 5:ea3ec65cbf5f 65
GeorgeJourneaux 6:64d346936f0e 66 //Format samples, send to FIFO buffer head
GeorgeJourneaux 6:64d346936f0e 67 memset(data_buffer[sample_h],NULL,64);
GeorgeJourneaux 5:ea3ec65cbf5f 68 time( &raw_time );
GeorgeJourneaux 5:ea3ec65cbf5f 69 sample_epoch = localtime( &raw_time );
GeorgeJourneaux 6:64d346936f0e 70 char sample_time[20];
GeorgeJourneaux 5:ea3ec65cbf5f 71 strftime(sample_time,20,"%d/%m/%Y %X",sample_epoch);
GeorgeJourneaux 6:64d346936f0e 72 sprintf(data_buffer[sample_h],"%s, %2.2f, %4.2f, %.4f\n\r", sample_time, mail->temp_Value, mail->press_Value, mail->LDR_Value);
GeorgeJourneaux 5:ea3ec65cbf5f 73 memset(sample_time,NULL,20);
GeorgeJourneaux 5:ea3ec65cbf5f 74
GeorgeJourneaux 6:64d346936f0e 75 //Set seperate FIFO head and tail for printing data
GeorgeJourneaux 6:64d346936f0e 76 data_h = sample_h;
GeorgeJourneaux 6:64d346936f0e 77 data_t = sample_t;
GeorgeJourneaux 6:64d346936f0e 78
GeorgeJourneaux 6:64d346936f0e 79 //Move sample FIFO buffer head to next row in buffer
GeorgeJourneaux 6:64d346936f0e 80 sample_h++;
GeorgeJourneaux 6:64d346936f0e 81 //Check sample FIFO buffer head
GeorgeJourneaux 6:64d346936f0e 82 if(sample_h >= MAX_SAMPLES){
GeorgeJourneaux 6:64d346936f0e 83 sample_h = 0;
GeorgeJourneaux 5:ea3ec65cbf5f 84 }
GeorgeJourneaux 6:64d346936f0e 85 //Check sample FIFO buffer tail
GeorgeJourneaux 6:64d346936f0e 86 if(sample_t == sample_h){
GeorgeJourneaux 6:64d346936f0e 87 sample_t++;
GeorgeJourneaux 6:64d346936f0e 88 if(sample_t >= (MAX_SAMPLES)){
GeorgeJourneaux 6:64d346936f0e 89 sample_t = 0;
GeorgeJourneaux 5:ea3ec65cbf5f 90 }
GeorgeJourneaux 5:ea3ec65cbf5f 91 }
GeorgeJourneaux 6:64d346936f0e 92 //Unlock data buffer
GeorgeJourneaux 6:64d346936f0e 93 DataBuffer.unlock();
GeorgeJourneaux 5:ea3ec65cbf5f 94
GeorgeJourneaux 3:73497379c0cb 95 Thread::wait (15000);
GeorgeJourneaux 3:73497379c0cb 96 }
GeorgeJourneaux 3:73497379c0cb 97 }
GeorgeJourneaux 3:73497379c0cb 98 /*--------------------------------------------------------------------*/
GeorgeJourneaux 3:73497379c0cb 99
GeorgeJourneaux 3:73497379c0cb 100 /*--------------------------------LCD---------------------------------*/
benparkes 0:cb3a5c15b01e 101 void PrintLCD () {
benparkes 0:cb3a5c15b01e 102
benparkes 0:cb3a5c15b01e 103 int i = 0;
benparkes 0:cb3a5c15b01e 104 while(1){
benparkes 1:bca9993a0df3 105 char lightString[16];
benparkes 1:bca9993a0df3 106 char tempString[16];
benparkes 1:bca9993a0df3 107 char pressString[16];
benparkes 1:bca9993a0df3 108
benparkes 0:cb3a5c15b01e 109 lcd.Clear();
benparkes 0:cb3a5c15b01e 110 lcd.RowSelect(0);
benparkes 1:bca9993a0df3 111
benparkes 0:cb3a5c15b01e 112 switch (i){
GeorgeJourneaux 5:ea3ec65cbf5f 113 case 0:{
GeorgeJourneaux 2:28d12a3db239 114 osEvent evt = mail_box.get();
benparkes 1:bca9993a0df3 115
GeorgeJourneaux 2:28d12a3db239 116 if (evt.status == osEventMail) {
GeorgeJourneaux 2:28d12a3db239 117 mail_t *mail = (mail_t*)evt.value.p;
benparkes 0:cb3a5c15b01e 118
GeorgeJourneaux 2:28d12a3db239 119 sprintf(lightString,"%.4f", mail->LDR_Value);
GeorgeJourneaux 2:28d12a3db239 120 sprintf(tempString,"%2.2f", mail->temp_Value);
GeorgeJourneaux 2:28d12a3db239 121 sprintf(pressString,"%4.2f", mail->press_Value);
benparkes 1:bca9993a0df3 122
GeorgeJourneaux 2:28d12a3db239 123 mail_box.free(mail);
GeorgeJourneaux 2:28d12a3db239 124 }
benparkes 1:bca9993a0df3 125
GeorgeJourneaux 2:28d12a3db239 126 lcd.Write("Light Level:");
GeorgeJourneaux 2:28d12a3db239 127 lcd.RowSelect(1);
GeorgeJourneaux 2:28d12a3db239 128 lcd.Write(lightString);
GeorgeJourneaux 5:ea3ec65cbf5f 129 i++;
benparkes 0:cb3a5c15b01e 130 break;
GeorgeJourneaux 5:ea3ec65cbf5f 131 }
GeorgeJourneaux 2:28d12a3db239 132 case 1:
GeorgeJourneaux 2:28d12a3db239 133 lcd.Write("Temperature:");
GeorgeJourneaux 2:28d12a3db239 134 lcd.RowSelect(1);
GeorgeJourneaux 2:28d12a3db239 135 lcd.Write(tempString);
GeorgeJourneaux 2:28d12a3db239 136 i++;
benparkes 0:cb3a5c15b01e 137 break;
benparkes 0:cb3a5c15b01e 138
GeorgeJourneaux 2:28d12a3db239 139 case 2:
GeorgeJourneaux 2:28d12a3db239 140 lcd.Write("Pressure:");
GeorgeJourneaux 2:28d12a3db239 141 lcd.RowSelect(1);
GeorgeJourneaux 2:28d12a3db239 142 lcd.Write(pressString);
GeorgeJourneaux 5:ea3ec65cbf5f 143 i =0;
benparkes 0:cb3a5c15b01e 144 break;
GeorgeJourneaux 2:28d12a3db239 145
GeorgeJourneaux 5:ea3ec65cbf5f 146 default:
GeorgeJourneaux 5:ea3ec65cbf5f 147 i = 0;
benparkes 0:cb3a5c15b01e 148 break;
benparkes 0:cb3a5c15b01e 149 }
benparkes 0:cb3a5c15b01e 150
GeorgeJourneaux 2:28d12a3db239 151 Red_int = !Red_int;
benparkes 1:bca9993a0df3 152
benparkes 0:cb3a5c15b01e 153 Thread::wait (5000);
GeorgeJourneaux 2:28d12a3db239 154 }
benparkes 0:cb3a5c15b01e 155 }
GeorgeJourneaux 3:73497379c0cb 156 /*--------------------------------------------------------------------*/
benparkes 1:bca9993a0df3 157
GeorgeJourneaux 3:73497379c0cb 158 /*------------------------------SERIAL_CMD----------------------------*/
GeorgeJourneaux 4:93d6d13d4de3 159 //Interrupt when recieving from serial port
GeorgeJourneaux 2:28d12a3db239 160 void Rx_interrupt() {
GeorgeJourneaux 2:28d12a3db239 161
GeorgeJourneaux 6:64d346936f0e 162 //Wait for serial input
GeorgeJourneaux 2:28d12a3db239 163 while (pc.readable()) {
GeorgeJourneaux 6:64d346936f0e 164
GeorgeJourneaux 6:64d346936f0e 165 //Return input to serial
GeorgeJourneaux 5:ea3ec65cbf5f 166 rx_buffer[rx_in] = pc.getc();
GeorgeJourneaux 5:ea3ec65cbf5f 167 pc.putc(rx_buffer[rx_in]);
GeorgeJourneaux 6:64d346936f0e 168
GeorgeJourneaux 6:64d346936f0e 169 //If enter key is pressed, set serial thread signal
GeorgeJourneaux 5:ea3ec65cbf5f 170 if(rx_buffer[rx_in] == 0xD){
GeorgeJourneaux 4:93d6d13d4de3 171 S_CMD.signal_set(ENTER_KEY);
GeorgeJourneaux 2:28d12a3db239 172 }
GeorgeJourneaux 6:64d346936f0e 173
GeorgeJourneaux 6:64d346936f0e 174 //Increment buffer head
GeorgeJourneaux 2:28d12a3db239 175 else{
GeorgeJourneaux 2:28d12a3db239 176 rx_in = (rx_in + 1);
GeorgeJourneaux 2:28d12a3db239 177 }
GeorgeJourneaux 2:28d12a3db239 178 }
GeorgeJourneaux 2:28d12a3db239 179 }
benparkes 0:cb3a5c15b01e 180
GeorgeJourneaux 4:93d6d13d4de3 181 //Check what command what recieved and execute
GeorgeJourneaux 2:28d12a3db239 182 void Serial_CMD(){
GeorgeJourneaux 2:28d12a3db239 183
GeorgeJourneaux 2:28d12a3db239 184 while(1){
GeorgeJourneaux 6:64d346936f0e 185 //Wait for thread signal
GeorgeJourneaux 4:93d6d13d4de3 186 Thread::signal_wait(ENTER_KEY);
GeorgeJourneaux 6:64d346936f0e 187
GeorgeJourneaux 6:64d346936f0e 188 //Detach serial interrupt
GeorgeJourneaux 2:28d12a3db239 189 pc.attach(NULL, Serial::RxIrq);
GeorgeJourneaux 6:64d346936f0e 190
GeorgeJourneaux 3:73497379c0cb 191 struct tm * s_time;
GeorgeJourneaux 3:73497379c0cb 192 char tm_n[4];
GeorgeJourneaux 3:73497379c0cb 193
GeorgeJourneaux 6:64d346936f0e 194 /*----CARRAGE RETURN-------------*/
GeorgeJourneaux 6:64d346936f0e 195 if(rx_buffer[0] == 0xD){
GeorgeJourneaux 6:64d346936f0e 196 pc.puts("\n\r");
GeorgeJourneaux 6:64d346936f0e 197 }
GeorgeJourneaux 6:64d346936f0e 198 /*----READ ALL----------------------------------*/
GeorgeJourneaux 6:64d346936f0e 199 else if(strstr(rx_buffer, "READ ALL")){
GeorgeJourneaux 6:64d346936f0e 200 pc.puts(" READ ALL\n\r");
GeorgeJourneaux 6:64d346936f0e 201
GeorgeJourneaux 6:64d346936f0e 202 //Lock data buffer
GeorgeJourneaux 6:64d346936f0e 203 DataBuffer.lock();
GeorgeJourneaux 6:64d346936f0e 204
GeorgeJourneaux 6:64d346936f0e 205 //Print all samples to serial
GeorgeJourneaux 6:64d346936f0e 206 for(int n=data_t; n<=MAX_SAMPLES; n++){
GeorgeJourneaux 6:64d346936f0e 207 pc.puts(data_buffer[n]);
GeorgeJourneaux 6:64d346936f0e 208 }
GeorgeJourneaux 6:64d346936f0e 209 if(data_t>data_h){
GeorgeJourneaux 6:64d346936f0e 210 for(int n=0; n<=(data_t-1); n++){
GeorgeJourneaux 6:64d346936f0e 211 pc.puts(data_buffer[n]);
GeorgeJourneaux 6:64d346936f0e 212 }
GeorgeJourneaux 6:64d346936f0e 213 }
GeorgeJourneaux 5:ea3ec65cbf5f 214
GeorgeJourneaux 6:64d346936f0e 215 //Lock data buffer
GeorgeJourneaux 6:64d346936f0e 216 DataBuffer.unlock();
GeorgeJourneaux 2:28d12a3db239 217 }
GeorgeJourneaux 6:64d346936f0e 218 /*----DELETE ALL----------------------------------*/
GeorgeJourneaux 5:ea3ec65cbf5f 219 else if(strstr(rx_buffer, "DELETE ALL")){
GeorgeJourneaux 6:64d346936f0e 220 pc.puts(" DELETE ALL\n\r");
GeorgeJourneaux 6:64d346936f0e 221
GeorgeJourneaux 6:64d346936f0e 222 //Lock data buffer
GeorgeJourneaux 6:64d346936f0e 223 DataBuffer.lock();
GeorgeJourneaux 6:64d346936f0e 224
GeorgeJourneaux 6:64d346936f0e 225 //Delete all sampled data
GeorgeJourneaux 6:64d346936f0e 226 for(int n=0; n<=MAX_SAMPLES; n++){
GeorgeJourneaux 6:64d346936f0e 227 memset(data_buffer[n], NULL, 64);
GeorgeJourneaux 6:64d346936f0e 228 }
GeorgeJourneaux 6:64d346936f0e 229 data_h = data_t;
GeorgeJourneaux 6:64d346936f0e 230 sample_h = sample_t;
GeorgeJourneaux 6:64d346936f0e 231
GeorgeJourneaux 6:64d346936f0e 232 //Unlock data buffer
GeorgeJourneaux 6:64d346936f0e 233 DataBuffer.unlock();
GeorgeJourneaux 2:28d12a3db239 234 }
GeorgeJourneaux 6:64d346936f0e 235 /*----READ----------------------------------*/
GeorgeJourneaux 5:ea3ec65cbf5f 236 else if(strstr(rx_buffer, "READ")){
GeorgeJourneaux 6:64d346936f0e 237 pc.puts(" READ \n\r");
GeorgeJourneaux 6:64d346936f0e 238 int N = atoi(strncpy(tm_n,&rx_buffer[5],4));
GeorgeJourneaux 6:64d346936f0e 239 int S = 0;
GeorgeJourneaux 6:64d346936f0e 240 pc.printf("N = %d\n\r",N);
GeorgeJourneaux 6:64d346936f0e 241
GeorgeJourneaux 6:64d346936f0e 242 //Lock data buffer
GeorgeJourneaux 6:64d346936f0e 243 DataBuffer.lock();
GeorgeJourneaux 6:64d346936f0e 244
GeorgeJourneaux 6:64d346936f0e 245 //Check if N is greater than buffer size
GeorgeJourneaux 6:64d346936f0e 246 if(N >= MAX_SAMPLES){
GeorgeJourneaux 6:64d346936f0e 247 N = MAX_SAMPLES;
GeorgeJourneaux 6:64d346936f0e 248 }
GeorgeJourneaux 6:64d346936f0e 249
GeorgeJourneaux 6:64d346936f0e 250 //Read N samples from FIFO buffer
GeorgeJourneaux 6:64d346936f0e 251 if(N <= 0){
GeorgeJourneaux 6:64d346936f0e 252 pc.puts("####ERROR####\n\r");
GeorgeJourneaux 6:64d346936f0e 253 }
GeorgeJourneaux 6:64d346936f0e 254 else{
GeorgeJourneaux 6:64d346936f0e 255 for(int n=data_t; n<=MAX_SAMPLES-1; n++){
GeorgeJourneaux 6:64d346936f0e 256 if(S>=N){}
GeorgeJourneaux 6:64d346936f0e 257 else{
GeorgeJourneaux 6:64d346936f0e 258 pc.puts(data_buffer[n]);
GeorgeJourneaux 6:64d346936f0e 259 S++;
GeorgeJourneaux 6:64d346936f0e 260 }
GeorgeJourneaux 6:64d346936f0e 261 }
GeorgeJourneaux 6:64d346936f0e 262 for(int n=0; n<=data_t; n++){
GeorgeJourneaux 6:64d346936f0e 263 if(S>=N){}
GeorgeJourneaux 6:64d346936f0e 264 else{
GeorgeJourneaux 6:64d346936f0e 265 pc.puts(data_buffer[n]);
GeorgeJourneaux 6:64d346936f0e 266 S++;
GeorgeJourneaux 6:64d346936f0e 267 }
GeorgeJourneaux 6:64d346936f0e 268 }
GeorgeJourneaux 6:64d346936f0e 269 }
GeorgeJourneaux 6:64d346936f0e 270
GeorgeJourneaux 6:64d346936f0e 271 //Unlock data buffer
GeorgeJourneaux 6:64d346936f0e 272 DataBuffer.unlock();
GeorgeJourneaux 2:28d12a3db239 273 }
GeorgeJourneaux 6:64d346936f0e 274 /*----DELETE----------------------------------*/
GeorgeJourneaux 5:ea3ec65cbf5f 275 else if(strstr(rx_buffer, "DELETE")){
GeorgeJourneaux 6:64d346936f0e 276 pc.puts(" DELETE \n\r");
GeorgeJourneaux 3:73497379c0cb 277 }
GeorgeJourneaux 6:64d346936f0e 278 /*----SETDATE----------------------------------*/
GeorgeJourneaux 5:ea3ec65cbf5f 279 else if(strstr(rx_buffer, "SETDATE")){
GeorgeJourneaux 5:ea3ec65cbf5f 280 time(&raw_time);
GeorgeJourneaux 5:ea3ec65cbf5f 281 s_time = localtime(&raw_time);
GeorgeJourneaux 3:73497379c0cb 282
GeorgeJourneaux 6:64d346936f0e 283 //Update day in time structure
GeorgeJourneaux 5:ea3ec65cbf5f 284 int dd = atoi(strncpy(tm_n,&rx_buffer[8],2));
GeorgeJourneaux 3:73497379c0cb 285 s_time->tm_mday = dd;
GeorgeJourneaux 3:73497379c0cb 286 memset(tm_n, NULL, 4);
GeorgeJourneaux 3:73497379c0cb 287
GeorgeJourneaux 6:64d346936f0e 288 //Update month in time structure
GeorgeJourneaux 5:ea3ec65cbf5f 289 int mm = atoi(strncpy(tm_n,&rx_buffer[11],2));
GeorgeJourneaux 3:73497379c0cb 290 s_time->tm_mon = mm-1;
GeorgeJourneaux 3:73497379c0cb 291 memset(tm_n, NULL, 4);
GeorgeJourneaux 3:73497379c0cb 292
GeorgeJourneaux 6:64d346936f0e 293 //Update year in time structure
GeorgeJourneaux 5:ea3ec65cbf5f 294 int yyyy = atoi(strncpy(tm_n,&rx_buffer[14],4));
GeorgeJourneaux 3:73497379c0cb 295 s_time->tm_year = yyyy-1900;
GeorgeJourneaux 3:73497379c0cb 296 memset(tm_n, NULL, 4);
GeorgeJourneaux 3:73497379c0cb 297
GeorgeJourneaux 6:64d346936f0e 298 //Set date from updated time structure
GeorgeJourneaux 3:73497379c0cb 299 set_time(mktime(s_time));
GeorgeJourneaux 6:64d346936f0e 300 strftime(serial_buffer, 80, "\n\r Set Date: %d/%m/%Y\n\r", s_time);
GeorgeJourneaux 5:ea3ec65cbf5f 301 pc.puts(serial_buffer);
GeorgeJourneaux 2:28d12a3db239 302 }
GeorgeJourneaux 6:64d346936f0e 303 /*----SETTIME---------------------------------*/
GeorgeJourneaux 5:ea3ec65cbf5f 304 else if(strstr(rx_buffer, "SETTIME")){
GeorgeJourneaux 5:ea3ec65cbf5f 305 time(&raw_time);
GeorgeJourneaux 5:ea3ec65cbf5f 306 s_time = localtime(&raw_time);
GeorgeJourneaux 3:73497379c0cb 307
GeorgeJourneaux 6:64d346936f0e 308 //Update seconds in time structure
GeorgeJourneaux 5:ea3ec65cbf5f 309 int ss = atoi(strncpy(tm_n,&rx_buffer[14],2));
GeorgeJourneaux 3:73497379c0cb 310 s_time->tm_sec = ss;
GeorgeJourneaux 3:73497379c0cb 311 memset(tm_n, NULL, 4);
GeorgeJourneaux 6:64d346936f0e 312
GeorgeJourneaux 6:64d346936f0e 313 //Update minutes in time structure
GeorgeJourneaux 5:ea3ec65cbf5f 314 int mm = atoi(strncpy(tm_n,&rx_buffer[11],2));
GeorgeJourneaux 3:73497379c0cb 315 s_time->tm_min = mm;
GeorgeJourneaux 3:73497379c0cb 316 memset(tm_n, NULL, 4);
GeorgeJourneaux 3:73497379c0cb 317
GeorgeJourneaux 6:64d346936f0e 318 //Update hour in time structure
GeorgeJourneaux 5:ea3ec65cbf5f 319 int hh = atoi(strncpy(tm_n,&rx_buffer[8],2));
GeorgeJourneaux 3:73497379c0cb 320 s_time->tm_hour = hh;
GeorgeJourneaux 3:73497379c0cb 321 memset(tm_n, NULL, 4);
GeorgeJourneaux 6:64d346936f0e 322
GeorgeJourneaux 6:64d346936f0e 323 //Set time from updated time structure
GeorgeJourneaux 3:73497379c0cb 324 set_time(mktime(s_time));
GeorgeJourneaux 6:64d346936f0e 325 strftime(serial_buffer, 80, "\n\r Set Time: %X\n\r", s_time);
GeorgeJourneaux 5:ea3ec65cbf5f 326 pc.puts(serial_buffer);
GeorgeJourneaux 2:28d12a3db239 327 }
GeorgeJourneaux 6:64d346936f0e 328 /*----SETT----------------------------------*/
GeorgeJourneaux 5:ea3ec65cbf5f 329 else if(strstr(rx_buffer, "SETT")){
GeorgeJourneaux 6:64d346936f0e 330 pc.puts(" SETT\n\r");
GeorgeJourneaux 2:28d12a3db239 331 }
GeorgeJourneaux 6:64d346936f0e 332 /*----STATE----------------------------------*/
GeorgeJourneaux 5:ea3ec65cbf5f 333 else if(strstr(rx_buffer, "STATE")){
GeorgeJourneaux 6:64d346936f0e 334 pc.puts(" STATE\n\r");
GeorgeJourneaux 2:28d12a3db239 335 }
GeorgeJourneaux 6:64d346936f0e 336 /*----LOGGING----------------------------------*/
GeorgeJourneaux 5:ea3ec65cbf5f 337 else if(strstr(rx_buffer, "LOGGING")){
GeorgeJourneaux 6:64d346936f0e 338 pc.puts(" LOGGING\n\r");
GeorgeJourneaux 2:28d12a3db239 339 }
GeorgeJourneaux 6:64d346936f0e 340 /*----ERROR---*/
GeorgeJourneaux 2:28d12a3db239 341 else{
GeorgeJourneaux 6:64d346936f0e 342 pc.puts("####ERROR####\n\r");
GeorgeJourneaux 2:28d12a3db239 343 }
GeorgeJourneaux 6:64d346936f0e 344 /*----------------------------------------------*/
GeorgeJourneaux 6:64d346936f0e 345
GeorgeJourneaux 6:64d346936f0e 346 //Clear serial buffers
GeorgeJourneaux 5:ea3ec65cbf5f 347 memset(serial_buffer, NULL, 80);
GeorgeJourneaux 5:ea3ec65cbf5f 348 memset(rx_buffer, NULL, 32);
GeorgeJourneaux 2:28d12a3db239 349 rx_in = 0;
GeorgeJourneaux 2:28d12a3db239 350
GeorgeJourneaux 6:64d346936f0e 351 //Attach serial interrupt
GeorgeJourneaux 2:28d12a3db239 352 pc.attach(&Rx_interrupt, Serial::RxIrq);
GeorgeJourneaux 2:28d12a3db239 353 }
GeorgeJourneaux 2:28d12a3db239 354 }
GeorgeJourneaux 3:73497379c0cb 355 /*--------------------------------------------------------------------*/