From 9d973d353aa0e42520947c3166b4c962897dbb73 Mon Sep 17 00:00:00 2001 From: mikecarper Date: Fri, 23 Oct 2026 11:13:35 -0700 Subject: [PATCH] Preserve the compact STM32WL interface and profile storage path --- examples/companion_radio/CompanionHelp.inc | 2 ++ src/Dispatcher.h | 2 ++ src/helpers/RadioProfileCLI.cpp | 16 +++++++++++++++- src/helpers/RadioProfileCLI.h | 2 +- .../switch_tuning_unsupported_test.cpp | 16 ++++++++++++---- 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/examples/companion_radio/CompanionHelp.inc b/examples/companion_radio/CompanionHelp.inc index f891f291c..a70f0c0f2 100644 --- a/examples/companion_radio/CompanionHelp.inc +++ b/examples/companion_radio/CompanionHelp.inc @@ -225,10 +225,12 @@ MESH_COMPANION_HELP_BEGIN MESH_COMPANION_HELP_END #endif // Keep native USB producer writes within 256 bytes. +#if !defined(MESH_RADIO_SWITCH_TUNING) || MESH_RADIO_SWITCH_TUNING MESH_COMPANION_HELP_BEGIN " get radio.fast / get radio.fast.caps (supported saved controls)\r\n" " set radio.fast / set radio.fast.spi <0|2|4|8|16>\r\n" MESH_COMPANION_HELP_END +#endif MESH_COMPANION_HELP_BEGIN " get radio.rxps.config\r\n" " get/set radio.rxps \r\n" diff --git a/src/Dispatcher.h b/src/Dispatcher.h index b81cc2352..64c72c8df 100644 --- a/src/Dispatcher.h +++ b/src/Dispatcher.h @@ -99,6 +99,7 @@ public: virtual void begin() { } virtual RadioProfiles* profiles() { return nullptr; } virtual const RadioProfiles* profiles() const { return nullptr; } +#if MESH_RADIO_SWITCH_TUNING virtual RadioSwitchCapabilities switchTuningCapabilities() const { return {}; } virtual RadioSwitchTuning switchTuning() const { return {}; } virtual uint32_t switchSpiHz() const { return 0; } @@ -109,6 +110,7 @@ public: bool (*)(void*, const RadioSwitchTuning&) = nullptr, void* = nullptr) { return RadioParamApplyResult::FAILED; } +#endif virtual bool validateProfile(const RadioProfileParams&) const { return false; } virtual bool supportsMeshtext() const { return false; } virtual bool supportsEthernetTunnel() const { return false; } diff --git a/src/helpers/RadioProfileCLI.cpp b/src/helpers/RadioProfileCLI.cpp index 5bb9806c6..562de844b 100644 --- a/src/helpers/RadioProfileCLI.cpp +++ b/src/helpers/RadioProfileCLI.cpp @@ -203,9 +203,24 @@ bool RadioProfileCLI::prepareSavedImage(const char* path, const RadioProfileConf } bool RadioProfileCLI::commitSavedImage(const char* path) { +#if MESH_RADIO_SWITCH_TUNING return commitImage(path, ImagePath, BackupPath, hold_); +#else + if (!fs_ || hold_) return false; + if (fs_->exists(ImagePath)) { + if (fs_->exists(BackupPath) && !fs_->remove(BackupPath)) return false; + if (!fs_->rename(ImagePath, BackupPath)) return false; + } + if (!fs_->rename(path, ImagePath)) { + if (fs_->exists(BackupPath) && !fs_->rename(BackupPath, ImagePath)) hold_ = true; + return false; + } + if (fs_->exists(BackupPath)) fs_->remove(BackupPath); + return true; +#endif } +#if MESH_RADIO_SWITCH_TUNING bool RadioProfileCLI::commitImage(const char* path, const char* active, const char* backup, bool& hold, bool preserve_backup) { if (!fs_ || hold) return false; @@ -225,7 +240,6 @@ bool RadioProfileCLI::commitImage(const char* path, const char* active, return true; } -#if MESH_RADIO_SWITCH_TUNING bool RadioProfileCLI::validFastImage(const uint8_t* bytes, RadioSwitchTuning& value) const { if (bytes[2] != 1) return false; for (size_t n = 5; n < ImageSize - 4; ++n) if (bytes[n]) return false; diff --git a/src/helpers/RadioProfileCLI.h b/src/helpers/RadioProfileCLI.h index 7f85108fd..a94063d17 100644 --- a/src/helpers/RadioProfileCLI.h +++ b/src/helpers/RadioProfileCLI.h @@ -88,9 +88,9 @@ class RadioProfileCLI { bool prepareSavedImage(const char* path, const RadioProfileConfig& config, uint16_t preamble, RadioCrossMode cross, int8_t manual_secondary = -1); bool commitSavedImage(const char* path); +#if MESH_RADIO_SWITCH_TUNING bool commitImage(const char* staged, const char* active, const char* backup, bool& hold, bool preserve_backup = false); -#if MESH_RADIO_SWITCH_TUNING bool validFastImage(const uint8_t* bytes, RadioSwitchTuning& value) const; void loadFastSettings(bool boot = false); bool saveFastSettings(const RadioSwitchTuning& value); diff --git a/test/fixtures/radio_profiles/switch_tuning_unsupported_test.cpp b/test/fixtures/radio_profiles/switch_tuning_unsupported_test.cpp index 42c442eb0..84b1d314b 100644 --- a/test/fixtures/radio_profiles/switch_tuning_unsupported_test.cpp +++ b/test/fixtures/radio_profiles/switch_tuning_unsupported_test.cpp @@ -3,6 +3,18 @@ #define main existing_cli_main #include "cli_test.cpp" #undef main +#include + +#define CHECK_TUNING_MEMBER_ABSENT(name) \ + template struct Has_##name : std::false_type {}; \ + template struct Has_##name : std::true_type {}; \ + static_assert(!Has_##name::value, "Unsupported radio API must be absent: " #name) +CHECK_TUNING_MEMBER_ABSENT(switchTuningCapabilities); +CHECK_TUNING_MEMBER_ABSENT(switchTuning); +CHECK_TUNING_MEMBER_ABSENT(switchSpiHz); +CHECK_TUNING_MEMBER_ABSENT(configureBootSwitchTuning); +CHECK_TUNING_MEMBER_ABSENT(trySetSwitchTuning); +#undef CHECK_TUNING_MEMBER_ABSENT int main() { static_assert(MESH_RADIO_SWITCH_TUNING == 0, "Integrated STM32WL tuning must be absent"); @@ -27,10 +39,6 @@ int main() { assert(fs.opened_paths.empty()); assert(fs.files["/radio_fast"] == record); assert(fs.files.size() == 1); - const auto capabilities = radio.switchTuningCapabilities(); - assert(capabilities.flags == 0 && capabilities.spi_clocks == 0); - assert(!radio.configureBootSwitchTuning({})); - assert(radio.trySetSwitchTuning({}) == mesh::RadioParamApplyResult::FAILED); // Existing radio2 configuration commands remain available. assert(cli.handle("get radio2", reply, sizeof(reply))); assert(!strncmp(reply, "> off", 5));