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:
Sat Mar 17 16:42:31 2012 +0000
Revision:
5:f693f68e9de6
Parent:
4:c0a69c32d054
Child:
6:d33e929ebaa9
override Serial io

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 5:f693f68e9de6 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 5:f693f68e9de6 20 Timer timer;
p3p 4:c0a69c32d054 21 TestProtocol testProtocol;
p3p 5:f693f68e9de6 22 MODDMA dma;
p3p 4:c0a69c32d054 23
p3p 4:c0a69c32d054 24 //the main loop
p3p 4:c0a69c32d054 25 int main() {
p3p 5:f693f68e9de6 26 timer.start();
p3p 5:f693f68e9de6 27 testProtocol.initialise();
p3p 5:f693f68e9de6 28 testProtocol.MODDMA(&dma);
p3p 5:f693f68e9de6 29
p3p 5:f693f68e9de6 30 testProtocol.printf("Hello printf\r\n");
p3p 5:f693f68e9de6 31 testProtocol.printf("Hello printf %s\r\n", "booyaa");
p3p 5:f693f68e9de6 32 testProtocol.puts("Hello puts\r\n");
p3p 5:f693f68e9de6 33
p3p 5:f693f68e9de6 34 testProtocol.putc('H');
p3p 5:f693f68e9de6 35 testProtocol.puts("\r\n");
p3p 5:f693f68e9de6 36
p3p 5:f693f68e9de6 37 testProtocol.puts("SimpleSerialProtocol Serial io overrides tested\r\n");
p3p 5:f693f68e9de6 38
p3p 5:f693f68e9de6 39 for (int i = 0; i < 20; ++i) {
p3p 5:f693f68e9de6 40 testProtocol.puts("*dma*");
p3p 5:f693f68e9de6 41 }
p3p 5:f693f68e9de6 42 testProtocol.puts("\r\n");
p3p 5:f693f68e9de6 43
p3p 5:f693f68e9de6 44 testProtocol.blockUntilDmaTxEmpty();
p3p 5:f693f68e9de6 45
p3p 5:f693f68e9de6 46
p3p 4:c0a69c32d054 47 while (1) {
p3p 4:c0a69c32d054 48 testProtocol.update();
p3p 5:f693f68e9de6 49
p3p 5:f693f68e9de6 50 for (int i = 0; i < 120; ++i) {
p3p 5:f693f68e9de6 51 testProtocol.puts("*dma*");
p3p 5:f693f68e9de6 52 }
p3p 5:f693f68e9de6 53 testProtocol.puts("\r\n");
p3p 5:f693f68e9de6 54 Timer timer;
p3p 5:f693f68e9de6 55 timer.start();
p3p 5:f693f68e9de6 56 testProtocol.blockUntilDmaTxEmpty();
p3p 5:f693f68e9de6 57
p3p 5:f693f68e9de6 58 testProtocol.printf("Serial write time: %d\r\n", timer.read_ms());
p3p 5:f693f68e9de6 59
p3p 5:f693f68e9de6 60 wait_ms(500);
p3p 4:c0a69c32d054 61 }
p3p 4:c0a69c32d054 62 }