update protocol to add sizes

This commit is contained in:
Adrien Marquès 2018-12-02 21:43:59 +01:00
parent 7d4a3b6e57
commit a6a2b53ca8
1 changed files with 27 additions and 21 deletions

View File

@ -1,10 +1,12 @@
#ifndef _PROTOCOL_H_ #ifndef _PROTOCOL_H_
#define _PROTOCOL_H_ #define _PROTOCOL_H_
#include <Wire.h>
#define DISCOVER_TTL 10000 #define DISCOVER_TTL 10000
#define DISCOVER_SIZE sizeof(int)*2
// discover request (c.f. class node) // discover request (c.f. class node)
#define DISCOVER_SIZE sizeof(uint8_t)*3 + 1
struct discover { struct discover {
uint8_t opcode; // opcode = 0 uint8_t opcode; // opcode = 0
uint8_t wave; // id de la wave 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 { struct message {
uint8_t opcode; // opcode = 1 uint8_t opcode; // opcode = 1
uint8_t dist; // distance of the last sender uint8_t dist; // distance of the last sender
@ -20,33 +24,35 @@
uint8_t data[]; // actual message uint8_t data[]; // actual message
}; };
#define PROTO_SIZE MESSAGE_MAX_SIZE
// A <node> object is held by each node which values are determined thanks // A <node> object is held by each node which values are determined thanks
// to the DISCOVER requests it receives; each node broadcasts a DISCOVER // to the DISCOVER requests it receives; each node broadcasts a DISCOVER
// request every DISCOVER_TTL milliseconds // request every DISCOVER_TTL milliseconds
class node{ // class node{
private: // private:
// unique id of the node : MAC ADDR // // unique id of the node : MAC ADDR
int id; // int id;
// last received wave id // // last received wave id
uint8_t last_wave; // uint8_t last_wave;
// relative node-distance to the well // // relative node-distance to the well
// WELL : dist = 0 // // WELL : dist = 0
// NODE1 can reach WELL : dist = 1 // // NODE1 can reach WELL : dist = 1
// NODE2 can reach NODE1 : dist = 2 // // NODE2 can reach NODE1 : dist = 2
// and so on... // // and so on...
uint8_t dist; // uint8_t dist;
public: // public:
// send a discover request // // send a discover request
bool discover(); // bool discover();
// update the current node according to a (received) // // update the current node according to a (received)
// discover request // // discover request
bool update(struct discover dsc); // bool update(struct discover dsc);
}; // };
#endif #endif