Skip to content

Lora settings expansion and validation logic improvement#9878

Merged
thebentern merged 44 commits intomeshtastic:developfrom
NomDeTom:radio_interface_cherrypick
Mar 20, 2026
Merged

Lora settings expansion and validation logic improvement#9878
thebentern merged 44 commits intomeshtastic:developfrom
NomDeTom:radio_interface_cherrypick

Conversation

@NomDeTom
Copy link
Contributor

@thebentern I think this has reached MVP stage. Please proceed to tear it to shreds.

🤝 Attestations

  • I have tested that my proposed changes behave as described.
  • I have tested that my proposed changes do not cause any obvious regressions on the following devices:
    • Heltec (Lora32) V3
    • LilyGo T-Deck
    • LilyGo T-Beam
    • RAK WisBlock 4631
    • Seeed Studio T-1000E tracker card
    • Other (please specify below)

@github-actions github-actions bot added needs-review Needs human review enhancement New feature or request labels Mar 10, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands LoRa region/preset metadata and introduces new validation/clamping helpers intended to improve modem configuration safety and region-specific preset enforcement.

Changes:

  • Extends RegionInfo with additional regulatory/preset metadata and adds per-region “available presets” lists.
  • Adds RadioInterface::{validateConfigRegion, validateConfigLora, clampConfigLora} and updates Admin/boot flows to use them.
  • Updates unit tests to target the new validation path (though the referenced API currently doesn’t exist).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
test/test_radio/test_main.cpp Renames tests to use a new validation helper (currently missing).
src/modules/AdminModule.h Changes handleSetConfig signature to pass fromOthers.
src/modules/AdminModule.cpp Applies new LoRa region/config validation and different behavior for remote vs local config updates.
src/mesh/RadioInterface.h Deprecates old preset bootstrap helper and declares new validation/clamp APIs.
src/mesh/RadioInterface.cpp Adds region preset lists, expands region definitions, implements validation/clamping, and modifies channel/frequency selection.
src/mesh/NodeDB.cpp Switches boot-time preset field coercion from the old helper to clampConfigLora().
src/mesh/MeshRadio.h Expands RegionInfo struct and exposes preset lists.

@NomDeTom NomDeTom marked this pull request as ready for review March 11, 2026 22:21
@NomDeTom
Copy link
Contributor Author

I need to think of some better tests, but I'm tired. Maybe tomorrow...

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 8 comments.

@thebentern thebentern requested a review from Copilot March 18, 2026 15:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 7 comments.

Comments suppressed due to low confidence (1)

src/modules/AdminModule.h:1

  • This changes both the signature and the access level of handleSetConfig (public → protected, plus a new fromOthers parameter). If anything outside AdminModule previously invoked handleSetConfig(const meshtastic_Config&), this becomes a breaking change. A safer approach is to keep a public overload with the old signature (forwarding to the new method with an explicit default like fromOthers=false), or keep the method public if it’s part of the module’s expected integration surface.
#pragma once

You can also share your feedback on Copilot code review. Take the survey.

@thebentern thebentern requested a review from Copilot March 18, 2026 19:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@NomDeTom NomDeTom requested a review from Copilot March 19, 2026 01:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 10 comments.

Comments suppressed due to low confidence (1)

src/graphics/draw/MenuHandler.cpp:294

  • After the early-return if (!myRegion) return;, the later if (myRegion) { ... } else { ... } block (and duplicated warning) is unreachable on the else branch. Removing the redundant conditional will simplify control flow and reduce duplicated logging.
        LOG_WARN("Region not set, cannot calculate number of channels");
        return;
    }

@NomDeTom NomDeTom requested a review from Copilot March 19, 2026 18:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

@NomDeTom NomDeTom requested a review from Copilot March 20, 2026 02:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 12 comments.

Comment on lines +997 to +998
uint32_t channel_num;
float freq;
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

channel_num is declared as uint32_t but is assigned -1 when override_frequency is set, which wraps to 0xFFFFFFFF. This later affects saveChannelNum(channel_num) and logging (channel_num + 1) and can result in invalid persisted state. Use a signed type for channel_num (e.g., int32_t) or represent “no channel” explicitly (e.g., a separate boolean/optional) and avoid writing a wrapped sentinel into storage.

Suggested change
uint32_t channel_num;
float freq;
int32_t channel_num = -1;
float freq = 0.0f;

Copilot uses AI. Check for mistakes.
Comment on lines 1012 to +1016
// override if we have a verbatim frequency
if (loraConfig.override_frequency) {
freq = loraConfig.override_frequency;
channel_num = -1;
uses_default_frequency_slot = false;
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

channel_num is declared as uint32_t but is assigned -1 when override_frequency is set, which wraps to 0xFFFFFFFF. This later affects saveChannelNum(channel_num) and logging (channel_num + 1) and can result in invalid persisted state. Use a signed type for channel_num (e.g., int32_t) or represent “no channel” explicitly (e.g., a separate boolean/optional) and avoid writing a wrapped sentinel into storage.

Copilot uses AI. Check for mistakes.
Comment on lines +851 to +852
float freqSlotWidth = newRegion->profile->spacing + (newRegion->profile->padding * 2) + (check_bw / 1000); // in MHz
uint32_t numFreqSlots = round((newRegion->freqEnd - newRegion->freqStart + newRegion->profile->spacing) / freqSlotWidth);
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

freqSlotWidth can become 0 (e.g., spacing/padding are 0 and check_bw resolves to 0), which causes division by zero when computing numFreqSlots. If numFreqSlots ends up as 0, the subsequent modulo operations (% numFreqSlots) are also undefined behavior. Add an explicit guard: if freqSlotWidth <= 0 or computed numFreqSlots == 0, then return false (validation) or clamp to a safe default (clamp mode) before any division/modulo.

Copilot uses AI. Check for mistakes.
Comment on lines +879 to +883
const char *channelName = channels.getName(channels.getPrimaryIndex());
const char *presetNameDisplay =
DisplayFormatters::getModemPresetDisplayName(loraConfig.modem_preset, false, loraConfig.use_preset);
uint32_t channelNameHashSlot = hash(channelName) % numFreqSlots;
uint32_t presetNameHashSlot = hash(presetNameDisplay) % numFreqSlots;
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

freqSlotWidth can become 0 (e.g., spacing/padding are 0 and check_bw resolves to 0), which causes division by zero when computing numFreqSlots. If numFreqSlots ends up as 0, the subsequent modulo operations (% numFreqSlots) are also undefined behavior. Add an explicit guard: if freqSlotWidth <= 0 or computed numFreqSlots == 0, then return false (validation) or clamp to a safe default (clamp mode) before any division/modulo.

Copilot uses AI. Check for mistakes.
#include <assert.h>
#include <pb_decode.h>
#include <pb_encode.h>
#include <string.h>
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

round() is used but there is no clear include for it in this translation unit (typically <cmath>). Relying on transitive includes is fragile and can break builds on different toolchains/settings. Include <cmath> and prefer the float-specific variant (roundf) or a cast-safe integer conversion (lroundf) consistent with the desired rounding semantics.

Suggested change
#include <string.h>
#include <string.h>
#include <cmath>

Copilot uses AI. Check for mistakes.
NomDeTom and others added 2 commits March 20, 2026 02:21
@NomDeTom
Copy link
Contributor Author

@thebentern Kind of going in circles here... I think its time.

@thebentern thebentern merged commit 22d63fa into meshtastic:develop Mar 20, 2026
77 checks passed
@NomDeTom
Copy link
Contributor Author

Woohoo!

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

Labels

enhancement New feature or request needs-review Needs human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants