split device info and status protocol messages

This commit is contained in:
Jan Käberich 2022-04-03 20:26:30 +02:00
parent 37d8474260
commit c6ef075f4f
22 changed files with 248 additions and 204 deletions

View File

@ -253,7 +253,7 @@ void AmplitudeCalDialog::RemoveAllPoints()
bool AmplitudeCalDialog::AddPoint(AmplitudeCalDialog::CorrectionPoint &p) bool AmplitudeCalDialog::AddPoint(AmplitudeCalDialog::CorrectionPoint &p)
{ {
if (points.size() >= Device::Info().limits_maxAmplitudePoints) { if (points.size() >= Device::Info(dev).limits_maxAmplitudePoints) {
// already at limit // already at limit
return false; return false;
} }
@ -299,8 +299,8 @@ void AmplitudeCalDialog::AddPointDialog()
ui->stopFreq->setUnit("Hz"); ui->stopFreq->setUnit("Hz");
ui->stopFreq->setPrefixes(" kMG"); ui->stopFreq->setPrefixes(" kMG");
ui->frequency->setValue(1000000000.0); ui->frequency->setValue(1000000000.0);
ui->startFreq->setValue(Device::Info().limits_minFreq); ui->startFreq->setValue(Device::Info(dev).limits_minFreq);
ui->stopFreq->setValue(Device::Info().limits_maxFreq); ui->stopFreq->setValue(Device::Info(dev).limits_maxFreq);
connect(ui->singlePoint, &QRadioButton::toggled, [=](bool single) { connect(ui->singlePoint, &QRadioButton::toggled, [=](bool single) {
ui->stopFreq->setEnabled(!single); ui->stopFreq->setEnabled(!single);
ui->startFreq->setEnabled(!single); ui->startFreq->setEnabled(!single);

View File

@ -120,16 +120,6 @@ static constexpr Protocol::DeviceInfo defaultInfo = {
.FW_minor = 0, .FW_minor = 0,
.FW_patch = 0, .FW_patch = 0,
.HW_Revision = '0', .HW_Revision = '0',
.extRefAvailable = 0,
.extRefInUse = 0,
.FPGA_configured = 0,
.source_locked = 0,
.LO1_locked = 0,
.ADC_overload = 0,
.unlevel = 0,
.temp_source = 0,
.temp_LO1 = 0,
.temp_MCU = 0,
.limits_minFreq = 0, .limits_minFreq = 0,
.limits_maxFreq = 6000000000, .limits_maxFreq = 6000000000,
.limits_minIFBW = 10, .limits_minIFBW = 10,
@ -143,14 +133,25 @@ static constexpr Protocol::DeviceInfo defaultInfo = {
.limits_maxFreqHarmonic = 18000000000, .limits_maxFreqHarmonic = 18000000000,
}; };
Protocol::DeviceInfo Device::lastInfo = defaultInfo; static constexpr Protocol::DeviceStatusV1 defaultStatusV1 = {
.extRefAvailable = 0,
.extRefInUse = 0,
.FPGA_configured = 0,
.source_locked = 0,
.LO1_locked = 0,
.ADC_overload = 0,
.unlevel = 0,
.temp_source = 0,
.temp_LO1 = 0,
.temp_MCU = 0,
};
Device::Device(QString serial) Device::Device(QString serial)
{ {
lastInfo = defaultInfo; info = defaultInfo;
m_handle = nullptr; m_handle = nullptr;
lastInfoValid = false; infoValid = false;
libusb_init(&m_context); libusb_init(&m_context);
#if LIBUSB_API_VERSION >= 0x01000106 #if LIBUSB_API_VERSION >= 0x01000106
libusb_set_option(m_context, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_INFO); libusb_set_option(m_context, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_INFO);
@ -261,10 +262,10 @@ bool Device::Configure(Protocol::SpectrumAnalyzerSettings settings)
return SendPacket(p); return SendPacket(p);
} }
bool Device::SetManual(Protocol::ManualControl manual) bool Device::SetManual(Protocol::ManualControlV1 manual)
{ {
Protocol::PacketInfo p; Protocol::PacketInfo p;
p.type = Protocol::PacketType::ManualControl; p.type = Protocol::PacketType::ManualControlV1;
p.manual = manual; p.manual = manual;
return SendPacket(p); return SendPacket(p);
} }
@ -393,25 +394,48 @@ void Device::SearchDevices(std::function<bool (libusb_device_handle *, QString)>
const Protocol::DeviceInfo &Device::Info() const Protocol::DeviceInfo &Device::Info()
{ {
return lastInfo; return info;
}
const Protocol::DeviceInfo &Device::Info(Device *dev)
{
if(dev) {
return dev->Info();
} else {
return defaultInfo;
}
}
Protocol::DeviceStatusV1 &Device::StatusV1()
{
return status.v1;
}
const Protocol::DeviceStatusV1 &Device::StatusV1(Device *dev)
{
if(dev) {
return dev->StatusV1();
} else {
return defaultStatusV1;
}
} }
QString Device::getLastDeviceInfoString() QString Device::getLastDeviceInfoString()
{ {
QString ret; QString ret;
if(!lastInfoValid) { if(!infoValid) {
ret.append("No device information available yet"); ret.append("No device information available yet");
} else { } else {
ret.append("HW Rev."); ret.append("HW Rev.");
ret.append(lastInfo.HW_Revision); ret.append(info.HW_Revision);
ret.append(" FW "+QString::number(lastInfo.FW_major)+"."+QString::number(lastInfo.FW_minor)+"."+QString::number(lastInfo.FW_patch)); ret.append(" FW "+QString::number(info.FW_major)+"."+QString::number(info.FW_minor)+"."+QString::number(info.FW_patch));
ret.append(" Temps: "+QString::number(lastInfo.temp_source)+"°C/"+QString::number(lastInfo.temp_LO1)+"°C/"+QString::number(lastInfo.temp_MCU)+"°C"); ret.append(" Temps: "+QString::number(status.v1.temp_source)+"°C/"+QString::number(status.v1.temp_LO1)+"°C/"+QString::number(status.v1.temp_MCU)+"°C");
ret.append(" Reference:"); ret.append(" Reference:");
if(lastInfo.extRefInUse) { if(status.v1.extRefInUse) {
ret.append("External"); ret.append("External");
} else { } else {
ret.append("Internal"); ret.append("Internal");
if(lastInfo.extRefAvailable) { if(status.v1.extRefAvailable) {
ret.append(" (External available)"); ret.append(" (External available)");
} }
} }
@ -431,8 +455,8 @@ void Device::ReceivedData()
case Protocol::PacketType::Datapoint: case Protocol::PacketType::Datapoint:
emit DatapointReceived(packet.datapoint); emit DatapointReceived(packet.datapoint);
break; break;
case Protocol::PacketType::Status: case Protocol::PacketType::ManualStatusV1:
emit ManualStatusReceived(packet.status); emit ManualStatusReceived(packet.manualStatusV1);
break; break;
case Protocol::PacketType::SpectrumAnalyzerResult: case Protocol::PacketType::SpectrumAnalyzerResult:
emit SpectrumResultReceived(packet.spectrumResult); emit SpectrumResultReceived(packet.spectrumResult);
@ -443,15 +467,19 @@ void Device::ReceivedData()
break; break;
case Protocol::PacketType::DeviceInfo: case Protocol::PacketType::DeviceInfo:
if(packet.info.ProtocolVersion != Protocol::Version) { if(packet.info.ProtocolVersion != Protocol::Version) {
if(!lastInfoValid) { if(!infoValid) {
emit NeedsFirmwareUpdate(packet.info.ProtocolVersion, Protocol::Version); emit NeedsFirmwareUpdate(packet.info.ProtocolVersion, Protocol::Version);
} }
} else { } else {
lastInfo = packet.info; info = packet.info;
} }
lastInfoValid = true; infoValid = true;
emit DeviceInfoUpdated(); emit DeviceInfoUpdated();
break; break;
case Protocol::PacketType::DeviceStatusV1:
status.v1 = packet.statusV1;
emit DeviceStatusUpdated();
break;
case Protocol::PacketType::Ack: case Protocol::PacketType::Ack:
emit AckReceived(); emit AckReceived();
emit receivedAnswer(TransmissionResult::Ack); emit receivedAnswer(TransmissionResult::Ack);

View File

@ -13,7 +13,7 @@
#include <QTimer> #include <QTimer>
Q_DECLARE_METATYPE(Protocol::Datapoint); Q_DECLARE_METATYPE(Protocol::Datapoint);
Q_DECLARE_METATYPE(Protocol::ManualStatus); Q_DECLARE_METATYPE(Protocol::ManualStatusV1);
Q_DECLARE_METATYPE(Protocol::SpectrumAnalyzerResult); Q_DECLARE_METATYPE(Protocol::SpectrumAnalyzerResult);
Q_DECLARE_METATYPE(Protocol::AmplitudeCorrectionPoint); Q_DECLARE_METATYPE(Protocol::AmplitudeCorrectionPoint);
@ -61,23 +61,27 @@ public:
bool SendPacket(const Protocol::PacketInfo& packet, std::function<void(TransmissionResult)> cb = nullptr, unsigned int timeout = 500); bool SendPacket(const Protocol::PacketInfo& packet, std::function<void(TransmissionResult)> cb = nullptr, unsigned int timeout = 500);
bool Configure(Protocol::SweepSettings settings, std::function<void(TransmissionResult)> cb = nullptr); bool Configure(Protocol::SweepSettings settings, std::function<void(TransmissionResult)> cb = nullptr);
bool Configure(Protocol::SpectrumAnalyzerSettings settings); bool Configure(Protocol::SpectrumAnalyzerSettings settings);
bool SetManual(Protocol::ManualControl manual); bool SetManual(Protocol::ManualControlV1 manual);
bool SetIdle(); bool SetIdle();
bool SendFirmwareChunk(Protocol::FirmwarePacket &fw); bool SendFirmwareChunk(Protocol::FirmwarePacket &fw);
bool SendCommandWithoutPayload(Protocol::PacketType type); bool SendCommandWithoutPayload(Protocol::PacketType type);
QString serial() const; QString serial() const;
static const Protocol::DeviceInfo& Info(); const Protocol::DeviceInfo& Info();
static const Protocol::DeviceInfo& Info(Device *dev);
Protocol::DeviceStatusV1& StatusV1();
static const Protocol::DeviceStatusV1& StatusV1(Device *dev);
QString getLastDeviceInfoString(); QString getLastDeviceInfoString();
// Returns serial numbers of all connected devices // Returns serial numbers of all connected devices
static std::set<QString> GetDevices(); static std::set<QString> GetDevices();
signals: signals:
void DatapointReceived(Protocol::Datapoint); void DatapointReceived(Protocol::Datapoint);
void ManualStatusReceived(Protocol::ManualStatus); void ManualStatusReceived(Protocol::ManualStatusV1);
void SpectrumResultReceived(Protocol::SpectrumAnalyzerResult); void SpectrumResultReceived(Protocol::SpectrumAnalyzerResult);
void AmplitudeCorrectionPointReceived(Protocol::AmplitudeCorrectionPoint); void AmplitudeCorrectionPointReceived(Protocol::AmplitudeCorrectionPoint);
void FrequencyCorrectionReceived(float ppm); void FrequencyCorrectionReceived(float ppm);
void DeviceInfoUpdated(); void DeviceInfoUpdated();
void DeviceStatusUpdated();
void ConnectionLost(); void ConnectionLost();
void AckReceived(); void AckReceived();
void NackReceived(); void NackReceived();
@ -122,8 +126,11 @@ private:
QString m_serial; QString m_serial;
bool m_connected; bool m_connected;
std::thread *m_receiveThread; std::thread *m_receiveThread;
static Protocol::DeviceInfo lastInfo; Protocol::DeviceInfo info;
bool lastInfoValid; bool infoValid;
union {
Protocol::DeviceStatusV1 v1;
} status;
}; };
#endif // DEVICE_H #endif // DEVICE_H

View File

@ -580,7 +580,7 @@ double ManualControlDialog::getRefPhase()
return ui->refphase->text().toDouble(); return ui->refphase->text().toDouble();
} }
void ManualControlDialog::NewStatus(Protocol::ManualStatus status) void ManualControlDialog::NewStatus(Protocol::ManualStatusV1 status)
{ {
// ADC values // ADC values
ui->port1min->setText(QString::number(status.port1min)); ui->port1min->setText(QString::number(status.port1min));
@ -616,7 +616,7 @@ void ManualControlDialog::NewStatus(Protocol::ManualStatus status)
void ManualControlDialog::UpdateDevice() void ManualControlDialog::UpdateDevice()
{ {
Protocol::ManualControl m; Protocol::ManualControlV1 m;
// Source highband // Source highband
m.SourceHighCE = ui->SourceCE->isChecked(); m.SourceHighCE = ui->SourceCE->isChecked();
m.SourceHighRFEN = ui->SourceRFEN->isChecked(); m.SourceHighRFEN = ui->SourceRFEN->isChecked();

View File

@ -103,7 +103,7 @@ public:
double getRefPhase(); double getRefPhase();
public slots: public slots:
void NewStatus(Protocol::ManualStatus status); void NewStatus(Protocol::ManualStatusV1 status);
private: private:
void UpdateDevice(); void UpdateDevice();

View File

@ -6,7 +6,7 @@ Generator::Generator(AppWindow *window)
: Mode(window, "Signal Generator") : Mode(window, "Signal Generator")
, SCPINode("GENerator") , SCPINode("GENerator")
{ {
central = new SignalgeneratorWidget(window); central = new SignalgeneratorWidget(window->getDevice(), window);
auto pref = Preferences::getInstance(); auto pref = Preferences::getInstance();

View File

@ -2,9 +2,10 @@
#include "ui_signalgenwidget.h" #include "ui_signalgenwidget.h"
SignalgeneratorWidget::SignalgeneratorWidget(QWidget *parent) : SignalgeneratorWidget::SignalgeneratorWidget(Device *&dev, QWidget *parent) :
QWidget(parent), QWidget(parent),
ui(new Ui::SignalgeneratorWidget) ui(new Ui::SignalgeneratorWidget),
dev(dev)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->frequency->setUnit("Hz"); ui->frequency->setUnit("Hz");
@ -31,16 +32,16 @@ SignalgeneratorWidget::SignalgeneratorWidget(QWidget *parent) :
ui->steps->setPrecision(0); ui->steps->setPrecision(0);
connect(ui->frequency, &SIUnitEdit::valueChanged, [=](double newval) { connect(ui->frequency, &SIUnitEdit::valueChanged, [=](double newval) {
if(newval < Device::Info().limits_minFreq) { if(newval < Device::Info(dev).limits_minFreq) {
newval = Device::Info().limits_minFreq; newval = Device::Info(dev).limits_minFreq;
} else if (newval > Device::Info().limits_maxFreq) { } else if (newval > Device::Info(dev).limits_maxFreq) {
newval = Device::Info().limits_maxFreq; newval = Device::Info(dev).limits_maxFreq;
} }
ui->frequency->setValueQuiet(newval); ui->frequency->setValueQuiet(newval);
if (newval < ui->span->value()/2) if (newval < ui->span->value()/2)
ui->span->setValueQuiet(newval/2); ui->span->setValueQuiet(newval/2);
if (newval + ui->span->value()/2 > Device::Info().limits_maxFreq) if (newval + ui->span->value()/2 > Device::Info(dev).limits_maxFreq)
ui->span->setValueQuiet((Device::Info().limits_maxFreq - newval)*2); ui->span->setValueQuiet((Device::Info(dev).limits_maxFreq - newval)*2);
newval = ui->frequency->value() - ui->span->value()/2; newval = ui->frequency->value() - ui->span->value()/2;
ui->current->setValueQuiet(newval); ui->current->setValueQuiet(newval);
emit SettingsChanged(); emit SettingsChanged();
@ -49,8 +50,8 @@ SignalgeneratorWidget::SignalgeneratorWidget(QWidget *parent) :
connect(ui->span, &SIUnitEdit::valueChanged, [=](double newval) { connect(ui->span, &SIUnitEdit::valueChanged, [=](double newval) {
if(newval < 0 ) { if(newval < 0 ) {
newval = 0; newval = 0;
} else if (newval > Device::Info().limits_maxFreq - Device::Info().limits_minFreq) { } else if (newval > Device::Info(dev).limits_maxFreq - Device::Info(dev).limits_minFreq) {
newval = Device::Info().limits_maxFreq - Device::Info().limits_minFreq; newval = Device::Info(dev).limits_maxFreq - Device::Info(dev).limits_minFreq;
} }
ui->span->setValueQuiet(newval); ui->span->setValueQuiet(newval);
@ -59,8 +60,8 @@ SignalgeneratorWidget::SignalgeneratorWidget(QWidget *parent) :
ui->frequency->setValueQuiet(ui->span->value()/2); ui->frequency->setValueQuiet(ui->span->value()/2);
} }
newF = ui->frequency->value() + ui->span->value()/2; newF = ui->frequency->value() + ui->span->value()/2;
if (newF > Device::Info().limits_maxFreq) { if (newF > Device::Info(dev).limits_maxFreq) {
ui->frequency->setValueQuiet(Device::Info().limits_maxFreq - ui->span->value()/2); ui->frequency->setValueQuiet(Device::Info(dev).limits_maxFreq - ui->span->value()/2);
} }
newval = ui->frequency->value() - ui->span->value()/2; newval = ui->frequency->value() - ui->span->value()/2;
@ -71,8 +72,8 @@ SignalgeneratorWidget::SignalgeneratorWidget(QWidget *parent) :
connect(ui->current, &SIUnitEdit::valueChanged, [=](double newval) { connect(ui->current, &SIUnitEdit::valueChanged, [=](double newval) {
if(newval < 0 ) { if(newval < 0 ) {
newval = 0; newval = 0;
} else if (newval > Device::Info().limits_maxFreq - Device::Info().limits_minFreq) { } else if (newval > Device::Info(dev).limits_maxFreq - Device::Info(dev).limits_minFreq) {
newval = Device::Info().limits_maxFreq - Device::Info().limits_minFreq; newval = Device::Info(dev).limits_maxFreq - Device::Info(dev).limits_minFreq;
} }
ui->current->setValueQuiet(newval); ui->current->setValueQuiet(newval);
emit SettingsChanged(); emit SettingsChanged();

View File

@ -15,7 +15,7 @@ class SignalgeneratorWidget : public QWidget, public Savable
Q_OBJECT Q_OBJECT
public: public:
explicit SignalgeneratorWidget(QWidget *parent = nullptr); explicit SignalgeneratorWidget(Device*&dev, QWidget *parent = nullptr);
~SignalgeneratorWidget(); ~SignalgeneratorWidget();
Protocol::GeneratorSettings getDeviceStatus(); Protocol::GeneratorSettings getDeviceStatus();
@ -36,6 +36,7 @@ protected:
private: private:
Ui::SignalgeneratorWidget *ui; Ui::SignalgeneratorWidget *ui;
int m_timerId; int m_timerId;
Device*&dev;
}; };
#endif // SIGNALGENERATOR_H #endif // SIGNALGENERATOR_H

View File

@ -555,14 +555,14 @@ void SpectrumAnalyzer::SetStopFreq(double freq)
void SpectrumAnalyzer::SetCenterFreq(double freq) void SpectrumAnalyzer::SetCenterFreq(double freq)
{ {
auto old_span = settings.f_stop - settings.f_start; auto old_span = settings.f_stop - settings.f_start;
if (freq - old_span / 2 <= Device::Info().limits_minFreq) { if (freq - old_span / 2 <= Device::Info(window->getDevice()).limits_minFreq) {
// would shift start frequency below minimum // would shift start frequency below minimum
settings.f_start = 0; settings.f_start = 0;
settings.f_stop = 2 * freq; settings.f_stop = 2 * freq;
} else if(freq + old_span / 2 >= Device::Info().limits_maxFreq) { } else if(freq + old_span / 2 >= Device::Info(window->getDevice()).limits_maxFreq) {
// would shift stop frequency above maximum // would shift stop frequency above maximum
settings.f_start = 2 * freq - Device::Info().limits_maxFreq; settings.f_start = 2 * freq - Device::Info(window->getDevice()).limits_maxFreq;
settings.f_stop = Device::Info().limits_maxFreq; settings.f_stop = Device::Info(window->getDevice()).limits_maxFreq;
} else { } else {
settings.f_start = freq - old_span / 2; settings.f_start = freq - old_span / 2;
settings.f_stop = freq + old_span / 2; settings.f_stop = freq + old_span / 2;
@ -573,14 +573,14 @@ void SpectrumAnalyzer::SetCenterFreq(double freq)
void SpectrumAnalyzer::SetSpan(double span) void SpectrumAnalyzer::SetSpan(double span)
{ {
auto old_center = (settings.f_start + settings.f_stop) / 2; auto old_center = (settings.f_start + settings.f_stop) / 2;
if(old_center < Device::Info().limits_minFreq + span / 2) { if(old_center < Device::Info(window->getDevice()).limits_minFreq + span / 2) {
// would shift start frequency below minimum // would shift start frequency below minimum
settings.f_start = Device::Info().limits_minFreq; settings.f_start = Device::Info(window->getDevice()).limits_minFreq;
settings.f_stop = Device::Info().limits_minFreq + span; settings.f_stop = Device::Info(window->getDevice()).limits_minFreq + span;
} else if(old_center > Device::Info().limits_maxFreq - span / 2) { } else if(old_center > Device::Info(window->getDevice()).limits_maxFreq - span / 2) {
// would shift stop frequency above maximum // would shift stop frequency above maximum
settings.f_start = Device::Info().limits_maxFreq - span; settings.f_start = Device::Info(window->getDevice()).limits_maxFreq - span;
settings.f_stop = Device::Info().limits_maxFreq; settings.f_stop = Device::Info(window->getDevice()).limits_maxFreq;
} else { } else {
settings.f_start = old_center - span / 2; settings.f_start = old_center - span / 2;
settings.f_stop = settings.f_start + span; settings.f_stop = settings.f_start + span;
@ -590,8 +590,8 @@ void SpectrumAnalyzer::SetSpan(double span)
void SpectrumAnalyzer::SetFullSpan() void SpectrumAnalyzer::SetFullSpan()
{ {
settings.f_start = Device::Info().limits_minFreq; settings.f_start = Device::Info(window->getDevice()).limits_minFreq;
settings.f_stop = Device::Info().limits_maxFreq; settings.f_stop = Device::Info(window->getDevice()).limits_maxFreq;
ConstrainAndUpdateFrequencies(); ConstrainAndUpdateFrequencies();
} }
@ -619,10 +619,10 @@ void SpectrumAnalyzer::SpanZoomOut()
void SpectrumAnalyzer::SetRBW(double bandwidth) void SpectrumAnalyzer::SetRBW(double bandwidth)
{ {
if(bandwidth > Device::Info().limits_maxRBW) { if(bandwidth > Device::Info(window->getDevice()).limits_maxRBW) {
bandwidth = Device::Info().limits_maxRBW; bandwidth = Device::Info(window->getDevice()).limits_maxRBW;
} else if(bandwidth < Device::Info().limits_minRBW) { } else if(bandwidth < Device::Info(window->getDevice()).limits_minRBW) {
bandwidth = Device::Info().limits_minRBW; bandwidth = Device::Info(window->getDevice()).limits_minRBW;
} }
settings.RBW = bandwidth; settings.RBW = bandwidth;
emit RBWChanged(settings.RBW); emit RBWChanged(settings.RBW);
@ -690,10 +690,10 @@ void SpectrumAnalyzer::SetTGPort(int port)
void SpectrumAnalyzer::SetTGLevel(double level) void SpectrumAnalyzer::SetTGLevel(double level)
{ {
if(level > Device::Info().limits_cdbm_max / 100.0) { if(level > Device::Info(window->getDevice()).limits_cdbm_max / 100.0) {
level = Device::Info().limits_cdbm_max / 100.0; level = Device::Info(window->getDevice()).limits_cdbm_max / 100.0;
} else if(level < Device::Info().limits_cdbm_min / 100.0) { } else if(level < Device::Info(window->getDevice()).limits_cdbm_min / 100.0) {
level = Device::Info().limits_cdbm_min / 100.0; level = Device::Info(window->getDevice()).limits_cdbm_min / 100.0;
} }
emit TGLevelChanged(level); emit TGLevelChanged(level);
settings.trackingPower = level * 100; settings.trackingPower = level * 100;
@ -1015,24 +1015,24 @@ void SpectrumAnalyzer::UpdateAverageCount()
void SpectrumAnalyzer::ConstrainAndUpdateFrequencies() void SpectrumAnalyzer::ConstrainAndUpdateFrequencies()
{ {
if(settings.f_stop > Device::Info().limits_maxFreq) { if(settings.f_stop > Device::Info(window->getDevice()).limits_maxFreq) {
settings.f_stop = Device::Info().limits_maxFreq; settings.f_stop = Device::Info(window->getDevice()).limits_maxFreq;
} }
if(settings.f_start > settings.f_stop) { if(settings.f_start > settings.f_stop) {
settings.f_start = settings.f_stop; settings.f_start = settings.f_stop;
} }
if(settings.f_start < Device::Info().limits_minFreq) { if(settings.f_start < Device::Info(window->getDevice()).limits_minFreq) {
settings.f_start = Device::Info().limits_minFreq; settings.f_start = Device::Info(window->getDevice()).limits_minFreq;
} }
bool trackingOffset_limited = false; bool trackingOffset_limited = false;
if(settings.f_stop + settings.trackingGeneratorOffset > Device::Info().limits_maxFreq) { if(settings.f_stop + settings.trackingGeneratorOffset > Device::Info(window->getDevice()).limits_maxFreq) {
trackingOffset_limited = true; trackingOffset_limited = true;
settings.trackingGeneratorOffset = Device::Info().limits_maxFreq - settings.f_stop; settings.trackingGeneratorOffset = Device::Info(window->getDevice()).limits_maxFreq - settings.f_stop;
} }
if((long) settings.f_start + settings.trackingGeneratorOffset < (long) Device::Info().limits_minFreq) { if((long) settings.f_start + settings.trackingGeneratorOffset < (long) Device::Info(window->getDevice()).limits_minFreq) {
trackingOffset_limited = true; trackingOffset_limited = true;
settings.trackingGeneratorOffset = Device::Info().limits_minFreq - settings.f_start; settings.trackingGeneratorOffset = Device::Info(window->getDevice()).limits_minFreq - settings.f_start;
} }
if(trackingOffset_limited) { if(trackingOffset_limited) {
InformationBox::ShowMessage("Warning", "The selected tracking generator offset is not reachable for all frequencies with the current span. " InformationBox::ShowMessage("Warning", "The selected tracking generator offset is not reachable for all frequencies with the current span. "

View File

@ -997,14 +997,14 @@ void VNA::SetStopFreq(double freq)
void VNA::SetCenterFreq(double freq) void VNA::SetCenterFreq(double freq)
{ {
auto old_span = settings.Freq.stop - settings.Freq.start; auto old_span = settings.Freq.stop - settings.Freq.start;
if (freq - old_span / 2 <= Device::Info().limits_minFreq) { if (freq - old_span / 2 <= Device::Info(window->getDevice()).limits_minFreq) {
// would shift start frequency below minimum // would shift start frequency below minimum
settings.Freq.start = 0; settings.Freq.start = 0;
settings.Freq.stop = 2 * freq; settings.Freq.stop = 2 * freq;
} else if(freq + old_span / 2 >= Device::Info().limits_maxFreq) { } else if(freq + old_span / 2 >= Device::Info(window->getDevice()).limits_maxFreq) {
// would shift stop frequency above maximum // would shift stop frequency above maximum
settings.Freq.start = 2 * freq - Device::Info().limits_maxFreq; settings.Freq.start = 2 * freq - Device::Info(window->getDevice()).limits_maxFreq;
settings.Freq.stop = Device::Info().limits_maxFreq; settings.Freq.stop = Device::Info(window->getDevice()).limits_maxFreq;
} else { } else {
settings.Freq.start = freq - old_span / 2; settings.Freq.start = freq - old_span / 2;
settings.Freq.stop = freq + old_span / 2; settings.Freq.stop = freq + old_span / 2;
@ -1014,12 +1014,12 @@ void VNA::SetCenterFreq(double freq)
void VNA::SetSpan(double span) void VNA::SetSpan(double span)
{ {
auto maxFreq = Preferences::getInstance().Acquisition.harmonicMixing ? Device::Info().limits_maxFreqHarmonic : Device::Info().limits_maxFreq; auto maxFreq = Preferences::getInstance().Acquisition.harmonicMixing ? Device::Info(window->getDevice()).limits_maxFreqHarmonic : Device::Info(window->getDevice()).limits_maxFreq;
auto old_center = (settings.Freq.start + settings.Freq.stop) / 2; auto old_center = (settings.Freq.start + settings.Freq.stop) / 2;
if(old_center < Device::Info().limits_minFreq + span / 2) { if(old_center < Device::Info(window->getDevice()).limits_minFreq + span / 2) {
// would shift start frequency below minimum // would shift start frequency below minimum
settings.Freq.start = Device::Info().limits_minFreq; settings.Freq.start = Device::Info(window->getDevice()).limits_minFreq;
settings.Freq.stop = Device::Info().limits_minFreq + span; settings.Freq.stop = Device::Info(window->getDevice()).limits_minFreq + span;
} else if(old_center > maxFreq - span / 2) { } else if(old_center > maxFreq - span / 2) {
// would shift stop frequency above maximum // would shift stop frequency above maximum
settings.Freq.start = maxFreq - span; settings.Freq.start = maxFreq - span;
@ -1033,8 +1033,8 @@ void VNA::SetSpan(double span)
void VNA::SetFullSpan() void VNA::SetFullSpan()
{ {
settings.Freq.start = Device::Info().limits_minFreq; settings.Freq.start = Device::Info(window->getDevice()).limits_minFreq;
settings.Freq.stop = Device::Info().limits_maxFreq; settings.Freq.stop = Device::Info(window->getDevice()).limits_maxFreq;
ConstrainAndUpdateFrequencies(); ConstrainAndUpdateFrequencies();
} }
@ -1072,10 +1072,10 @@ void VNA::SetLogSweep(bool log)
void VNA::SetSourceLevel(double level) void VNA::SetSourceLevel(double level)
{ {
if(level > Device::Info().limits_cdbm_max / 100.0) { if(level > Device::Info(window->getDevice()).limits_cdbm_max / 100.0) {
level = Device::Info().limits_cdbm_max / 100.0; level = Device::Info(window->getDevice()).limits_cdbm_max / 100.0;
} else if(level < Device::Info().limits_cdbm_min / 100.0) { } else if(level < Device::Info(window->getDevice()).limits_cdbm_min / 100.0) {
level = Device::Info().limits_cdbm_min / 100.0; level = Device::Info(window->getDevice()).limits_cdbm_min / 100.0;
} }
emit sourceLevelChanged(level); emit sourceLevelChanged(level);
settings.Freq.excitation_power = level; settings.Freq.excitation_power = level;
@ -1105,15 +1105,15 @@ void VNA::SetPowerSweepFrequency(double freq)
void VNA::SetPoints(unsigned int points) void VNA::SetPoints(unsigned int points)
{ {
unsigned int maxPoints = Preferences::getInstance().Acquisition.allowSegmentedSweep ? UINT16_MAX : Device::Info().limits_maxPoints; unsigned int maxPoints = Preferences::getInstance().Acquisition.allowSegmentedSweep ? UINT16_MAX : Device::Info(window->getDevice()).limits_maxPoints;
if(points > maxPoints) { if(points > maxPoints) {
points = maxPoints; points = maxPoints;
} else if (points < 2) { } else if (points < 2) {
points = 2; points = 2;
} }
if (points > Device::Info().limits_maxPoints) { if (points > Device::Info(window->getDevice()).limits_maxPoints) {
// needs segmented sweep // needs segmented sweep
settings.segments = ceil((double) points / Device::Info().limits_maxPoints); settings.segments = ceil((double) points / Device::Info(window->getDevice()).limits_maxPoints);
settings.activeSegment = 0; settings.activeSegment = 0;
} else { } else {
// can fit all points into one segment // can fit all points into one segment
@ -1127,10 +1127,10 @@ void VNA::SetPoints(unsigned int points)
void VNA::SetIFBandwidth(double bandwidth) void VNA::SetIFBandwidth(double bandwidth)
{ {
if(bandwidth > Device::Info().limits_maxIFBW) { if(bandwidth > Device::Info(window->getDevice()).limits_maxIFBW) {
bandwidth = Device::Info().limits_maxIFBW; bandwidth = Device::Info(window->getDevice()).limits_maxIFBW;
} else if(bandwidth < Device::Info().limits_minIFBW) { } else if(bandwidth < Device::Info(window->getDevice()).limits_minIFBW) {
bandwidth = Device::Info().limits_minIFBW; bandwidth = Device::Info(window->getDevice()).limits_minIFBW;
} }
settings.bandwidth = bandwidth; settings.bandwidth = bandwidth;
emit IFBandwidthChanged(settings.bandwidth); emit IFBandwidthChanged(settings.bandwidth);
@ -1478,9 +1478,9 @@ void VNA::ConstrainAndUpdateFrequencies()
auto pref = Preferences::getInstance(); auto pref = Preferences::getInstance();
double maxFreq; double maxFreq;
if(pref.Acquisition.harmonicMixing) { if(pref.Acquisition.harmonicMixing) {
maxFreq = Device::Info().limits_maxFreqHarmonic; maxFreq = Device::Info(window->getDevice()).limits_maxFreqHarmonic;
} else { } else {
maxFreq = Device::Info().limits_maxFreq; maxFreq = Device::Info(window->getDevice()).limits_maxFreq;
} }
if(settings.Freq.stop > maxFreq) { if(settings.Freq.stop > maxFreq) {
settings.Freq.stop = maxFreq; settings.Freq.stop = maxFreq;
@ -1488,8 +1488,8 @@ void VNA::ConstrainAndUpdateFrequencies()
if(settings.Freq.start > settings.Freq.stop) { if(settings.Freq.start > settings.Freq.stop) {
settings.Freq.start = settings.Freq.stop; settings.Freq.start = settings.Freq.stop;
} }
if(settings.Freq.start < Device::Info().limits_minFreq) { if(settings.Freq.start < Device::Info(window->getDevice()).limits_minFreq) {
settings.Freq.start = Device::Info().limits_minFreq; settings.Freq.start = Device::Info(window->getDevice()).limits_minFreq;
} }
emit startFreqChanged(settings.Freq.start); emit startFreqChanged(settings.Freq.start);
emit stopFreqChanged(settings.Freq.stop); emit stopFreqChanged(settings.Freq.stop);

View File

@ -235,7 +235,7 @@ AppWindow::AppWindow(QWidget *parent)
vna->activate(); vna->activate();
qRegisterMetaType<Protocol::Datapoint>("Datapoint"); qRegisterMetaType<Protocol::Datapoint>("Datapoint");
qRegisterMetaType<Protocol::ManualStatus>("Manual"); qRegisterMetaType<Protocol::ManualStatusV1>("ManualV1");
qRegisterMetaType<Protocol::SpectrumAnalyzerResult>("SpectrumAnalyzerResult"); qRegisterMetaType<Protocol::SpectrumAnalyzerResult>("SpectrumAnalyzerResult");
qRegisterMetaType<Protocol::AmplitudeCorrectionPoint>("AmplitudeCorrection"); qRegisterMetaType<Protocol::AmplitudeCorrectionPoint>("AmplitudeCorrection");
@ -309,7 +309,7 @@ bool AppWindow::ConnectToDevice(QString serial)
UpdateStatusBar(AppWindow::DeviceStatusBar::Connected); UpdateStatusBar(AppWindow::DeviceStatusBar::Connected);
connect(device, &Device::LogLineReceived, &deviceLog, &DeviceLog::addLine); connect(device, &Device::LogLineReceived, &deviceLog, &DeviceLog::addLine);
connect(device, &Device::ConnectionLost, this, &AppWindow::DeviceConnectionLost); connect(device, &Device::ConnectionLost, this, &AppWindow::DeviceConnectionLost);
connect(device, &Device::DeviceInfoUpdated, this, &AppWindow::DeviceInfoUpdated); connect(device, &Device::DeviceStatusUpdated, this, &AppWindow::DeviceStatusUpdated);
connect(device, &Device::NeedsFirmwareUpdate, this, &AppWindow::DeviceNeedsUpdate); connect(device, &Device::NeedsFirmwareUpdate, this, &AppWindow::DeviceNeedsUpdate);
ui->actionDisconnect->setEnabled(true); ui->actionDisconnect->setEnabled(true);
ui->actionManual_Control->setEnabled(true); ui->actionManual_Control->setEnabled(true);
@ -465,7 +465,7 @@ void AppWindow::SetupSCPI()
} }
return ""; return "";
}, [=](QStringList) -> QString { }, [=](QStringList) -> QString {
switch(Device::Info().extRefInUse) { switch(Device::StatusV1(getDevice()).extRefInUse) {
case 0: return "INT"; case 0: return "INT";
case 1: return "EXT"; case 1: return "EXT";
default: return "ERROR"; default: return "ERROR";
@ -500,57 +500,57 @@ void AppWindow::SetupSCPI()
auto scpi_status = new SCPINode("STAtus"); auto scpi_status = new SCPINode("STAtus");
scpi_dev->add(scpi_status); scpi_dev->add(scpi_status);
scpi_status->add(new SCPICommand("UNLOcked", nullptr, [=](QStringList){ scpi_status->add(new SCPICommand("UNLOcked", nullptr, [=](QStringList){
bool locked = Device::Info().source_locked && Device::Info().LO1_locked; bool locked = Device::StatusV1(getDevice()).source_locked && Device::StatusV1(getDevice()).LO1_locked;
return locked ? "FALSE" : "TRUE"; return locked ? "FALSE" : "TRUE";
})); }));
scpi_status->add(new SCPICommand("ADCOVERload", nullptr, [=](QStringList){ scpi_status->add(new SCPICommand("ADCOVERload", nullptr, [=](QStringList){
return Device::Info().ADC_overload ? "TRUE" : "FALSE"; return Device::StatusV1(getDevice()).ADC_overload ? "TRUE" : "FALSE";
})); }));
scpi_status->add(new SCPICommand("UNLEVel", nullptr, [=](QStringList){ scpi_status->add(new SCPICommand("UNLEVel", nullptr, [=](QStringList){
return Device::Info().unlevel ? "TRUE" : "FALSE"; return Device::StatusV1(getDevice()).unlevel ? "TRUE" : "FALSE";
})); }));
auto scpi_info = new SCPINode("INFo"); auto scpi_info = new SCPINode("INFo");
scpi_dev->add(scpi_info); scpi_dev->add(scpi_info);
scpi_info->add(new SCPICommand("FWREVision", nullptr, [=](QStringList){ scpi_info->add(new SCPICommand("FWREVision", nullptr, [=](QStringList){
return QString::number(Device::Info().FW_major)+"."+QString::number(Device::Info().FW_minor)+"."+QString::number(Device::Info().FW_patch); return QString::number(Device::Info(getDevice()).FW_major)+"."+QString::number(Device::Info(getDevice()).FW_minor)+"."+QString::number(Device::Info(getDevice()).FW_patch);
})); }));
scpi_info->add(new SCPICommand("HWREVision", nullptr, [=](QStringList){ scpi_info->add(new SCPICommand("HWREVision", nullptr, [=](QStringList){
return QString(Device::Info().HW_Revision); return QString(Device::Info(getDevice()).HW_Revision);
})); }));
scpi_info->add(new SCPICommand("TEMPeratures", nullptr, [=](QStringList){ scpi_info->add(new SCPICommand("TEMPeratures", nullptr, [=](QStringList){
return QString::number(Device::Info().temp_source)+"/"+QString::number(Device::Info().temp_LO1)+"/"+QString::number(Device::Info().temp_MCU); return QString::number(Device::StatusV1(getDevice()).temp_source)+"/"+QString::number(Device::StatusV1(getDevice()).temp_LO1)+"/"+QString::number(Device::StatusV1(getDevice()).temp_MCU);
})); }));
auto scpi_limits = new SCPINode("LIMits"); auto scpi_limits = new SCPINode("LIMits");
scpi_info->add(scpi_limits); scpi_info->add(scpi_limits);
scpi_limits->add(new SCPICommand("MINFrequency", nullptr, [=](QStringList){ scpi_limits->add(new SCPICommand("MINFrequency", nullptr, [=](QStringList){
return QString::number(Device::Info().limits_minFreq); return QString::number(Device::Info(getDevice()).limits_minFreq);
})); }));
scpi_limits->add(new SCPICommand("MAXFrequency", nullptr, [=](QStringList){ scpi_limits->add(new SCPICommand("MAXFrequency", nullptr, [=](QStringList){
return QString::number(Device::Info().limits_maxFreq); return QString::number(Device::Info(getDevice()).limits_maxFreq);
})); }));
scpi_limits->add(new SCPICommand("MINIFBW", nullptr, [=](QStringList){ scpi_limits->add(new SCPICommand("MINIFBW", nullptr, [=](QStringList){
return QString::number(Device::Info().limits_minIFBW); return QString::number(Device::Info(getDevice()).limits_minIFBW);
})); }));
scpi_limits->add(new SCPICommand("MAXIFBW", nullptr, [=](QStringList){ scpi_limits->add(new SCPICommand("MAXIFBW", nullptr, [=](QStringList){
return QString::number(Device::Info().limits_maxIFBW); return QString::number(Device::Info(getDevice()).limits_maxIFBW);
})); }));
scpi_limits->add(new SCPICommand("MAXPoints", nullptr, [=](QStringList){ scpi_limits->add(new SCPICommand("MAXPoints", nullptr, [=](QStringList){
return QString::number(Device::Info().limits_maxPoints); return QString::number(Device::Info(getDevice()).limits_maxPoints);
})); }));
scpi_limits->add(new SCPICommand("MINPOWer", nullptr, [=](QStringList){ scpi_limits->add(new SCPICommand("MINPOWer", nullptr, [=](QStringList){
return QString::number(Device::Info().limits_cdbm_min / 100.0); return QString::number(Device::Info(getDevice()).limits_cdbm_min / 100.0);
})); }));
scpi_limits->add(new SCPICommand("MAXPOWer", nullptr, [=](QStringList){ scpi_limits->add(new SCPICommand("MAXPOWer", nullptr, [=](QStringList){
return QString::number(Device::Info().limits_cdbm_max / 100.0); return QString::number(Device::Info(getDevice()).limits_cdbm_max / 100.0);
})); }));
scpi_limits->add(new SCPICommand("MINRBW", nullptr, [=](QStringList){ scpi_limits->add(new SCPICommand("MINRBW", nullptr, [=](QStringList){
return QString::number(Device::Info().limits_minRBW); return QString::number(Device::Info(getDevice()).limits_minRBW);
})); }));
scpi_limits->add(new SCPICommand("MAXRBW", nullptr, [=](QStringList){ scpi_limits->add(new SCPICommand("MAXRBW", nullptr, [=](QStringList){
return QString::number(Device::Info().limits_maxRBW); return QString::number(Device::Info(getDevice()).limits_maxRBW);
})); }));
scpi_limits->add(new SCPICommand("MAXHARMonicfrequency", nullptr, [=](QStringList){ scpi_limits->add(new SCPICommand("MAXHARMonicfrequency", nullptr, [=](QStringList){
return QString::number(Device::Info().limits_maxFreqHarmonic); return QString::number(Device::Info(getDevice()).limits_maxFreqHarmonic);
})); }));
scpi.add(vna); scpi.add(vna);
@ -918,7 +918,7 @@ void AppWindow::DeviceNeedsUpdate(int reported, int expected)
} }
} }
void AppWindow::DeviceInfoUpdated() void AppWindow::DeviceStatusUpdated()
{ {
UpdateStatusBar(DeviceStatusBar::Updated); UpdateStatusBar(DeviceStatusBar::Updated);
} }
@ -1024,7 +1024,7 @@ void AppWindow::LoadSetup(nlohmann::json j)
} }
} }
Device *AppWindow::getDevice() const Device *&AppWindow::getDevice()
{ {
return device; return device;
} }
@ -1104,9 +1104,9 @@ void AppWindow::UpdateStatusBar(DeviceStatusBar status)
break; break;
case DeviceStatusBar::Updated: case DeviceStatusBar::Updated:
lDeviceInfo.setText(device->getLastDeviceInfoString()); lDeviceInfo.setText(device->getLastDeviceInfoString());
lADCOverload.setVisible(device->Info().ADC_overload); lADCOverload.setVisible(device->StatusV1().ADC_overload);
lUnlevel.setVisible(device->Info().unlevel); lUnlevel.setVisible(device->StatusV1().unlevel);
lUnlock.setVisible(!device->Info().LO1_locked || !device->Info().source_locked); lUnlock.setVisible(!device->StatusV1().LO1_locked || !device->StatusV1().source_locked);
break; break;
default: default:
// invalid status // invalid status

View File

@ -41,7 +41,7 @@ public:
Ui::MainWindow *getUi() const; Ui::MainWindow *getUi() const;
QStackedWidget *getCentral() const; QStackedWidget *getCentral() const;
Device *getDevice() const; Device*&getDevice();
const QString& getAppVersion() const; const QString& getAppVersion() const;
const QString& getAppGitHash() const; const QString& getAppGitHash() const;
@ -59,7 +59,7 @@ private slots:
void UpdateAcquisitionFrequencies(); void UpdateAcquisitionFrequencies();
void StartFirmwareUpdateDialog(); void StartFirmwareUpdateDialog();
void DeviceNeedsUpdate(int reported, int expected); void DeviceNeedsUpdate(int reported, int expected);
void DeviceInfoUpdated(); void DeviceStatusUpdated();
void SourceCalibrationDialog(); void SourceCalibrationDialog();
void ReceiverCalibrationDialog(); void ReceiverCalibrationDialog();
void FrequencyCalibrationDialog(); void FrequencyCalibrationDialog();

View File

@ -117,7 +117,7 @@ inline void App_Process() {
sweepActive = VNA::Setup(recv_packet.settings); sweepActive = VNA::Setup(recv_packet.settings);
Communication::SendWithoutPayload(Protocol::PacketType::Ack); Communication::SendWithoutPayload(Protocol::PacketType::Ack);
break; break;
case Protocol::PacketType::ManualControl: case Protocol::PacketType::ManualControlV1:
sweepActive = false; sweepActive = false;
last_measure_packet = recv_packet; last_measure_packet = recv_packet;
Manual::Setup(recv_packet.manual); Manual::Setup(recv_packet.manual);
@ -145,12 +145,21 @@ inline void App_Process() {
SA::Setup(recv_packet.spectrumSettings); SA::Setup(recv_packet.spectrumSettings);
Communication::SendWithoutPayload(Protocol::PacketType::Ack); Communication::SendWithoutPayload(Protocol::PacketType::Ack);
break; break;
case Protocol::PacketType::RequestDeviceInfo: case Protocol::PacketType::RequestDeviceInfo: {
Communication::SendWithoutPayload(Protocol::PacketType::Ack); Communication::SendWithoutPayload(Protocol::PacketType::Ack);
Protocol::PacketInfo p; Protocol::PacketInfo p;
p.type = Protocol::PacketType::DeviceInfo; p.type = Protocol::PacketType::DeviceInfo;
HW::fillDeviceInfo(&p.info); p.info = HW::Info;
Communication::Send(p); Communication::Send(p);
}
break;
case Protocol::PacketType::RequestDeviceStatus: {
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
Protocol::PacketInfo p;
p.type = Protocol::PacketType::DeviceStatusV1;
HW::getDeviceStatus(&p.statusV1);
Communication::Send(p);
}
break; break;
case Protocol::PacketType::SetIdle: case Protocol::PacketType::SetIdle:
HW::SetMode(HW::Mode::Idle); HW::SetMode(HW::Mode::Idle);

View File

@ -91,8 +91,9 @@ uint16_t Protocol::EncodePacket(const PacketInfo &packet, uint8_t *dest, uint16_
case PacketType::SweepSettings: payload_size = sizeof(packet.settings); break; case PacketType::SweepSettings: payload_size = sizeof(packet.settings); break;
case PacketType::Reference: payload_size = sizeof(packet.reference); break; case PacketType::Reference: payload_size = sizeof(packet.reference); break;
case PacketType::DeviceInfo: payload_size = sizeof(packet.info); break; case PacketType::DeviceInfo: payload_size = sizeof(packet.info); break;
case PacketType::Status: payload_size = sizeof(packet.status); break; case PacketType::DeviceStatusV1: payload_size = sizeof(packet.statusV1); break;
case PacketType::ManualControl: payload_size = sizeof(packet.manual); break; case PacketType::ManualStatusV1: payload_size = sizeof(packet.manualStatusV1); break;
case PacketType::ManualControlV1: payload_size = sizeof(packet.manual); break;
case PacketType::FirmwarePacket: payload_size = sizeof(packet.firmware); break; case PacketType::FirmwarePacket: payload_size = sizeof(packet.firmware); break;
case PacketType::Generator: payload_size = sizeof(packet.generator); break; case PacketType::Generator: payload_size = sizeof(packet.generator); break;
case PacketType::SpectrumAnalyzerSettings: payload_size = sizeof(packet.spectrumSettings); break; case PacketType::SpectrumAnalyzerSettings: payload_size = sizeof(packet.spectrumSettings); break;

View File

@ -4,7 +4,7 @@
namespace Protocol { namespace Protocol {
static constexpr uint16_t Version = 9; static constexpr uint16_t Version = 10;
#pragma pack(push, 1) #pragma pack(push, 1)
@ -50,17 +50,8 @@ using DeviceInfo = struct _deviceInfo {
uint8_t FW_major; uint8_t FW_major;
uint8_t FW_minor; uint8_t FW_minor;
uint8_t FW_patch; uint8_t FW_patch;
uint8_t hardware_version;
char HW_Revision; char HW_Revision;
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;
uint64_t limits_minFreq; uint64_t limits_minFreq;
uint64_t limits_maxFreq; uint64_t limits_maxFreq;
uint32_t limits_minIFBW; uint32_t limits_minIFBW;
@ -74,7 +65,21 @@ using DeviceInfo = struct _deviceInfo {
uint64_t limits_maxFreqHarmonic; uint64_t limits_maxFreqHarmonic;
}; };
using ManualStatus = struct _manualstatus { 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 ManualStatusV1 = struct _manualstatusV1 {
int16_t port1min, port1max; int16_t port1min, port1max;
int16_t port2min, port2max; int16_t port2min, port2max;
int16_t refmin, refmax; int16_t refmin, refmax;
@ -87,7 +92,7 @@ using ManualStatus = struct _manualstatus {
uint8_t LO_locked :1; uint8_t LO_locked :1;
}; };
using ManualControl = struct _manualControl { using ManualControlV1 = struct _manualControlV1 {
// Highband Source // Highband Source
uint8_t SourceHighCE :1; uint8_t SourceHighCE :1;
uint8_t SourceHighRFEN :1; uint8_t SourceHighRFEN :1;
@ -170,8 +175,8 @@ enum class PacketType : uint8_t {
None = 0, None = 0,
Datapoint = 1, Datapoint = 1,
SweepSettings = 2, SweepSettings = 2,
Status = 3, ManualStatusV1 = 3,
ManualControl = 4, ManualControlV1 = 4,
DeviceInfo = 5, DeviceInfo = 5,
FirmwarePacket = 6, FirmwarePacket = 6,
Ack = 7, Ack = 7,
@ -192,6 +197,8 @@ enum class PacketType : uint8_t {
FrequencyCorrection = 22, FrequencyCorrection = 22,
RequestAcquisitionFrequencySettings = 23, RequestAcquisitionFrequencySettings = 23,
AcquisitionFrequencySettings = 24, AcquisitionFrequencySettings = 24,
DeviceStatusV1 = 25,
RequestDeviceStatus = 26,
}; };
using PacketInfo = struct _packetinfo { using PacketInfo = struct _packetinfo {
@ -201,10 +208,11 @@ using PacketInfo = struct _packetinfo {
SweepSettings settings; SweepSettings settings;
ReferenceSettings reference; ReferenceSettings reference;
GeneratorSettings generator; GeneratorSettings generator;
DeviceStatusV1 statusV1;
DeviceInfo info; DeviceInfo info;
ManualControl manual; ManualControlV1 manual;
FirmwarePacket firmware; FirmwarePacket firmware;
ManualStatus status; ManualStatusV1 manualStatusV1;
SpectrumAnalyzerSettings spectrumSettings; SpectrumAnalyzerSettings spectrumSettings;
SpectrumAnalyzerResult spectrumResult; SpectrumAnalyzerResult spectrumResult;
AmplitudeCorrectionPoint amplitudePoint; AmplitudeCorrectionPoint amplitudePoint;

View File

@ -11,7 +11,7 @@ void Generator::Setup(Protocol::GeneratorSettings g) {
HW::SetIdle(); HW::SetIdle();
return; return;
} }
Protocol::ManualControl m; Protocol::ManualControlV1 m;
// LOs not required // LOs not required
m.LO1CE = 0; m.LO1CE = 0;
m.LO1Frequency = 1000000000; m.LO1Frequency = 1000000000;

View File

@ -299,9 +299,7 @@ void HW::SetOutputUnlevel(bool unlev) {
unlevel = unlev; unlevel = unlev;
} }
void HW::fillDeviceInfo(Protocol::DeviceInfo *info, bool updateEvenWhenBusy) { void HW::getDeviceStatus(Protocol::DeviceStatusV1 *status, bool updateEvenWhenBusy) {
// copy constant default values
memcpy(info, &HW::Info, sizeof(HW::Info));
if(activeMode == Mode::Idle || updateEvenWhenBusy) { if(activeMode == Mode::Idle || updateEvenWhenBusy) {
// updating values from FPGA allowed // updating values from FPGA allowed
@ -318,21 +316,21 @@ void HW::fillDeviceInfo(Protocol::DeviceInfo *info, bool updateEvenWhenBusy) {
if(limits.P1min < -ADC_LIMIT || limits.P1max > ADC_LIMIT if(limits.P1min < -ADC_LIMIT || limits.P1max > ADC_LIMIT
|| limits.P2min < -ADC_LIMIT || limits.P2max > ADC_LIMIT || limits.P2min < -ADC_LIMIT || limits.P2max > ADC_LIMIT
|| limits.Rmin < -ADC_LIMIT || limits.Rmax > ADC_LIMIT) { || limits.Rmin < -ADC_LIMIT || limits.Rmax > ADC_LIMIT) {
info->ADC_overload = true; status->ADC_overload = true;
} else { } else {
info->ADC_overload = false; status->ADC_overload = false;
} }
auto status = FPGA::GetStatus(); auto FPGA_status = FPGA::GetStatus();
info->LO1_locked = (status & (int) FPGA::Interrupt::LO1Unlock) ? 0 : 1; status->LO1_locked = (FPGA_status & (int) FPGA::Interrupt::LO1Unlock) ? 0 : 1;
info->source_locked = (status & (int) FPGA::Interrupt::SourceUnlock) ? 0 : 1; status->source_locked = (FPGA_status & (int) FPGA::Interrupt::SourceUnlock) ? 0 : 1;
info->extRefAvailable = Ref::available(); status->extRefAvailable = Ref::available();
info->extRefInUse = extRefInUse; status->extRefInUse = extRefInUse;
info->unlevel = unlevel; status->unlevel = unlevel;
info->temp_LO1 = tempLO; status->temp_LO1 = tempLO;
info->temp_source = tempSource; status->temp_source = tempSource;
FPGA::ResetADCLimits(); FPGA::ResetADCLimits();
} }
info->temp_MCU = STM::getTemperature(); status->temp_MCU = STM::getTemperature();
} }
bool HW::Ref::available() { bool HW::Ref::available() {

View File

@ -70,17 +70,8 @@ static constexpr Protocol::DeviceInfo Info = {
.FW_major = FW_MAJOR, .FW_major = FW_MAJOR,
.FW_minor = FW_MINOR, .FW_minor = FW_MINOR,
.FW_patch = FW_PATCH, .FW_patch = FW_PATCH,
.hardware_version = 1,
.HW_Revision = HW_REVISION, .HW_Revision = HW_REVISION,
.extRefAvailable = 0,
.extRefInUse = 0,
.FPGA_configured = 0,
.source_locked = 0,
.LO1_locked = 0,
.ADC_overload = 0,
.unlevel = 0,
.temp_source = 0,
.temp_LO1 = 0,
.temp_MCU = 0,
.limits_minFreq = 0, .limits_minFreq = 0,
.limits_maxFreq = 6000000000, .limits_maxFreq = 6000000000,
.limits_minIFBW = DefaultADCSamplerate / MaxSamples, .limits_minIFBW = DefaultADCSamplerate / MaxSamples,
@ -120,7 +111,7 @@ using AmplitudeSettings = struct _amplitudeSettings {
AmplitudeSettings GetAmplitudeSettings(int16_t cdbm, uint64_t freq = 0, bool applyCorrections = false, bool port2 = false); AmplitudeSettings GetAmplitudeSettings(int16_t cdbm, uint64_t freq = 0, bool applyCorrections = false, bool port2 = false);
bool GetTemps(uint8_t *source, uint8_t *lo); bool GetTemps(uint8_t *source, uint8_t *lo);
void fillDeviceInfo(Protocol::DeviceInfo *info, bool updateEvenWhenBusy = false); void getDeviceStatus(Protocol::DeviceStatusV1 *status, bool updateEvenWhenBusy = false);
namespace Ref { namespace Ref {
bool available(); bool available();
bool usingExternal(); bool usingExternal();

View File

@ -6,11 +6,11 @@
static bool active = false; static bool active = false;
static uint32_t samples; static uint32_t samples;
static Protocol::ManualStatus status; static Protocol::ManualStatusV1 status;
using namespace HWHAL; using namespace HWHAL;
void Manual::Setup(Protocol::ManualControl m) { void Manual::Setup(Protocol::ManualControlV1 m) {
HW::SetMode(HW::Mode::Manual); HW::SetMode(HW::Mode::Manual);
samples = m.Samples; samples = m.Samples;
FPGA::AbortSweep(); FPGA::AbortSweep();
@ -99,38 +99,38 @@ void Manual::Work() {
return; return;
} }
Protocol::PacketInfo p; Protocol::PacketInfo p;
p.type = Protocol::PacketType::Status; p.type = Protocol::PacketType::ManualStatusV1;
p.status = status; p.manualStatusV1 = status;
uint16_t isr_flags = FPGA::GetStatus(); uint16_t isr_flags = FPGA::GetStatus();
if (!(isr_flags & 0x0002)) { if (!(isr_flags & 0x0002)) {
p.status.source_locked = 1; p.manualStatusV1.source_locked = 1;
} else { } else {
p.status.source_locked = 0; p.manualStatusV1.source_locked = 0;
} }
if (!(isr_flags & 0x0001)) { if (!(isr_flags & 0x0001)) {
p.status.LO_locked = 1; p.manualStatusV1.LO_locked = 1;
} else { } else {
p.status.LO_locked = 0; p.manualStatusV1.LO_locked = 0;
} }
auto limits = FPGA::GetADCLimits(); auto limits = FPGA::GetADCLimits();
FPGA::ResetADCLimits(); FPGA::ResetADCLimits();
p.status.port1min = limits.P1min; p.manualStatusV1.port1min = limits.P1min;
p.status.port1max = limits.P1max; p.manualStatusV1.port1max = limits.P1max;
p.status.port2min = limits.P2min; p.manualStatusV1.port2min = limits.P2min;
p.status.port2max = limits.P2max; p.manualStatusV1.port2max = limits.P2max;
p.status.refmin = limits.Rmin; p.manualStatusV1.refmin = limits.Rmin;
p.status.refmax = limits.Rmax; p.manualStatusV1.refmax = limits.Rmax;
HW::GetTemps(&p.status.temp_source, &p.status.temp_LO); HW::GetTemps(&p.manualStatusV1.temp_source, &p.manualStatusV1.temp_LO);
Communication::Send(p); Communication::Send(p);
HW::Ref::update(); HW::Ref::update();
Protocol::PacketInfo packet; Protocol::PacketInfo packet;
packet.type = Protocol::PacketType::DeviceInfo; packet.type = Protocol::PacketType::DeviceStatusV1;
// Enable PLL chips for temperature reading // Enable PLL chips for temperature reading
bool srcEn = FPGA::IsEnabled(FPGA::Periphery::SourceChip); bool srcEn = FPGA::IsEnabled(FPGA::Periphery::SourceChip);
bool LOEn = FPGA::IsEnabled(FPGA::Periphery::LO1Chip); bool LOEn = FPGA::IsEnabled(FPGA::Periphery::LO1Chip);
FPGA::Enable(FPGA::Periphery::SourceChip); FPGA::Enable(FPGA::Periphery::SourceChip);
FPGA::Enable(FPGA::Periphery::LO1Chip); FPGA::Enable(FPGA::Periphery::LO1Chip);
HW::fillDeviceInfo(&packet.info, true); HW::getDeviceStatus(&packet.statusV1, true);
// restore PLL state // restore PLL state
FPGA::Enable(FPGA::Periphery::SourceChip, srcEn); FPGA::Enable(FPGA::Periphery::SourceChip, srcEn);
FPGA::Enable(FPGA::Periphery::LO1Chip, LOEn); FPGA::Enable(FPGA::Periphery::LO1Chip, LOEn);

View File

@ -5,7 +5,7 @@
namespace Manual { namespace Manual {
void Setup(Protocol::ManualControl m); void Setup(Protocol::ManualControlV1 m);
bool MeasurementDone(const FPGA::SamplingResult &result); bool MeasurementDone(const FPGA::SamplingResult &result);
void Work(); void Work();
void Stop(); void Stop();

View File

@ -385,8 +385,8 @@ void SA::Work() {
// send device info every nth point // send device info every nth point
FPGA::Enable(FPGA::Periphery::SourceChip); // needs to enable the chip to get a valid temperature reading FPGA::Enable(FPGA::Periphery::SourceChip); // needs to enable the chip to get a valid temperature reading
Protocol::PacketInfo packet; Protocol::PacketInfo packet;
packet.type = Protocol::PacketType::DeviceInfo; packet.type = Protocol::PacketType::DeviceStatusV1;
HW::fillDeviceInfo(&packet.info, true); HW::getDeviceStatus(&packet.statusV1, true);
FPGA::Disable(FPGA::Periphery::SourceChip); FPGA::Disable(FPGA::Periphery::SourceChip);
Communication::Send(packet); Communication::Send(packet);
} }

View File

@ -367,8 +367,8 @@ void VNA::Work() {
HW::Ref::update(); HW::Ref::update();
// Compile info packet // Compile info packet
Protocol::PacketInfo packet; Protocol::PacketInfo packet;
packet.type = Protocol::PacketType::DeviceInfo; packet.type = Protocol::PacketType::DeviceStatusV1;
HW::fillDeviceInfo(&packet.info, true); HW::getDeviceStatus(&packet.statusV1, true);
Communication::Send(packet); Communication::Send(packet);
// do not reset unlevel flag here, as it is calculated only once at the setup of the sweep // do not reset unlevel flag here, as it is calculated only once at the setup of the sweep
// Start next sweep // Start next sweep