opportunistic-xbee/node/main/packet.h

37 lines
859 B
C++

#ifndef _PACKET_H_
#define _PACKET_H_
#include "protocol.h"
#include <Wire.h>
#define PKTREAD_OK 0
#define PKTREAD_EMPTY 1
#define PKTREAD_OVERFLOW 2
#define PKTREAD_INVALID_DISCOVER_FORMAT 3
#define PKTREAD_INVALID_MESSAGE_FORMAT 4
class Packet {
private:
// 1. common
uint8_t buf[];
uint8_t bufsize;
bool type; // true = discover ; false = message
// 2. wrappers
struct discover dsc;
struct message msg;
// 3. helpers
uint8_t read_discover(uint8_t buf[], uint8_t size);
uint8_t read_message(uint8_t buf[], uint8_t size);
public:
// builds a packet from raw data and returns the status code
uint8_t read(uint8_t buf[], uint8_t size);
// writes the binary representation of the packet
uint8_t write(uint8_t buf[], uint8_t size);
};
#endif