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:
- 10:47e6166f0797
- Parent:
- 9:6fb498cf6156
- Child:
- 11:573cf2feced3
--- a/serial_protocol/serial_protocol.cpp Thu Dec 14 16:53:18 2017 +0000 +++ b/serial_protocol/serial_protocol.cpp Fri Dec 15 11:50:57 2017 +0000 @@ -8,7 +8,6 @@ char string1[128]; char string2[128]; -int number; char dayStr[3]; char monthStr[3]; char yearStr[5]; @@ -38,39 +37,36 @@ else if(strcmp(string1,"READ")==0){ int test=0; sscanf(string2,"%d",&test); - + if(test>0){ - number = atoi(string2); - if(number > 0){ - pc.printf("reading <%d>\n",number); - } - else{ - pc.printf("invalid value\n"); - } + pc.printf("reading <%d>\n",test); } else{ - pc.printf("invalid command\n"); - } + pc.printf("invalid value\n"); + } } - + else if(strcmp(string1,"SETT")==0){ + float number=0; + sscanf(string2,"%f",&number); + if(number>=0.1f && number<=60.0f){ + pc.printf("sampling period set to %f\n",number); + } + else{ + pc.printf("invalid value\n"); + } + } else if(strcmp(string1,"DELETE")==0){ int test=0; sscanf(string2,"%d",&test); if(test>0){ - number = atoi(string2); - if(number > 0){ - pc.printf("deleting <%d>\n",number); - } - else{ - pc.printf("invalid value\n"); - } + pc.printf("deleting <%d>\n",test); } else{ - pc.printf("invalid command\n"); - } + pc.printf("invalid value\n"); + } } else if(strcmp(string1,"SETDATE")==0) @@ -86,9 +82,7 @@ validDigit++; } - if(validDigit==9){ - pc.printf("**********SETTING DATE**********\n"); - pc.printf("date string: %s\n", string2); + if(validDigit==9){ dayStr[0] = string2[0]; dayStr[1] = string2[1]; @@ -100,12 +94,11 @@ yearStr[1] = string2[5]; yearStr[2] = string2[6]; yearStr[3] = string2[7]; - yearStr[4] = NULL; + yearStr[4] = NULL; + //note if date is required in int form, use atoi() to convert from string to int - pc.printf("Day = %s\n", dayStr); - pc.printf("Month = %s\n",monthStr); - pc.printf("Year = %s\n",yearStr); - pc.printf("**********DATE SET**********\n"); + pc.printf("DATE UPDATED TO <%s><%s><%s>\n",dayStr,monthStr,yearStr); + } else{ pc.printf("invalid value\n"); @@ -126,8 +119,6 @@ } if(validDigit==7){ - pc.printf("**********SETTING TIME**********\n"); - pc.printf("time string: %s\n", string2); hourStr[0] = string2[0]; hourStr[1] = string2[1]; @@ -137,24 +128,9 @@ 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; - + secondStr[2] = NULL; - pc.printf("Hour = %s\n", hourStr); - pc.printf("Minute = %s\n",minuteStr); - pc.printf("Second = %s\n",secondStr); - pc.printf("**********TIME SET**********\n"); + pc.printf("TIME UPDATE TO <%s><%s><%s>",hourStr,minuteStr,secondStr); } else{ pc.printf("invalid value\n");