fix(cpn): Load models into slot based on filename for B&W radios (#3373)

* Fix(cpn) - load models into slot based on filename for non-label radios

* Check model filename index within bounds and if not skip file

* Check if slot is free before loading file if not skip
This commit is contained in:
Neil Horne
2023-03-27 14:01:08 +10:00
committed by GitHub
parent 45e76f3a3d
commit 5465984239
+18 -2
View File
@@ -241,7 +241,7 @@ bool LabelsStorageFormat::loadYaml(RadioData & radioData)
if (match.size() == 3) { if (match.size() == 3) {
std::ssub_match modelFile = match[1]; std::ssub_match modelFile = match[1];
std::ssub_match modelIdx = match[2]; std::ssub_match modelIdx = match[2];
modelFiles.push_back({ modelFile.str(), "", std::stoi(modelIdx.str()) }); modelFiles.push_back({ modelFile.str(), "", std::stoi(modelIdx.str()) });
} }
} }
} }
@@ -249,10 +249,26 @@ bool LabelsStorageFormat::loadYaml(RadioData & radioData)
int modelIdx = 0; int modelIdx = 0;
bool hasLabels = getCurrentFirmware()->getCapability(HasModelLabels); bool hasLabels = getCurrentFirmware()->getCapability(HasModelLabels);
radioData.models.resize(modelFiles.size()); if (hasLabels)
radioData.models.resize(modelFiles.size());
for (const auto& mc : modelFiles) { for (const auto& mc : modelFiles) {
qDebug() << "Filename: " << mc.filename.c_str(); qDebug() << "Filename: " << mc.filename.c_str();
if (!hasLabels) {
if (mc.modelIdx >= 0 && mc.modelIdx < (int)radioData.models.size()) {
modelIdx = mc.modelIdx;
if (!radioData.models[modelIdx].isEmpty()) {
qDebug() << QString("Warning: file %1 skipped as slot %2 already used").arg(mc.filename.c_str()).arg(mc.modelIdx + 1);
continue;
}
}
else {
qDebug() << QString("Warning: file %1 skipped as slot %2 not available").arg(mc.filename.c_str()).arg(mc.modelIdx + 1);
continue;
}
}
QByteArray modelBuffer; QByteArray modelBuffer;
QString filename = "MODELS/" + QString::fromStdString(mc.filename); QString filename = "MODELS/" + QString::fromStdString(mc.filename);
if (!loadFile(modelBuffer, filename)) { if (!loadFile(modelBuffer, filename)) {