From 8b669af363ae103a95bd30b7413fa73963d23c84 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 11 Dec 2018 13:33:51 +0100 Subject: [PATCH] update protocol default MESSAGE_TTL | fix node.send_message() to send before printing | fix node.manage_message() to use same packet to re-send the received message packet --- node/main/main.ino | 23 +++++++++++------------ protocol.h | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/node/main/main.ino b/node/main/main.ino index 07f2039..b23b2ae 100644 --- a/node/main/main.ino +++ b/node/main/main.ino @@ -59,18 +59,17 @@ void send_data(){ send.setDist(dist); send.setTTL(MESSAGE_TTL); char data[64] = {0}; - strcpy(data, "https://git.xdrm.io"); + sprintf(data, "%d has: dist %d / wave %d", SENDERID, dist, wave_id); send.setData(data); + // 2. broadcast + xbee.broadcast(send); + // 2. debug screen.clear(); screen.printfn(0, "msg[%3d/%3d] %3d", send.getDist(), send.getTTL(), send.getSize()); screen.printfn_overflow(1, "%s", (char*) send.getData()); - delay(1000); - - // 3. send - xbee.broadcast(send); - screen.printfn(1, "sent "); + delay(500); } @@ -129,11 +128,11 @@ void manage_message(){ } // propagation - send.setOpcode(OPCODE_MESSAGE); - send.setTTL(recv.getTTL()-1); - send.setDist(dist); - send.setData(recv.getData()); + // send.setOpcode(OPCODE_MESSAGE); + recv.setTTL(recv.getTTL()-1); + recv.setDist(dist); + // send.setData(recv.getData()); - screen.printfn(1, "msg[%3d/%3d] %3d", send.getDist(), send.getTTL(), send.getSize()); - xbee.broadcast(send); + screen.printfn(1, "msg[%3d/%3d] %3d", recv.getDist(), recv.getTTL(), recv.getSize()); + xbee.broadcast(recv); } diff --git a/protocol.h b/protocol.h index 00046ee..b72c7c0 100644 --- a/protocol.h +++ b/protocol.h @@ -5,7 +5,7 @@ #define DISCOVER_TTL 5000 #define SENDERID 42 - #define MESSAGE_TTL 10 + #define MESSAGE_TTL 3 #define OPCODE_DISCOVER 0 #define OPCODE_MESSAGE 1