From f917275cbc0d52ce45792398df72159d190ac985 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 1 Dec 2018 18:30:09 +0100 Subject: [PATCH] make the 'protocol.h' definition shared with symlinks --- protocol.h | 52 +++++++++++++++++++++++++++++++++++++++++++ well/main/main.ino | 10 ++++----- well/main/protocol.h | 53 +------------------------------------------- 3 files changed, 57 insertions(+), 58 deletions(-) create mode 100644 protocol.h mode change 100644 => 120000 well/main/protocol.h diff --git a/protocol.h b/protocol.h new file mode 100644 index 0000000..6c7ba3b --- /dev/null +++ b/protocol.h @@ -0,0 +1,52 @@ +#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 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 \ No newline at end of file diff --git a/well/main/main.ino b/well/main/main.ino index a95fd57..43e5918 100644 --- a/well/main/main.ino +++ b/well/main/main.ino @@ -3,8 +3,6 @@ #include "protocol.h" #include -// CONSTANTS -#define WAVE_TIMEOUT 5000 // send wave every (in ms) // Peripherals LiquidCrystal_I2C screen(0x27, 16, 2); @@ -12,7 +10,7 @@ XBee xbee = XBee(); // ACTUAL DATA uint8_t wave_id = 250; -struct discover req = {0,0,0}; +struct discover dsc = {0,0,0}; void setup() { Serial.begin(38400); @@ -32,13 +30,13 @@ void loop() { delay(WAVE_TIMEOUT); // increment wave id (will overflow from 255 to 0) - req.wave = ++wave_id; // set wave id + dsc.wave = ++wave_id; // set wave id screen.clear(); screen.print("+ wave"); - screen.print(req.wave); + screen.print(dsc.wave); - uint8_t payload[3] = {req.opcode, req.wave, req.dist}; + uint8_t payload[3] = {dsc.opcode, dsc.wave, dsc.dist}; XBeeAddress64 addr64 = XBeeAddress64(0x00000000, 0x0000FFFF); Tx64Request tx = Tx64Request(addr64, payload, sizeof(payload)); diff --git a/well/main/protocol.h b/well/main/protocol.h deleted file mode 100644 index 6c7ba3b..0000000 --- a/well/main/protocol.h +++ /dev/null @@ -1,52 +0,0 @@ -#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 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 \ No newline at end of file diff --git a/well/main/protocol.h b/well/main/protocol.h new file mode 120000 index 0000000..c9b722e --- /dev/null +++ b/well/main/protocol.h @@ -0,0 +1 @@ +../../protocol.h \ No newline at end of file