mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-07 07:23:43 +00:00
Additional de-embedding options: 2xthru and matching network
This commit is contained in:
parent
51806b936c
commit
09d5c53bc7
37 changed files with 2954 additions and 100 deletions
93
Software/PC_Application/VNA/Deembedding/deembedding.cpp
Normal file
93
Software/PC_Application/VNA/Deembedding/deembedding.cpp
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
#include "deembedding.h"
|
||||
#include "deembeddingdialog.h"
|
||||
#include <QDebug>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void Deembedding::configure()
|
||||
{
|
||||
auto d = new DeembeddingDialog(this);
|
||||
d->show();
|
||||
}
|
||||
|
||||
void Deembedding::Deembed(Protocol::Datapoint &d)
|
||||
{
|
||||
for(auto it = options.begin();it != options.end();it++) {
|
||||
(*it)->transformDatapoint(d);
|
||||
}
|
||||
}
|
||||
|
||||
void Deembedding::removeOption(unsigned int index)
|
||||
{
|
||||
if(index < options.size()) {
|
||||
delete options[index];
|
||||
options.erase(options.begin() + index);
|
||||
}
|
||||
}
|
||||
|
||||
void Deembedding::addOption(DeembeddingOption *option)
|
||||
{
|
||||
options.push_back(option);
|
||||
connect(option, &DeembeddingOption::deleted, [=](DeembeddingOption *o){
|
||||
// find deleted option and remove from list
|
||||
auto pos = find(options.begin(), options.end(), o);
|
||||
if(pos != options.end()) {
|
||||
options.erase(pos);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Deembedding::swapOptions(unsigned int index)
|
||||
{
|
||||
if(index + 1 >= options.size()) {
|
||||
return;
|
||||
}
|
||||
std::swap(options[index], options[index+1]);
|
||||
}
|
||||
|
||||
nlohmann::json Deembedding::toJSON()
|
||||
{
|
||||
nlohmann::json list;
|
||||
for(auto m : options) {
|
||||
nlohmann::json jm;
|
||||
jm["operation"] = DeembeddingOption::getName(m->getType()).toStdString();
|
||||
jm["settings"] = m->toJSON();
|
||||
list.push_back(jm);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
void Deembedding::fromJSON(nlohmann::json j)
|
||||
{
|
||||
// clear all options
|
||||
while(options.size() > 0) {
|
||||
removeOption(0);
|
||||
}
|
||||
for(auto jm : j) {
|
||||
QString operation = QString::fromStdString(jm.value("operation", ""));
|
||||
if(operation.isEmpty()) {
|
||||
qWarning() << "Skipping empty de-embedding operation";
|
||||
continue;
|
||||
}
|
||||
// attempt to find the type of operation
|
||||
DeembeddingOption::Type type = DeembeddingOption::Type::Last;
|
||||
for(unsigned int i=0;i<(int) DeembeddingOption::Type::Last;i++) {
|
||||
if(DeembeddingOption::getName((DeembeddingOption::Type) i) == operation) {
|
||||
// found the correct operation
|
||||
type = (DeembeddingOption::Type) i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(type == DeembeddingOption::Type::Last) {
|
||||
// unable to find this operation
|
||||
qWarning() << "Unable to create de-embedding operation:" << operation;
|
||||
continue;
|
||||
}
|
||||
qDebug() << "Creating math operation of type:" << operation;
|
||||
auto op = DeembeddingOption::create(type);
|
||||
if(jm.contains("settings")) {
|
||||
op->fromJSON(jm["settings"]);
|
||||
}
|
||||
addOption(op);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue