Chris Pepper / Mbed 2 deprecated SimpleSerialProtocolExample

Dependencies:   mbed SimpleSerialProtocol MODSERIAL

TestProtocol.h

Committer:
p3p
Date:
2012-01-16
Revision:
2:8799090c0fe4
Child:
3:8ac7e37d0e0e
Child:
5:f693f68e9de6

File content as of revision 2:8799090c0fe4:

#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(p9, p10, NC) { //LED1 to 4 for a status led, NC to disable
        _dma_port = 0; //set the dma port, must be unique per class 0 - 9
        packetCallback(1, this, &TestProtocol::onEchoPacket);
    }
    virtual ~TestProtocol() {};
    uint32_t onEchoPacket(uint32_t packet_ptr_value);
    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