fix: stop moduleData antennaMode aliasing subType on boards without an external antenna (#7735)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
3f7f6b6db0
commit
73390c738e
@@ -145,6 +145,13 @@ static const YamlLookupTable moduleAntennaModeLut = {
|
||||
{ GeneralSettings::ANTENNA_MODE_EXTERNAL, "MODE_EXTERNAL" },
|
||||
};
|
||||
|
||||
// Firmware built before the field was made unconditional emitted antennaMode on
|
||||
// boards without an external antenna, where it aliased the top bits of subType.
|
||||
static bool hasModuleAntennaMode()
|
||||
{
|
||||
return Boards::getCapability(getCurrentBoard(), Board::HasExternalAntenna);
|
||||
}
|
||||
|
||||
static int exportPpmDelay(int delay) { return (delay - 300) / 50; }
|
||||
static int importPpmDelay(int delay) { return 300 + 50 * delay; }
|
||||
|
||||
@@ -204,7 +211,7 @@ Node convert<ModuleData>::encode(const ModuleData& rhs)
|
||||
node["channelsStart"] = rhs.channelsStart;
|
||||
node["channelsCount"] = rhs.channelsCount;
|
||||
node["failsafeMode"] = LookupValue(failsafeLut, rhs.failsafeMode);
|
||||
if (rhs.antennaMode)
|
||||
if (rhs.antennaMode && hasModuleAntennaMode())
|
||||
node["antennaMode"] = LookupValue(moduleAntennaModeLut, rhs.antennaMode);
|
||||
|
||||
Node mod;
|
||||
@@ -370,7 +377,7 @@ bool convert<ModuleData>::decode(const Node& node, ModuleData& rhs)
|
||||
node["channelsStart"] >> rhs.channelsStart;
|
||||
node["channelsCount"] >> rhs.channelsCount;
|
||||
node["failsafeMode"] >> failsafeLut >> rhs.failsafeMode;
|
||||
if (node["antennaMode"])
|
||||
if (node["antennaMode"] && hasModuleAntennaMode())
|
||||
node["antennaMode"] >> moduleAntennaModeLut >> rhs.antennaMode;
|
||||
|
||||
if (node["mod"]) {
|
||||
@@ -397,7 +404,7 @@ bool convert<ModuleData>::decode(const Node& node, ModuleData& rhs)
|
||||
// pxx["receiverTelemetryOff"] >> rhs.pxx.receiverTelemetryOff;
|
||||
// pxx["receiverHigherChannels"] >> rhs.pxx.receiverHigherChannels;
|
||||
// Migration: legacy raw-int antennaMode, only if not already set
|
||||
if (!node["antennaMode"] && pxx["antennaMode"]) {
|
||||
if (!node["antennaMode"] && pxx["antennaMode"] && hasModuleAntennaMode()) {
|
||||
pxx["antennaMode"] >> rhs.antennaMode;
|
||||
}
|
||||
} else if (mod["sbus"]) {
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
#include "firmwares/eeprominterface.h"
|
||||
#include "firmwares/edgetx/edgetxinterface.h"
|
||||
#include "firmwares/edgetx/yaml_moduledata.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -124,3 +125,54 @@ TEST_F(ModelYamlRoundTrip, OverlongNameTruncatesAndRoundTrips)
|
||||
ModelData m3 = roundTrip(m2, y2);
|
||||
EXPECT_EQ(m2.name.str(), m3.name.str());
|
||||
}
|
||||
|
||||
// A module written by a radio that emitted antennaMode must decode. The field is
|
||||
// a string enum firmware side; read as a raw int, yaml-cpp throws
|
||||
// TypedBadConversion and the whole model fails to open.
|
||||
TEST_F(ModelYamlRoundTrip, RadioWrittenAntennaModeDecodes)
|
||||
{
|
||||
YAML::Node node = YAML::Load(
|
||||
"type: TYPE_MULTIMODULE\n"
|
||||
"subType: 6,7\n"
|
||||
"channelsStart: 0\n"
|
||||
"channelsCount: 16\n"
|
||||
"failsafeMode: NOT_SET\n"
|
||||
"antennaMode: MODE_PER_MODEL\n");
|
||||
|
||||
ModuleData md;
|
||||
bool threw = false;
|
||||
std::string err;
|
||||
try {
|
||||
node >> md;
|
||||
} catch (const std::exception& e) {
|
||||
threw = true;
|
||||
err = e.what();
|
||||
} catch (...) {
|
||||
threw = true;
|
||||
err = "non-std exception";
|
||||
}
|
||||
|
||||
ASSERT_FALSE(threw) << "decoding threw: " << err;
|
||||
EXPECT_EQ(md.subType, 7u) << "subType lost alongside antennaMode";
|
||||
}
|
||||
|
||||
// The fixture selects tx16s, which has no external antenna. Such radios parse
|
||||
// antennaMode over the top two bits of subType, so writing the key back would
|
||||
// change the sub-protocol on load.
|
||||
TEST_F(ModelYamlRoundTrip, AntennaModeNotWrittenWithoutExternalAntenna)
|
||||
{
|
||||
ASSERT_FALSE(Boards::getCapability(getCurrentBoard(), Board::HasExternalAntenna))
|
||||
<< "fixture board is expected to have no external antenna";
|
||||
|
||||
ModelData m;
|
||||
m.clear();
|
||||
m.used = true;
|
||||
// only modules with a protocol are serialised at all
|
||||
m.moduleData[1].protocol = PULSES_MULTIMODULE;
|
||||
m.moduleData[1].antennaMode = GeneralSettings::ANTENNA_MODE_EXTERNAL;
|
||||
|
||||
QByteArray y;
|
||||
writeModelToYaml(m, y);
|
||||
ASSERT_TRUE(y.contains("moduleData")) << "module was not serialised";
|
||||
EXPECT_FALSE(y.contains("antennaMode"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user