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
TestProtocol.h@5:f693f68e9de6, 2012-03-17 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
p3p |
4:c0a69c32d054 | 1 | #ifndef _TEST_PROTOCOL_H |
p3p |
4:c0a69c32d054 | 2 | #define _TEST_PROTOCOL_H |
p3p |
4:c0a69c32d054 | 3 | |
p3p |
4:c0a69c32d054 | 4 | #include <mbed.h> |
p3p |
4:c0a69c32d054 | 5 | #include <SimpleSerialProtocol/Protocol.h> |
p3p |
4:c0a69c32d054 | 6 | |
p3p |
4:c0a69c32d054 | 7 | //class will receive a packet and echo it back out |
p3p |
4:c0a69c32d054 | 8 | class TestProtocol : public SimpleSerialProtocol::Protocol { |
p3p |
4:c0a69c32d054 | 9 | public: |
p3p | 5:f693f68e9de6 | 10 | TestProtocol() : Protocol(USBTX, USBRX, LED1) { //LED1 to 4 for a status led, NC to disable |
p3p | 5:f693f68e9de6 | 11 | _dma_port = MODDMA::Channel_7; //set the dma port, must be unique per class 0 - 9 |
p3p | 5:f693f68e9de6 | 12 | receiveCallback(1, this, &TestProtocol::onEchoPacket); |
p3p |
4:c0a69c32d054 | 13 | } |
p3p |
4:c0a69c32d054 | 14 | virtual ~TestProtocol() {}; |
p3p | 5:f693f68e9de6 | 15 | void onEchoPacket(SimpleSerialProtocol::Packet* packet); |
p3p |
4:c0a69c32d054 | 16 | void reply(); |
p3p |
4:c0a69c32d054 | 17 | |
p3p |
4:c0a69c32d054 | 18 | class EchoPacket : public SimpleSerialProtocol::Packet { |
p3p |
4:c0a69c32d054 | 19 | public: |
p3p |
4:c0a69c32d054 | 20 | EchoPacket() {} |
p3p |
4:c0a69c32d054 | 21 | virtual ~EchoPacket() {} |
p3p |
4:c0a69c32d054 | 22 | |
p3p |
4:c0a69c32d054 | 23 | #pragma pack(push, 1) //must pack the structure to byte boundary for raw recast to work reliably |
p3p |
4:c0a69c32d054 | 24 | struct Interface { |
p3p |
4:c0a69c32d054 | 25 | Interface() { |
p3p |
4:c0a69c32d054 | 26 | type = 1; // initialise the type |
p3p |
4:c0a69c32d054 | 27 | } |
p3p |
4:c0a69c32d054 | 28 | uint8_t type; |
p3p |
4:c0a69c32d054 | 29 | uint8_t data; |
p3p |
4:c0a69c32d054 | 30 | uint16_t datashort; |
p3p |
4:c0a69c32d054 | 31 | uint32_t dataint; |
p3p |
4:c0a69c32d054 | 32 | float datafloat; |
p3p |
4:c0a69c32d054 | 33 | } interface; |
p3p |
4:c0a69c32d054 | 34 | #pragma pack(pop) |
p3p |
4:c0a69c32d054 | 35 | |
p3p |
4:c0a69c32d054 | 36 | }; |
p3p |
4:c0a69c32d054 | 37 | |
p3p |
4:c0a69c32d054 | 38 | uint8_t temp; |
p3p |
4:c0a69c32d054 | 39 | short temp1; |
p3p |
4:c0a69c32d054 | 40 | int temp2; |
p3p |
4:c0a69c32d054 | 41 | float temp3; |
p3p |
4:c0a69c32d054 | 42 | }; |
p3p |
4:c0a69c32d054 | 43 | |
p3p |
4:c0a69c32d054 | 44 | #endif |