Mdot control and communication for the exosonde

Dependencies:   libmDot-mbed5 mbed

Committer:
brettsawyers
Date:
Mon Aug 28 22:46:55 2017 +0000
Revision:
1:3bb9d88c2646
Parent:
0:d8d49519a14a
Child:
2:e7e272186bf2
removed dynamic memory calls, use a set 256 buffer for sonde now

Who changed what in which revision?

UserRevisionLine numberNew contents of line
brettsawyers 0:d8d49519a14a 1 #include "mbed.h"
brettsawyers 0:d8d49519a14a 2 #include "mDot.h"
brettsawyers 0:d8d49519a14a 3 #include "MTSLog.h"
brettsawyers 0:d8d49519a14a 4 #include <string>
brettsawyers 0:d8d49519a14a 5 #include <vector>
brettsawyers 0:d8d49519a14a 6 #include <algorithm>
brettsawyers 0:d8d49519a14a 7
brettsawyers 1:3bb9d88c2646 8 char sonde_buffer[256];
brettsawyers 1:3bb9d88c2646 9 void flushRXbuffer(Serial *serial){
brettsawyers 1:3bb9d88c2646 10 while(serial -> readable()) serial -> getc();
brettsawyers 1:3bb9d88c2646 11 }
brettsawyers 1:3bb9d88c2646 12
brettsawyers 1:3bb9d88c2646 13 bool checkforcomma(Serial *debugger){
brettsawyers 1:3bb9d88c2646 14 debugger -> printf("received: %s\r\n",sonde_buffer);
brettsawyers 1:3bb9d88c2646 15 for(int i = 0; i < strlen(sonde_buffer); i++) {
brettsawyers 1:3bb9d88c2646 16 if(sonde_buffer[i] == ','){
brettsawyers 1:3bb9d88c2646 17 return true;
brettsawyers 1:3bb9d88c2646 18 }
brettsawyers 1:3bb9d88c2646 19 }
brettsawyers 1:3bb9d88c2646 20 return false;
brettsawyers 1:3bb9d88c2646 21 }
brettsawyers 1:3bb9d88c2646 22
brettsawyers 1:3bb9d88c2646 23 void getsondedata(Serial *device, Serial *debugger){
brettsawyers 1:3bb9d88c2646 24 char datachar;
brettsawyers 1:3bb9d88c2646 25 device -> printf("data\r\n");
brettsawyers 1:3bb9d88c2646 26 int charcount = 0;
brettsawyers 1:3bb9d88c2646 27 while(datachar = device -> getc(),datachar != '\r' && datachar != '\n'){
brettsawyers 1:3bb9d88c2646 28 sonde_buffer[charcount] = datachar;
brettsawyers 1:3bb9d88c2646 29 charcount++;
brettsawyers 1:3bb9d88c2646 30 }
brettsawyers 1:3bb9d88c2646 31 //flush the remaining '\n' character from the buffer
brettsawyers 1:3bb9d88c2646 32 flushRXbuffer(device);
brettsawyers 1:3bb9d88c2646 33 sonde_buffer[charcount] = '\0';
brettsawyers 1:3bb9d88c2646 34 }
brettsawyers 1:3bb9d88c2646 35
brettsawyers 1:3bb9d88c2646 36 void setcommadelim(Serial *device){
brettsawyers 1:3bb9d88c2646 37 device -> printf("delim 2\r\n");
brettsawyers 1:3bb9d88c2646 38 }
brettsawyers 0:d8d49519a14a 39 int main() {
brettsawyers 1:3bb9d88c2646 40 Serial device(USBTX, USBRX); //will need to change this to the appropriate pins once connected ot the exosonde
brettsawyers 1:3bb9d88c2646 41 Serial debugger(USBTX,USBRX);
brettsawyers 1:3bb9d88c2646 42 while(1){
brettsawyers 1:3bb9d88c2646 43 getsondedata(&device, &debugger);
brettsawyers 1:3bb9d88c2646 44 debugger.printf("sonde: %s\r\n",sonde_buffer);
brettsawyers 1:3bb9d88c2646 45 if(!checkforcomma(&debugger)){
brettsawyers 1:3bb9d88c2646 46 setcommadelim(&device);
brettsawyers 1:3bb9d88c2646 47 continue;
brettsawyers 0:d8d49519a14a 48 }
brettsawyers 1:3bb9d88c2646 49 }
brettsawyers 1:3bb9d88c2646 50 }
brettsawyers 1:3bb9d88c2646 51