chore: centralize board manufacturer/model/USB identity in hw_defs JSON (#7786)

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Peter Feerick
2026-09-25 13:46:09 +10:00
committed by GitHub
co-authored by Claude Sonnet 5
parent 598255e1d1
commit 425944bff2
95 changed files with 460 additions and 610 deletions
+12 -2
View File
@@ -73,6 +73,7 @@ BoardJson::BoardJson(Board::Type board, QString hwdefn) :
m_display({0, 0, 0, 0, 0, 0, 0, 0}),
m_cfs({0, 0}),
m_hardware({0, 0, 0}),
m_identity({"", ""}),
m_inputCnt({0, 0, 0, 0, 0, 0, 0, 0, 0}),
m_switchCnt({0, 0, 0})
{
@@ -1005,7 +1006,7 @@ bool BoardJson::loadDefinition()
if (m_board == Board::BOARD_UNKNOWN)
return true;
if (!loadFile(m_board, m_hwdefn, m_inputs, m_switches, m_keys, m_trims, m_display, m_cfs, m_hardware, m_hasKeyLockCombo))
if (!loadFile(m_board, m_hwdefn, m_inputs, m_switches, m_keys, m_trims, m_display, m_cfs, m_hardware, m_identity, m_hasKeyLockCombo))
return false;
afterLoadFixups(m_board, m_inputs, m_switches, m_keys, m_trims);
@@ -1042,7 +1043,7 @@ bool BoardJson::loadDefinition()
// static
bool BoardJson::loadFile(Board::Type board, QString hwdefn, InputsTable * inputs, SwitchesTable * switches,
KeysTable * keys, TrimsTable * trims, DisplayDefn & display, CustomSwitchesDefn & cfs,
HardwareDefn & hardware, bool & hasKeyLockCombo)
HardwareDefn & hardware, IdentityDefn & identity, bool & hasKeyLockCombo)
{
if (board == Board::BOARD_UNKNOWN) {
return false;
@@ -1293,6 +1294,13 @@ bool BoardJson::loadFile(Board::Type board, QString hwdefn, InputsTable * inputs
hardware.cpu_type = o.value("cpu_type").toString().toStdString();
}
if (obj.value("identity").isObject()) {
const QJsonObject &o = obj.value("identity").toObject();
identity.manufacturer = o.value("manufacturer").toString().toStdString();
identity.model = o.value("model").toString().toStdString();
}
delete json;
return true;
}
@@ -1342,6 +1350,8 @@ const QString BoardJson::getCapabilityStr(const Board::Capability capability) co
return m_hardware.cpu.c_str();
case Board::CPUType:
return m_hardware.cpu_type.c_str();
case Board::Manufacturer:
return m_identity.manufacturer.c_str();
default:
return QString();
}
+7 -1
View File
@@ -127,6 +127,11 @@ class BoardJson
std::string cpu_type = "";
};
struct IdentityDefn {
std::string manufacturer = "";
std::string model = "";
};
typedef std::vector<TrimDefn> TrimsTable;
explicit BoardJson(Board::Type board, QString hwdefn);
@@ -202,6 +207,7 @@ private:
DisplayDefn m_display;
CustomSwitchesDefn m_cfs;
HardwareDefn m_hardware;
IdentityDefn m_identity;
bool m_hasKeyLockCombo = false;
struct InputCounts {
@@ -228,7 +234,7 @@ private:
static bool loadFile(Board::Type board, QString hwdefn, InputsTable * inputs, SwitchesTable * switches,
KeysTable * keys, TrimsTable * trims, DisplayDefn & lcd, CustomSwitchesDefn & cfs,
HardwareDefn & hardware, bool & hasKeyLockCombo);
HardwareDefn & hardware, IdentityDefn & identity, bool & hasKeyLockCombo);
static void afterLoadFixups(Board::Type board, InputsTable * inputs, SwitchesTable * switches,
KeysTable * keys, TrimsTable * trims);
+1 -68
View File
@@ -1255,72 +1255,5 @@ QString Boards::getCapabilityStr(Board::Type board, Board::Capability capability
QString Boards::getManufacturer(Board::Type board)
{
switch (board) {
case BOARD_BETAFPV_LR3PRO:
return "BETAFPV";
case BOARD_FATFISH_F16:
return "Fatfish";
case BOARD_FLYSKY_NV14:
case BOARD_FLYSKY_EL18:
case BOARD_FLYSKY_PA01:
case BOARD_FLYSKY_PL18:
case BOARD_FLYSKY_PL18EV:
case BOARD_FLYSKY_PL18U:
case BOARD_FLYSKY_NB4P:
case BOARD_FLYSKY_ST16:
return "FlySky";
case BOARD_TARANIS_X7:
case BOARD_TARANIS_X7_ACCESS:
case BOARD_TARANIS_XLITE:
case BOARD_TARANIS_XLITES:
case BOARD_TARANIS_X9D:
case BOARD_TARANIS_X9DP:
case BOARD_TARANIS_X9DP_2019:
case BOARD_TARANIS_X9E:
case BOARD_TARANIS_X9LITE:
case BOARD_TARANIS_X9LITES:
case BOARD_HORUS_X12S:
case BOARD_X10:
case BOARD_X10_EXPRESS:
return "FrSky";
case BOARD_HELLORADIOSKY_V16:
case BOARD_HELLORADIOSKY_V12:
case BOARD_HELLORADIOSKY_V14:
case BOARD_HELLORADIOSKY_V14LCD:
return "HelloRadioSky";
case BOARD_IFLIGHT_COMMANDO8:
case BOARD_IFLIGHT_COMMANDO14:
return "iFlight";
case BOARD_JUMPER_T12:
case BOARD_JUMPER_TLITE:
case BOARD_JUMPER_TLITE_F4:
case BOARD_JUMPER_TPRO:
case BOARD_JUMPER_TPROV2:
case BOARD_JUMPER_TPROS:
case BOARD_JUMPER_T12MAX:
case BOARD_JUMPER_BUMBLEBEE:
case BOARD_JUMPER_T14:
case BOARD_JUMPER_T15:
case BOARD_JUMPER_T15PRO:
case BOARD_JUMPER_T22:
case BOARD_JUMPER_T16:
case BOARD_JUMPER_T18:
case BOARD_JUMPER_T20:
case BOARD_JUMPER_T20V2:
return "Jumper";
case BOARD_RADIOMASTER_BOXER:
case BOARD_RADIOMASTER_POCKET:
case BOARD_RADIOMASTER_MT12:
case BOARD_RADIOMASTER_T8:
case BOARD_RADIOMASTER_TX12:
case BOARD_RADIOMASTER_TX12_MK2:
case BOARD_RADIOMASTER_TX16S:
case BOARD_RADIOMASTER_TX16SMK3:
case BOARD_RADIOMASTER_TX15:
case BOARD_RADIOMASTER_ZORRO:
case BOARD_RADIOMASTER_GX12:
return "Radiomaster";
default:
return CPN_STR_UNKNOWN_ITEM;
}
return getCapabilityStr(board, Board::Manufacturer);
}
+1
View File
@@ -262,6 +262,7 @@ namespace Board {
LcdHeight,
LcdOLED,
LcdWidth,
Manufacturer,
MaxContrast,
MaxVolume,
MinContrast,
@@ -0,0 +1,57 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
// Boards::getManufacturer() now reads the "manufacturer" field from each
// board's hw_defs JSON (via BoardJson) instead of a hand-maintained switch
// statement. This guards against the JSON entries and the switch it replaced
// silently drifting apart, e.g. a newly-added board being forgotten (as
// happened with BOARD_SENDUWING_H17 and BOARD_RADIOMASTER_GX15, both of
// which fell through to "???" under the old switch).
#include "gtests.h"
#include "constants.h"
#include "firmwares/boards.h"
#include "firmwares/eeprominterface.h"
TEST(BoardManufacturer, NoRegisteredBoardIsUnknown)
{
for (Firmware *firmware : Firmware::getRegisteredFirmwares()) {
const QString manufacturer = Boards::getManufacturer(firmware->getBoard());
EXPECT_FALSE(manufacturer.isEmpty()) << "board: " << firmware->getId().toStdString();
EXPECT_NE(manufacturer, QString(CPN_STR_UNKNOWN_ITEM))
<< "board: " << firmware->getId().toStdString();
}
}
TEST(BoardManufacturer, KnownBoardsMatchExpectedManufacturer)
{
EXPECT_EQ(Boards::getManufacturer(Board::BOARD_RADIOMASTER_TX16S), QString("RadioMaster"));
EXPECT_EQ(Boards::getManufacturer(Board::BOARD_RADIOMASTER_GX15), QString("RadioMaster"));
EXPECT_EQ(Boards::getManufacturer(Board::BOARD_FLYSKY_NV14), QString("Flysky"));
EXPECT_EQ(Boards::getManufacturer(Board::BOARD_HELLORADIOSKY_V12), QString("HelloRadioSky"));
EXPECT_EQ(Boards::getManufacturer(Board::BOARD_SENDUWING_H17), QString("Senduwing"));
EXPECT_EQ(Boards::getManufacturer(Board::BOARD_JUMPER_T16), QString("Jumper"));
EXPECT_EQ(Boards::getManufacturer(Board::BOARD_IFLIGHT_COMMANDO14), QString("iFlight"));
EXPECT_EQ(Boards::getManufacturer(Board::BOARD_TARANIS_X9E), QString("FrSky"));
EXPECT_EQ(Boards::getManufacturer(Board::BOARD_BETAFPV_LR3PRO), QString("BETAFPV"));
EXPECT_EQ(Boards::getManufacturer(Board::BOARD_FATFISH_F16), QString("Fatfish"));
}