#ifndef _PROTOCOL_H_ #define _PROTOCOL_H_ #include #define DISCOVER_TTL 10000 // discover request (c.f. class node) #define DISCOVER_SIZE sizeof(uint8_t)*3 struct discover { uint8_t opcode; // opcode = 0 uint8_t wave; // id de la wave uint8_t dist; // current node's distance }; #define MESSAGE_MIN_SIZE sizeof(uint8_t)*4 #define MESSAGE_MAX_SIZE sizeof(uint8_t)*4+sizeof(uint8_t)*255 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 }; #define PROTO_SIZE MESSAGE_MAX_SIZE // A 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 dsc); // }; #endif