test to establish how we can share the project on MBED
Dependencies: BME280 BMP280 ELEC350-Coursework-2017 TextLCD
Fork of ELEC350-CWTEMPLATE-2017 by
Diff: serial_protocol/serial_protocol.cpp
- Revision:
- 9:6fb498cf6156
- Parent:
- 8:e3aff00ef600
- Child:
- 10:47e6166f0797
diff -r e3aff00ef600 -r 6fb498cf6156 serial_protocol/serial_protocol.cpp --- a/serial_protocol/serial_protocol.cpp Thu Dec 14 16:44:07 2017 +0000 +++ b/serial_protocol/serial_protocol.cpp Thu Dec 14 16:53:18 2017 +0000 @@ -12,6 +12,9 @@ char dayStr[3]; char monthStr[3]; char yearStr[5]; +char hourStr[3]; +char minuteStr[3]; +char secondStr[3]; int day; int month; int year; @@ -108,6 +111,55 @@ pc.printf("invalid value\n"); } } + + else if(strcmp(string1,"SETTIME")==0) + { + int validDigit=0; + int i; + for(i=0;i<6;i++){ //check first 8 elements of array are digits + if(isdigit(string2[i])){ + validDigit++; + } + } + if(string2[6] == NULL){ //check element 8 of array is NULL, where the string terminates + validDigit++; + } + + if(validDigit==7){ + pc.printf("**********SETTING TIME**********\n"); + pc.printf("time string: %s\n", string2); + + hourStr[0] = string2[0]; + hourStr[1] = string2[1]; + hourStr[2] = NULL; + minuteStr[0] = string2[2]; + minuteStr[1] = string2[3]; + minuteStr[2] = NULL; + secondStr[0] = string2[4]; + secondStr[1] = string2[5]; + secondStr[2] = NULL; + // dayStr[0] = string2[0]; +// dayStr[1] = string2[1]; +// dayStr[2] = NULL; +// monthStr[0] = string2[2]; +// monthStr[1] = string2[3]; +// monthStr[2] = NULL; +// yearStr[0] = string2[4]; +// yearStr[1] = string2[5]; +// yearStr[2] = string2[6]; +// yearStr[3] = string2[7]; +// yearStr[4] = NULL; + + + pc.printf("Hour = %s\n", hourStr); + pc.printf("Minute = %s\n",minuteStr); + pc.printf("Second = %s\n",secondStr); + pc.printf("**********TIME SET**********\n"); + } + else{ + pc.printf("invalid value\n"); + } + } else{ pc.printf("invalid command\n");