#ifndef __P_SERIAL_PACKET_H__ #define __P_SERIAL_PACKET_H__ // start byte // src_addr {1} + // dest_addr {1} + // frame_length {1} + // checksum {1} + // frame_data {510} -- making it 510 instead of 511 so it is easily divisible #define MAX_MESSAGE_LEN (516) #define MAX_FRAME_DATA_LEN (510) #define MASTER_ADDR (0x01) #include #include class ps_packet { public: // for encoding ps_packet(uint8_t _src_addr, uint8_t _dest_addr, uint8_t* _frame_data, uint8_t _frame_data_len); // for decoding ps_packet(uint8_t* data); ~ps_packet(); uint8_t* src_addr; uint8_t* dest_addr; uint8_t* frame_data_len; uint8_t* checksum; uint8_t* frame_data; uint8_t data[MAX_MESSAGE_LEN]; std::size_t msg_len; bool encode(); bool decode(); static ps_packet from_xy(int x, int y); private: bool stuff_bytes(); bool destuff_bytes(); bool validate(); void calc_checksum(); }; #endif