Skip to content

Commit cf8c99d

Browse files
elecpowerpfeerick
elecpower
authored andcommitted
fixcpn): use model semver over radio semver for decoding model sources and switches
1 parent 80f5d3d commit cf8c99d

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

companion/src/firmwares/edgetx/yaml_modeldata.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
#include "helpers.h"
3939

4040
#include <string>
41-
42-
SemanticVersion version; // used for data conversions
41+
#include <QMessageBox>
4342

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

868867
Node convert<ModelData>::encode(const ModelData& rhs)
869868
{
870-
version = SemanticVersion(VERSION);
869+
modelSettingsVersion = SemanticVersion(VERSION);
871870

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

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

1166-
if (modelSettingsVersion > SemanticVersion(VERSION))
1167-
qDebug() << "Warning: version not supported by Companion!";
1165+
if (modelSettingsVersion > SemanticVersion(VERSION)) {
1166+
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.");
1167+
if (QMessageBox::warning(NULL, CPN_STR_APP_NAME, prmpt.arg(modelSettingsVersion.toString()), (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) != QMessageBox::Yes) {
1168+
// TODO: this triggers an error in the calling code so we need a graceful way to handle
1169+
return false;
1170+
}
1171+
}
11681172

11691173
if (node["header"]) {
11701174
const auto& header = node["header"];

companion/src/firmwares/edgetx/yaml_rawsource.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ RawSource YamlRawSourceDecode(const std::string& src_str)
263263
std::string ana_str;
264264
node >> ana_str;
265265

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

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

299-
if (radioSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) {
299+
if (modelSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) {
300300
if (special_str.size() == 6 && special_str.substr(0, 5) == "TIMER") {
301301
special_str = "Tmr" + special_str.substr(5, 1);
302302
}

companion/src/firmwares/edgetx/yaml_rawswitch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str)
119119
try {
120120
mp_input_index = std::stoi(sw_str_tmp.substr(2, val_len - 3));
121121

122-
if (radioSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) {
122+
if (modelSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) {
123123
if (IS_HORUS_X10(board) || IS_FAMILY_T16(board)) {
124124
if (mp_input_index > 2)
125125
mp_input_index += 2;

0 commit comments

Comments
 (0)