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:
- 13:aa200749dba6
- Parent:
- 12:4af6b1d09c90
--- a/serial_protocol/serial_protocol.cpp Fri Dec 15 12:00:59 2017 +0000 +++ b/serial_protocol/serial_protocol.cpp Fri Dec 15 16:13:06 2017 +0000 @@ -1,12 +1,20 @@ +/*This module enables a user to communicate with the system using a serial +connection, commands can be sent using a terminal emulator +*/ #include "serial_protocol.hpp" #include "sample_hardware.hpp" #include <string> #include <ctype.h> + +#define SETT_UPPER_BOUND 60.0f //upper bound for sampling period +#define SETT_LOWER_BOUND 0.1f //lower bound for sampling period + + Serial pc(SERIAL_TX, SERIAL_RX); -char string1[128]; -char string2[128]; +char string1[32]; +char string2[32]; char dayStr[3]; char monthStr[3]; @@ -17,14 +25,19 @@ int day; int month; int year; +int readSamples=0; +int deleteSamples=0; +float sampleRate=0; - +//reads serial keyboard input from pc void getData(){ pc.scanf("%s %s", string1, string2); //pc.printf("%s %s\n",string1, string2); \\for debugging } +//compares strings received from getData function against available commands +//can alter global variables void readSerial(){ if((strcmp(string1,"READ")==0) && (strcmp(string2,"ALL")==0)){ pc.printf("reading all\n"); @@ -35,11 +48,12 @@ } else if(strcmp(string1,"READ")==0){ - int test=0; - sscanf(string2,"%d",&test); + int num=0; + sscanf(string2,"%d",&num); - if(test>0){ - pc.printf("reading <%d>\n",test); + if(num>0){ + readSamples = num; + pc.printf("reading <%d>\n",readSamples); } else{ pc.printf("invalid value\n"); @@ -73,8 +87,9 @@ 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); + if(number>=SETT_LOWER_BOUND && number<=SETT_UPPER_BOUND){ + sampleRate = number; + pc.printf("sampling period set to %f\n",sampleRate); } else{ pc.printf("invalid value\n"); @@ -82,11 +97,12 @@ } else if(strcmp(string1,"DELETE")==0){ - int test=0; - sscanf(string2,"%d",&test); + int num=0; + sscanf(string2,"%d",&num); - if(test>0){ - pc.printf("deleting <%d>\n",test); + if(num>0){ + deleteSamples=num; + pc.printf("deleting <%d>\n",deleteSamples); } else{ pc.printf("invalid value\n"); @@ -154,7 +170,7 @@ secondStr[1] = string2[5]; secondStr[2] = NULL; - pc.printf("TIME UPDATE TO <%s><%s><%s>",hourStr,minuteStr,secondStr); + pc.printf("TIME UPDATE TO <%s><%s><%s>\n",hourStr,minuteStr,secondStr); } else{ pc.printf("invalid value\n");