Experiment of serial command protocol
Dependencies: RingBuffer SerialInterfaceProtocol duinotech_16x2_LCD mbed
You can edit this area
SerialInterfaceProtocol.h
- Committer:
- rba90
- Date:
- 2016-06-09
- Revision:
- 2:54932809c7b2
- Child:
- 3:0c4aa3cec685
File content as of revision 2:54932809c7b2:
// SerialInterfaceProtocol (SIP) is a protocol which help to exchange // information between host and slave devices #ifndef SERIALINTERFACEPROTOCOL_H_ #define SERIALINTERFACEPROTOCOL_H_ #include "mbed.h" #include "stdint.h" #include "CommandPacket.h" #include "buffer.h" #define SIP_CMD_VECTOR_TABLE_SZ 256 #define SIP_MAX_RESP_LEN 256 #define SIP_MAX_PAYLOAD_LEN 256 typedef int (*callback_func)(uint8_t *payload, uint8_t payload_length, uint8_t *response, uint8_t *response_length); typedef CircularBuffer<uint8_t> SerialBuffer_t; class SerialInterfaceProtocol { public: // namespace private: // internal variable callback_func CommandVectorTable[SIP_CMD_VECTOR_TABLE_SZ]; // buffered interface SerialBuffer_t *SerialInputBuffer; SerialBuffer_t *SerialOutputBuffer; CommandPacket PacketBuffer; // state machine CommandPacket::State_t state; // internal state bool isChecksumEnabled; private: // internal methods int execute(uint8_t *response, uint8_t *response_length); int assemble(uint8_t *response, uint8_t response_length); public: // public methods // constructor SerialInterfaceProtocol(SerialBuffer_t *in, SerialBuffer_t *out); ~SerialInterfaceProtocol(); // member function void poll(); void registerCommand(uint8_t command, callback_func f); void deRegisterCommand(uint8_t command); void disableChecksum(); void enableChecksum(); }; #endif