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:
3:8ac7e37d0e0e
Child:
12:1d1d8425c79c
--- a/TestProtocol.cpp	Sun Jul 29 19:46:09 2012 +0000
+++ b/TestProtocol.cpp	Wed Aug 27 18:05:51 2014 +0000
@@ -1,6 +1,6 @@
 #include "TestProtocol.h"
 
-void TestProtocol::onEchoPacket(SimpleSerialProtocol::Packet* packet){
+void TestProtocol::onEchoPacket(SimpleSerialProtocol::Protocol* comms, SimpleSerialProtocol::Packet* packet){
     if(!packet)return;
     if (packet->_valid) {
         EchoPacket::Interface* interface = packet->interpretData<EchoPacket::Interface>();
@@ -9,18 +9,16 @@
             temp1 = interface->datashort;
             temp2 = interface->dataint;
             temp3 = interface->datafloat;
-            reply();
+            
+            //we can use the Protocol pointer to send a response from the callback
+            EchoPacket echoMessage; // initialise a packet to send
+            echoMessage.interface.data = temp;
+            echoMessage.interface.datashort = temp1;
+            echoMessage.interface.dataint = temp2;
+            echoMessage.interface.datafloat = temp3;
+            echoMessage.buildData<EchoPacket::Interface>(&echoMessage.interface);
+            comms->sendPacket(&echoMessage); //send the packet (async)
         }
     }
     return;
-}
-
-void TestProtocol::reply() {
-    EchoPacket echoMessage; // initialise a packet to send
-    echoMessage.interface.data = temp;
-    echoMessage.interface.datashort = temp1;
-    echoMessage.interface.dataint = temp2;
-    echoMessage.interface.datafloat = temp3;
-    echoMessage.buildData<EchoPacket::Interface>(&echoMessage.interface);
-    sendPacket(&echoMessage); //send the packet (async)
 }
\ No newline at end of file