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 4:c0a69c32d054 1 #include "mbed.h"
p3p 4:c0a69c32d054 2 #include "Protocol.h"
p3p 4:c0a69c32d054 3 #include "TestProtocol.h"
p3p 4:c0a69c32d054 4
p3p 4:c0a69c32d054 5 //valid test packet bytes
p3p 4:c0a69c32d054 6 //
p3p 2:8799090c0fe4 7 // 255 127 // packet start 2 bytes
p3p 4:c0a69c32d054 8 // 12 // payload size 1 byte
p3p 4:c0a69c32d054 9 // 0 0 0 0 0 0 0 0 0 0 0 0 // payload data
p3p 4:c0a69c32d054 10 // 16 // checksum 1 byte
p3p 4:c0a69c32d054 11
p3p 4:c0a69c32d054 12 //checksum calculation
p3p 4:c0a69c32d054 13 //
p3p 4:c0a69c32d054 14 // uint8_t tmp_checksum = 16;
p3p 4:c0a69c32d054 15 // for (int i = 0; i < packet_size; i++) {
p3p 4:c0a69c32d054 16 // tmp_checksum ^= packet[i];
p3p 4:c0a69c32d054 17 // }
p3p 4:c0a69c32d054 18 // return tmp_checksum;
p3p 4:c0a69c32d054 19
p3p 4:c0a69c32d054 20 TestProtocol testProtocol;
p3p 11:a051c3f9ca6d 21 SimpleSerialProtocol::Protocol comms(USBTX, USBRX, LED1);
p3p 4:c0a69c32d054 22
p3p 4:c0a69c32d054 23 //the main loop
p3p 13:e27d84516fa8 24 int main() {
p3p 13:e27d84516fa8 25 comms.initialise(115200);
p3p 11:a051c3f9ca6d 26 comms.receiveCallback(1, &testProtocol, &TestProtocol::onEchoPacket);
p3p 11:a051c3f9ca6d 27
p3p 4:c0a69c32d054 28 while (1) {
p3p 11:a051c3f9ca6d 29 comms.update();
p3p 4:c0a69c32d054 30 }
p3p 4:c0a69c32d054 31 }