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

Committer:
p3p
Date:
Fri Sep 19 15:51:52 2014 +0000
Revision:
13:e27d84516fa8
Parent:
12:1d1d8425c79c
SSP api change

Who changed what in which revision?

UserRevisionLine numberNew contents of line
p3p 2:8799090c0fe4 1 #include "TestProtocol.h"
p3p 2:8799090c0fe4 2
p3p 11:a051c3f9ca6d 3 void TestProtocol::onEchoPacket(SimpleSerialProtocol::Protocol* comms, SimpleSerialProtocol::Packet* packet){
p3p 3:8ac7e37d0e0e 4 if(!packet)return;
p3p 2:8799090c0fe4 5 if (packet->_valid) {
p3p 2:8799090c0fe4 6 EchoPacket::Interface* interface = packet->interpretData<EchoPacket::Interface>();
p3p 2:8799090c0fe4 7 if (interface) {
p3p 2:8799090c0fe4 8 temp = interface->data;
p3p 2:8799090c0fe4 9 temp1 = interface->datashort;
p3p 2:8799090c0fe4 10 temp2 = interface->dataint;
p3p 2:8799090c0fe4 11 temp3 = interface->datafloat;
p3p 11:a051c3f9ca6d 12
p3p 11:a051c3f9ca6d 13 //we can use the Protocol pointer to send a response from the callback
p3p 11:a051c3f9ca6d 14 EchoPacket echoMessage; // initialise a packet to send
p3p 11:a051c3f9ca6d 15 echoMessage.interface.data = temp;
p3p 11:a051c3f9ca6d 16 echoMessage.interface.datashort = temp1;
p3p 11:a051c3f9ca6d 17 echoMessage.interface.dataint = temp2;
p3p 11:a051c3f9ca6d 18 echoMessage.interface.datafloat = temp3;
p3p 11:a051c3f9ca6d 19 echoMessage.buildData<EchoPacket::Interface>(&echoMessage.interface);
p3p 12:1d1d8425c79c 20 comms->send(&echoMessage); //send the packet (async)
p3p 2:8799090c0fe4 21 }
p3p 2:8799090c0fe4 22 }
p3p 3:8ac7e37d0e0e 23 return;
p3p 2:8799090c0fe4 24 }