From a6a2b53ca8c45653088aa45df4d71eb412ec2c8c Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 2 Dec 2018 21:43:59 +0100 Subject: [PATCH] update protocol to add sizes --- protocol.h | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/protocol.h b/protocol.h index 7ee52e3..220e2fe 100644 --- a/protocol.h +++ b/protocol.h @@ -1,10 +1,12 @@ #ifndef _PROTOCOL_H_ #define _PROTOCOL_H_ - #define DISCOVER_TTL 10000 - #define DISCOVER_SIZE sizeof(int)*2 + #include + + #define DISCOVER_TTL 10000 // discover request (c.f. class node) + #define DISCOVER_SIZE sizeof(uint8_t)*3 + 1 struct discover { uint8_t opcode; // opcode = 0 uint8_t wave; // id de la wave @@ -12,6 +14,8 @@ }; + #define MESSAGE_MIN_SIZE sizeof(uint8_t)*4 + 1 + #define MESSAGE_MAX_SIZE sizeof(uint8_t)*4+sizeof(uint8_t)*255 + 1 struct message { uint8_t opcode; // opcode = 1 uint8_t dist; // distance of the last sender @@ -20,33 +24,35 @@ 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; + // class node{ + // private: + // // unique id of the node : MAC ADDR + // int id; - // last received wave id - uint8_t last_wave; + // // 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; + // // 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: + // public: - // send a discover request - bool discover(); + // // send a discover request + // bool discover(); - // update the current node according to a (received) - // discover request - bool update(struct discover dsc); - }; + // // update the current node according to a (received) + // // discover request + // bool update(struct discover dsc); + // }; #endif \ No newline at end of file