Experiment of serial command protocol

Dependencies:   RingBuffer SerialInterfaceProtocol duinotech_16x2_LCD mbed

You can edit this area

Revision:
3:0c4aa3cec685
Parent:
2:54932809c7b2
--- a/main.cpp	Thu Jun 09 12:28:31 2016 +0000
+++ b/main.cpp	Thu Jun 16 03:52:01 2016 +0000
@@ -147,6 +147,24 @@
     
     return 0;
 }
+
+int setBaudRate(uint8_t *payload, uint8_t payload_length, uint8_t *response, uint8_t *response_length)
+{  
+    int baudRate = atoi((char *)payload);
+    
+    // set baud rate
+    pc.baud(baudRate);
+    
+    return 0;
+}
+
+int echoPayload(uint8_t *payload, uint8_t payload_length, uint8_t *response, uint8_t *response_length)
+{
+    memcpy(response, payload, payload_length);
+    *response_length = payload_length;
+
+    return 0;
+}
  
 int main() {
     // turn on the back light (it's off by default)
@@ -158,6 +176,10 @@
     
     // control
     SIP.registerCommand(0x00, toggleChecksum);
+    SIP.registerCommand(0x01, setBaudRate);
+    
+    // misc
+    SIP.registerCommand(0xe0, echoPayload);
     
     // lcd
     SIP.registerCommand(0xf0, toggleLcdBackLight);