simple serial protocol
Dependents: AwsomeStation LoRaBaseStation LoRaTerminal
CommandPacket2.h@11:390476907bfc, 2016-09-02 (annotated)
- Committer:
- rba90
- Date:
- Fri Sep 02 02:39:04 2016 +0000
- Revision:
- 11:390476907bfc
The CommandPacket is reconstructed.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rba90 | 11:390476907bfc | 1 | // command packet consists of following parts |
rba90 | 11:390476907bfc | 2 | // u4 sflag |
rba90 | 11:390476907bfc | 3 | // u8 command |
rba90 | 11:390476907bfc | 4 | // u8 length |
rba90 | 11:390476907bfc | 5 | // u8 payload[len] |
rba90 | 11:390476907bfc | 6 | // u8 checksum |
rba90 | 11:390476907bfc | 7 | // u4 eflag |
rba90 | 11:390476907bfc | 8 | |
rba90 | 11:390476907bfc | 9 | |
rba90 | 11:390476907bfc | 10 | #ifndef COMMAND_PACKET2_H_ |
rba90 | 11:390476907bfc | 11 | #define COMMAND_PACKET2_H_ |
rba90 | 11:390476907bfc | 12 | |
rba90 | 11:390476907bfc | 13 | #include <stdint.h> |
rba90 | 11:390476907bfc | 14 | |
rba90 | 11:390476907bfc | 15 | class CommandPacket2 |
rba90 | 11:390476907bfc | 16 | { |
rba90 | 11:390476907bfc | 17 | // public types |
rba90 | 11:390476907bfc | 18 | public: |
rba90 | 11:390476907bfc | 19 | typedef enum |
rba90 | 11:390476907bfc | 20 | { |
rba90 | 11:390476907bfc | 21 | CP_SFLAG = '<', |
rba90 | 11:390476907bfc | 22 | CP_EFLAG = '>' |
rba90 | 11:390476907bfc | 23 | } CPFlag_t; |
rba90 | 11:390476907bfc | 24 | |
rba90 | 11:390476907bfc | 25 | // private properties |
rba90 | 11:390476907bfc | 26 | private: |
rba90 | 11:390476907bfc | 27 | uint8_t _sflag; |
rba90 | 11:390476907bfc | 28 | uint8_t _command; |
rba90 | 11:390476907bfc | 29 | uint8_t _length; |
rba90 | 11:390476907bfc | 30 | uint8_t _payload[256]; |
rba90 | 11:390476907bfc | 31 | uint8_t _checksum; |
rba90 | 11:390476907bfc | 32 | uint8_t _eflag; |
rba90 | 11:390476907bfc | 33 | |
rba90 | 11:390476907bfc | 34 | bool _isVerified; |
rba90 | 11:390476907bfc | 35 | |
rba90 | 11:390476907bfc | 36 | // private methods |
rba90 | 11:390476907bfc | 37 | private: |
rba90 | 11:390476907bfc | 38 | uint8_t calculate_checksum(); |
rba90 | 11:390476907bfc | 39 | |
rba90 | 11:390476907bfc | 40 | // public methods |
rba90 | 11:390476907bfc | 41 | public: |
rba90 | 11:390476907bfc | 42 | CommandPacket2(); |
rba90 | 11:390476907bfc | 43 | ~CommandPacket2(); |
rba90 | 11:390476907bfc | 44 | |
rba90 | 11:390476907bfc | 45 | void setSFlag(uint8_t sflag=CP_SFLAG); |
rba90 | 11:390476907bfc | 46 | void setCommand(uint8_t command); |
rba90 | 11:390476907bfc | 47 | void setLength(uint8_t length); |
rba90 | 11:390476907bfc | 48 | void setPayload(uint8_t idx, uint8_t payload); |
rba90 | 11:390476907bfc | 49 | void setChecksum(uint8_t checksum); |
rba90 | 11:390476907bfc | 50 | void setEFlag(uint8_t eflag=CP_EFLAG); |
rba90 | 11:390476907bfc | 51 | |
rba90 | 11:390476907bfc | 52 | uint8_t getSFlag(); |
rba90 | 11:390476907bfc | 53 | uint8_t getCommand(); |
rba90 | 11:390476907bfc | 54 | uint8_t getLength(); |
rba90 | 11:390476907bfc | 55 | uint8_t getPayload(uint8_t idx); |
rba90 | 11:390476907bfc | 56 | uint8_t getEFlag(); |
rba90 | 11:390476907bfc | 57 | uint8_t getChecksum(); |
rba90 | 11:390476907bfc | 58 | |
rba90 | 11:390476907bfc | 59 | |
rba90 | 11:390476907bfc | 60 | |
rba90 | 11:390476907bfc | 61 | bool verify(); |
rba90 | 11:390476907bfc | 62 | void generateChecksum(); |
rba90 | 11:390476907bfc | 63 | int serialize(uint8_t *buffer); |
rba90 | 11:390476907bfc | 64 | |
rba90 | 11:390476907bfc | 65 | }; |
rba90 | 11:390476907bfc | 66 | |
rba90 | 11:390476907bfc | 67 | #endif |