Skip to content

Make CAD-busy timeout tunable via full-size packet airtimes - #3943

Open
mavericm1 wants to merge 1 commit into
meshcore-dev:mainfrom
mavericm1:cad-max-wait
Open

mavericm1 wants to merge 1 commit into
meshcore-dev:mainfrom
mavericm1:cad-max-wait

Conversation

@mavericm1

Copy link
Copy Markdown

Summary

Replaces the hardcoded 4-second CAD-busy timeout in Dispatcher::getCADFailMaxDuration() with a persisted, tunable count of full-size (255-byte) packet airtimes computed from the current LoRa settings. Adds get cad.wait.packets / set cad.wait.packets <n> to the shared radio CLI.

  • Default: 4 packets (≈4 s at SF10 / BW250)
  • Range: 1–16
  • Scope: companion radio, repeater, room server and sensor firmware

Motivation

A fixed 4000 ms wait does not scale with radio settings. At slow spreading factors / narrow bandwidths a single full-size packet can take seconds on the air, so the old timeout could force a TX while the channel was still busy. At fast settings it held transmissions off much longer than necessary. Expressing the wait as a number of packet airtimes makes it adapt automatically to the configured SF, BW and CR.

Changes

Core — src/Dispatcher.{h,cpp}

  • getCADFailMaxDuration() now returns calcCADFailMaxDuration(*_radio, getCADFailWaitPackets()) instead of 4000.
  • Added public static Dispatcher::calcCADFailMaxDuration(Radio&, uint32_t) so the Dispatcher and the CLI use one shared formula.
  • Guards: a zero packet count falls back to 1, and the result is capped at 300000 ms (5 min) to prevent overflow.
  • New virtual getCADFailWaitPackets() defaults to 4, so builds without CLI prefs (KISS modem, secure chat) keep sensible behavior.

CLI — src/helpers/CommonRadioPrefs.{h,cpp}

  • Added getCADWaitPackets() / setCADWaitPackets(uint8_t) to the radio prefs interface, plus getCADFailWaitMs().
  • get cad.wait.packets reports the computed timeout in milliseconds, with packet count and per-packet airtime.
  • set cad.wait.packets <n> validates the range, persists the value and echoes the resulting timeout.

Persistence

  • Added cad_wait_packets = 4 with JSON key radio.cad_wait_pkts to both NodePrefs classes (companion radio and CommonCLI).
  • Existing prefs.json files without the new key load with the default of 4. Changes are saved through the existing dirty-prefs flow.

Firmware overrides

  • Companion MyMesh, repeater MyMesh, room server MyMesh and SensorMesh now override getCADFailMaxDuration() and return the prefs-derived value.

Docs and tests

  • Documented the commands in docs/cli_commands.md.
  • Added a serialization/default round-trip test in test/test_companion_node_prefs/.

Example

> get cad.wait.packets
> 4400 ms (4 x 1100 ms packets)

> set cad.wait.packets 8
OK - 8 packets (8800 ms)
Changing set radio (SF/BW/CR) immediately changes the reported wait time, even with the packet count unchanged.
Compatibility
- Default of 4 packets closely matches the previous 4 s behavior at common settings.
- Old config files remain valid; the missing key simply uses the new default.
- Firmware without the shared radio CLI keeps the core default behavior.
Verification
Built successfully with PlatformIO (via Nix):
- heltec_rc32_without_display_sensor
- Heltec_E213_repeater
- heltec_rc32_without_display_companion_radio_usb

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant