Skip to content

Commit

Permalink
fixcpn): use model semver over radio semver for decoding model source…
Browse files Browse the repository at this point in the history
…s and switches (EdgeTX#4768)
  • Loading branch information
Neil Horne authored and felipemanga committed Mar 29, 2024
1 parent 0520358 commit f0b5da2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
14 changes: 9 additions & 5 deletions companion/src/firmwares/edgetx/yaml_modeldata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
#include "helpers.h"

#include <string>

SemanticVersion version; // used for data conversions
#include <QMessageBox>

void YamlValidateLabelsNames(ModelData& model, Board::Type board)
{
Expand Down Expand Up @@ -867,7 +866,7 @@ struct convert<FrSkyScreenData> {

Node convert<ModelData>::encode(const ModelData& rhs)
{
version = SemanticVersion(VERSION);
modelSettingsVersion = SemanticVersion(VERSION);

Node node;
auto board = getCurrentBoard();
Expand Down Expand Up @@ -1163,8 +1162,13 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)

qDebug() << "Settings version:" << modelSettingsVersion.toString();

if (modelSettingsVersion > SemanticVersion(VERSION))
qDebug() << "Warning: version not supported by Companion!";
if (modelSettingsVersion > SemanticVersion(VERSION)) {
QString prmpt = QCoreApplication::translate("YamlModelSettings", "Warning: Model settings file version %1 is not supported by this version of Companion!\n\nModel and radio settings may be corrupted if you continue.\n\nI acknowledge and accept the consequences.");
if (QMessageBox::warning(NULL, CPN_STR_APP_NAME, prmpt.arg(modelSettingsVersion.toString()), (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) != QMessageBox::Yes) {
// TODO: this triggers an error in the calling code so we need a graceful way to handle
return false;
}
}

if (node["header"]) {
const auto& header = node["header"];
Expand Down
6 changes: 3 additions & 3 deletions companion/src/firmwares/edgetx/yaml_rawsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ RawSource YamlRawSourceDecode(const std::string& src_str)
std::string ana_str;
node >> ana_str;

if (radioSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) {
if (modelSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) {
ana_str = Boards::getLegacyAnalogMappedInputTag(ana_str.c_str());
int idx = Boards::getInputIndex(ana_str.c_str(), Board::LVT_TAG);
if (idx >= 0 && Boards::isInputStick(idx))
Expand All @@ -280,7 +280,7 @@ RawSource YamlRawSourceDecode(const std::string& src_str)
std::string trim_str;
node >> trim_str;

if (radioSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) {
if (modelSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) {
int idx = b.getLegacyTrimSourceIndex(src_str.c_str());
if (idx >= 0)
trim_str = Boards::getTrimYamlName(idx, BoardJson::YLT_REF).toStdString();
Expand All @@ -296,7 +296,7 @@ RawSource YamlRawSourceDecode(const std::string& src_str)
std::string special_str;
node >> special_str;

if (radioSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) {
if (modelSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) {
if (special_str.size() == 6 && special_str.substr(0, 5) == "TIMER") {
special_str = "Tmr" + special_str.substr(5, 1);
}
Expand Down
2 changes: 1 addition & 1 deletion companion/src/firmwares/edgetx/yaml_rawswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str)
try {
mp_input_index = std::stoi(sw_str_tmp.substr(2, val_len - 3));

if (radioSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) {
if (modelSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) {
if (IS_HORUS_X10(board) || IS_FAMILY_T16(board)) {
if (mp_input_index > 2)
mp_input_index += 2;
Expand Down

0 comments on commit f0b5da2

Please sign in to comment.