A library to send and receive packets over serial, uses MODSERIAL

Dependents:   SimpleSerialProtocolExample SerialFileReceiver

Revision:
3:5caff50e14a7
Parent:
2:43794e0b738f
--- a/Protocol.cpp	Thu Sep 18 17:37:04 2014 +0000
+++ b/Protocol.cpp	Fri Sep 19 15:51:05 2014 +0000
@@ -4,7 +4,7 @@
 
 Protocol::Protocol(PinName tx, PinName rx, PinName led_pin) : MODSERIAL(tx, rx, 64, 512), _receive_led(led_pin), _send_buffer(512){
     _receive_timeout.start();
-    codec = 0;
+    codec = &default_codec;
 }
 
 Protocol::~Protocol() {
@@ -39,6 +39,7 @@
             }
         }
         _packet.reset();
+        _receive_led = 0;
     }
 }
 
@@ -66,7 +67,7 @@
 
 void Protocol::receive() {
     _receive_timeout.reset();
-    while (MODSERIAL::rxBufferGetCount() > 0 &&  _receive_timeout.read_us() < 50) {
+    while ((MODSERIAL::rxBufferGetCount() > 0 &&  _receive_timeout.read_us() < 50) && !_packet._valid) {
         if(codec){
             codec->decode(&_packet, MODSERIAL::getc());
         }