diff --git a/docs/software/mesh-alg.md b/docs/software/mesh-alg.md index 7d7837be..ecad282a 100644 --- a/docs/software/mesh-alg.md +++ b/docs/software/mesh-alg.md @@ -31,6 +31,9 @@ dsr tasks optimizations / low priority: - read @cyclomies long email with good ideas on optimizations and reply +- Remove NodeNum assignment algorithm (now that we use 4 byte node nums) +- make android app warn if firmware is too old or too new to talk to +- change nodenums and packetids in protobuf to be fixed32 - low priority: think more careful about reliable retransmit intervals - make ReliableRouter.pending threadsafe - bump up PacketPool size for all the new ack/nak/routing packets diff --git a/src/mesh/MeshTypes.h b/src/mesh/MeshTypes.h index f491ce50..adba7841 100644 --- a/src/mesh/MeshTypes.h +++ b/src/mesh/MeshTypes.h @@ -9,7 +9,7 @@ typedef uint8_t NodeNum; typedef uint8_t PacketId; // A packet sequence number -#define NODENUM_BROADCAST 255 +#define NODENUM_BROADCAST (sizeof(NodeNum) == 4 ? UINT32_MAX : UINT8_MAX) #define ERRNO_OK 0 #define ERRNO_NO_INTERFACES 33 #define ERRNO_UNKNOWN 32 // pick something that doesn't conflict with RH_ROUTER_ERROR_UNABLE_TO_DELIVER diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index faa03593..1e263134 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -178,8 +178,10 @@ void NodeDB::init() */ void NodeDB::pickNewNodeNum() { - // FIXME not the right way to guess node numes - uint8_t r = ourMacAddr[5]; + // Pick an initial nodenum based on the macaddr + NodeNum r = sizeof(NodeNum) == 1 ? ourMacAddr[5] + : ((ourMacAddr[2] << 24) | (ourMacAddr[3] << 16) | (ourMacAddr[4] << 8) | ourMacAddr[5]); + if (r == 0xff || r < NUM_RESERVED) r = NUM_RESERVED; // don't pick a reserved node number diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 45ecc42a..c7edf74d 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -26,7 +26,7 @@ separated by 2.16 MHz with respect to the adjacent channels. Channel zero starts RadioInterface::RadioInterface() : txQueue(MAX_TX_QUEUE) { - assert(sizeof(PacketHeader) == 4); // make sure the compiler did what we expected + assert(sizeof(PacketHeader) == 4 || sizeof(PacketHeader) == 16); // make sure the compiler did what we expected myNodeInfo.num_channels = NUM_CHANNELS; diff --git a/src/mesh/RadioInterface.h b/src/mesh/RadioInterface.h index 41976375..64222a76 100644 --- a/src/mesh/RadioInterface.h +++ b/src/mesh/RadioInterface.h @@ -19,7 +19,9 @@ * wtih the old radiohead implementation. */ typedef struct { - uint8_t to, from, id; + NodeNum to, from; // can be 1 byte or four bytes + + PacketId id; // can be 1 byte or 4 bytes /** * Usage of flags: diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index dc7409a0..eb8a1ab3 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -51,7 +51,8 @@ PacketId generatePacketId() static uint32_t i; // Note: trying to keep this in noinit didn't help for working across reboots static bool didInit = false; - uint32_t numPacketId = 255; // 0 is consider invalid + assert(sizeof(PacketId) == 4 || sizeof(PacketId) == 1); // only supported values + uint32_t numPacketId = sizeof(PacketId) == 1 ? UINT8_MAX : UINT32_MAX; // 0 is consider invalid if (!didInit) { didInit = true; @@ -60,7 +61,7 @@ PacketId generatePacketId() } i++; - PacketId id = (i % numPacketId) + 1; // return number between 1 and 255 (ie - never zero) + PacketId id = (i % numPacketId) + 1; // return number between 1 and numPacketId (ie - never zero) myNodeInfo.current_packet_id = id; // Kinda crufty - we keep updating this so the phone can see a current value return id; }