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

Committer:
p3p
Date:
2012-03-17
Revision:
5:f693f68e9de6
Parent:
4:c0a69c32d054
Child:
6:d33e929ebaa9

File content as of revision 5:f693f68e9de6:

#ifndef _TEST_PROTOCOL_H
#define _TEST_PROTOCOL_H

#include <mbed.h>
#include <SimpleSerialProtocol/Protocol.h>

//class will receive a packet and echo it back out
class TestProtocol : public SimpleSerialProtocol::Protocol {
public:
    TestProtocol() : Protocol(USBTX, USBRX, LED1) { //LED1 to 4 for a status led, NC to disable
        _dma_port = MODDMA::Channel_7; //set the dma port, must be unique per class 0 - 9
        receiveCallback(1, this, &TestProtocol::onEchoPacket);
    }
    virtual ~TestProtocol() {};
    void onEchoPacket(SimpleSerialProtocol::Packet* packet);
    void reply();

    class EchoPacket : public SimpleSerialProtocol::Packet {
    public:
        EchoPacket() {}
        virtual ~EchoPacket() {}
        
#pragma pack(push, 1) //must pack the structure to byte boundary for raw recast to work reliably
        struct Interface {
            Interface() {
                type = 1; // initialise the type
            }
            uint8_t type;
            uint8_t data;
            uint16_t datashort;
            uint32_t dataint;
            float datafloat;
        } interface;
#pragma pack(pop)

    };

    uint8_t temp;
    short temp1;
    int temp2;
    float temp3;
};

#endif