Legacy switchWarningState decoded with 3 bits per switch since 2.12 (storage uses 2): impossible switch warnings after update
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- cpp, yaml
- Domain
- backend, embedded-iot
Research direction
Read r_swtchWarn() in radio/src/storage/yaml/yaml_datastructs_funcs.cpp and the 2-bit accessors in radio/src/datastructs_private.h. Reproduce the issue by loading switchWarningState: AuBuCuDu through YamlTreeWalker/get_modeldata_nodes(), then add a gtest checking getSwitchWarning(0..4). Done when the values are up, up, up, up, none and the regression test passes.
Written by the indexing model from the issue text.
Description
Is there an existing issue for this problem?
- I have searched the existing issues
What part of EdgeTX is the focus of this bug?
Transmitter firmware
Current Behavior
Since 2.12, ModelData::switchWarning stores 2 bits per switch (getSwitchWarning() / setSwitchWarning() in radio/src/datastructs_private.h), but the YAML reader of the legacy key switchWarningState (r_swtchWarn() in radio/src/storage/yaml/yaml_datastructs_funcs.cpp) still packs 3 bits per switch:
// 3 bits per switch
swtchWarn |= (state << (3 * swtch));
Any model file that still contains the legacy string gets wrong switch warnings on its first load in 2.12, and the wrong values are then saved in the new switchWarning: format.
Example on a RadioMaster Pocket: the factory model contains switchWarningState: AuBuCuDu (SA, SB, SC, SD up). r_swtchWarn builds 1 | 1<<3 | 1<<6 | 1<<9 = 585, which read back 2 bits per switch gives SA up, SB mid, SC none, SD up, SE mid. After flashing 2.12.4 the radio asks for SB and SE in the middle. SE is a momentary button on the Pocket, so the warning can never be cleared, and the model is saved as:
switchWarning:
SA:
pos: up
SB:
pos: mid
SD:
pos: up
SE:
pos: mid
Confirmed with a gtest built from v2.12.4 (PCB=X7 PCBREV=POCKET), loading the string through YamlTreeWalker / get_modeldata_nodes():
AuBuCuDu read by 2.12: SA=1 SB=2 SC=0 SD=1 SE=2 (0 none, 1 up, 2 mid, 3 down)
v2.10 and v2.11 are consistent (3 bits for both the storage and the legacy reader). The mismatch is present in v2.12.0 to v2.12.4 and on main today.
Expected Behavior
switchWarningState: AuBuCuDu is read as SA, SB, SC, SD up and no check on SE, exactly like in 2.10/2.11.
Steps To Reproduce
- Put a model file containing
switchWarningState: AuBuCuDuon the SD card (for example the factory models of a RadioMaster Pocket, or any model never re-saved since the legacy format). - Flash 2.12.x and start the radio on that model.
- The switch warning asks for SB and SE in the middle instead of SA, SB, SC, SD up.
Version
2.12.4 (also 2.12.0 to 2.12.3 and main)
Transmitter
RadioMaster Pocket
Anything else?
Suggested fix, packing the legacy string with the same width as the storage:
// 2 bits per switch, same as ModelData::switchWarning
swtchWarn |= ((swarnstate_t)state << (2 * swtch));
(The cast also avoids an int shift overflow on radios with many switches.) A gtest loading switchWarningState: AuBuCuDu and checking getSwitchWarning(0..4) = up, up, up, up, none would cover it. I can open a PR if that helps.
Found while building an installer for Pocket owners that rewrites the legacy string in the native format before the first 2.12 boot: https://github.com/GaboITB/PocketUFDS
- Dominant language
- C
- Stars
- 2.4k
- Forks
- 614
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 75
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from EdgeTX/edgetx
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Ghost GPS heading (Hdg) reads ~1000x too smallPossibly taken @r3wretrhy claimed this 10 days ago. Openbug 🪲 triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
bug 🪲 triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
EdgeTX/edgetx#7412 · 2 comments ·
Maintainers usually reply within 1 day
-
bug 🪲 triage
Difficulty 2/5 Under an hour Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
bug 🪲 triage
Difficulty 4/5 1-2 days Newbie friendliness 48/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 8 days
-
native-cpu: -Wreturn-type in skainet_row_threads.c:150 (worker fn has no return)Possibly taken @Doomguy-BFG9000 claimed this today. Opengood first issue size:xs skill:native
Difficulty 1/5 Under an hour Newbie friendliness 78/100
SKaiNET-developers/SKaiNET#1358 · 1 comment ·
Maintainers usually reply within 1 day
-
I/O internal correctness medium priority rt_lib
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
libsdl-org/SDL#16539 ·
Maintainers usually reply within 1 day
-
git-workflow task-4
Difficulty 2/5 1-3 hours Newbie friendliness 66/100