An example Program for the SimpleSerialProtocol Library, This program will receive a packet, then echo it back to the client

Dependencies:   mbed SimpleSerialProtocol MODSERIAL

A simple example program that receives a packet over serial and echos it back.

I include this java program to show an example client application, all this program does is send packets as fast as it can without filling up its output buffer, the mbed will echo these packets back.

This is a good benchmark of the serial connection, and should show about 11KB/s at 115200baud

/media/uploads/p3p/serialecho.zip

example command: java -jar SerialEcho.jar com3 115200

Revision:
11:a051c3f9ca6d
Parent:
10:f6862abba2d5
--- a/TestProtocol.h	Sun Jul 29 19:46:09 2012 +0000
+++ b/TestProtocol.h	Wed Aug 27 18:05:51 2014 +0000
@@ -5,14 +5,16 @@
 #include <SimpleSerialProtocol/Protocol.h>
 
 //class will receive a packet and echo it back out
-class TestProtocol : public SimpleSerialProtocol::Protocol {
+class TestProtocol {
 public:
-    TestProtocol() : Protocol(USBTX, USBRX, LED1) { //LED1 to 4 for a status led, NC to disable
-        receiveCallback(1, this, &TestProtocol::onEchoPacket);
+    TestProtocol() {
+        temp = 0;
+        temp1 = 0;
+        temp2 = 0;
+        temp3 = 0.0f;
     }
     virtual ~TestProtocol() {};
-    void onEchoPacket(SimpleSerialProtocol::Packet* packet);
-    void reply();
+    void onEchoPacket(SimpleSerialProtocol::Protocol* comms, SimpleSerialProtocol::Packet* packet);
 
     class EchoPacket : public SimpleSerialProtocol::Packet {
     public:
@@ -20,6 +22,7 @@
         virtual ~EchoPacket() {}
         
 #pragma pack(push, 1) //must pack the structure to byte boundary for raw recast to work reliably
+                      //this is used in Packet::interpretData and used to validate the packet
         struct Interface {
             Interface() {
                 type = 1; // initialise the type
@@ -35,8 +38,8 @@
     };
 
     uint8_t temp;
-    short temp1;
-    int temp2;
+    uint16_t temp1;
+    uint32_t temp2;
     float temp3;
 };