Check device serial when loading calibration

This commit is contained in:
Jan Käberich 2022-12-15 22:43:41 +01:00
parent fe340ac620
commit 0cc5968b12
8 changed files with 37 additions and 42872 deletions

View File

@ -1248,6 +1248,24 @@ QString Calibration::descriptiveCalName()
return tmp;
}
QString Calibration::getValidDevice() const
{
return validDevice;
}
bool Calibration::validForDevice(QString serial) const
{
if(validDevice.isEmpty()) {
// no device indicated, always assume that the calibration is valid
return true;
}
if(validDevice == serial) {
return true;
} else {
return false;
}
}
bool Calibration::hasUnsavedChanges() const
{
return unsavedChanges;
@ -1279,9 +1297,7 @@ nlohmann::json Calibration::toJSON()
}
j["ports"] = jports;
j["version"] = qlibrevnaApp->applicationVersion().toStdString();
if(VirtualDevice::getConnected()) {
j["device"] = VirtualDevice::getConnected()->serial().toStdString();
}
j["device"] = validDevice.toStdString();
return j;
}
@ -1326,6 +1342,7 @@ void Calibration::fromJSON(nlohmann::json j)
if(ct.type != Type::None) {
compute(ct);
}
validDevice = QString::fromStdString(j.value("device", ""));
}
break;
case 2: {
@ -1716,6 +1733,9 @@ void Calibration::addMeasurements(std::set<CalibrationMeasurement::Base *> m, co
meas->addPoint(data);
}
unsavedChanges = true;
if(VirtualDevice::getConnected()) {
validDevice = VirtualDevice::getConnected()->serial();
}
}
void Calibration::clearMeasurements(std::set<CalibrationMeasurement::Base *> m)

View File

@ -93,6 +93,9 @@ public:
int getNumPoints();
bool hasUnsavedChanges() const;
QString getValidDevice() const;
bool validForDevice(QString serial) const;
public slots:
// Call once all datapoints of the current span have been added
void measurementsComplete();
@ -154,6 +157,8 @@ private:
QString descriptiveCalName();
QString currentCalFile;
QString validDevice;
bool unsavedChanges;
std::recursive_mutex access;

View File

@ -97,6 +97,10 @@ VNA::VNA(AppWindow *window, QString name)
connect(calLoad, &QAction::triggered, [=](){
LoadCalibration();
if(window->getDevice() && !cal.validForDevice(window->getDevice()->serial())) {
InformationBox::ShowMessage("Invalid calibration", "The selected calibration was created for a different device. You can still load it but the resulting "
"data likely isn't useful.");
}
});
connect(saveCal, &QAction::triggered, [=](){
@ -215,6 +219,7 @@ VNA::VNA(AppWindow *window, QString name)
if(!filename.isEmpty()) {
settings.setValue(key, filename);
removeDefaultCal->setEnabled(true);
LoadCalibration(filename);
}
}
});
@ -697,6 +702,10 @@ void VNA::initializeDevice()
// Configure initial state of device
SettingsChanged();
emit deviceInitialized();
if(window->getDevice() && !cal.validForDevice(window->getDevice()->serial())) {
InformationBox::ShowMessage("Invalid calibration", "The current calibration was created for a different device. You can still use it but the resulting "
"data likely isn't useful.");
}
}
void VNA::deviceDisconnected()

File diff suppressed because it is too large Load Diff

View File

@ -1,34 +0,0 @@
{
"Description": "TRL test calibration kit",
"Manufacturer": "Hugen",
"Serialnumber": "-",
"standards": [
{
"params": {
"id": 5166523964218309461,
"isShort": true,
"name": "TRL"
},
"type": "Reflect"
},
{
"params": {
"Z0": 50.0,
"delay": 0.0,
"id": 4725361202400330854,
"loss": 0.0,
"name": "TRL"
},
"type": "Through"
},
{
"params": {
"delay": 1e-09,
"id": 10060287735088848795,
"name": "TRL"
},
"type": "Line"
}
],
"version": "1.4.0-b20e5598b"
}

File diff suppressed because it is too large Load Diff

View File

@ -1,34 +0,0 @@
{
"Description": "TRL test calibration kit",
"Manufacturer": "Hugen",
"Serialnumber": "-",
"standards": [
{
"params": {
"id": 5166523964218309461,
"isShort": true,
"name": "TRL"
},
"type": "Reflect"
},
{
"params": {
"Z0": 50.0,
"delay": 0.0,
"id": 4725361202400330854,
"loss": 0.0,
"name": "TRL"
},
"type": "Through"
},
{
"params": {
"delay": 1e-09,
"id": 10060287735088848795,
"name": "TRL"
},
"type": "Line"
}
],
"version": "1.4.0-b20e5598b"
}