Allow packet and nodenums to be 32 bits long (but don't change yet)

This commit is contained in:
geeksville 2020-06-03 13:46:31 -07:00
parent a34cfb0ee0
commit 5b1488ddf0
6 changed files with 15 additions and 7 deletions

View File

@ -31,6 +31,9 @@ dsr tasks
optimizations / low priority: optimizations / low priority:
- read @cyclomies long email with good ideas on optimizations and reply - 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 - low priority: think more careful about reliable retransmit intervals
- make ReliableRouter.pending threadsafe - make ReliableRouter.pending threadsafe
- bump up PacketPool size for all the new ack/nak/routing packets - bump up PacketPool size for all the new ack/nak/routing packets

View File

@ -9,7 +9,7 @@
typedef uint8_t NodeNum; typedef uint8_t NodeNum;
typedef uint8_t PacketId; // A packet sequence number 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_OK 0
#define ERRNO_NO_INTERFACES 33 #define ERRNO_NO_INTERFACES 33
#define ERRNO_UNKNOWN 32 // pick something that doesn't conflict with RH_ROUTER_ERROR_UNABLE_TO_DELIVER #define ERRNO_UNKNOWN 32 // pick something that doesn't conflict with RH_ROUTER_ERROR_UNABLE_TO_DELIVER

View File

@ -178,8 +178,10 @@ void NodeDB::init()
*/ */
void NodeDB::pickNewNodeNum() void NodeDB::pickNewNodeNum()
{ {
// FIXME not the right way to guess node numes // Pick an initial nodenum based on the macaddr
uint8_t r = ourMacAddr[5]; NodeNum r = sizeof(NodeNum) == 1 ? ourMacAddr[5]
: ((ourMacAddr[2] << 24) | (ourMacAddr[3] << 16) | (ourMacAddr[4] << 8) | ourMacAddr[5]);
if (r == 0xff || r < NUM_RESERVED) if (r == 0xff || r < NUM_RESERVED)
r = NUM_RESERVED; // don't pick a reserved node number r = NUM_RESERVED; // don't pick a reserved node number

View File

@ -26,7 +26,7 @@ separated by 2.16 MHz with respect to the adjacent channels. Channel zero starts
RadioInterface::RadioInterface() : txQueue(MAX_TX_QUEUE) 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; myNodeInfo.num_channels = NUM_CHANNELS;

View File

@ -19,7 +19,9 @@
* wtih the old radiohead implementation. * wtih the old radiohead implementation.
*/ */
typedef struct { 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: * Usage of flags:

View File

@ -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 uint32_t i; // Note: trying to keep this in noinit didn't help for working across reboots
static bool didInit = false; 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) { if (!didInit) {
didInit = true; didInit = true;
@ -60,7 +61,7 @@ PacketId generatePacketId()
} }
i++; 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 myNodeInfo.current_packet_id = id; // Kinda crufty - we keep updating this so the phone can see a current value
return id; return id;
} }