PROTOCOL CHANGE! activate 32 bit nodenums/packetids

This commit is contained in:
geeksville 2020-06-06 13:16:36 -07:00
parent 5d874cd43b
commit e124d2094f
8 changed files with 22 additions and 20 deletions

View File

@ -34,7 +34,4 @@ Note that for both stategies, sizes are measured in blocks and that an AES block
## Remaining todo
- Make the packet numbers 32 bit
- Confirm the packet #s are stored in flash across deep sleep (and otherwise in in RAM)
- Have the app change the crypto key when the user generates a new channel
- Implement for NRF52 [NRF52](https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.0.0/lib_crypto_aes.html#sub_aes_ctr)

View File

@ -40,7 +40,6 @@ Needed to be fully functional at least at the same level of the ESP32 boards. At
## Items to be 'feature complete'
- change packet numbers to be 32 bits
- check datasheet about sx1262 temperature compensation
- enable brownout detection and watchdog
- stop polling for GPS characters, instead stay blocked on read in a thread
@ -128,6 +127,7 @@ Nice ideas worth considering someday...
- scheduleOSCallback doesn't work yet - it is way too fast (causes rapid polling of busyTx, high power draw etc...)
- find out why we reboot while debugging - it was bluetooth/softdevice
- make a file system implementation (preferably one that can see the files the bootloader also sees) - preferably https://github.com/adafruit/Adafruit_nRF52_Arduino/blob/master/libraries/InternalFileSytem/examples/Internal_ReadWrite/Internal_ReadWrite.ino else use https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.3.0/lib_fds_usage.html?cp=7_5_0_3_55_3
- change packet numbers to be 32 bits
```

2
proto

@ -1 +1 @@
Subproject commit 9d083d5d4ff4ef095135b18468004eaba77cb691
Subproject commit 3ba76bbe4c98ee9c9e422d8dc10844cc9fb5272a

View File

@ -86,12 +86,14 @@ void MeshService::sendOurOwner(NodeNum dest, bool wantReplies)
const MeshPacket *MeshService::handleFromRadioUser(const MeshPacket *mp)
{
bool wasBroadcast = mp->to == NODENUM_BROADCAST;
bool isCollision = mp->from == myNodeInfo.my_node_num;
// we win if we have a lower macaddr
bool weWin = memcmp(&owner.macaddr, &mp->decoded.user.macaddr, sizeof(owner.macaddr)) < 0;
// Disable this collision testing if we use 32 bit nodenums
bool isCollision = (sizeof(NodeNum) == 1) && (mp->from == myNodeInfo.my_node_num);
if (isCollision) {
// we win if we have a lower macaddr
bool weWin = memcmp(&owner.macaddr, &mp->decoded.user.macaddr, sizeof(owner.macaddr)) < 0;
if (weWin) {
DEBUG_MSG("NOTE! Received a nodenum collision and we are vetoing\n");

View File

@ -6,8 +6,8 @@
#include "mesh.pb.h"
#include <Arduino.h>
typedef uint8_t NodeNum;
typedef uint8_t PacketId; // A packet sequence number
typedef uint32_t NodeNum;
typedef uint32_t PacketId; // A packet sequence number
#define NODENUM_BROADCAST (sizeof(NodeNum) == 4 ? UINT32_MAX : UINT8_MAX)
#define ERRNO_OK 0

View File

@ -56,8 +56,11 @@ PacketId generatePacketId()
if (!didInit) {
didInit = true;
i = random(0, numPacketId +
1); // pick a random initial sequence number at boot (to prevent repeated reboots always starting at 0)
// pick a random initial sequence number at boot (to prevent repeated reboots always starting at 0)
// Note: we mask the high order bit to ensure that we never pass a 'negative' number to random
i = random(numPacketId & 0x7fffffff);
DEBUG_MSG("Initial packet id %u, numPacketId %u\n", i, numPacketId);
}
i++;

View File

@ -9,7 +9,7 @@
PB_BIND(Position, Position, AUTO)
PB_BIND(Data, Data, 2)
PB_BIND(Data, Data, AUTO)
PB_BIND(User, User, AUTO)

View File

@ -47,7 +47,7 @@ typedef struct _ChannelSettings {
char name[12];
} ChannelSettings;
typedef PB_BYTES_ARRAY_T(251) Data_payload_t;
typedef PB_BYTES_ARRAY_T(240) Data_payload_t;
typedef struct _Data {
Data_Type typ;
Data_payload_t payload;
@ -586,20 +586,20 @@ extern const pb_msgdesc_t ManufacturingData_msg;
/* Maximum encoded size of messages (where known) */
#define Position_size 39
#define Data_size 256
#define Data_size 245
#define User_size 72
#define RouteDiscovery_size 88
#define SubPacket_size 285
#define MeshPacket_size 324
#define SubPacket_size 274
#define MeshPacket_size 313
#define ChannelSettings_size 60
#define RadioConfig_size 157
#define RadioConfig_UserPreferences_size 93
#define NodeInfo_size 132
#define MyNodeInfo_size 110
#define DeviceState_size 15463
#define DeviceState_size 15100
#define DebugString_size 258
#define FromRadio_size 333
#define ToRadio_size 327
#define FromRadio_size 322
#define ToRadio_size 316
/* ManufacturingData_size depends on runtime parameters */
#ifdef __cplusplus