Skip to content

Commit

Permalink
Check for ID collisions when loading calibration standards
Browse files Browse the repository at this point in the history
  • Loading branch information
jankae committed May 10, 2024
1 parent 792a6a4 commit e1168f2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,21 +245,21 @@ void LibreCALDialog::startCalibration()
o->setName("Port "+QString::number(i));
o->setMeasurement(coeffSet.opens[i-1]->t);
openStandards.push_back(o);
kit.standards.push_back(o);
kit.addStandard(o);
}
if(coeffSet.shorts[i-1]->t.points() > 0) {
auto o = new CalStandard::Short();
o->setName("Port "+QString::number(i));
o->setMeasurement(coeffSet.shorts[i-1]->t);
shortStandards.push_back(o);
kit.standards.push_back(o);
kit.addStandard(o);
}
if(coeffSet.loads[i-1]->t.points() > 0) {
auto o = new CalStandard::Load();
o->setName("Port "+QString::number(i));
o->setMeasurement(coeffSet.loads[i-1]->t);
loadStandards.push_back(o);
kit.standards.push_back(o);
kit.addStandard(o);
}
for(unsigned int j=i+1;j<=device->getNumPorts();j++) {
auto c = coeffSet.getThrough(i,j);
Expand All @@ -271,7 +271,7 @@ void LibreCALDialog::startCalibration()
o->setName("Port "+QString::number(i)+" to "+QString::number(j));
o->setMeasurement(c->t);
throughStandards.push_back(o);
kit.standards.push_back(o);
kit.addStandard(o);
}
}
}
Expand Down
29 changes: 21 additions & 8 deletions Software/PC_Application/LibreVNA-GUI/Calibration/calkit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,15 @@ Calkit Calkit::fromFile(QString filename)
ts.fromFile(SOLT.open_m.file.toStdString());
open_m->setMeasurement(ts, SOLT.open_m.Sparam);
}
c.standards.push_back(open_m);
c.addStandard(open_m);
if(SOLT.separate_male_female) {
auto open_f = new CalStandard::Open("Default female standard", SOLT.open_f.Z0, SOLT.open_f.delay, SOLT.open_f.loss, SOLT.open_f.C0, SOLT.open_f.C1, SOLT.open_f.C2, SOLT.open_f.C3);
if(SOLT.open_f.useMeasurements) {
auto ts = Touchstone(1);
ts.fromFile(SOLT.open_f.file.toStdString());
open_m->setMeasurement(ts, SOLT.open_f.Sparam);
}
c.standards.push_back(open_f);
c.addStandard(open_f);
}

auto short_m = new CalStandard::Short(SOLT.separate_male_female ? "Default male standard" : "Default standard", SOLT.short_m.Z0, SOLT.short_m.delay, SOLT.short_m.loss, SOLT.short_m.L0, SOLT.short_m.L1, SOLT.short_m.L2, SOLT.short_m.L3);
Expand All @@ -303,15 +303,15 @@ Calkit Calkit::fromFile(QString filename)
ts.fromFile(SOLT.short_m.file.toStdString());
short_m->setMeasurement(ts, SOLT.short_m.Sparam);
}
c.standards.push_back(short_m);
c.addStandard(short_m);
if(SOLT.separate_male_female) {
auto short_f = new CalStandard::Short("Default female standard", SOLT.short_f.Z0, SOLT.short_f.delay, SOLT.short_f.loss, SOLT.short_f.L0, SOLT.short_f.L1, SOLT.short_f.L2, SOLT.short_f.L3);
if(SOLT.short_f.useMeasurements) {
auto ts = Touchstone(1);
ts.fromFile(SOLT.short_f.file.toStdString());
short_m->setMeasurement(ts, SOLT.short_f.Sparam);
}
c.standards.push_back(short_f);
c.addStandard(short_f);
}

auto load_m = new CalStandard::Load(SOLT.separate_male_female ? "Default male standard" : "Default standard", SOLT.load_m.Z0, SOLT.load_m.delay, 0.0, SOLT.load_m.resistance, SOLT.load_m.Cparallel, SOLT.load_m.Lseries, SOLT.loadModelCFirst);
Expand All @@ -320,15 +320,15 @@ Calkit Calkit::fromFile(QString filename)
ts.fromFile(SOLT.load_m.file.toStdString());
load_m->setMeasurement(ts, SOLT.load_m.Sparam);
}
c.standards.push_back(load_m);
c.addStandard(load_m);
if(SOLT.separate_male_female) {
auto load_f = new CalStandard::Load("Default female standard", SOLT.load_m.Z0, SOLT.load_f.delay, 0.0, SOLT.load_f.resistance, SOLT.load_f.Cparallel, SOLT.load_f.Lseries, SOLT.loadModelCFirst);
if(SOLT.load_f.useMeasurements) {
auto ts = Touchstone(1);
ts.fromFile(SOLT.load_f.file.toStdString());
load_m->setMeasurement(ts, SOLT.load_f.Sparam);
}
c.standards.push_back(load_f);
c.addStandard(load_f);
}

auto through = new CalStandard::Through("Default standard", SOLT.Through.Z0, SOLT.Through.delay, SOLT.Through.loss);
Expand All @@ -337,7 +337,7 @@ Calkit Calkit::fromFile(QString filename)
ts.fromFile(SOLT.Through.file.toStdString());
through->setMeasurement(ts, SOLT.Through.Sparam1, SOLT.Through.Sparam2);
}
c.standards.push_back(through);
c.addStandard(through);

InformationBox::ShowMessage("Loading calkit file", "The file \"" + filename + "\" is stored in a deprecated"
" calibration kit format. Future versions of this application might not support"
Expand Down Expand Up @@ -377,6 +377,19 @@ std::vector<CalStandard::Virtual *> Calkit::getStandards() const

void Calkit::addStandard(CalStandard::Virtual *s)
{
// check for ID collisions. This should never happen but would mess up further
// usage of the standards. Better to catch this now and throw an error
for(auto comp : standards) {
if(comp->getID() == s->getID()) {
// collision, do not add
InformationBox::ShowError("Calibration standard ID collision", "New standard \""
+s->getName()+"\" of type \""+CalStandard::Virtual::TypeToString(s->getType())
+"\" has the same ID as already existing standard \""
+comp->getName()+"\" of type \""+CalStandard::Virtual::TypeToString(comp->getType())
+"\" (ID="+QString::number(s->getID())+"). It will be removed from the calibration kit");
return;
}
}
standards.push_back(s);
}

Expand Down Expand Up @@ -411,7 +424,7 @@ void Calkit::fromJSON(nlohmann::json j)
}
auto s = CalStandard::Virtual::create(type);
s->fromJSON(js["params"]);
standards.push_back(s);
addStandard(s);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ CalkitDialog::CalkitDialog(Calkit &c, QWidget *parent) :
connect(action, &QAction::triggered, [=](){
auto newStandard = CalStandard::Virtual::create(t);
if(newStandard) {
kit.standards.push_back(newStandard);
kit.addStandard(newStandard);
updateStandardList();
// start the edit dialog of the newly created standard
kit.standards.back()->edit(bind(&CalkitDialog::updateStandardList, this));
Expand Down

0 comments on commit e1168f2

Please sign in to comment.