From 2108f70ff9d580c85ddc296c386a13d6b4a77ae7 Mon Sep 17 00:00:00 2001 From: xmutantson Date: Fri, 7 Aug 2026 08:43:37 -0700 Subject: [PATCH] fw: apply serial channel mode selections Serial channel-profile commands (WGN/MPG/MPM/MPP/MPD) validated the requested mode and updated the target S:N, but never assigned the global intMode: ParseSetSimParameter's intMode parameter shadows the global of the same name, so an acknowledged command left the running channel profile unchanged. The main loop keeps configuring tap delays and Doppler updates from the stale global, so for example MPP:9 answered OK while the simulator stayed in whichever mode the front-panel encoder had last selected. ParseSetParameter's parameter shadows the global the same way, so nothing on the serial path ever wrote it. Assign the global mode and clear blnInitialized in the serial dispatch before applying the parameter update, so the next loop pass configures the selected profile through the same initialization path a front-panel mode change uses. Applied to both firmware variants, with a regression test over both sources. --- .../HFSim_BFD_2_03_Proto.ino | 7 ++- src/HFSim_BFD_2_03/HFSim_BFD_2_03.ino | 7 ++- tests/test_serial_mode_dispatch.py | 43 +++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 tests/test_serial_mode_dispatch.py diff --git a/hardware/Alternate hardware platforms/src/HFSim_BFD_2_03_Proto/HFSim_BFD_2_03_Proto.ino b/hardware/Alternate hardware platforms/src/HFSim_BFD_2_03_Proto/HFSim_BFD_2_03_Proto.ino index ce30195..edca331 100644 --- a/hardware/Alternate hardware platforms/src/HFSim_BFD_2_03_Proto/HFSim_BFD_2_03_Proto.ino +++ b/hardware/Alternate hardware platforms/src/HFSim_BFD_2_03_Proto/HFSim_BFD_2_03_Proto.ino @@ -2520,7 +2520,12 @@ void loop() if (ParseSetSimParameter(strParameter, intSerialCmdMode)) { Serial.println("OK"); //Serial Command is OK - if (intSerialCmdMode < 5){ ParseSetParameter(strParameter, intSerialCmdMode);} + if (intSerialCmdMode < 5) + { + intMode = intSerialCmdMode; + blnInitialized = false; + ParseSetParameter(strParameter, intSerialCmdMode); + } } else { Serial.println("?"); }//Serial Command fail} } diff --git a/src/HFSim_BFD_2_03/HFSim_BFD_2_03.ino b/src/HFSim_BFD_2_03/HFSim_BFD_2_03.ino index 7075424..11054ad 100755 --- a/src/HFSim_BFD_2_03/HFSim_BFD_2_03.ino +++ b/src/HFSim_BFD_2_03/HFSim_BFD_2_03.ino @@ -2423,7 +2423,12 @@ void loop() if (ParseSetSimParameter(strParameter, intSerialCmdMode)) { Serial.println("OK"); //Serial Command is OK - if (intSerialCmdMode < 5){ ParseSetParameter(strParameter, intSerialCmdMode);} + if (intSerialCmdMode < 5) + { + intMode = intSerialCmdMode; + blnInitialized = false; + ParseSetParameter(strParameter, intSerialCmdMode); + } } else { Serial.println("?"); }//Serial Command fail} } diff --git a/tests/test_serial_mode_dispatch.py b/tests/test_serial_mode_dispatch.py new file mode 100644 index 0000000..3443c96 --- /dev/null +++ b/tests/test_serial_mode_dispatch.py @@ -0,0 +1,43 @@ +import re +import unittest +from pathlib import Path + + +ROOT = Path(__file__).resolve().parents[1] +FIRMWARES = ( + ROOT / "src" / "HFSim_BFD_2_03" / "HFSim_BFD_2_03.ino", + ROOT + / "hardware" + / "Alternate hardware platforms" + / "src" + / "HFSim_BFD_2_03_Proto" + / "HFSim_BFD_2_03_Proto.ino", +) + + +def successful_serial_simulation_dispatch(source: str) -> str: + start = source.index("if (ParseSetSimParameter(strParameter, intSerialCmdMode))") + end = source.index("else { Serial.println(\"?\"); }//Serial Command fail", start) + return source[start:end] + + +class SerialModeDispatchTest(unittest.TestCase): + def test_channel_mode_commands_apply_and_reinitialize_the_selected_mode(self): + for firmware in FIRMWARES: + with self.subTest(firmware=str(firmware.relative_to(ROOT))): + block = successful_serial_simulation_dispatch( + firmware.read_text(encoding="utf-8") + ) + mode_branch = re.search( + r"if\s*\(intSerialCmdMode\s*<\s*5\)\s*\{(?P.*?)\}", + block, + re.DOTALL, + ) + self.assertIsNotNone(mode_branch, "missing channel-mode branch") + body = mode_branch.group("body") + self.assertRegex(body, r"\bintMode\s*=\s*intSerialCmdMode\s*;") + self.assertRegex(body, r"\bblnInitialized\s*=\s*false\s*;") + + +if __name__ == "__main__": + unittest.main()