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:
- 6:c7220f7c1ae0
- Child:
- 8:e3aff00ef600
diff -r d8e149da9f3f -r c7220f7c1ae0 serial_protocol/serial_protocol.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/serial_protocol/serial_protocol.cpp Thu Dec 14 12:30:30 2017 +0000 @@ -0,0 +1,105 @@ +#include "serial_protocol.hpp" +#include "sample_hardware.hpp" +//#include <iostream> +#include <string> +Serial pc(SERIAL_TX, SERIAL_RX); + +using namespace std; + + +char string1[128]; +char string2[128]; + + +//std::string string1; +//std::string string2; +int number; +//string dayStr; +char dayStr[3]; +char monthStr[3]; +char yearStr[5]; +int day; +int month; +int year; + + +void getData(){ + pc.scanf("%s %s", string1, string2); + //pc.printf("%s %s", string1, string2); + + +} + +void readSerial(){ + if((strcmp(string1,"READ")==0) && (strcmp(string2,"ALL")==0)){ + //if((string1.compare("READ") == 0) && (string2.compare("ALL") == 0)){ + pc.printf("reading all\n"); + } + + else if((strcmp(string1,"DELETE")==0) && (strcmp(string2,"ALL")==0)){ + //else if((string1.compare("DELETE")==0) && (string2.compare("ALL")==0)){ + pc.printf("deleting all\n"); + } + + else if(strcmp(string1,"READ")==0){ + //else if(string1.compare("READ")==0){ + if(sscanf(string2,"%d")>0){ + number = atoi(string2); + if(number > 0){ + pc.printf("reading <%d>\n",number); + } + else{ + pc.printf("invalid value\n"); + } + } + else{ + pc.printf("invalid command\n"); + } + } + + else if(strcmp(string1,"DELETE")==0){ + if(sscanf(string2,"%d")>0){ + number = atoi(string2); + if(number > 0){ + pc.printf("deleting <%d>\n",number); + } + else{ + pc.printf("invalid value\n"); + } + } + else{ + pc.printf("invalid command\n"); + } + + } + + else if(strcmp(string1,"SETDATE")==0) + { + pc.printf("Setdate started\n\r"); + if(sscanf(string2,"%8s") > 0) + { + pc.printf("date string is %s\n\r", string2); + + 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("Day = %s Month = %s Year = %s\n\r", dayStr, monthStr, yearStr); + } + else{ + pc.printf("invalid value\n"); + } + } + + else{ + pc.printf("invalid command\n"); + } +}