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_
#define _PROTOCOL_H_
#define DISCOVER_TTL 10000
#define DISCOVER_SIZE sizeof(int)*2
#include <Wire.h>
#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 <node> 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