Skip to content

Commit

Permalink
start msg sequence numbers with a random number each boot
Browse files Browse the repository at this point in the history
  • Loading branch information
geeksville committed May 1, 2020
1 parent 31eb2f5 commit 5a4fab2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion docs/software/nrf52-TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Minimum items needed to make sure hardware is good.

- add a hard fault handler
- at boot we are starting our message IDs at 1, rather we should start them at a random number. also, seed random based on timer. this could be the cause of our first message not seen bug.
- use "variants" to get all gpio bindings
- plug in correct variants for the real board
- Use the PMU driver on real hardware
Expand Down Expand Up @@ -57,6 +56,7 @@ Needed to be fully functional at least at the same level of the ESP32 boards. At
- currently using soft device SD140, is that ideal?
- turn on the watchdog timer, require servicing from key application threads
- install a hardfault handler for null ptrs (if one isn't already installed)
- nrf52setup should call randomSeed(tbd)

## Things to do 'someday'

Expand Down Expand Up @@ -97,6 +97,7 @@ Nice ideas worth considering someday...
- DONE track rxbad, rxgood, txgood
- DONE neg 7 error code from receive
- DONE remove unused sx1262 lib from github
- at boot we are starting our message IDs at 1, rather we should start them at a random number. also, seed random based on timer. this could be the cause of our first message not seen bug.

```
Expand Down
2 changes: 2 additions & 0 deletions src/esp32/main-esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ void axp192Init()

void esp32Setup()
{
randomSeed(esp_random()); // ESP docs say this is fairly random

#ifdef AXP192_SLAVE_ADDRESS
axp192Init();
#endif
Expand Down
10 changes: 8 additions & 2 deletions src/mesh/MeshService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ static Periodic sendOwnerPeriod(sendOwnerCb);
// FIXME, move this someplace better
PacketId generatePacketId()
{
static uint32_t i __attribute__((
section(".noinit"))); // We try to keep this in noinit so that hopefully it keeps increasing even across reboots
static uint32_t i; // Note: trying to keep this in noinit didn't help for working across reboots
static bool didInit = false;

if (!didInit) {
didInit = true;
i = random(0, NUM_PACKET_ID +
1); // pick a random initial sequence number at boot (to prevent repeated reboots always starting at 0)
}

i++;
return (i % NUM_PACKET_ID) + 1; // return number between 1 and 255
Expand Down
1 change: 1 addition & 0 deletions src/nrf52/main-nrf52.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ void nrf52Setup()
{
// Not yet on board
// pmu.init();
DEBUG_MSG("FIXME, need to call randomSeed on nrf52!\n");
}
2 changes: 1 addition & 1 deletion src/rf95/RadioLibInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class RadioLibInterface : public RadioInterface
void applyModemConfig();

/** Could we send right now (i.e. either not actively receiving or transmitting)? */
virtual bool canSendImmediately();
bool canSendImmediately();

/** are we actively receiving a packet (only called during receiving state) */
virtual bool isActivelyReceiving() = 0;
Expand Down

0 comments on commit 5a4fab2

Please sign in to comment.