opportunistic-xbee/protocol.h

60 lines
1.5 KiB
C
Raw Normal View History

#ifndef _PROTOCOL_H_
#define _PROTOCOL_H_
2018-12-02 20:43:59 +00:00
#include <Wire.h>
#define DISCOVER_TTL 10000
// discover request (c.f. class node)
2018-12-03 10:24:32 +00:00
#define DISCOVER_SIZE sizeof(uint8_t)*4
struct discover {
uint8_t opcode; // opcode = 0
uint8_t wave; // id de la wave
uint8_t dist; // current node's distance
2018-12-03 10:24:32 +00:00
uint8_t sender; // sender id
};
#define MESSAGE_MIN_SIZE sizeof(uint8_t)*5
#define MESSAGE_MAX_SIZE sizeof(uint8_t)*5+sizeof(uint8_t)*255
2018-12-01 17:36:02 +00:00
struct message {
uint8_t opcode; // opcode = 1
uint8_t dist; // distance of the last sender
uint8_t ttl; // time to live default = 10
uint8_t size; // size of message in bytes
uint8_t *data; // actual message
uint8_t sender; // sender id
};
2018-12-02 20:43:59 +00:00
#define PROTO_SIZE MESSAGE_MAX_SIZE
// A <node> object is held by each node which values are determined thanks
// to the DISCOVER requests it receives; each node broadcasts a DISCOVER
// request every DISCOVER_TTL milliseconds
2018-12-02 20:43:59 +00:00
// class node{
// private:
// // unique id of the node : MAC ADDR
// int id;
// // last received wave id
// uint8_t last_wave;
// // relative node-distance to the well
// // WELL : dist = 0
// // NODE1 can reach WELL : dist = 1
// // NODE2 can reach NODE1 : dist = 2
// // and so on...
// uint8_t dist;
// public:
// // send a discover request
// bool discover();
// // update the current node according to a (received)
// // discover request
// bool update(struct discover dsc);
// };
#endif