fix(cpn): preserve current calibration when writing models and settings to radio (#6722)
This commit is contained in:
@@ -57,21 +57,8 @@ bool LabelsStorageFormat::load(RadioData & radioData)
|
||||
qDebug() << tr("Found %1").arg(filename);
|
||||
}
|
||||
|
||||
QByteArray radioSettingsBuffer;
|
||||
if (!loadFile(radioSettingsBuffer, "RADIO/radio.yml")) {
|
||||
setError(tr("Cannot extract RADIO/radio.yml"));
|
||||
if (!loadRadioSettings(radioData.generalSettings))
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!loadRadioSettingsFromYaml(radioData.generalSettings, radioSettingsBuffer)) {
|
||||
setError(tr("Cannot load RADIO/radio.yml"));
|
||||
return false;
|
||||
}
|
||||
} catch(const std::runtime_error& e) {
|
||||
setError(tr("Cannot load RADIO/radio.yml") + ":\n" + QString(e.what()));
|
||||
return false;
|
||||
}
|
||||
|
||||
board = (Board::Type)radioData.generalSettings.variant;
|
||||
|
||||
@@ -187,8 +174,34 @@ bool LabelsStorageFormat::load(RadioData & radioData)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LabelsStorageFormat::write(const RadioData & radioData)
|
||||
bool LabelsStorageFormat::write(RadioData & radioData)
|
||||
{
|
||||
// TODO
|
||||
// move all unique radio settings to a separate file eg RADIO/hardware.yml.
|
||||
// These settings/values should never be transferred to another radio.
|
||||
// Also some are at a point in time eg calibration and
|
||||
// therefore not restored to the radio from say an etx file
|
||||
|
||||
// may not exist on a new sd card or path
|
||||
if (QFile(filename + "/RADIO/radio.yml").exists()) {
|
||||
GeneralSettings gsCur;
|
||||
|
||||
if (loadRadioSettings(gsCur)) {
|
||||
GeneralSettings & gsNew = radioData.generalSettings;
|
||||
gsNew.txCurrentCalibration = gsCur.txCurrentCalibration;
|
||||
gsNew.txVoltageCalibration = gsCur.txVoltageCalibration;
|
||||
|
||||
for (int i = 0; i < CPN_MAX_INPUTS; i++) {
|
||||
gsNew.inputConfig[i].calib = gsCur.inputConfig[i].calib;
|
||||
}
|
||||
|
||||
qDebug() << "Hardware specific settings preserved";
|
||||
} else {
|
||||
setError("Error reading current settings from radio");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray radioSettingsBuffer;
|
||||
if (!writeRadioSettingsToYaml(radioData.generalSettings, radioSettingsBuffer))
|
||||
return false;
|
||||
@@ -280,3 +293,28 @@ bool LabelsStorageFormat::writeChecklist(const ModelData & model)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LabelsStorageFormat::loadRadioSettings(GeneralSettings & generalSettings)
|
||||
{
|
||||
QByteArray radioSettingsBuffer;
|
||||
|
||||
const QString file("RADIO/radio.yml");
|
||||
const QString filePath(QDir::toNativeSeparators(filename + "/" + file));
|
||||
|
||||
if (!loadFile(radioSettingsBuffer, file)) {
|
||||
setError(tr("Cannot extract %1").arg(filePath));
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!loadRadioSettingsFromYaml(generalSettings, radioSettingsBuffer)) {
|
||||
setError(tr("Cannot load %1").arg(filePath));
|
||||
return false;
|
||||
}
|
||||
} catch(const std::runtime_error& e) {
|
||||
setError(tr("Cannot load %1").arg(filePath) + ":\n" + QString(e.what()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user