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:
Mon Jan 16 22:46:45 2012 +0000
Revision:
2:8799090c0fe4
Child:
3:8ac7e37d0e0e
Modified to reflect changes in the SimpleSerialProtocol Library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
p3p 2:8799090c0fe4 1 #include "TestProtocol.h"
p3p 2:8799090c0fe4 2
p3p 2:8799090c0fe4 3 uint32_t TestProtocol::onEchoPacket(uint32_t packet_ptr_value) {
p3p 2:8799090c0fe4 4 EchoPacket *packet = (EchoPacket*)packet_ptr_value;
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 2:8799090c0fe4 12 reply();
p3p 2:8799090c0fe4 13 }
p3p 2:8799090c0fe4 14 }
p3p 2:8799090c0fe4 15 return 0;
p3p 2:8799090c0fe4 16 }
p3p 2:8799090c0fe4 17
p3p 2:8799090c0fe4 18 void TestProtocol::reply() {
p3p 2:8799090c0fe4 19 EchoPacket echoMessage; // initialise a packet to send
p3p 2:8799090c0fe4 20 echoMessage.interface.data = temp;
p3p 2:8799090c0fe4 21 echoMessage.interface.datashort = temp1;
p3p 2:8799090c0fe4 22 echoMessage.interface.dataint = temp2;
p3p 2:8799090c0fe4 23 echoMessage.interface.datafloat = temp3;
p3p 2:8799090c0fe4 24 echoMessage.buildData<EchoPacket::Interface>(&echoMessage.interface);
p3p 2:8799090c0fe4 25 sendPacket(&echoMessage); //send the packet (async)
p3p 2:8799090c0fe4 26 }