simple serial protocol
Dependents: AwsomeStation LoRaBaseStation LoRaTerminal
Diff: CommandPacket.h
- Revision:
- 11:390476907bfc
- Parent:
- 10:2a710d0bab2c
diff -r 2a710d0bab2c -r 390476907bfc CommandPacket.h --- a/CommandPacket.h Thu Sep 01 04:15:40 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -#ifndef COMMAND_PACKET_H_ -#define COMMAND_PACKET_H_ - -#include "stdint.h" - -// command packet consists of following parts -// u4 sflag -// u8 command -// u8 length -// u8 payload[len] -// u8 checksum -// u4 eflag - -uint8_t generate_checksum(uint8_t *payload, uint8_t length, uint8_t offset=0); -uint8_t hexchar_to_uint8(uint8_t ch); - -class CommandPacket -{ -public: - typedef enum - { - CP_SFLAG = '<', - CP_EFLAG = '>' - } CPFlag_t; - - typedef enum - { - NONE = 0, - SFLAG, - COMMAND_H, - COMMAND_L, - LENGTH_H, - LENGTH_L, - PAYLOAD_H, - PAYLOAD_L, - CHECKSUM_H, - CHECKSUM_L, - EFLAG - } State_t; - - typedef enum - { - NO_ERROR = 0, - INVALID_SFLAG_ERROR, - INVALID_EFLAG_ERROR, - INVALID_CMD_ERROR, - INVALID_CS_ERROR, - INVALID_EXEC_ERROR - } Error_t; - -public: - Error_t errno; - -public: - uint8_t sflag; - uint8_t command; - uint8_t length; - uint8_t payload[256 + 1]; // payload include terminator - uint8_t checksum; - uint8_t eflag; - -public: - CommandPacket(); - ~CommandPacket() {}; - - bool verify(); - int serialize(uint8_t *output); - uint8_t generate_checksum(); -}; - - - - -#endif