Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cpn): ensure hardware definitions are loaded when reading binary files #5037

Merged
merged 1 commit into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions companion/src/firmwares/opentx/opentxinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ const char * OpenTxEepromInterface::getName()

bool OpenTxEepromInterface::loadRadioSettingsFromRLE(GeneralSettings & settings, RleFile * rleFile, uint8_t version)
{
// Companion loads the current profile firmware and associated board hardware definition ONLY!!!!
// For each OpenTxEepromInterface create a firmware variant to force the associated base firmware board hardware definition to be loaded.
// Note: The base firmware instance does not do load its hardware definition to save unnecessary processing.
// To create the variant take the base id and append the language from the current radio profile.
Firmware *fw = Firmware::getFirmwareForId(firmware->getId().append("-%1").arg(g.currentProfile().fwType().split('-').last()));
if (!fw) {
qWarning() << " error unable to create firmware variant";
return false;
}

QByteArray data(sizeof(settings), 0); // GeneralSettings should be always bigger than the EEPROM struct
OpenTxGeneralData open9xSettings(settings, board, version);
efile->openRd(FILE_GENERAL);
Expand Down Expand Up @@ -194,6 +204,16 @@ bool OpenTxEepromInterface::saveToByteArray(const T & src, QByteArray & data, ui
template <class T, class M>
bool OpenTxEepromInterface::loadFromByteArray(T & dest, const QByteArray & data, uint8_t version, uint32_t variant)
{
// Companion loads the current profile firmware and associated board hardware definition ONLY!!!!
// For each OpenTxEepromInterface create a firmware variant to force the associated base firmware board hardware definition to be loaded.
// Note: The base firmware instance does not do load its hardware definition to save unnecessary processing.
// To create the variant take the base id and append the language from the current radio profile.
Firmware *fw = Firmware::getFirmwareForId(firmware->getId().append("-%1").arg(g.currentProfile().fwType().split('-').last()));
if (!fw) {
qWarning() << " error unable to create firmware variant";
return false;
}

M manager(dest, board, version, variant);
if (manager.Import(data) != 0) {
return false;
Expand All @@ -216,8 +236,9 @@ bool OpenTxEepromInterface::loadFromByteArray(T & dest, const QByteArray & data)
}
}

if (board != getCurrentBoard()) {
qDebug() << QString("%1: not a match to profile %2").arg(getName()).arg(Boards::getBoardName(getCurrentBoard()));
if (Boards::getFourCC(board) == Boards::getFourCC(getCurrentBoard()) &&
board != getCurrentFirmware()->getBoard()) {
qDebug() << QString("%1: Fourcc not unique and does not match profile board: %2").arg(getName()).arg(Boards::getBoardName(getCurrentBoard()));
return false;
}

Expand Down