Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Comms.cpp
- Revision:
- 0:7d01a895b45d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Comms.cpp	Tue Sep 19 11:53:38 2017 +0000
@@ -0,0 +1,39 @@
+#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;   
+    } 
+}
+
+       
\ No newline at end of file