52 lines
1.2 KiB
C
52 lines
1.2 KiB
C
|
#ifndef _PROTOCOL_H_
|
||
|
#define _PROTOCOL_H_
|
||
|
|
||
|
#define DISCOVER_TTL 10000
|
||
|
#define DISCOVER_SIZE sizeof(int)*2
|
||
|
|
||
|
// discover request (c.f. class node)
|
||
|
struct discover {
|
||
|
uint8_t opcode; // opcode = 0
|
||
|
uint8_t wave; // id de la wave
|
||
|
uint8_t dist; // current node's distance
|
||
|
};
|
||
|
|
||
|
|
||
|
struct data {
|
||
|
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 message[]; // actual message
|
||
|
};
|
||
|
|
||
|
// 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
|
||
|
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 req);
|
||
|
};
|
||
|
|
||
|
|
||
|
#endif
|