simple serial protocol

Dependents:   AwsomeStation LoRaBaseStation LoRaTerminal

Revision:
1:03208c983c8b
Parent:
0:21e4e3afa5e6
Child:
3:22bb958f0eb0
--- a/SerialInterfaceProtocol.cpp	Sun Jun 19 01:37:43 2016 +0000
+++ b/SerialInterfaceProtocol.cpp	Wed Jul 13 03:41:58 2016 +0000
@@ -1,4 +1,5 @@
 #include "SerialInterfaceProtocol.h"
+#include "mbed.h"
 
 // #define DEBUG_MESSAGE
 
@@ -77,7 +78,7 @@
     memset(buffer, 0x0, total_len);
     
     PacketBuffer.serialize(buffer);
-    
+
     // add to ring buffer
     for (int i = 0; i < total_len; i++)
     {
@@ -203,7 +204,9 @@
                     }
                     else // checksum mismatch
                     {
-                        PacketBuffer.errno = CommandPacket::INVALID_CS_ERROR;
+                        // clear response and response length
+                        response_length = 0;
+                        memset(response, 0x0, sizeof(response));
                         
                         // prepare for checksum error response
                         PacketBuffer.errno = CommandPacket::INVALID_CS_ERROR;
@@ -253,9 +256,11 @@
                 break;
                 
             case CommandPacket::NONE:
-                PacketBuffer.errno = CommandPacket::INVALID_SFLAG_ERROR;
+                // clear response and response length
+                response_length = 0;
+                memset(response, 0x0, sizeof(response));
                 
-                // TODO:: Execute error generator
+                // Execute error generator
                 PacketBuffer.errno = CommandPacket::INVALID_SFLAG_ERROR;
                 assemble(response, response_length);