#ifndef _PROTOCOL_H_ #define _PROTOCOL_H_ #include #define DISCOVER_TTL 5000 #define SENDERID 42 #define MESSAGE_TTL 3 #define OPCODE_DISCOVER 0 #define OPCODE_MESSAGE 1 // 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_MAX_PAYLOAD 255 #define PROTO_MIN_SIZE 5 * sizeof(uint8_t) #define PROTO_SIZE (5 + MESSAGE_MAX_PAYLOAD) * sizeof(uint8_t) struct message { uint8_t opcode; // opcode = 1 uint8_t sender; // sender id 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[MESSAGE_MAX_PAYLOAD]; // actual message }; class Node{ private: uint8_t wave = 0; uint8_t dist = 255; public: getWave(){ return wave; } getDist(){ return dist; } bool update(uint8_t new_dist, uint8_t new_wave){ // ignore if already setup for this wave if( new_wave == wave ) return false; // update with new wave // // Note: // - We consider that we will receive lowest dist(ance) // in the first receive of each wave because of the XBee stack wave = new_wave; dist = new_dist+1; return true; } }; #endif