From 9b4865dceb00a6306c95c32635b42868690031ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=A4berich?= Date: Mon, 20 Feb 2023 13:08:31 +0100 Subject: [PATCH] Renaming packet types, implementing different packet contents per hardware version --- .../LibreVNA/Compound/compounddriver.cpp | 40 +- .../Device/LibreVNA/Compound/compounddriver.h | 6 +- .../LibreVNA/deviceconfigurationdialogv1.cpp | 84 +++ .../LibreVNA/deviceconfigurationdialogv1.h | 28 + .../LibreVNA/deviceconfigurationdialogv1.ui | 159 ++++ .../LibreVNA/deviceconfigurationdialogvff.cpp | 80 +++ .../LibreVNA/deviceconfigurationdialogvff.h | 31 + .../LibreVNA/deviceconfigurationdialogvff.ui | 83 +++ .../Device/LibreVNA/devicepacketlogview.cpp | 71 +- .../Device/LibreVNA/librevnadriver.cpp | 148 ++-- .../Device/LibreVNA/librevnadriver.h | 6 +- .../LibreVNA/librevnadriversettingswidget.ui | 122 +--- .../Device/LibreVNA/librevnatcpdriver.cpp | 9 +- .../Device/LibreVNA/librevnausbdriver.cpp | 5 +- ...oldialog.cpp => manualcontroldialogV1.cpp} | 172 ++--- ...ontroldialog.h => manualcontroldialogV1.h} | 18 +- ...troldialog.ui => manualcontroldialogV1.ui} | 6 +- .../LibreVNA/manualcontroldialogvff.cpp | 432 +++++++++++ .../Device/LibreVNA/manualcontroldialogvff.h | 107 +++ .../Device/LibreVNA/manualcontroldialogvff.ui | 676 ++++++++++++++++++ .../LibreVNA-GUI/LibreVNA-GUI.pro | 15 +- .../SpectrumAnalyzer/spectrumanalyzer.cpp | 1 + .../PC_Application/LibreVNA-GUI/VNA/vna.cpp | 1 + .../LibreVNA-Test/LibreVNA-Test.pro | 15 +- .../.settings/stm32cubeide.project.prefs | 6 +- Software/VNA_embedded/Application/App.cpp | 20 +- .../Application/Communication/Protocol.cpp | 10 +- .../Application/Communication/Protocol.hpp | 189 +++-- .../VNA_embedded/Application/Hardware.cpp | 34 +- .../VNA_embedded/Application/Hardware.hpp | 4 +- Software/VNA_embedded/Application/Manual.cpp | 96 +-- Software/VNA_embedded/Application/Manual.hpp | 2 +- .../Application/SpectrumAnalyzer.cpp | 4 +- Software/VNA_embedded/Application/VNA.cpp | 4 +- 34 files changed, 2184 insertions(+), 500 deletions(-) create mode 100644 Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogv1.cpp create mode 100644 Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogv1.h create mode 100644 Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogv1.ui create mode 100644 Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogvff.cpp create mode 100644 Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogvff.h create mode 100644 Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogvff.ui rename Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/{manualcontroldialog.cpp => manualcontroldialogV1.cpp} (74%) rename Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/{manualcontroldialog.h => manualcontroldialogV1.h} (87%) rename Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/{manualcontroldialog.ui => manualcontroldialogV1.ui} (99%) create mode 100644 Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogvff.cpp create mode 100644 Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogvff.h create mode 100644 Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogvff.ui diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/Compound/compounddriver.cpp b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/Compound/compounddriver.cpp index e048014..a8c071c 100644 --- a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/Compound/compounddriver.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/Compound/compounddriver.cpp @@ -160,16 +160,16 @@ QString CompoundDriver::getSerial() std::set CompoundDriver::getFlags() { std::set ret; - if(lastStatus.extRefInUse) { + if(lastStatus.V1.extRefInUse) { ret.insert(Flag::ExtRef); } - if(!lastStatus.source_locked || !lastStatus.LO1_locked) { + if(!lastStatus.V1.source_locked || !lastStatus.V1.LO1_locked) { ret.insert(Flag::Unlocked); } - if(lastStatus.unlevel) { + if(lastStatus.V1.unlevel) { ret.insert(Flag::Unlevel); } - if(lastStatus.ADC_overload) { + if(lastStatus.V1.ADC_overload) { ret.insert(Flag::Overload); } return ret; @@ -181,13 +181,13 @@ QString CompoundDriver::getStatus() ret.append("HW Rev."); ret.append(info.hardware_version); ret.append(" FW "+info.firmware_version); - ret.append(" Temps: "+QString::number(lastStatus.temp_source)+"°C/"+QString::number(lastStatus.temp_LO1)+"°C/"+QString::number(lastStatus.temp_MCU)+"°C"); + ret.append(" Temps: "+QString::number(lastStatus.V1.temp_source)+"°C/"+QString::number(lastStatus.V1.temp_LO1)+"°C/"+QString::number(lastStatus.V1.temp_MCU)+"°C"); ret.append(" Reference:"); - if(lastStatus.extRefInUse) { + if(lastStatus.V1.extRefInUse) { ret.append("External"); } else { ret.append("Internal"); - if(lastStatus.extRefAvailable) { + if(lastStatus.V1.extRefAvailable) { ret.append(" (External available)"); } } @@ -495,8 +495,8 @@ void CompoundDriver::createCompoundJSON() void CompoundDriver::incomingPacket(LibreVNADriver *device, const Protocol::PacketInfo &p) { switch(p.type) { - case Protocol::PacketType::DeviceStatusV1: - updatedStatus(device, p.statusV1); + case Protocol::PacketType::DeviceStatus: + updatedStatus(device, p.status); break; case Protocol::PacketType::VNADatapoint: datapointReceivecd(device, p.VNAdatapoint); @@ -557,7 +557,7 @@ void CompoundDriver::updatedInfo(LibreVNADriver *device) } } -void CompoundDriver::updatedStatus(LibreVNADriver *device, const Protocol::DeviceStatusV1 &status) +void CompoundDriver::updatedStatus(LibreVNADriver *device, const Protocol::DeviceStatus &status) { deviceStatus[device] = status; if(deviceStatus.size() == devices.size()) { @@ -567,16 +567,16 @@ void CompoundDriver::updatedStatus(LibreVNADriver *device, const Protocol::Devic if(i==0) { lastStatus = devStat; } else { - lastStatus.extRefAvailable &= devStat.extRefAvailable; - lastStatus.extRefInUse |= devStat.extRefInUse; - lastStatus.FPGA_configured &= devStat.FPGA_configured; - lastStatus.source_locked &= devStat.source_locked; - lastStatus.LO1_locked &= devStat.LO1_locked; - lastStatus.ADC_overload |= devStat.ADC_overload; - lastStatus.unlevel |= devStat.unlevel; - lastStatus.temp_source = std::max(lastStatus.temp_source, devStat.temp_source); - lastStatus.temp_LO1 = std::max(lastStatus.temp_LO1, devStat.temp_LO1); - lastStatus.temp_MCU = std::max(lastStatus.temp_MCU, devStat.temp_MCU); + lastStatus.V1.extRefAvailable &= devStat.V1.extRefAvailable; + lastStatus.V1.extRefInUse |= devStat.V1.extRefInUse; + lastStatus.V1.FPGA_configured &= devStat.V1.FPGA_configured; + lastStatus.V1.source_locked &= devStat.V1.source_locked; + lastStatus.V1.LO1_locked &= devStat.V1.LO1_locked; + lastStatus.V1.ADC_overload |= devStat.V1.ADC_overload; + lastStatus.V1.unlevel |= devStat.V1.unlevel; + lastStatus.V1.temp_source = std::max(lastStatus.V1.temp_source, devStat.V1.temp_source); + lastStatus.V1.temp_LO1 = std::max(lastStatus.V1.temp_LO1, devStat.V1.temp_LO1); + lastStatus.V1.temp_MCU = std::max(lastStatus.V1.temp_MCU, devStat.V1.temp_MCU); } } emit StatusUpdated(); diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/Compound/compounddriver.h b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/Compound/compounddriver.h index 51a2a58..7e3a9f1 100644 --- a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/Compound/compounddriver.h +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/Compound/compounddriver.h @@ -174,16 +174,16 @@ private: void createCompoundJSON(); void incomingPacket(LibreVNADriver *device, const Protocol::PacketInfo &p); void updatedInfo(LibreVNADriver *device); - void updatedStatus(LibreVNADriver *device, const Protocol::DeviceStatusV1 &status); + void updatedStatus(LibreVNADriver *device, const Protocol::DeviceStatus &status); void datapointReceivecd(LibreVNADriver *dev, Protocol::VNADatapoint<32> *data); void spectrumResultReceived(LibreVNADriver *dev, Protocol::SpectrumAnalyzerResult res); Info info; std::map deviceInfos; - std::map deviceStatus; + std::map deviceStatus; std::map*>> compoundVNABuffer; std::map> compoundSABuffer; - Protocol::DeviceStatusV1 lastStatus; + Protocol::DeviceStatus lastStatus; // Parsed configuration of compound devices (as extracted from compoundJSONString std::vector configuredDevices; diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogv1.cpp b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogv1.cpp new file mode 100644 index 0000000..35e08c6 --- /dev/null +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogv1.cpp @@ -0,0 +1,84 @@ +#include "deviceconfigurationdialogv1.h" +#include "ui_deviceconfigurationdialogv1.h" + +DeviceConfigurationDialogV1::DeviceConfigurationDialogV1(LibreVNADriver &dev, QWidget *parent) : + QDialog(parent), + ui(new Ui::DeviceConfigurationDialogV1), + dev(dev) +{ + ui->setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + + emit dev.acquireControl(); + + + auto updateADCRate = [=]() { + // update ADC rate, see FPGA protocol for calculation + ui->ADCRate->setValue(102400000.0 / ui->ADCpresc->value()); + }; + auto updateIF2 = [=]() { + auto ADCrate = ui->ADCRate->value(); + ui->IF2->setValue(ADCrate * ui->ADCphaseInc->value() / 4096); + }; + + connect(ui->ADCpresc, qOverload(&QSpinBox::valueChanged), updateADCRate); + connect(ui->ADCpresc, qOverload(&QSpinBox::valueChanged), updateIF2); + connect(ui->ADCphaseInc, qOverload(&QSpinBox::valueChanged), updateIF2); + + ui->IF1->setUnit("Hz"); + ui->IF1->setPrefixes(" kM"); + ui->IF1->setPrecision(5); + ui->ADCRate->setUnit("Hz"); + ui->ADCRate->setPrefixes(" kM"); + ui->ADCRate->setPrecision(5); + ui->IF2->setUnit("Hz"); + ui->IF2->setPrefixes(" kM"); + ui->IF2->setPrecision(5); + ui->IF1->setValue(62000000); + ui->ADCpresc->setValue(128); + ui->ADCphaseInc->setValue(1280); + + updateADCRate(); + updateIF2(); + + connect(&dev, &LibreVNADriver::receivedPacket, this, [=](const Protocol::PacketInfo &p) { + if(p.type == Protocol::PacketType::DeviceConfiguration) { + updateGUI(p.deviceConfig); + } + }); + + dev.sendWithoutPayload(Protocol::PacketType::RequestDeviceConfiguration); + + connect(ui->buttonBox, &QDialogButtonBox::accepted, this, [=](){ + updateDevice(); + accept(); + }); + connect(ui->buttonBox, &QDialogButtonBox::rejected, this, [=](){ + reject(); + }); +} + +DeviceConfigurationDialogV1::~DeviceConfigurationDialogV1() +{ + dev.releaseControl(); + delete ui; +} + +void DeviceConfigurationDialogV1::updateGUI(const Protocol::DeviceConfig &c) +{ + ui->IF1->setEnabled(false); + ui->IF1->setValue(c.V1.IF1); + ui->IF1->setEnabled(true); + ui->ADCpresc->setValue(c.V1.ADCprescaler); + ui->ADCphaseInc->setValue(c.V1.DFTphaseInc); +} + +void DeviceConfigurationDialogV1::updateDevice() +{ + Protocol::PacketInfo p; + p.type = Protocol::PacketType::DeviceConfiguration; + p.deviceConfig.V1.IF1 = ui->IF1->value(); + p.deviceConfig.V1.ADCprescaler = ui->ADCpresc->value(); + p.deviceConfig.V1.DFTphaseInc = ui->ADCphaseInc->value(); + dev.SendPacket(p); +} diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogv1.h b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogv1.h new file mode 100644 index 0000000..cf47d0e --- /dev/null +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogv1.h @@ -0,0 +1,28 @@ +#ifndef DEVICECONFIGURATIONDIALOGV1_H +#define DEVICECONFIGURATIONDIALOGV1_H + +#include + +#include "librevnadriver.h" + +namespace Ui { +class DeviceConfigurationDialogV1; +} + +class DeviceConfigurationDialogV1 : public QDialog +{ + Q_OBJECT + +public: + explicit DeviceConfigurationDialogV1(LibreVNADriver &dev, QWidget *parent = nullptr); + ~DeviceConfigurationDialogV1(); + +private: + void updateGUI(const Protocol::DeviceConfig &c); + void updateDevice(); + + Ui::DeviceConfigurationDialogV1 *ui; + LibreVNADriver &dev; +}; + +#endif // DEVICECONFIGURATIONDIALOGV1_H diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogv1.ui b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogv1.ui new file mode 100644 index 0000000..a24e6a8 --- /dev/null +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogv1.ui @@ -0,0 +1,159 @@ + + + DeviceConfigurationDialogV1 + + + + 0 + 0 + 497 + 297 + + + + Device Configuration + + + + + + IF frequencies + + + + + + This section contains advanced system settings. It is recommended to leave them at default values unless you know what you are doing. Slight changes of the IF frequencies can be used to shift possible spikes to less problematic frequencies. Large changes of these frequencies may severely impact device performance. + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + IF 1: + + + + + + + <html><head/><body><p>Frequency of the first IF</p></body></html> + + + + + + + ADC prescaler: + + + + + + + <html><head/><body><p>ADC prescaler in FPGA. The ADC sample rate is determined by 102.4MHz/prescaler</p></body></html> + + + 112 + + + 255 + + + 128 + + + + + + + ADC sample rate: + + + + + + + false + + + + + + + Phase increment: + + + + + + + <html><head/><body><p>Phase increment per ADC sample. Together with the ADC sample rate this determines the frequency of the second IF</p></body></html> + + + 1 + + + 4095 + + + 1280 + + + + + + + IF 2: + + + + + + + false + + + + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + SIUnitEdit + QLineEdit +
CustomWidgets/siunitedit.h
+
+
+ + +
diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogvff.cpp b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogvff.cpp new file mode 100644 index 0000000..3fd6bd1 --- /dev/null +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogvff.cpp @@ -0,0 +1,80 @@ +#include "deviceconfigurationdialogvff.h" +#include "ui_deviceconfigurationdialogvff.h" + +#include + +DeviceConfigurationDialogVFF::DeviceConfigurationDialogVFF(LibreVNADriver &dev, QWidget *parent) : + QDialog(parent), + ui(new Ui::DeviceConfigurationDialogVFF), + dev(dev) +{ + ui->setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + + emit dev.acquireControl(); + + auto updateAddress = [](QLineEdit* line, QHostAddress &address) { + auto newAddress = QHostAddress(line->text()); + if(newAddress.isNull()) { + // address is invalid, set edit to old address + line->setText(address.toString()); + } else { + // input is valid, store new address + address = newAddress; + } + }; + + connect(ui->ip, &QLineEdit::editingFinished, this, [=](){ + updateAddress(ui->ip, ip); + }); + connect(ui->mask, &QLineEdit::editingFinished, this, [=](){ + updateAddress(ui->mask, mask); + }); + connect(ui->gateway, &QLineEdit::editingFinished, this, [=](){ + updateAddress(ui->gateway, gateway); + }); + + connect(&dev, &LibreVNADriver::receivedPacket, this, [=](const Protocol::PacketInfo &p) { + if(p.type == Protocol::PacketType::DeviceConfiguration) { + updateGUI(p.deviceConfig); + } + }); + + dev.sendWithoutPayload(Protocol::PacketType::RequestDeviceConfiguration); + + connect(ui->buttonBox, &QDialogButtonBox::accepted, this, [=](){ + updateDevice(); + accept(); + }); + connect(ui->buttonBox, &QDialogButtonBox::rejected, this, [=](){ + reject(); + }); +} + +DeviceConfigurationDialogVFF::~DeviceConfigurationDialogVFF() +{ + dev.releaseControl(); + delete ui; +} + +void DeviceConfigurationDialogVFF::updateGUI(const Protocol::DeviceConfig &c) +{ + ui->dhcp->setChecked(c.VFF.dhcp); + ip = QHostAddress(qFromBigEndian(c.VFF.ip)); + ui->ip->setText(ip.toString()); + mask = QHostAddress(qFromBigEndian(c.VFF.mask)); + ui->mask->setText(mask.toString()); + gateway = QHostAddress(qFromBigEndian(c.VFF.gw)); + ui->gateway->setText(gateway.toString()); +} + +void DeviceConfigurationDialogVFF::updateDevice() +{ + Protocol::PacketInfo p; + p.type = Protocol::PacketType::DeviceConfiguration; + p.deviceConfig.VFF.dhcp = ui->dhcp->isChecked() ? 1 : 0; + p.deviceConfig.VFF.ip = qToBigEndian(ip.toIPv4Address()); + p.deviceConfig.VFF.mask = qToBigEndian(mask.toIPv4Address()); + p.deviceConfig.VFF.gw = qToBigEndian(gateway.toIPv4Address()); + dev.SendPacket(p); +} diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogvff.h b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogvff.h new file mode 100644 index 0000000..d676f7f --- /dev/null +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogvff.h @@ -0,0 +1,31 @@ +#ifndef DEVICECONFIGURATIONDIALOGVFF_H +#define DEVICECONFIGURATIONDIALOGVFF_H + +#include "librevnadriver.h" + +#include +#include + +namespace Ui { +class DeviceConfigurationDialogVFF; +} + +class DeviceConfigurationDialogVFF : public QDialog +{ + Q_OBJECT + +public: + explicit DeviceConfigurationDialogVFF(LibreVNADriver &dev, QWidget *parent = nullptr); + ~DeviceConfigurationDialogVFF(); + +private: + void updateGUI(const Protocol::DeviceConfig &c); + void updateDevice(); + + Ui::DeviceConfigurationDialogVFF *ui; + LibreVNADriver &dev; + + QHostAddress ip, mask, gateway; +}; + +#endif // DEVICECONFIGURATIONDIALOGVFF_H diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogvff.ui b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogvff.ui new file mode 100644 index 0000000..54e3956 --- /dev/null +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogvff.ui @@ -0,0 +1,83 @@ + + + DeviceConfigurationDialogVFF + + + + 0 + 0 + 389 + 224 + + + + Device Configuration + + + + + + Address configuration + + + + + + DHCP + + + + + + + Static/DHCP fallback + + + + + + IP: + + + + + + + + + + Mask: + + + + + + + + + + Gateway: + + + + + + + + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/devicepacketlogview.cpp b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/devicepacketlogview.cpp index fee3ba2..349f9de 100644 --- a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/devicepacketlogview.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/devicepacketlogview.cpp @@ -10,6 +10,8 @@ #include #include #include +#include +#include using namespace std; @@ -105,11 +107,11 @@ void DevicePacketLogView::addEntry(const DevicePacketLog::LogEntry &e) if(e.type == DevicePacketLog::LogEntry::Type::Packet) { item->setData(2, Qt::DisplayRole, "Packet"); - static const QStringList packetNames = {"None", "Datapoint", "SweepSettings", "ManualStatusV1", "ManualControlV1", "DeviceInfo", "FirmwarePacket", "Ack", + static const QStringList packetNames = {"None", "Datapoint", "SweepSettings", "ManualStatus", "ManualControl", "DeviceInfo", "FirmwarePacket", "Ack", "ClearFlash", "PerformFirmwareUpdate", "Nack", "Reference", "Generator", "SpectrumAnalyzerSettings", "SpectrumAnalyzerResult", "RequestDeviceInfo", "RequestSourceCal", "RequestReceiverCal", "SourceCalPoint", - "ReceiverCalPoint", "SetIdle", "RequestFrequencyCorrection", "FrequencyCorrection", "RequestAcquisitionFrequencySettings", - "AcquisitionFrequencySettings", "DeviceStatusV1", "RequestDeviceStatus", "VNADatapoint", "SetTrigger", "ClearTrigger"}; + "ReceiverCalPoint", "SetIdle", "RequestFrequencyCorrection", "FrequencyCorrection", "RequestDeviceConfiguration", + "DeviceConfiguration", "DeviceStatus", "RequestDeviceStatus", "VNADatapoint", "SetTrigger", "ClearTrigger"}; item->setData(3, Qt::DisplayRole, "Type "+QString::number((int)e.p->type)+"("+packetNames[(int)e.p->type]+")"); auto addDouble = [=](QTreeWidgetItem *parent, QString name, double value, QString unit = "", int precision = 8) { @@ -177,18 +179,31 @@ void DevicePacketLogView::addEntry(const DevicePacketLog::LogEntry &e) addInteger(item, "Active port", s.activePort); } break; - case Protocol::PacketType::DeviceStatusV1: { - Protocol::DeviceStatusV1 s = e.p->statusV1; - addBool(item, "External reference available", s.extRefAvailable); - addBool(item, "External reference in use", s.extRefInUse); - addBool(item, "FPGA configured", s.FPGA_configured); - addBool(item, "Source locked", s.source_locked); - addBool(item, "1.LO locked", s.LO1_locked); - addBool(item, "ADC overload", s.ADC_overload); - addBool(item, "Unlevel", s.unlevel); - addInteger(item, "Source temperature", s.temp_source); - addInteger(item, "1.LO temperature", s.temp_LO1); - addInteger(item, "MCU temperature", s.temp_MCU); + case Protocol::PacketType::DeviceStatus: { + auto s = e.p->status.V1; + auto V1 = new QTreeWidgetItem(); + V1->setData(2, Qt::DisplayRole, "V1"); + item->addChild(V1); + addBool(V1, "External reference available", s.extRefAvailable); + addBool(V1, "External reference in use", s.extRefInUse); + addBool(V1, "FPGA configured", s.FPGA_configured); + addBool(V1, "Source locked", s.source_locked); + addBool(V1, "1.LO locked", s.LO1_locked); + addBool(V1, "ADC overload", s.ADC_overload); + addBool(V1, "Unlevel", s.unlevel); + addInteger(V1, "Source temperature", s.temp_source); + addInteger(V1, "1.LO temperature", s.temp_LO1); + addInteger(V1, "MCU temperature", s.temp_MCU); + + auto sFF = e.p->status.VFF; + auto VFF = new QTreeWidgetItem(); + VFF->setData(2, Qt::DisplayRole, "VFF"); + item->addChild(VFF); + addBool(VFF, "Source locked", sFF.source_locked); + addBool(VFF, "LO locked", sFF.LO_locked); + addBool(VFF, "ADC overload", sFF.ADC_overload); + addBool(VFF, "Unlevel", sFF.unlevel); + addInteger(VFF, "MCU temperature", s.temp_MCU); } break; case Protocol::PacketType::DeviceInfo: { @@ -212,8 +227,8 @@ void DevicePacketLogView::addEntry(const DevicePacketLog::LogEntry &e) addDouble(item, "Maximum harmonic frequency", s.limits_maxFreqHarmonic, "Hz"); } break; - case Protocol::PacketType::ManualControlV1: - case Protocol::PacketType::ManualStatusV1: + case Protocol::PacketType::ManualControl: + case Protocol::PacketType::ManualStatus: // TODO break; case Protocol::PacketType::SpectrumAnalyzerSettings: { @@ -295,11 +310,23 @@ void DevicePacketLogView::addEntry(const DevicePacketLog::LogEntry &e) addDouble(item, "ppm", s.ppm, ""); } break; - case Protocol::PacketType::AcquisitionFrequencySettings: { - Protocol::AcquisitionFrequencySettings s = e.p->acquisitionFrequencySettings; - addDouble(item, "1.IF", s.IF1, "Hz"); - addInteger(item, "ADC prescaler", s.ADCprescaler); - addInteger(item, "DFT phase increment", s.DFTphaseInc); + case Protocol::PacketType::DeviceConfiguration: { + auto s1 = e.p->deviceConfig.V1; + auto V1 = new QTreeWidgetItem(); + V1->setData(2, Qt::DisplayRole, "V1"); + item->addChild(V1); + addDouble(V1, "1.IF", s1.IF1, "Hz"); + addInteger(V1, "ADC prescaler", s1.ADCprescaler); + addInteger(V1, "DFT phase increment", s1.DFTphaseInc); + + auto sFF = e.p->deviceConfig.VFF; + auto VFF = new QTreeWidgetItem(); + VFF->setData(2, Qt::DisplayRole, "VFF"); + item->addChild(VFF); + addBool(VFF, "DHCP enabled", sFF.dhcp); + addString(VFF, "IP", QHostAddress(qFromBigEndian(sFF.ip)).toString()); + addString(VFF, "Mask", QHostAddress(qFromBigEndian(sFF.mask)).toString()); + addString(VFF, "Gateway", QHostAddress(qFromBigEndian(sFF.gw)).toString()); } break; default: diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.cpp b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.cpp index 512a3a4..3458a11 100644 --- a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.cpp @@ -1,6 +1,9 @@ #include "librevnadriver.h" -#include "manualcontroldialog.h" +#include "manualcontroldialogV1.h" +#include "manualcontroldialogvff.h" +#include "deviceconfigurationdialogv1.h" +#include "deviceconfigurationdialogvff.h" #include "firmwareupdatedialog.h" #include "frequencycaldialog.h" #include "sourcecaldialog.h" @@ -113,11 +116,38 @@ LibreVNADriver::LibreVNADriver() auto manual = new QAction("Manual Control"); connect(manual, &QAction::triggered, this, [=](){ - auto d = new ManualControlDialog(*this); - d->show(); + QDialog *d = nullptr; + switch(hardwareVersion) { + case 1: + d = new ManualControlDialogV1(*this); + break; + case 0xFF: + d = new ManualControlDialogVFF(*this); + break; + } + if(d) { + d->show(); + } }); specificActions.push_back(manual); + auto config = new QAction("Configuration"); + connect(config, &QAction::triggered, this, [=](){ + QDialog *d = nullptr; + switch(hardwareVersion) { + case 1: + d = new DeviceConfigurationDialogV1(*this); + break; + case 0xFF: + d = new DeviceConfigurationDialogVFF(*this); + break; + } + if(d) { + d->show(); + } + }); + specificActions.push_back(config); + auto update = new QAction("Firmware Update"); connect(update, &QAction::triggered, this, [=](){ auto d = new FirmwareUpdateDialog(this); @@ -165,17 +195,32 @@ LibreVNADriver::LibreVNADriver() std::set LibreVNADriver::getFlags() { std::set ret; - if(lastStatus.extRefInUse) { - ret.insert(Flag::ExtRef); - } - if(!lastStatus.source_locked || !lastStatus.LO1_locked) { - ret.insert(Flag::Unlocked); - } - if(lastStatus.unlevel) { - ret.insert(Flag::Unlevel); - } - if(lastStatus.ADC_overload) { - ret.insert(Flag::Overload); + switch(hardwareVersion) { + case 1: + if(lastStatus.V1.extRefInUse) { + ret.insert(Flag::ExtRef); + } + if(!lastStatus.V1.source_locked || !lastStatus.V1.LO1_locked) { + ret.insert(Flag::Unlocked); + } + if(lastStatus.V1.unlevel) { + ret.insert(Flag::Unlevel); + } + if(lastStatus.V1.ADC_overload) { + ret.insert(Flag::Overload); + } + break; + case 0xFF: + if(!lastStatus.VFF.source_locked || !lastStatus.VFF.LO_locked) { + ret.insert(Flag::Unlocked); + } + if(lastStatus.VFF.unlevel) { + ret.insert(Flag::Unlevel); + } + if(lastStatus.VFF.ADC_overload) { + ret.insert(Flag::Overload); + } + break; } return ret; } @@ -186,15 +231,22 @@ QString LibreVNADriver::getStatus() ret.append("HW "); ret.append(info.hardware_version); ret.append(" FW "+info.firmware_version); - ret.append(" Temps: "+QString::number(lastStatus.temp_source)+"°C/"+QString::number(lastStatus.temp_LO1)+"°C/"+QString::number(lastStatus.temp_MCU)+"°C"); - ret.append(" Reference:"); - if(lastStatus.extRefInUse) { - ret.append("External"); - } else { - ret.append("Internal"); - if(lastStatus.extRefAvailable) { - ret.append(" (External available)"); + switch (hardwareVersion) { + case 1: + ret.append(" Temps: "+QString::number(lastStatus.V1.temp_source)+"°C/"+QString::number(lastStatus.V1.temp_LO1)+"°C/"+QString::number(lastStatus.V1.temp_MCU)+"°C"); + ret.append(" Reference:"); + if(lastStatus.V1.extRefInUse) { + ret.append("External"); + } else { + ret.append("Internal"); + if(lastStatus.V1.extRefAvailable) { + ret.append(" (External available)"); + } } + break; + case 0xFF: + ret.append("MCU Temp: "+QString::number(lastStatus.VFF.temp_MCU)+"°C"); + break; } return ret; } @@ -219,35 +271,6 @@ QWidget *LibreVNADriver::createSettingsWidget() ui->DFTlimitRBW->setPrecision(3); ui->DFTlimitRBW->setValue(SARBWLimitForDFT); - auto updateADCRate = [=]() { - // update ADC rate, see FPGA protocol for calculation - ui->ADCRate->setValue(102400000.0 / ui->ADCpresc->value()); - }; - auto updateIF2 = [=]() { - auto ADCrate = ui->ADCRate->value(); - ui->IF2->setValue(ADCrate * ui->ADCphaseInc->value() / 4096); - }; - - connect(ui->ADCpresc, qOverload(&QSpinBox::valueChanged), updateADCRate); - connect(ui->ADCpresc, qOverload(&QSpinBox::valueChanged), updateIF2); - connect(ui->ADCphaseInc, qOverload(&QSpinBox::valueChanged), updateIF2); - - ui->IF1->setUnit("Hz"); - ui->IF1->setPrefixes(" kM"); - ui->IF1->setPrecision(5); - ui->ADCRate->setUnit("Hz"); - ui->ADCRate->setPrefixes(" kM"); - ui->ADCRate->setPrecision(5); - ui->IF2->setUnit("Hz"); - ui->IF2->setPrefixes(" kM"); - ui->IF2->setPrecision(5); - ui->IF1->setValue(IF1); - ui->ADCpresc->setValue(ADCprescaler); - ui->ADCphaseInc->setValue(DFTPhaseInc); - - updateADCRate(); - updateIF2(); - connect(ui->UseHarmonicMixing, &QCheckBox::toggled, [=](bool enabled) { if(enabled) { InformationBox::ShowMessage("Harmonic Mixing", "When harmonic mixing is enabled, the frequency range of the VNA is (theoretically) extended up to 18GHz " @@ -280,15 +303,6 @@ QWidget *LibreVNADriver::createSettingsWidget() connect(ui->DFTlimitRBW, &SIUnitEdit::valueChanged, this, [=](){ SARBWLimitForDFT = ui->DFTlimitRBW->value(); }); - connect(ui->IF1, &SIUnitEdit::valueChanged, this, [=](){ - IF1 = ui->IF1->value(); - }); - connect(ui->ADCpresc, qOverload(&QSpinBox::valueChanged), this, [=](){ - ADCprescaler = ui->ADCpresc->value(); - }); - connect(ui->ADCphaseInc, qOverload(&QSpinBox::valueChanged), this, [=](){ - DFTPhaseInc = ui->ADCphaseInc->value(); - }); return w; } @@ -593,8 +607,8 @@ void LibreVNADriver::handleReceivedPacket(const Protocol::PacketInfo &packet) emit InfoUpdated(); } break; - case Protocol::PacketType::DeviceStatusV1: - lastStatus = packet.statusV1; + case Protocol::PacketType::DeviceStatus: + lastStatus = packet.status; emit StatusUpdated(); emit FlagsUpdated(); break; @@ -650,16 +664,6 @@ void LibreVNADriver::handleReceivedPacket(const Protocol::PacketInfo &packet) } } -void LibreVNADriver::updateIFFrequencies() -{ - Protocol::PacketInfo p; - p.type = Protocol::PacketType::AcquisitionFrequencySettings; - p.acquisitionFrequencySettings.IF1 = IF1; - p.acquisitionFrequencySettings.ADCprescaler = ADCprescaler; - p.acquisitionFrequencySettings.DFTphaseInc = DFTPhaseInc; - SendPacket(p); -} - QString LibreVNADriver::hardwareVersionToString(uint8_t version) { switch(version) { diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.h b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.h index 44bfdfa..b5052dc 100644 --- a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.h +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.h @@ -191,7 +191,6 @@ signals: protected slots: void handleReceivedPacket(const Protocol::PacketInfo& packet); protected: - void updateIFFrequencies(); QString hardwareVersionToString(uint8_t version); bool connected; @@ -200,7 +199,7 @@ protected: uint8_t hardwareVersion; unsigned int limits_maxAmplitudePoints; - Protocol::DeviceStatusV1 lastStatus; + Protocol::DeviceStatus lastStatus; bool skipOwnPacketHandling; bool zerospan; @@ -219,9 +218,6 @@ protected: double SARBWLimitForDFT; bool VNASuppressInvalidPeaks; bool VNAAdjustPowerLevel; - double IF1; - unsigned int ADCprescaler; - unsigned int DFTPhaseInc; }; Q_DECLARE_METATYPE(Protocol::PacketInfo) diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriversettingswidget.ui b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriversettingswidget.ui index 0507b5f..869b4cb 100644 --- a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriversettingswidget.ui +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriversettingswidget.ui @@ -6,8 +6,8 @@ 0 0 - 615 - 598 + 545 + 417 @@ -100,115 +100,17 @@ - - - IF frequencies + + + Qt::Vertical - - - - - This section contains advanced system settings. It is recommended to leave them at default values unless you know what you are doing. Slight changes of the IF frequencies can be used to shift possible spikes to less problematic frequencies. Large changes of these frequencies may severely impact device performance. - - - true - - - - - - - - - IF 1: - - - - - - - <html><head/><body><p>Frequency of the first IF</p></body></html> - - - - - - - ADC prescaler: - - - - - - - <html><head/><body><p>ADC prescaler in FPGA. The ADC sample rate is determined by 102.4MHz/prescaler</p></body></html> - - - 112 - - - 255 - - - 128 - - - - - - - ADC sample rate: - - - - - - - false - - - - - - - Phase increment: - - - - - - - <html><head/><body><p>Phase increment per ADC sample. Together with the ADC sample rate this determines the frequency of the second IF</p></body></html> - - - 1 - - - 4095 - - - 1280 - - - - - - - IF 2: - - - - - - - false - - - - - - - + + + 20 + 40 + + + diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnatcpdriver.cpp b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnatcpdriver.cpp index c9b7156..e8e5d01 100644 --- a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnatcpdriver.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnatcpdriver.cpp @@ -52,9 +52,6 @@ LibreVNATCPDriver::LibreVNATCPDriver() specificSettings.push_back(Savable::SettingDescription(&VNAAdjustPowerLevel, "LibreVNATCPDriver.adjustPowerLevel", false)); specificSettings.push_back(Savable::SettingDescription(&SAUseDFT, "LibreVNATCPDriver.useDFT", true)); specificSettings.push_back(Savable::SettingDescription(&SARBWLimitForDFT, "LibreVNATCPDriver.RBWlimitDFT", 3000)); - specificSettings.push_back(Savable::SettingDescription(&IF1, "LibreVNATCPDriver.IF1", 62000000)); - specificSettings.push_back(Savable::SettingDescription(&ADCprescaler, "LibreVNATCPDriver.ADCprescaler", 128)); - specificSettings.push_back(Savable::SettingDescription(&DFTPhaseInc, "LibreVNATCPDriver.DFTPhaseInc", 1280)); } QString LibreVNATCPDriver::getDriverName() @@ -74,7 +71,9 @@ std::set LibreVNATCPDriver::GetAvailableDevices() data.append("\r\n" "\r\n"); - pruneDetectedDevices(); + // just delete everything instead of keeping old entries (they will answer again if they are still available) + detectedDevices.clear(); +// pruneDetectedDevices(); for(auto s : ssdpSockets) { s->writeDatagram(data.data(), SSDPaddress, SSDPport); } @@ -144,7 +143,7 @@ bool LibreVNATCPDriver::connectTo(QString serial) sendWithoutPayload(Protocol::PacketType::RequestDeviceInfo); sendWithoutPayload(Protocol::PacketType::RequestDeviceStatus); - updateIFFrequencies(); +// updateIFFrequencies(); return true; } diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnausbdriver.cpp b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnausbdriver.cpp index 0f01c38..9cbf9ab 100644 --- a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnausbdriver.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnausbdriver.cpp @@ -134,9 +134,6 @@ LibreVNAUSBDriver::LibreVNAUSBDriver() specificSettings.push_back(Savable::SettingDescription(&VNAAdjustPowerLevel, "LibreVNAUSBDriver.adjustPowerLevel", false)); specificSettings.push_back(Savable::SettingDescription(&SAUseDFT, "LibreVNAUSBDriver.useDFT", true)); specificSettings.push_back(Savable::SettingDescription(&SARBWLimitForDFT, "LibreVNAUSBDriver.RBWlimitDFT", 3000)); - specificSettings.push_back(Savable::SettingDescription(&IF1, "LibreVNAUSBDriver.IF1", 62000000)); - specificSettings.push_back(Savable::SettingDescription(&ADCprescaler, "LibreVNAUSBDriver.ADCprescaler", 128)); - specificSettings.push_back(Savable::SettingDescription(&DFTPhaseInc, "LibreVNAUSBDriver.DFTPhaseInc", 1280)); } QString LibreVNAUSBDriver::getDriverName() @@ -230,7 +227,7 @@ bool LibreVNAUSBDriver::connectTo(QString serial) sendWithoutPayload(Protocol::PacketType::RequestDeviceInfo); sendWithoutPayload(Protocol::PacketType::RequestDeviceStatus); - updateIFFrequencies(); +// updateIFFrequencies(); return true; } diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialog.cpp b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogV1.cpp similarity index 74% rename from Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialog.cpp rename to Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogV1.cpp index e9d97a0..5d2862f 100644 --- a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialog.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogV1.cpp @@ -1,6 +1,6 @@ -#include "manualcontroldialog.h" +#include "manualcontroldialogV1.h" -#include "ui_manualcontroldialog.h" +#include "ui_manualcontroldialogV1.h" #include "Util/util.h" #include @@ -11,9 +11,9 @@ using namespace std; -ManualControlDialog::ManualControlDialog(LibreVNADriver &dev, QWidget *parent) : +ManualControlDialogV1::ManualControlDialogV1(LibreVNADriver &dev, QWidget *parent) : QDialog(parent), - ui(new Ui::ManualControlDialog), + ui(new Ui::ManualControlDialogV1), dev(dev) { ui->setupUi(this); @@ -152,8 +152,8 @@ ManualControlDialog::ManualControlDialog(LibreVNADriver &dev, QWidget *parent) : MakeReadOnly(ui->refphase); connect(&dev, &LibreVNADriver::receivedPacket, this, [=](const Protocol::PacketInfo &p){ - if(p.type == Protocol::PacketType::ManualStatusV1) { - NewStatus(p.manualStatusV1); + if(p.type == Protocol::PacketType::ManualStatus) { + NewStatus(p.manualStatus); } }, Qt::QueuedConnection); @@ -189,38 +189,38 @@ ManualControlDialog::ManualControlDialog(LibreVNADriver &dev, QWidget *parent) : UpdateDevice(); } -ManualControlDialog::~ManualControlDialog() +ManualControlDialogV1::~ManualControlDialogV1() { emit dev.releaseControl(); delete ui; } -void ManualControlDialog::setHighSourceChipEnable(bool enable) +void ManualControlDialogV1::setHighSourceChipEnable(bool enable) { ui->SourceCE->setChecked(enable); } -bool ManualControlDialog::getHighSourceChipEnable() +bool ManualControlDialogV1::getHighSourceChipEnable() { return ui->SourceCE->isChecked(); } -void ManualControlDialog::setHighSourceRFEnable(bool enable) +void ManualControlDialogV1::setHighSourceRFEnable(bool enable) { ui->SourceRFEN->setChecked(enable); } -bool ManualControlDialog::getHighSourceRFEnable() +bool ManualControlDialogV1::getHighSourceRFEnable() { return ui->SourceRFEN->isChecked(); } -bool ManualControlDialog::getHighSourceLocked() +bool ManualControlDialogV1::getHighSourceLocked() { return ui->SourceLocked->isChecked(); } -bool ManualControlDialog::setHighSourcePower(int dBm) +bool ManualControlDialogV1::setHighSourcePower(int dBm) { switch(dBm) { case -4: @@ -242,23 +242,23 @@ bool ManualControlDialog::setHighSourcePower(int dBm) return true; } -int ManualControlDialog::getHighSourcePower() +int ManualControlDialogV1::getHighSourcePower() { int powers[4] = {-4,-1,2,5}; return powers[ui->SourceHighPower->currentIndex()]; } -void ManualControlDialog::setHighSourceFrequency(double f) +void ManualControlDialogV1::setHighSourceFrequency(double f) { ui->SourceHighFrequency->setValue(f); } -double ManualControlDialog::getHighSourceFrequency() +double ManualControlDialogV1::getHighSourceFrequency() { return ui->SourceHighFrequency->value(); } -void ManualControlDialog::setHighSourceLPF(ManualControlDialog::LPF lpf) +void ManualControlDialogV1::setHighSourceLPF(ManualControlDialogV1::LPF lpf) { switch(lpf) { case LPF::M947: @@ -276,23 +276,23 @@ void ManualControlDialog::setHighSourceLPF(ManualControlDialog::LPF lpf) } } -ManualControlDialog::LPF ManualControlDialog::getHighSourceLPF() +ManualControlDialogV1::LPF ManualControlDialogV1::getHighSourceLPF() { LPF lpfs[4] = {LPF::M947, LPF::M1880, LPF::M3500, LPF::None}; return lpfs[ui->SourceLowpass->currentIndex()]; } -void ManualControlDialog::setLowSourceEnable(bool enable) +void ManualControlDialogV1::setLowSourceEnable(bool enable) { ui->SourceLowEnable->setChecked(enable); } -bool ManualControlDialog::getLowSourceEnable() +bool ManualControlDialogV1::getLowSourceEnable() { return ui->SourceLowEnable->isChecked(); } -bool ManualControlDialog::setLowSourcePower(int mA) +bool ManualControlDialogV1::setLowSourcePower(int mA) { switch(mA) { case 2: @@ -314,23 +314,23 @@ bool ManualControlDialog::setLowSourcePower(int mA) return true; } -int ManualControlDialog::getLowSourcePower() +int ManualControlDialogV1::getLowSourcePower() { int powers[4] = {2,4,6,8}; return powers[ui->SourceLowPower->currentIndex()]; } -void ManualControlDialog::setLowSourceFrequency(double f) +void ManualControlDialogV1::setLowSourceFrequency(double f) { ui->SourceLowFrequency->setValue(f); } -double ManualControlDialog::getLowSourceFrequency() +double ManualControlDialogV1::getLowSourceFrequency() { return ui->SourceLowFrequency->value(); } -void ManualControlDialog::setHighband(bool high) +void ManualControlDialogV1::setHighband(bool high) { if(high) { ui->SwitchHighband->setChecked(true); @@ -339,32 +339,32 @@ void ManualControlDialog::setHighband(bool high) } } -bool ManualControlDialog::getHighband() +bool ManualControlDialogV1::getHighband() { return ui->SwitchHighband->isChecked(); } -void ManualControlDialog::setAttenuator(double att) +void ManualControlDialogV1::setAttenuator(double att) { ui->Attenuator->setValue(att); } -double ManualControlDialog::getAttenuator() +double ManualControlDialogV1::getAttenuator() { return ui->Attenuator->value(); } -void ManualControlDialog::setAmplifierEnable(bool enable) +void ManualControlDialogV1::setAmplifierEnable(bool enable) { ui->AmplifierEnable->setChecked(enable); } -bool ManualControlDialog::getAmplifierEnable() +bool ManualControlDialogV1::getAmplifierEnable() { return ui->AmplifierEnable->isChecked(); } -bool ManualControlDialog::setPortSwitch(int port) +bool ManualControlDialogV1::setPortSwitch(int port) { switch(port) { case 1: @@ -380,7 +380,7 @@ bool ManualControlDialog::setPortSwitch(int port) return true; } -int ManualControlDialog::getPortSwitch() +int ManualControlDialogV1::getPortSwitch() { if(ui->Port1Switch->isChecked()) { return 1; @@ -389,223 +389,223 @@ int ManualControlDialog::getPortSwitch() } } -void ManualControlDialog::setLO1ChipEnable(bool enable) +void ManualControlDialogV1::setLO1ChipEnable(bool enable) { ui->LO1CE->setChecked(enable); } -bool ManualControlDialog::getLO1ChipEnable() +bool ManualControlDialogV1::getLO1ChipEnable() { return ui->LO1CE->isChecked(); } -void ManualControlDialog::setLO1RFEnable(bool enable) +void ManualControlDialogV1::setLO1RFEnable(bool enable) { ui->LO1RFEN->setChecked(enable); } -bool ManualControlDialog::getLO1RFEnable() +bool ManualControlDialogV1::getLO1RFEnable() { return ui->LO1RFEN->isChecked(); } -bool ManualControlDialog::getLO1Locked() +bool ManualControlDialogV1::getLO1Locked() { return ui->LO1locked->isChecked(); } -void ManualControlDialog::setLO1Frequency(double f) +void ManualControlDialogV1::setLO1Frequency(double f) { ui->LO1FreqType->setCurrentIndex(1); ui->LO1Frequency->setValue(f); } -double ManualControlDialog::getLO1Frequency() +double ManualControlDialogV1::getLO1Frequency() { return ui->LO1Frequency->value(); } -void ManualControlDialog::setIF1Frequency(double f) +void ManualControlDialogV1::setIF1Frequency(double f) { ui->LO1FreqType->setCurrentIndex(0); ui->IF1->setValue(f); } -double ManualControlDialog::getIF1Frequency() +double ManualControlDialogV1::getIF1Frequency() { return ui->IF1->value(); } -void ManualControlDialog::setLO2Enable(bool enable) +void ManualControlDialogV1::setLO2Enable(bool enable) { ui->LO2EN->setChecked(enable); } -bool ManualControlDialog::getLO2Enable() +bool ManualControlDialogV1::getLO2Enable() { return ui->LO2EN->isChecked(); } -void ManualControlDialog::setLO2Frequency(double f) +void ManualControlDialogV1::setLO2Frequency(double f) { ui->LO2FreqType->setCurrentIndex(1); ui->LO2Frequency->setValue(f); } -double ManualControlDialog::getLO2Frequency() +double ManualControlDialogV1::getLO2Frequency() { return ui->LO2Frequency->value(); } -void ManualControlDialog::setIF2Frequency(double f) +void ManualControlDialogV1::setIF2Frequency(double f) { ui->LO2FreqType->setCurrentIndex(0); ui->IF2->setValue(f); } -double ManualControlDialog::getIF2Frequency() +double ManualControlDialogV1::getIF2Frequency() { return ui->IF2->value(); } -void ManualControlDialog::setPort1Enable(bool enable) +void ManualControlDialogV1::setPort1Enable(bool enable) { ui->Port1Enable->setChecked(enable); } -bool ManualControlDialog::getPort1Enable() +bool ManualControlDialogV1::getPort1Enable() { return ui->Port1Enable->isChecked(); } -void ManualControlDialog::setPort2Enable(bool enable) +void ManualControlDialogV1::setPort2Enable(bool enable) { ui->Port2Enable->setChecked(enable); } -bool ManualControlDialog::getPort2Enable() +bool ManualControlDialogV1::getPort2Enable() { return ui->Port2Enable->isChecked(); } -void ManualControlDialog::setRefEnable(bool enable) +void ManualControlDialogV1::setRefEnable(bool enable) { ui->RefEnable->setChecked(enable); } -bool ManualControlDialog::getRefEnable() +bool ManualControlDialogV1::getRefEnable() { return ui->RefEnable->isChecked(); } -void ManualControlDialog::setNumSamples(int samples) +void ManualControlDialogV1::setNumSamples(int samples) { ui->Samples->setValue(samples); } -int ManualControlDialog::getNumSamples() +int ManualControlDialogV1::getNumSamples() { return ui->Samples->value(); } -void ManualControlDialog::setWindow(ManualControlDialog::Window w) +void ManualControlDialogV1::setWindow(ManualControlDialogV1::Window w) { ui->cbWindow->setCurrentIndex((int) w); } -ManualControlDialog::Window ManualControlDialog::getWindow() +ManualControlDialogV1::Window ManualControlDialogV1::getWindow() { return (Window) ui->cbWindow->currentIndex(); } -int ManualControlDialog::getPort1MinADC() +int ManualControlDialogV1::getPort1MinADC() { return ui->port1min->text().toInt(); } -int ManualControlDialog::getPort1MaxADC() +int ManualControlDialogV1::getPort1MaxADC() { return ui->port1max->text().toInt(); } -double ManualControlDialog::getPort1Magnitude() +double ManualControlDialogV1::getPort1Magnitude() { return ui->port1mag->text().toDouble(); } -double ManualControlDialog::getPort1Phase() +double ManualControlDialogV1::getPort1Phase() { return ui->port1phase->text().toDouble(); } -std::complex ManualControlDialog::getPort1Referenced() +std::complex ManualControlDialogV1::getPort1Referenced() { return port1referenced; } -int ManualControlDialog::getPort2MinADC() +int ManualControlDialogV1::getPort2MinADC() { return ui->port2min->text().toInt(); } -int ManualControlDialog::getPort2MaxADC() +int ManualControlDialogV1::getPort2MaxADC() { return ui->port2max->text().toInt(); } -double ManualControlDialog::getPort2Magnitude() +double ManualControlDialogV1::getPort2Magnitude() { return ui->port2mag->text().toDouble(); } -double ManualControlDialog::getPort2Phase() +double ManualControlDialogV1::getPort2Phase() { return ui->port2phase->text().toDouble(); } -std::complex ManualControlDialog::getPort2Referenced() +std::complex ManualControlDialogV1::getPort2Referenced() { return port2referenced; } -int ManualControlDialog::getRefMinADC() +int ManualControlDialogV1::getRefMinADC() { return ui->refmin->text().toInt(); } -int ManualControlDialog::getRefMaxADC() +int ManualControlDialogV1::getRefMaxADC() { return ui->refmax->text().toInt(); } -double ManualControlDialog::getRefMagnitude() +double ManualControlDialogV1::getRefMagnitude() { return ui->refmag->text().toDouble(); } -double ManualControlDialog::getRefPhase() +double ManualControlDialogV1::getRefPhase() { return ui->refphase->text().toDouble(); } -void ManualControlDialog::NewStatus(Protocol::ManualStatusV1 status) +void ManualControlDialogV1::NewStatus(Protocol::ManualStatus status) { // ADC values - ui->port1min->setText(QString::number(status.port1min)); - ui->port1max->setText(QString::number(status.port1max)); - auto port1 = complex(status.port1real, status.port1imag); + ui->port1min->setText(QString::number(status.V1.port1min)); + ui->port1max->setText(QString::number(status.V1.port1max)); + auto port1 = complex(status.V1.port1real, status.V1.port1imag); ui->port1mag->setText(QString::number(abs(port1))); ui->port1phase->setText(QString::number(arg(port1)*180/M_PI)); - ui->port2min->setText(QString::number(status.port2min)); - ui->port2max->setText(QString::number(status.port2max)); - auto port2 = complex(status.port2real, status.port2imag); + ui->port2min->setText(QString::number(status.V1.port2min)); + ui->port2max->setText(QString::number(status.V1.port2max)); + auto port2 = complex(status.V1.port2real, status.V1.port2imag); ui->port2mag->setText(QString::number(abs(port2))); ui->port2phase->setText(QString::number(arg(port2)*180/M_PI)); - ui->refmin->setText(QString::number(status.refmin)); - ui->refmax->setText(QString::number(status.refmax)); - auto ref = complex(status.refreal, status.refimag); + ui->refmin->setText(QString::number(status.V1.refmin)); + ui->refmax->setText(QString::number(status.V1.refmax)); + auto ref = complex(status.V1.refreal, status.V1.refimag); ui->refmag->setText(QString::number(abs(ref))); ui->refphase->setText(QString::number(arg(ref)*180/M_PI)); @@ -618,15 +618,15 @@ void ManualControlDialog::NewStatus(Protocol::ManualStatusV1 status) ui->port2referenced->setText(QString::number(port2db, 'f', 1) + "db@" + QString::number(arg(port2referenced)*180/M_PI, 'f', 0) + "°"); // PLL state - ui->SourceLocked->setChecked(status.source_locked); - ui->LO1locked->setChecked(status.LO_locked); + ui->SourceLocked->setChecked(status.V1.source_locked); + ui->LO1locked->setChecked(status.V1.LO_locked); } -void ManualControlDialog::UpdateDevice() +void ManualControlDialogV1::UpdateDevice() { Protocol::PacketInfo p; - p.type = Protocol::PacketType::ManualControlV1; - Protocol::ManualControlV1 &m = p.manual; + p.type = Protocol::PacketType::ManualControl; + auto &m = p.manual.V1; // Source highband m.SourceHighCE = ui->SourceCE->isChecked(); m.SourceHighRFEN = ui->SourceRFEN->isChecked(); diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialog.h b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogV1.h similarity index 87% rename from Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialog.h rename to Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogV1.h index cbd9643..2b9c6df 100644 --- a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialog.h +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogV1.h @@ -1,5 +1,5 @@ -#ifndef MANUALCONTROLDIALOG_H -#define MANUALCONTROLDIALOG_H +#ifndef MANUALCONTROLDIALOGV1_H +#define MANUALCONTROLDIALOGV1_H #include "librevnadriver.h" @@ -7,16 +7,16 @@ #include namespace Ui { -class ManualControlDialog; +class ManualControlDialogV1; } -class ManualControlDialog : public QDialog +class ManualControlDialogV1 : public QDialog { Q_OBJECT public: - explicit ManualControlDialog(LibreVNADriver &dev, QWidget *parent = nullptr); - ~ManualControlDialog(); + explicit ManualControlDialogV1(LibreVNADriver &dev, QWidget *parent = nullptr); + ~ManualControlDialogV1(); void setHighSourceChipEnable(bool enable); bool getHighSourceChipEnable(); @@ -103,14 +103,14 @@ public: double getRefPhase(); public slots: - void NewStatus(Protocol::ManualStatusV1 status); + void NewStatus(Protocol::ManualStatus status); private: void UpdateDevice(); - Ui::ManualControlDialog *ui; + Ui::ManualControlDialogV1 *ui; LibreVNADriver &dev; std::complex port1referenced; std::complex port2referenced; }; -#endif // MANUALCONTROLDIALOG_H +#endif // MANUALCONTROLDIALOGV1_H diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialog.ui b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogV1.ui similarity index 99% rename from Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialog.ui rename to Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogV1.ui index 81e5ccd..b10d7d9 100644 --- a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialog.ui +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogV1.ui @@ -1,7 +1,7 @@ - ManualControlDialog - + ManualControlDialogV1 + Qt::ApplicationModal @@ -776,7 +776,7 @@ - + diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogvff.cpp b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogvff.cpp new file mode 100644 index 0000000..ce5a0a7 --- /dev/null +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogvff.cpp @@ -0,0 +1,432 @@ +#include "manualcontroldialogvff.h" + +#include "ui_manualcontroldialogvff.h" +#include "Util/util.h" + +#include +#include +#include +#include + + +using namespace std; + +ManualControlDialogVFF::ManualControlDialogVFF(LibreVNADriver &dev, QWidget *parent) : + QDialog(parent), + ui(new Ui::ManualControlDialogVFF), + dev(dev) +{ + ui->setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + + emit dev.acquireControl(); + + ui->SourceFrequency->setUnit("Hz"); + ui->SourceFrequency->setPrefixes(" kMG"); + ui->SourceFrequency->setPrecision(6); + ui->SourceFrequency->setValueQuiet(1000000000); + + ui->IF->setUnit("Hz"); + ui->IF->setPrefixes(" kM"); + ui->IF->setPrecision(6); + + ui->LOFrequency->setUnit("Hz"); + ui->LOFrequency->setPrefixes(" kMG"); + ui->LOFrequency->setPrecision(6); + + auto UpdateLO = [=]() { + double sourceFreq = ui->SourceFrequency->value(); + if (ui->LOFreqType->currentIndex() == 0) { + // fixed IF mode + ui->LOFrequency->setValueQuiet(sourceFreq + ui->IF->value()); + } else { + // Manual Frequency mode + ui->IF->setValueQuiet(ui->LOFrequency->value() - sourceFreq); + } + }; + + connect(ui->IF, &SIUnitEdit::valueChanged, [=](double) { + UpdateLO(); + }); + connect(ui->LOFrequency, &SIUnitEdit::valueChanged, [=](double) { + UpdateLO(); + }); + connect(ui->SourceFrequency, &SIUnitEdit::valueChanged, [=](double) { + UpdateLO(); + }); + + ui->IF->setValue(100000); + + // LO mode switch connections + connect(ui->LOFreqType, qOverload(&QComboBox::activated), [=](int index) { + switch(index) { + case 0: + ui->LOFrequency->setEnabled(false); + ui->IF->setEnabled(true); + break; + case 1: + ui->LOFrequency->setEnabled(true); + ui->IF->setEnabled(false); + break; + } + }); + + // Readonly widgets + auto MakeReadOnly = [](QWidget* w) { + w->setAttribute(Qt::WA_TransparentForMouseEvents); + w->setFocusPolicy(Qt::NoFocus); + }; + MakeReadOnly(ui->SourceLocked); + MakeReadOnly(ui->LOlocked); + MakeReadOnly(ui->portmin); + MakeReadOnly(ui->portmax); + MakeReadOnly(ui->portmag); + MakeReadOnly(ui->portphase); + MakeReadOnly(ui->portreferenced); + MakeReadOnly(ui->refmin); + MakeReadOnly(ui->refmax); + MakeReadOnly(ui->refmag); + MakeReadOnly(ui->refphase); + + connect(&dev, &LibreVNADriver::receivedPacket, this, [=](const Protocol::PacketInfo &p){ + if(p.type == Protocol::PacketType::ManualStatus) { + NewStatus(p.manualStatus); + } + }, Qt::QueuedConnection); + + connect(ui->SourceCE, &QCheckBox::toggled, [=](bool) { UpdateDevice(); }); + connect(ui->SourceRFEN, &QCheckBox::toggled, [=](bool) { UpdateDevice(); }); + connect(ui->LOCE, &QCheckBox::toggled, [=](bool) { UpdateDevice(); }); + connect(ui->LORFEN, &QCheckBox::toggled, [=](bool) { UpdateDevice(); }); + connect(ui->SourceAmplifierEnable, &QCheckBox::toggled, [=](bool) { UpdateDevice(); }); + connect(ui->Port1Enable, &QCheckBox::toggled, [=](bool) { UpdateDevice(); }); + connect(ui->RefEnable, &QCheckBox::toggled, [=](bool) { UpdateDevice(); }); + connect(ui->portgain, qOverload(&QComboBox::currentIndexChanged), [=](int) { UpdateDevice(); }); + connect(ui->refgain, qOverload(&QComboBox::currentIndexChanged), [=](int) { UpdateDevice(); }); + + connect(ui->SourcePower, qOverload(&QComboBox::currentIndexChanged), [=](int) { UpdateDevice(); }); + connect(ui->SourceFrequency, &SIUnitEdit::valueChanged, [=](double) { UpdateDevice(); }); + connect(ui->LOAmplifierEnable, &QCheckBox::toggled, [=](bool) { UpdateDevice(); }); + connect(ui->LOExternal, &QRadioButton::toggled, [=](bool) { UpdateDevice(); }); + connect(ui->LOFrequency, &SIUnitEdit::valueChanged, [=](double) { UpdateDevice(); }); + connect(ui->IF, &SIUnitEdit::valueChanged, [=](double) { UpdateDevice(); }); + + connect(ui->Attenuator, qOverload(&QDoubleSpinBox::valueChanged), [=](double) { UpdateDevice(); }); + connect(ui->Samples, qOverload(&QSpinBox::valueChanged), [=](double) { UpdateDevice(); }); + connect(ui->cbWindow, qOverload(&QComboBox::activated), [=](int) { UpdateDevice(); }); + + UpdateDevice(); +} + +ManualControlDialogVFF::~ManualControlDialogVFF() +{ + emit dev.releaseControl(); + delete ui; +} + +void ManualControlDialogVFF::setSourceChipEnable(bool enable) +{ + ui->SourceCE->setChecked(enable); +} + +bool ManualControlDialogVFF::getSourceChipEnable() +{ + return ui->SourceCE->isChecked(); +} + +void ManualControlDialogVFF::setSourceRFEnable(bool enable) +{ + ui->SourceRFEN->setChecked(enable); +} + +bool ManualControlDialogVFF::getSourceRFEnable() +{ + return ui->SourceRFEN->isChecked(); +} + +bool ManualControlDialogVFF::getSourceLocked() +{ + return ui->SourceLocked->isChecked(); +} + +static constexpr double powers[8] = {-1, +1, +2.5, +3.5, +4.5, +5.5, +6.5, +7}; + +bool ManualControlDialogVFF::setSourcePower(double dBm) +{ + for(unsigned int i=0;i<8;i++) { + if(dBm == powers[i]) { + ui->SourcePower->setCurrentIndex(i); + return true; + } + } + // invalid power setting + return false; +} + +double ManualControlDialogVFF::getSourcePower() +{ + return powers[ui->SourcePower->currentIndex()]; +} + +void ManualControlDialogVFF::setSourceFrequency(double f) +{ + ui->SourceFrequency->setValue(f); +} + +double ManualControlDialogVFF::getSourceFrequency() +{ + return ui->SourceFrequency->value(); +} + +void ManualControlDialogVFF::setAttenuator(double att) +{ + ui->Attenuator->setValue(att); +} + +double ManualControlDialogVFF::getAttenuator() +{ + return ui->Attenuator->value(); +} + +void ManualControlDialogVFF::setSourceAmplifierEnable(bool enable) +{ + ui->SourceAmplifierEnable->setChecked(enable); +} + +bool ManualControlDialogVFF::getSourceAmplifierEnable() +{ + return ui->SourceAmplifierEnable->isChecked(); +} + +void ManualControlDialogVFF::setLOAmplifierEnable(bool enable) +{ + ui->LOAmplifierEnable->setChecked(enable); +} + +bool ManualControlDialogVFF::getLOAmplifierEnable() +{ + return ui->LOAmplifierEnable->isChecked(); +} + +void ManualControlDialogVFF::setLOPath(bool external) +{ + if(external) { + ui->LOExternal->setChecked(true); + } else { + ui->LOInternal->setChecked(true); + } +} + +bool ManualControlDialogVFF::getLOPath() +{ + return ui->LOExternal->isChecked(); +} + +void ManualControlDialogVFF::setLOChipEnable(bool enable) +{ + ui->LOCE->setChecked(enable); +} + +bool ManualControlDialogVFF::getLOChipEnable() +{ + return ui->LOCE->isChecked(); +} + +void ManualControlDialogVFF::setLORFEnable(bool enable) +{ + ui->LORFEN->setChecked(enable); +} + +bool ManualControlDialogVFF::getLORFEnable() +{ + return ui->LORFEN->isChecked(); +} + +bool ManualControlDialogVFF::getLOLocked() +{ + return ui->LOlocked->isChecked(); +} + +void ManualControlDialogVFF::setLOFrequency(double f) +{ + ui->LOFreqType->setCurrentIndex(1); + ui->LOFrequency->setValue(f); +} + +double ManualControlDialogVFF::getLOFrequency() +{ + return ui->LOFrequency->value(); +} + +void ManualControlDialogVFF::setIFFrequency(double f) +{ + ui->LOFreqType->setCurrentIndex(0); + ui->IF->setValue(f); +} + +double ManualControlDialogVFF::getIFFrequency() +{ + return ui->IF->value(); +} + +void ManualControlDialogVFF::setPortEnable(bool enable) +{ + ui->Port1Enable->setChecked(enable); +} + +bool ManualControlDialogVFF::getPortEnable() +{ + return ui->Port1Enable->isChecked(); +} + +void ManualControlDialogVFF::setRefEnable(bool enable) +{ + ui->RefEnable->setChecked(enable); +} + +bool ManualControlDialogVFF::getRefEnable() +{ + return ui->RefEnable->isChecked(); +} + +void ManualControlDialogVFF::setPortGain(Gain g) +{ + ui->portgain->setCurrentIndex((int) g); +} + +ManualControlDialogVFF::Gain ManualControlDialogVFF::getPortGain() +{ + return (Gain) ui->portgain->currentIndex(); +} + +void ManualControlDialogVFF::setRefGain(Gain g) +{ + ui->refgain->setCurrentIndex((int) g); +} + +ManualControlDialogVFF::Gain ManualControlDialogVFF::getRefGain() +{ + return (Gain) ui->refgain->currentIndex(); +} + +void ManualControlDialogVFF::setNumSamples(int samples) +{ + ui->Samples->setValue(samples); +} + +int ManualControlDialogVFF::getNumSamples() +{ + return ui->Samples->value(); +} + +void ManualControlDialogVFF::setWindow(ManualControlDialogVFF::Window w) +{ + ui->cbWindow->setCurrentIndex((int) w); +} + +ManualControlDialogVFF::Window ManualControlDialogVFF::getWindow() +{ + return (Window) ui->cbWindow->currentIndex(); +} + +int ManualControlDialogVFF::getPortMinADC() +{ + return ui->portmin->text().toInt(); +} + +int ManualControlDialogVFF::getPortMaxADC() +{ + return ui->portmax->text().toInt(); +} + +double ManualControlDialogVFF::getPortMagnitude() +{ + return ui->portmag->text().toDouble(); +} + +double ManualControlDialogVFF::getPortPhase() +{ + return ui->portphase->text().toDouble(); +} + +std::complex ManualControlDialogVFF::getPortReferenced() +{ + return portreferenced; +} + +int ManualControlDialogVFF::getRefMinADC() +{ + return ui->refmin->text().toInt(); +} + +int ManualControlDialogVFF::getRefMaxADC() +{ + return ui->refmax->text().toInt(); +} + +double ManualControlDialogVFF::getRefMagnitude() +{ + return ui->refmag->text().toDouble(); +} + +double ManualControlDialogVFF::getRefPhase() +{ + return ui->refphase->text().toDouble(); +} + +void ManualControlDialogVFF::NewStatus(Protocol::ManualStatus status) +{ + // ADC values + ui->portmin->setText(QString::number(status.VFF.portmin)); + ui->portmax->setText(QString::number(status.VFF.portmax)); + auto port = complex(status.VFF.portreal, status.VFF.portimag); + ui->portmag->setText(QString::number(abs(port))); + ui->portphase->setText(QString::number(arg(port)*180/M_PI)); + + ui->refmin->setText(QString::number(status.VFF.refmin)); + ui->refmax->setText(QString::number(status.VFF.refmax)); + auto ref = complex(status.VFF.refreal, status.VFF.refimag); + ui->refmag->setText(QString::number(abs(ref))); + ui->refphase->setText(QString::number(arg(ref)*180/M_PI)); + + portreferenced = port / ref; + auto portdb = Util::SparamTodB(portreferenced); + + ui->portreferenced->setText(QString::number(portdb, 'f', 1) + "db@" + QString::number(arg(portreferenced)*180/M_PI, 'f', 0) + "°"); + + // PLL state + ui->SourceLocked->setChecked(status.VFF.source_locked); + ui->LOlocked->setChecked(status.VFF.LO_locked); +} + +void ManualControlDialogVFF::UpdateDevice() +{ + Protocol::PacketInfo p; + p.type = Protocol::PacketType::ManualControl; + auto &m = p.manual.VFF; + // Source highband + m.SourceCE = ui->SourceCE->isChecked(); + m.SourceRFEN = ui->SourceRFEN->isChecked(); + m.SourcePower = ui->SourcePower->currentIndex(); + m.SourceFrequency = ui->SourceFrequency->value(); + m.SourceAmplifierEN = ui->SourceAmplifierEnable->isChecked(); + m.attenuator = -ui->Attenuator->value() / 0.25; + // LO + m.LOCE = ui->LOCE->isChecked(); + m.LORFEN = ui->LORFEN->isChecked(); + m.LOAmplifierEN = ui->LOAmplifierEnable->isChecked(); + m.LOexternal = ui->LOExternal->isChecked(); + m.LOFrequency = ui->LOFrequency->value(); + + // Acquisition + m.PortEN = ui->Port1Enable->isChecked(); + m.PortGain = ui->portgain->currentIndex(); + m.RefEN = ui->RefEnable->isChecked(); + m.RefGain = ui->refgain->currentIndex(); + m.Samples = ui->Samples->value(); + m.WindowType = ui->cbWindow->currentIndex(); + + qDebug() << "Updating manual control state"; + + dev.SendPacket(p); +} diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogvff.h b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogvff.h new file mode 100644 index 0000000..f5d2b78 --- /dev/null +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogvff.h @@ -0,0 +1,107 @@ +#ifndef MANUALCONTROLDIALOGVFF_H +#define MANUALCONTROLDIALOGVFF_H + +#include "librevnadriver.h" + +#include +#include + +namespace Ui { +class ManualControlDialogVFF; +} + +class ManualControlDialogVFF : public QDialog +{ + Q_OBJECT + +public: + explicit ManualControlDialogVFF(LibreVNADriver &dev, QWidget *parent = nullptr); + ~ManualControlDialogVFF(); + + void setSourceChipEnable(bool enable); + bool getSourceChipEnable(); + void setSourceRFEnable(bool enable); + bool getSourceRFEnable(); + bool getSourceLocked(); + bool setSourcePower(double dBm); + double getSourcePower(); + void setSourceFrequency(double f); + double getSourceFrequency(); + + void setAttenuator(double att); + double getAttenuator(); + void setSourceAmplifierEnable(bool enable); + bool getSourceAmplifierEnable(); + void setLOAmplifierEnable(bool enable); + bool getLOAmplifierEnable(); + + void setLOPath(bool external); + bool getLOPath(); + + void setLOChipEnable(bool enable); + bool getLOChipEnable(); + void setLORFEnable(bool enable); + bool getLORFEnable(); + bool getLOLocked(); + void setLOFrequency(double f); + double getLOFrequency(); + void setIFFrequency(double f); + double getIFFrequency(); + void setPortEnable(bool enable); + bool getPortEnable(); + void setRefEnable(bool enable); + bool getRefEnable(); + + enum class Gain { + G1 = 0, + G10 = 1, + G20 = 2, + G30 = 3, + G40 = 4, + G60 = 5, + G80 = 6, + G120 = 7, + G157 = 8, + G0_25 = 9, + }; + + void setPortGain(Gain g); + Gain getPortGain(); + void setRefGain(Gain g); + Gain getRefGain(); + + void setNumSamples(int samples); + int getNumSamples(); + + enum class Window { + None = 0, + Kaiser = 1, + Hann = 2, + FlatTop = 3 + }; + + void setWindow(Window w); + Window getWindow(); + + int getPortMinADC(); + int getPortMaxADC(); + double getPortMagnitude(); + double getPortPhase(); + std::complex getPortReferenced(); + + int getRefMinADC(); + int getRefMaxADC(); + double getRefMagnitude(); + double getRefPhase(); + +public slots: + void NewStatus(Protocol::ManualStatus status); + +private: + void UpdateDevice(); + Ui::ManualControlDialogVFF *ui; + LibreVNADriver &dev; + std::complex portreferenced; +}; + +#endif // MANUALCONTROLDIALOGVFF_H diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogvff.ui b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogvff.ui new file mode 100644 index 0000000..9b6d2b8 --- /dev/null +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/manualcontroldialogvff.ui @@ -0,0 +1,676 @@ + + + ManualControlDialogVFF + + + + 0 + 0 + 724 + 464 + + + + Manual System Control + + + + + + + + + + Signal Generation + + + + + + + + Source + + + + + + Chip Enable + + + + + + + RF Enable + + + + + + + true + + + Locked + + + + + + + + + Power: + + + + + + + + -1dBm + + + + + +1dBm + + + + + +2.5dBm + + + + + +3.5dBm + + + + + +4.5dBm + + + + + +5.5dBm + + + + + +6.5dBm + + + + + +7dBm + + + + + + + + Frequency: + + + + + + + + + + + + + + + + + + + Attenuator + + + + + + db + + + -31.750000000000000 + + + 0.000000000000000 + + + 0.250000000000000 + + + + + + + + + + Amplifier + + + + + + Enable + + + false + + + + + + + + + + + + + + + Signal Analysis + + + + + + LO + + + + + + + + Chip Enable + + + + + + + RF Enable + + + + + + + true + + + Locked + + + + + + + + + Freq. Type: + + + + + + + + IF + + + + + Absolute + + + + + + + + Frequency: + + + + + + + false + + + + + + + IF1: + + + + + + + + + + + + + + + + Amplifier + + + + + + Enable + + + false + + + + + + + + + + Path + + + + + + Internal + + + true + + + buttonGroup + + + + + + + External + + + buttonGroup + + + + + + + + + + + + + + + Aquisition + + + + + + Port Enable + + + + + + + Reference Enable + + + + + + + + + + 1V/V + + + + + 10V/V + + + + + 20V/V + + + + + 30V/V + + + + + 40V/V + + + + + 60V/V + + + + + 80V/V + + + + + 120V/V + + + + + 157V/V + + + + + 0.25V/V + + + + + + + + + 1V/V + + + + + 10V/V + + + + + 20V/V + + + + + 30V/V + + + + + 40V/V + + + + + 60V/V + + + + + 80V/V + + + + + 120V/V + + + + + 157V/V + + + + + 0.25V/V + + + + + + + + Samples: + + + + + + + 96 + + + 32000 + + + 16 + + + 32000 + + + + + + + Window: + + + + + + + + None + + + + + Kaiser + + + + + Hann + + + + + Flat Top + + + + + + + + Reference PGA gain: + + + + + + + Port PGA gain: + + + + + + + + + + + + + + + + + Measurements + + + + + + Port + + + + + + + + ADC min: + + + + + + + + + + ADC max: + + + + + + + + + + Magnitude: + + + + + + + + + + Phase: + + + + + + + + + + Referenced: + + + + + + + + + + + + + + + Reference + + + + + + + + ADC min: + + + + + + + + + + ADC max: + + + + + + + + + + Magnitude: + + + + + + + + + + Phase: + + + + + + + + + + + + + + + + + + + + + SIUnitEdit + QLineEdit +
CustomWidgets/siunitedit.h
+
+
+ + + + + +
diff --git a/Software/PC_Application/LibreVNA-GUI/LibreVNA-GUI.pro b/Software/PC_Application/LibreVNA-GUI/LibreVNA-GUI.pro index 9bfbb56..0b27443 100644 --- a/Software/PC_Application/LibreVNA-GUI/LibreVNA-GUI.pro +++ b/Software/PC_Application/LibreVNA-GUI/LibreVNA-GUI.pro @@ -23,6 +23,8 @@ HEADERS += \ Device/LibreVNA/Compound/compounddeviceeditdialog.h \ Device/LibreVNA/Compound/compounddriver.h \ Device/LibreVNA/amplitudecaldialog.h \ + Device/LibreVNA/deviceconfigurationdialogv1.h \ + Device/LibreVNA/deviceconfigurationdialogvff.h \ Device/LibreVNA/devicepacketlog.h \ Device/LibreVNA/devicepacketlogview.h \ Device/LibreVNA/firmwareupdatedialog.h \ @@ -30,7 +32,8 @@ HEADERS += \ Device/LibreVNA/librevnadriver.h \ Device/LibreVNA/librevnatcpdriver.h \ Device/LibreVNA/librevnausbdriver.h \ - Device/LibreVNA/manualcontroldialog.h \ + Device/LibreVNA/manualcontroldialogV1.h \ + Device/LibreVNA/manualcontroldialogvff.h \ Device/LibreVNA/receivercaldialog.h \ Device/LibreVNA/sourcecaldialog.h \ Device/SSA3000X/ssa3000xdriver.h \ @@ -177,6 +180,8 @@ SOURCES += \ Device/LibreVNA/Compound/compounddeviceeditdialog.cpp \ Device/LibreVNA/Compound/compounddriver.cpp \ Device/LibreVNA/amplitudecaldialog.cpp \ + Device/LibreVNA/deviceconfigurationdialogv1.cpp \ + Device/LibreVNA/deviceconfigurationdialogvff.cpp \ Device/LibreVNA/devicepacketlog.cpp \ Device/LibreVNA/devicepacketlogview.cpp \ Device/LibreVNA/firmwareupdatedialog.cpp \ @@ -184,7 +189,8 @@ SOURCES += \ Device/LibreVNA/librevnadriver.cpp \ Device/LibreVNA/librevnatcpdriver.cpp \ Device/LibreVNA/librevnausbdriver.cpp \ - Device/LibreVNA/manualcontroldialog.cpp \ + Device/LibreVNA/manualcontroldialogV1.cpp \ + Device/LibreVNA/manualcontroldialogvff.cpp \ Device/LibreVNA/receivercaldialog.cpp \ Device/LibreVNA/sourcecaldialog.cpp \ Device/SSA3000X/ssa3000xdriver.cpp \ @@ -321,11 +327,14 @@ FORMS += \ Device/LibreVNA/addamplitudepointsdialog.ui \ Device/LibreVNA/amplitudecaldialog.ui \ Device/LibreVNA/automaticamplitudedialog.ui \ + Device/LibreVNA/deviceconfigurationdialogv1.ui \ + Device/LibreVNA/deviceconfigurationdialogvff.ui \ Device/LibreVNA/devicepacketlogview.ui \ Device/LibreVNA/firmwareupdatedialog.ui \ Device/LibreVNA/frequencycaldialog.ui \ Device/LibreVNA/librevnadriversettingswidget.ui \ - Device/LibreVNA/manualcontroldialog.ui \ + Device/LibreVNA/manualcontroldialogV1.ui \ + Device/LibreVNA/manualcontroldialogvff.ui \ Device/devicelog.ui \ Device/devicetcpdriversettings.ui \ Generator/signalgenwidget.ui \ diff --git a/Software/PC_Application/LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.cpp b/Software/PC_Application/LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.cpp index 50bb925..d6289aa 100644 --- a/Software/PC_Application/LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.cpp +++ b/Software/PC_Application/LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.cpp @@ -351,6 +351,7 @@ void SpectrumAnalyzer::initializeDevice() connect(window->getDevice(), &DeviceDriver::SAmeasurementReceived, this, &SpectrumAnalyzer::NewDatapoint, Qt::UniqueConnection); // Configure initial state of device + ConstrainAndUpdateFrequencies(); SettingsChanged(); } diff --git a/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp b/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp index e859d34..30abb11 100644 --- a/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp +++ b/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp @@ -724,6 +724,7 @@ void VNA::initializeDevice() removeDefaultCal->setEnabled(false); } // Configure initial state of device + ConstrainAndUpdateFrequencies(); SettingsChanged(); emit deviceInitialized(); if(window->getDevice() && !cal.validForDevice(window->getDevice()->getSerial())) { diff --git a/Software/PC_Application/LibreVNA-Test/LibreVNA-Test.pro b/Software/PC_Application/LibreVNA-Test/LibreVNA-Test.pro index 09bb9c2..80b8565 100644 --- a/Software/PC_Application/LibreVNA-Test/LibreVNA-Test.pro +++ b/Software/PC_Application/LibreVNA-Test/LibreVNA-Test.pro @@ -26,12 +26,15 @@ SOURCES += \ ../LibreVNA-GUI/CustomWidgets/touchstoneimport.cpp \ ../LibreVNA-GUI/CustomWidgets/tracesetselector.cpp \ ../LibreVNA-GUI/Device/LibreVNA/amplitudecaldialog.cpp \ + ../LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogv1.cpp \ + ../LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogvff.cpp \ ../LibreVNA-GUI/Device/LibreVNA/firmwareupdatedialog.cpp \ ../LibreVNA-GUI/Device/LibreVNA/frequencycaldialog.cpp \ ../LibreVNA-GUI/Device/LibreVNA/librevnadriver.cpp \ ../LibreVNA-GUI/Device/LibreVNA/librevnatcpdriver.cpp \ ../LibreVNA-GUI/Device/LibreVNA/librevnausbdriver.cpp \ - ../LibreVNA-GUI/Device/LibreVNA/manualcontroldialog.cpp \ + ../LibreVNA-GUI/Device/LibreVNA/manualcontroldialogV1.cpp \ + ../LibreVNA-GUI/Device/LibreVNA/manualcontroldialogvff.cpp \ ../LibreVNA-GUI/Device/LibreVNA/receivercaldialog.cpp \ ../LibreVNA-GUI/Device/LibreVNA/sourcecaldialog.cpp \ ../LibreVNA-GUI/Device/LibreVNA/Compound/compounddevice.cpp \ @@ -198,12 +201,15 @@ HEADERS += \ ../LibreVNA-GUI/CustomWidgets/touchstoneimport.h \ ../LibreVNA-GUI/CustomWidgets/tracesetselector.h \ ../LibreVNA-GUI/Device/LibreVNA/amplitudecaldialog.h \ + ../LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogv1.h \ + ../LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogvff.h \ ../LibreVNA-GUI/Device/LibreVNA/firmwareupdatedialog.h \ ../LibreVNA-GUI/Device/LibreVNA/frequencycaldialog.h \ ../LibreVNA-GUI/Device/LibreVNA/librevnadriver.h \ ../LibreVNA-GUI/Device/LibreVNA/librevnatcpdriver.h \ ../LibreVNA-GUI/Device/LibreVNA/librevnausbdriver.h \ - ../LibreVNA-GUI/Device/LibreVNA/manualcontroldialog.h \ + ../LibreVNA-GUI/Device/LibreVNA/manualcontroldialogV1.h \ + ../LibreVNA-GUI/Device/LibreVNA/manualcontroldialogvff.h \ ../LibreVNA-GUI/Device/LibreVNA/receivercaldialog.h \ ../LibreVNA-GUI/Device/LibreVNA/sourcecaldialog.h \ ../LibreVNA-GUI/Device/LibreVNA/Compound/compounddevice.h \ @@ -355,11 +361,14 @@ FORMS += \ ../LibreVNA-GUI/Device/LibreVNA/addamplitudepointsdialog.ui \ ../LibreVNA-GUI/Device/LibreVNA/amplitudecaldialog.ui \ ../LibreVNA-GUI/Device/LibreVNA/automaticamplitudedialog.ui \ + ../LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogv1.ui \ + ../LibreVNA-GUI/Device/LibreVNA/deviceconfigurationdialogvff.ui \ ../LibreVNA-GUI/Device/LibreVNA/firmwareupdatedialog.ui \ ../LibreVNA-GUI/Device/LibreVNA/frequencycaldialog.ui \ ../LibreVNA-GUI/Device/LibreVNA/librevnadriversettingswidget.ui \ - ../LibreVNA-GUI/Device/LibreVNA/manualcontroldialog.ui \ + ../LibreVNA-GUI/Device/LibreVNA/manualcontroldialogV1.ui \ ../LibreVNA-GUI/Device/LibreVNA/Compound/compounddeviceeditdialog.ui \ + ../LibreVNA-GUI/Device/LibreVNA/manualcontroldialogvff.ui \ ../LibreVNA-GUI/Device/devicelog.ui \ ../LibreVNA-GUI/Device/LibreVNA/devicepacketlogview.ui \ ../LibreVNA-GUI/Device/devicetcpdriversettings.ui \ diff --git a/Software/VNA_embedded/.settings/stm32cubeide.project.prefs b/Software/VNA_embedded/.settings/stm32cubeide.project.prefs index 60e3eec..35098be 100644 --- a/Software/VNA_embedded/.settings/stm32cubeide.project.prefs +++ b/Software/VNA_embedded/.settings/stm32cubeide.project.prefs @@ -1,5 +1,5 @@ -2F62501ED4689FB349E356AB974DBE57=6F84FD31C089E822CF61FFCABCD0B7D1 +2F62501ED4689FB349E356AB974DBE57=EF826FD321FB312AEADE4DB74B81458C 66BE74F758C12D739921AEA421D593D3=2 -8DF89ED150041C4CBC7CB9A9CAA90856=6F84FD31C089E822CF61FFCABCD0B7D1 -DC22A860405A8BF2F2C095E5B6529F12=6E2D4146EA2709ED1E4A1764BC291F57 +8DF89ED150041C4CBC7CB9A9CAA90856=EF826FD321FB312AEADE4DB74B81458C +DC22A860405A8BF2F2C095E5B6529F12=A01929E06A3F8E0B7C263320E5AF494F eclipse.preferences.version=1 diff --git a/Software/VNA_embedded/Application/App.cpp b/Software/VNA_embedded/Application/App.cpp index 2ac489b..c085473 100644 --- a/Software/VNA_embedded/Application/App.cpp +++ b/Software/VNA_embedded/Application/App.cpp @@ -129,7 +129,7 @@ inline void App_Process() { sweepActive = VNA::Setup(recv_packet.settings); Communication::SendWithoutPayload(Protocol::PacketType::Ack); break; - case Protocol::PacketType::ManualControlV1: + case Protocol::PacketType::ManualControl: sweepActive = false; last_measure_packet = recv_packet; Manual::Setup(recv_packet.manual); @@ -168,8 +168,8 @@ inline void App_Process() { case Protocol::PacketType::RequestDeviceStatus: { Communication::SendWithoutPayload(Protocol::PacketType::Ack); Protocol::PacketInfo p; - p.type = Protocol::PacketType::DeviceStatusV1; - HW::getDeviceStatus(&p.statusV1); + p.type = Protocol::PacketType::DeviceStatus; + HW::getDeviceStatus(&p.status); Communication::Send(p); } break; @@ -263,19 +263,19 @@ inline void App_Process() { Cal::setFrequencyCal(recv_packet.frequencyCorrection.ppm); Communication::SendWithoutPayload(Protocol::PacketType::Ack); break; - case Protocol::PacketType::RequestAcquisitionFrequencySettings: + case Protocol::PacketType::RequestDeviceConfiguration: Communication::SendWithoutPayload(Protocol::PacketType::Ack); { Protocol::PacketInfo send; - send.type = Protocol::PacketType::AcquisitionFrequencySettings; - send.acquisitionFrequencySettings.IF1 = HW::getIF1(); - send.acquisitionFrequencySettings.ADCprescaler = HW::getADCPrescaler(); - send.acquisitionFrequencySettings.DFTphaseInc = HW::getDFTPhaseInc(); + send.type = Protocol::PacketType::DeviceConfiguration; + send.deviceConfig.V1.IF1 = HW::getIF1(); + send.deviceConfig.V1.ADCprescaler = HW::getADCPrescaler(); + send.deviceConfig.V1.DFTphaseInc = HW::getDFTPhaseInc(); Communication::Send(send); } break; - case Protocol::PacketType::AcquisitionFrequencySettings: - HW::setAcquisitionFrequencies(recv_packet.acquisitionFrequencySettings); + case Protocol::PacketType::DeviceConfiguration: + HW::setAcquisitionFrequencies(recv_packet.deviceConfig); Communication::SendWithoutPayload(Protocol::PacketType::Ack); break; case Protocol::PacketType::SetTrigger: diff --git a/Software/VNA_embedded/Application/Communication/Protocol.cpp b/Software/VNA_embedded/Application/Communication/Protocol.cpp index f16f621..80f91b8 100644 --- a/Software/VNA_embedded/Application/Communication/Protocol.cpp +++ b/Software/VNA_embedded/Application/Communication/Protocol.cpp @@ -99,9 +99,9 @@ uint16_t Protocol::EncodePacket(const PacketInfo &packet, uint8_t *dest, uint16_ case PacketType::SweepSettings: payload_size = sizeof(packet.settings); break; case PacketType::Reference: payload_size = sizeof(packet.reference); break; case PacketType::DeviceInfo: payload_size = sizeof(packet.info); break; - case PacketType::DeviceStatusV1: payload_size = sizeof(packet.statusV1); break; - case PacketType::ManualStatusV1: payload_size = sizeof(packet.manualStatusV1); break; - case PacketType::ManualControlV1: payload_size = sizeof(packet.manual); break; + case PacketType::DeviceStatus: payload_size = sizeof(packet.status); break; + case PacketType::ManualStatus: payload_size = sizeof(packet.manualStatus); break; + case PacketType::ManualControl: payload_size = sizeof(packet.manual); break; case PacketType::FirmwarePacket: payload_size = sizeof(packet.firmware); break; case PacketType::Generator: payload_size = sizeof(packet.generator); break; case PacketType::SpectrumAnalyzerSettings: payload_size = sizeof(packet.spectrumSettings); break; @@ -109,7 +109,7 @@ uint16_t Protocol::EncodePacket(const PacketInfo &packet, uint8_t *dest, uint16_ case PacketType::SourceCalPoint: case PacketType::ReceiverCalPoint: payload_size = sizeof(packet.amplitudePoint); break; case PacketType::FrequencyCorrection: payload_size = sizeof(packet.frequencyCorrection); break; - case PacketType::AcquisitionFrequencySettings: payload_size = sizeof(packet.acquisitionFrequencySettings); break; + case PacketType::DeviceConfiguration: payload_size = sizeof(packet.deviceConfig); break; case PacketType::Ack: case PacketType::PerformFirmwareUpdate: case PacketType::ClearFlash: @@ -119,7 +119,7 @@ uint16_t Protocol::EncodePacket(const PacketInfo &packet, uint8_t *dest, uint16_ case PacketType::RequestReceiverCal: case PacketType::SetIdle: case PacketType::RequestFrequencyCorrection: - case PacketType::RequestAcquisitionFrequencySettings: + case PacketType::RequestDeviceConfiguration: case PacketType::RequestDeviceStatus: case PacketType::SetTrigger: case PacketType::ClearTrigger: diff --git a/Software/VNA_embedded/Application/Communication/Protocol.hpp b/Software/VNA_embedded/Application/Communication/Protocol.hpp index 11f9f02..e5e4cf4 100644 --- a/Software/VNA_embedded/Application/Communication/Protocol.hpp +++ b/Software/VNA_embedded/Application/Communication/Protocol.hpp @@ -1,6 +1,5 @@ #pragma once - #include #include #include @@ -210,62 +209,112 @@ using DeviceInfo = struct _deviceInfo { uint64_t limits_maxFreqHarmonic; }; -using DeviceStatusV1 = struct _deviceStatusV1 { - uint8_t extRefAvailable:1; - uint8_t extRefInUse:1; - uint8_t FPGA_configured:1; - uint8_t source_locked:1; - uint8_t LO1_locked:1; - uint8_t ADC_overload:1; - uint8_t unlevel:1; - uint8_t temp_source; - uint8_t temp_LO1; - uint8_t temp_MCU; +using DeviceStatus = struct _deviceStatus { + union { + struct { + uint8_t extRefAvailable:1; + uint8_t extRefInUse:1; + uint8_t FPGA_configured:1; + uint8_t source_locked:1; + uint8_t LO1_locked:1; + uint8_t ADC_overload:1; + uint8_t unlevel:1; + uint8_t temp_source; + uint8_t temp_LO1; + uint8_t temp_MCU; + } V1; + struct { + uint8_t source_locked:1; + uint8_t LO_locked:1; + uint8_t ADC_overload:1; + uint8_t unlevel:1; + uint8_t temp_MCU; + } VFF; + }; }; -using ManualStatusV1 = struct _manualstatusV1 { - int16_t port1min, port1max; - int16_t port2min, port2max; - int16_t refmin, refmax; - float port1real, port1imag; - float port2real, port2imag; - float refreal, refimag; - uint8_t temp_source; - uint8_t temp_LO; - uint8_t source_locked :1; - uint8_t LO_locked :1; +using ManualStatus = struct _manualstatus { + union { + struct { + int16_t port1min, port1max; + int16_t port2min, port2max; + int16_t refmin, refmax; + float port1real, port1imag; + float port2real, port2imag; + float refreal, refimag; + uint8_t temp_source; + uint8_t temp_LO; + uint8_t source_locked :1; + uint8_t LO_locked :1; + } V1; + struct { + int16_t portmin, portmax; + int16_t refmin, refmax; + float portreal, portimag; + float refreal, refimag; + uint8_t source_locked :1; + uint8_t LO_locked :1; + } VFF; + }; }; -using ManualControlV1 = struct _manualControlV1 { - // Highband Source - uint8_t SourceHighCE :1; - uint8_t SourceHighRFEN :1; - uint8_t SourceHighPower :2; - uint8_t SourceHighLowpass :2; - uint64_t SourceHighFrequency; - // Lowband Source - uint8_t SourceLowEN :1; - uint8_t SourceLowPower :2; - uint32_t SourceLowFrequency; - // Source signal path - uint8_t attenuator :7; - uint8_t SourceHighband :1; - uint8_t AmplifierEN :1; - uint8_t PortSwitch :1; - // LO1 - uint8_t LO1CE :1; - uint8_t LO1RFEN :1; - uint64_t LO1Frequency; - // LO2 - uint8_t LO2EN :1; - uint32_t LO2Frequency; - // Acquisition - uint8_t Port1EN :1; - uint8_t Port2EN :1; - uint8_t RefEN :1; - uint32_t Samples; - uint8_t WindowType :2; +using ManualControl = struct _manualControl { + union { + struct { + // Highband Source + uint8_t SourceHighCE :1; + uint8_t SourceHighRFEN :1; + uint8_t SourceHighPower :2; + uint8_t SourceHighLowpass :2; + uint64_t SourceHighFrequency; + // Lowband Source + uint8_t SourceLowEN :1; + uint8_t SourceLowPower :2; + uint32_t SourceLowFrequency; + // Source signal path + uint8_t attenuator :7; + uint8_t SourceHighband :1; + uint8_t AmplifierEN :1; + uint8_t PortSwitch :1; + // LO1 + uint8_t LO1CE :1; + uint8_t LO1RFEN :1; + uint64_t LO1Frequency; + // LO2 + uint8_t LO2EN :1; + uint32_t LO2Frequency; + // Acquisition + uint8_t Port1EN :1; + uint8_t Port2EN :1; + uint8_t RefEN :1; + uint32_t Samples; + uint8_t WindowType :2; + } V1; + struct { + // Source + uint8_t SourceCE :1; + uint8_t SourceRFEN :1; + uint8_t SourcePower :3; + uint64_t SourceFrequency; + // Source signal path + uint8_t attenuator :7; + uint8_t SourceAmplifierEN :1; + // LO + uint8_t LOCE :1; + uint8_t LORFEN :1; + uint8_t LOAmplifierEN :1; + uint8_t LOexternal :1; + uint64_t LOFrequency; + // Acquisition + uint8_t PortEN :1; + uint8_t RefEN :1; + uint8_t WindowType :2; + uint8_t PortGain :4; + uint8_t RefGain :4; + uint16_t Samples; + } VFF; + }; }; using SpectrumAnalyzerSettings = struct _spectrumAnalyzerSettings { @@ -327,18 +376,28 @@ using FrequencyCorrection = struct _frequencycorrection { float ppm; }; -using AcquisitionFrequencySettings = struct _acquisitionfrequencysettigns { - uint32_t IF1; - uint8_t ADCprescaler; - uint16_t DFTphaseInc; +using DeviceConfig = struct _deviceconfig { + union { + struct { + uint32_t IF1; + uint8_t ADCprescaler; + uint16_t DFTphaseInc; + } V1; + struct { + uint32_t ip; + uint32_t mask; + uint32_t gw; + uint8_t dhcp :1; + } VFF; + }; }; enum class PacketType : uint8_t { None = 0, //Datapoint = 1, // Deprecated, replaced by VNADatapoint SweepSettings = 2, - ManualStatusV1 = 3, - ManualControlV1 = 4, + ManualStatus = 3, + ManualControl = 4, DeviceInfo = 5, FirmwarePacket = 6, Ack = 7, @@ -357,9 +416,9 @@ enum class PacketType : uint8_t { SetIdle = 20, RequestFrequencyCorrection = 21, FrequencyCorrection = 22, - RequestAcquisitionFrequencySettings = 23, - AcquisitionFrequencySettings = 24, - DeviceStatusV1 = 25, + RequestDeviceConfiguration = 23, + DeviceConfiguration = 24, + DeviceStatus = 25, RequestDeviceStatus = 26, VNADatapoint = 27, SetTrigger = 28, @@ -376,16 +435,16 @@ using PacketInfo = struct _packetinfo { SweepSettings settings; ReferenceSettings reference; GeneratorSettings generator; - DeviceStatusV1 statusV1; + DeviceStatus status; DeviceInfo info; - ManualControlV1 manual; + ManualControl manual; FirmwarePacket firmware; - ManualStatusV1 manualStatusV1; + ManualStatus manualStatus; SpectrumAnalyzerSettings spectrumSettings; SpectrumAnalyzerResult spectrumResult; AmplitudeCorrectionPoint amplitudePoint; FrequencyCorrection frequencyCorrection; - AcquisitionFrequencySettings acquisitionFrequencySettings; + DeviceConfig deviceConfig; /* * When encoding: Pointer may go invalid after call to EncodePacket * When decoding: VNADatapoint is created on heap by DecodeBuffer, freeing is up to the caller diff --git a/Software/VNA_embedded/Application/Hardware.cpp b/Software/VNA_embedded/Application/Hardware.cpp index 3d0da00..00cde2f 100644 --- a/Software/VNA_embedded/Application/Hardware.cpp +++ b/Software/VNA_embedded/Application/Hardware.cpp @@ -322,7 +322,7 @@ void HW::SetOutputUnlevel(bool unlev) { unlevel = unlev; } -void HW::getDeviceStatus(Protocol::DeviceStatusV1 *status, bool updateEvenWhenBusy) { +void HW::getDeviceStatus(Protocol::DeviceStatus *status, bool updateEvenWhenBusy) { if(activeMode == Mode::Idle || updateEvenWhenBusy) { // updating values from FPGA allowed @@ -339,21 +339,21 @@ void HW::getDeviceStatus(Protocol::DeviceStatusV1 *status, bool updateEvenWhenBu if(limits.P1min < -ADC_LIMIT || limits.P1max > ADC_LIMIT || limits.P2min < -ADC_LIMIT || limits.P2max > ADC_LIMIT || limits.Rmin < -ADC_LIMIT || limits.Rmax > ADC_LIMIT) { - status->ADC_overload = true; + status->V1.ADC_overload = true; } else { - status->ADC_overload = false; + status->V1.ADC_overload = false; } auto FPGA_status = FPGA::GetStatus(); - status->LO1_locked = (FPGA_status & (int) FPGA::Interrupt::LO1Unlock) ? 0 : 1; - status->source_locked = (FPGA_status & (int) FPGA::Interrupt::SourceUnlock) ? 0 : 1; - status->extRefAvailable = Ref::available(); - status->extRefInUse = extRefInUse; - status->unlevel = unlevel; - status->temp_LO1 = tempLO; - status->temp_source = tempSource; + status->V1.LO1_locked = (FPGA_status & (int) FPGA::Interrupt::LO1Unlock) ? 0 : 1; + status->V1.source_locked = (FPGA_status & (int) FPGA::Interrupt::SourceUnlock) ? 0 : 1; + status->V1.extRefAvailable = Ref::available(); + status->V1.extRefInUse = extRefInUse; + status->V1.unlevel = unlevel; + status->V1.temp_LO1 = tempLO; + status->V1.temp_source = tempSource; FPGA::ResetADCLimits(); } - status->temp_MCU = STM::getTemperature(); + status->V1.temp_MCU = STM::getTemperature(); } bool HW::Ref::available() { @@ -413,10 +413,10 @@ void HW::Ref::update() { } } -void HW::setAcquisitionFrequencies(Protocol::AcquisitionFrequencySettings s) { - IF1 = s.IF1; - ADCprescaler = s.ADCprescaler; - DFTphaseInc = s.DFTphaseInc; +void HW::setAcquisitionFrequencies(Protocol::DeviceConfig s) { + IF1 = s.V1.IF1; + ADCprescaler = s.V1.ADCprescaler; + DFTphaseInc = s.V1.DFTphaseInc; float ADCrate = (float) FPGA::Clockrate / ADCprescaler; IF2 = ADCrate * DFTphaseInc / 4096; ADCsamplerate = ADCrate; @@ -457,13 +457,13 @@ void HW::updateDeviceStatus() { last_update = HAL_GetTick(); HW::Ref::update(); Protocol::PacketInfo packet; - packet.type = Protocol::PacketType::DeviceStatusV1; + packet.type = Protocol::PacketType::DeviceStatus; // Enable PLL chips for temperature reading bool srcEn = FPGA::IsEnabled(FPGA::Periphery::SourceChip); bool LOEn = FPGA::IsEnabled(FPGA::Periphery::LO1Chip); FPGA::Enable(FPGA::Periphery::SourceChip); FPGA::Enable(FPGA::Periphery::LO1Chip); - HW::getDeviceStatus(&packet.statusV1, true); + HW::getDeviceStatus(&packet.status, true); // restore PLL state FPGA::Enable(FPGA::Periphery::SourceChip, srcEn); FPGA::Enable(FPGA::Periphery::LO1Chip, LOEn); diff --git a/Software/VNA_embedded/Application/Hardware.hpp b/Software/VNA_embedded/Application/Hardware.hpp index d3efb4b..97d5ffc 100644 --- a/Software/VNA_embedded/Application/Hardware.hpp +++ b/Software/VNA_embedded/Application/Hardware.hpp @@ -119,7 +119,7 @@ using AmplitudeSettings = struct _amplitudeSettings { AmplitudeSettings GetAmplitudeSettings(int16_t cdbm, uint64_t freq = 0, bool applyCorrections = false, bool port2 = false); bool GetTemps(uint8_t *source, uint8_t *lo); -void getDeviceStatus(Protocol::DeviceStatusV1 *status, bool updateEvenWhenBusy = false); +void getDeviceStatus(Protocol::DeviceStatus *status, bool updateEvenWhenBusy = false); namespace Ref { bool available(); bool usingExternal(); @@ -129,7 +129,7 @@ namespace Ref { } // Acquisition frequency settings -void setAcquisitionFrequencies(Protocol::AcquisitionFrequencySettings s); +void setAcquisitionFrequencies(Protocol::DeviceConfig s); uint32_t getIF1(); uint32_t getIF2(); uint32_t getADCRate(); diff --git a/Software/VNA_embedded/Application/Manual.cpp b/Software/VNA_embedded/Application/Manual.cpp index 33ed532..7ea11df 100644 --- a/Software/VNA_embedded/Application/Manual.cpp +++ b/Software/VNA_embedded/Application/Manual.cpp @@ -6,37 +6,37 @@ static bool active = false; static uint32_t samples; -static Protocol::ManualStatusV1 status; +static Protocol::ManualStatus status; using namespace HWHAL; -void Manual::Setup(Protocol::ManualControlV1 m) { +void Manual::Setup(Protocol::ManualControl m) { HW::SetMode(HW::Mode::Manual); - samples = m.Samples; + samples = m.V1.Samples; FPGA::AbortSweep(); // Configure lowband source - if (m.SourceLowEN) { - Si5351.SetCLK(SiChannel::LowbandSource, m.SourceLowFrequency, Si5351C::PLL::B, - (Si5351C::DriveStrength) m.SourceLowPower); + if (m.V1.SourceLowEN) { + Si5351.SetCLK(SiChannel::LowbandSource, m.V1.SourceLowFrequency, Si5351C::PLL::B, + (Si5351C::DriveStrength) m.V1.SourceLowPower); Si5351.Enable(SiChannel::LowbandSource); } else { Si5351.Disable(SiChannel::LowbandSource); } // Configure highband source - Source.SetFrequency(m.SourceHighFrequency); - Source.SetPowerOutA((MAX2871::Power) m.SourceHighPower); + Source.SetFrequency(m.V1.SourceHighFrequency); + Source.SetPowerOutA((MAX2871::Power) m.V1.SourceHighPower); // Configure LO1 - LO1.SetFrequency(m.LO1Frequency); + LO1.SetFrequency(m.V1.LO1Frequency); // Configure LO2 - if(m.LO2EN) { + if(m.V1.LO2EN) { // Generate second LO with Si5351 - Si5351.SetCLK(SiChannel::Port1LO2, m.LO2Frequency, Si5351C::PLL::B, Si5351C::DriveStrength::mA2); + Si5351.SetCLK(SiChannel::Port1LO2, m.V1.LO2Frequency, Si5351C::PLL::B, Si5351C::DriveStrength::mA2); Si5351.Enable(SiChannel::Port1LO2); - Si5351.SetCLK(SiChannel::Port2LO2, m.LO2Frequency, Si5351C::PLL::B, Si5351C::DriveStrength::mA2); + Si5351.SetCLK(SiChannel::Port2LO2, m.V1.LO2Frequency, Si5351C::PLL::B, Si5351C::DriveStrength::mA2); Si5351.Enable(SiChannel::Port2LO2); - Si5351.SetCLK(SiChannel::RefLO2, m.LO2Frequency, Si5351C::PLL::B, Si5351C::DriveStrength::mA2); + Si5351.SetCLK(SiChannel::RefLO2, m.V1.LO2Frequency, Si5351C::PLL::B, Si5351C::DriveStrength::mA2); Si5351.Enable(SiChannel::RefLO2); // PLL reset appears to realign phases of clock signals @@ -50,26 +50,26 @@ void Manual::Setup(Protocol::ManualControlV1 m) { FPGA::WriteMAX2871Default(Source.GetRegisters()); FPGA::SetNumberOfPoints(1); - FPGA::SetSamplesPerPoint(m.Samples); + FPGA::SetSamplesPerPoint(m.V1.Samples); // Configure single sweep point - FPGA::WriteSweepConfig(0, !m.SourceHighband, Source.GetRegisters(), - LO1.GetRegisters(), m.attenuator, 0, FPGA::SettlingTime::us60, + FPGA::WriteSweepConfig(0, !m.V1.SourceHighband, Source.GetRegisters(), + LO1.GetRegisters(), m.V1.attenuator, 0, FPGA::SettlingTime::us60, FPGA::Samples::SPPRegister, 0, - (FPGA::LowpassFilter) m.SourceHighLowpass); + (FPGA::LowpassFilter) m.V1.SourceHighLowpass); - FPGA::SetWindow((FPGA::Window) m.WindowType); + FPGA::SetWindow((FPGA::Window) m.V1.WindowType); // Enable/Disable periphery - FPGA::Enable(FPGA::Periphery::SourceChip, m.SourceHighCE); - FPGA::Enable(FPGA::Periphery::SourceRF, m.SourceHighRFEN); - FPGA::Enable(FPGA::Periphery::LO1Chip, m.LO1CE); - FPGA::Enable(FPGA::Periphery::LO1RF, m.LO1RFEN); - FPGA::Enable(FPGA::Periphery::Amplifier, m.AmplifierEN); - FPGA::Enable(FPGA::Periphery::Port1Mixer, m.Port1EN); - FPGA::Enable(FPGA::Periphery::Port2Mixer, m.Port2EN); - FPGA::Enable(FPGA::Periphery::RefMixer, m.RefEN); - FPGA::SetupSweep(0, m.PortSwitch == 1, m.PortSwitch == 0); + FPGA::Enable(FPGA::Periphery::SourceChip, m.V1.SourceHighCE); + FPGA::Enable(FPGA::Periphery::SourceRF, m.V1.SourceHighRFEN); + FPGA::Enable(FPGA::Periphery::LO1Chip, m.V1.LO1CE); + FPGA::Enable(FPGA::Periphery::LO1RF, m.V1.LO1RFEN); + FPGA::Enable(FPGA::Periphery::Amplifier, m.V1.AmplifierEN); + FPGA::Enable(FPGA::Periphery::Port1Mixer, m.V1.Port1EN); + FPGA::Enable(FPGA::Periphery::Port2Mixer, m.V1.Port2EN); + FPGA::Enable(FPGA::Periphery::RefMixer, m.V1.RefEN); + FPGA::SetupSweep(0, m.V1.PortSwitch == 1, m.V1.PortSwitch == 0); FPGA::Enable(FPGA::Periphery::PortSwitch); // Enable new data and sweep halt interrupt @@ -84,12 +84,12 @@ bool Manual::MeasurementDone(const FPGA::SamplingResult &result) { return false; } // save measurement - status.port1real = (float) result.P1I / samples; - status.port1imag = (float) result.P1Q / samples; - status.port2real = (float) result.P2I / samples; - status.port2imag = (float) result.P2Q / samples; - status.refreal = (float) result.RefI / samples; - status.refimag = (float) result.RefQ / samples; + status.V1.port1real = (float) result.P1I / samples; + status.V1.port1imag = (float) result.P1Q / samples; + status.V1.port2real = (float) result.P2I / samples; + status.V1.port2imag = (float) result.P2Q / samples; + status.V1.refreal = (float) result.RefI / samples; + status.V1.refimag = (float) result.RefQ / samples; return true; } @@ -99,39 +99,39 @@ void Manual::Work() { return; } Protocol::PacketInfo p; - p.type = Protocol::PacketType::ManualStatusV1; - p.manualStatusV1 = status; + p.type = Protocol::PacketType::ManualStatus; + p.manualStatus = status; uint16_t isr_flags = FPGA::GetStatus(); if (!(isr_flags & 0x0002)) { - p.manualStatusV1.source_locked = 1; + p.manualStatus.V1.source_locked = 1; } else { - p.manualStatusV1.source_locked = 0; + p.manualStatus.V1.source_locked = 0; } if (!(isr_flags & 0x0001)) { - p.manualStatusV1.LO_locked = 1; + p.manualStatus.V1.LO_locked = 1; } else { - p.manualStatusV1.LO_locked = 0; + p.manualStatus.V1.LO_locked = 0; } auto limits = FPGA::GetADCLimits(); FPGA::ResetADCLimits(); - p.manualStatusV1.port1min = limits.P1min; - p.manualStatusV1.port1max = limits.P1max; - p.manualStatusV1.port2min = limits.P2min; - p.manualStatusV1.port2max = limits.P2max; - p.manualStatusV1.refmin = limits.Rmin; - p.manualStatusV1.refmax = limits.Rmax; - HW::GetTemps(&p.manualStatusV1.temp_source, &p.manualStatusV1.temp_LO); + p.manualStatus.V1.port1min = limits.P1min; + p.manualStatus.V1.port1max = limits.P1max; + p.manualStatus.V1.port2min = limits.P2min; + p.manualStatus.V1.port2max = limits.P2max; + p.manualStatus.V1.refmin = limits.Rmin; + p.manualStatus.V1.refmax = limits.Rmax; + HW::GetTemps(&p.manualStatus.V1.temp_source, &p.manualStatus.V1.temp_LO); Communication::Send(p); HW::Ref::update(); if(HW::getStatusUpdateFlag()) { Protocol::PacketInfo packet; - packet.type = Protocol::PacketType::DeviceStatusV1; + packet.type = Protocol::PacketType::DeviceStatus; // Enable PLL chips for temperature reading bool srcEn = FPGA::IsEnabled(FPGA::Periphery::SourceChip); bool LOEn = FPGA::IsEnabled(FPGA::Periphery::LO1Chip); FPGA::Enable(FPGA::Periphery::SourceChip); FPGA::Enable(FPGA::Periphery::LO1Chip); - HW::getDeviceStatus(&packet.statusV1, true); + HW::getDeviceStatus(&packet.status, true); // restore PLL state FPGA::Enable(FPGA::Periphery::SourceChip, srcEn); FPGA::Enable(FPGA::Periphery::LO1Chip, LOEn); diff --git a/Software/VNA_embedded/Application/Manual.hpp b/Software/VNA_embedded/Application/Manual.hpp index e13ed81..35e6517 100644 --- a/Software/VNA_embedded/Application/Manual.hpp +++ b/Software/VNA_embedded/Application/Manual.hpp @@ -5,7 +5,7 @@ namespace Manual { -void Setup(Protocol::ManualControlV1 m); +void Setup(Protocol::ManualControl m); bool MeasurementDone(const FPGA::SamplingResult &result); void Work(); void Stop(); diff --git a/Software/VNA_embedded/Application/SpectrumAnalyzer.cpp b/Software/VNA_embedded/Application/SpectrumAnalyzer.cpp index 150b32e..640357d 100644 --- a/Software/VNA_embedded/Application/SpectrumAnalyzer.cpp +++ b/Software/VNA_embedded/Application/SpectrumAnalyzer.cpp @@ -432,8 +432,8 @@ void SA::Work() { // send device info every nth point FPGA::Enable(FPGA::Periphery::SourceChip); // needs to enable the chip to get a valid temperature reading Protocol::PacketInfo packet; - packet.type = Protocol::PacketType::DeviceStatusV1; - HW::getDeviceStatus(&packet.statusV1, true); + packet.type = Protocol::PacketType::DeviceStatus; + HW::getDeviceStatus(&packet.status, true); FPGA::Disable(FPGA::Periphery::SourceChip); Communication::Send(packet); } diff --git a/Software/VNA_embedded/Application/VNA.cpp b/Software/VNA_embedded/Application/VNA.cpp index 192a99f..bd17870 100644 --- a/Software/VNA_embedded/Application/VNA.cpp +++ b/Software/VNA_embedded/Application/VNA.cpp @@ -351,9 +351,9 @@ void VNA::Work() { } // Compile info packet Protocol::PacketInfo packet; - packet.type = Protocol::PacketType::DeviceStatusV1; + packet.type = Protocol::PacketType::DeviceStatus; if(HW::getStatusUpdateFlag()) { - HW::getDeviceStatus(&packet.statusV1, true); + HW::getDeviceStatus(&packet.status, true); Communication::Send(packet); } // do not reset unlevel flag here, as it is calculated only once at the setup of the sweep