Comms Library for communicating via bluetooth
Comms.cpp
- Committer:
- Armand
- Date:
- 2017-09-19
- Revision:
- 0:7d01a895b45d
File content as of revision 0:7d01a895b45d:
#include "Comms.h" #include "mbed.h" Comms::Comms(PinName TX, PinName RX) : RawSerial(TX, RX) { msg_counter = 0; newmsg = false; attach(this, &Comms::commsinterrupt); } void Comms::commsinterrupt() { char c = getc(); //read the incoming character if(c == '!') { msg_counter = 0; } else if(c == '#') { msg[msg_counter] = '\0'; newmsg = true; //enable the new message flag to indicate a COMPLETE message was received msg_counter = 0; //clear the message string } else { msg[msg_counter] = c; //add the character to the message string msg_counter++; //move to the next character in the string } if(newmsg == true) { sscanf(msg,"%s %f", &cmd, &data); newmsg = false; } }