decouple RST settings from startup settings

This commit is contained in:
Jan Käberich 2024-05-01 13:33:18 +02:00
parent 77efc4d924
commit 5692356e90
9 changed files with 60 additions and 9 deletions

View file

@ -46,6 +46,13 @@ void Generator::initializeDevice()
updateDevice();
}
void Generator::resetSettings()
{
central->setFrequency(1000000000);
central->setLevel(0);
central->setPort(0);
}
nlohmann::json Generator::toJSON()
{
return central->toJSON();

View file

@ -15,6 +15,8 @@ public:
virtual Type getType() override { return Type::SG;}
virtual void resetSettings() override;
// Nothing to do for now
virtual nlohmann::json toJSON() override;
virtual void fromJSON(nlohmann::json j) override;

View file

@ -366,6 +366,18 @@ void SpectrumAnalyzer::deviceDisconnected()
emit sweepStopped();
}
void SpectrumAnalyzer::resetSettings()
{
settings.freqStart = DeviceDriver::getInfo(window->getDevice()).Limits.SA.minFreq;
settings.freqStop = DeviceDriver::getInfo(window->getDevice()).Limits.SA.maxFreq;
ConstrainAndUpdateFrequencies();
SetRBW(1000000);
SetAveraging(1);
SetWindow(DeviceDriver::SASettings::Window::FlatTop);
SetDetector(DeviceDriver::SASettings::Detector::PPeak);
Stop();
}
nlohmann::json SpectrumAnalyzer::toJSON()
{
nlohmann::json j;

View file

@ -25,6 +25,8 @@ public:
virtual Type getType() override { return Type::SA;}
virtual void resetSettings() override;
// Only save/load user changeable stuff, no need to save the widgets/mode name etc.
virtual nlohmann::json toJSON() override;
virtual void fromJSON(nlohmann::json j) override;

View file

@ -772,6 +772,23 @@ void VNA::shutdown()
}
}
void VNA::resetSettings()
{
settings.Freq.start = DeviceDriver::getInfo(window->getDevice()).Limits.VNA.minFreq;
settings.Freq.stop = DeviceDriver::getInfo(window->getDevice()).Limits.VNA.maxFreq;
SetLogSweep(false);
SetSourceLevel(DeviceDriver::getInfo(window->getDevice()).Limits.VNA.maxdBm);
ConstrainAndUpdateFrequencies();
SetStartPower(DeviceDriver::getInfo(window->getDevice()).Limits.VNA.mindBm);
SetStopPower(DeviceDriver::getInfo(window->getDevice()).Limits.VNA.maxdBm);
SetPowerSweepFrequency(DeviceDriver::getInfo(window->getDevice()).Limits.VNA.maxFreq);
SetIFBandwidth(1000);
SetAveraging(1);
SetPoints(501);
SetSweepType(SweepType::Frequency);
Stop();
}
nlohmann::json VNA::toJSON()
{
nlohmann::json j;

View file

@ -27,6 +27,8 @@ public:
virtual Type getType() override { return Type::VNA;}
virtual void resetSettings() override;
// Only save/load user changeable stuff, no need to save the widgets/mode name etc.
virtual nlohmann::json toJSON() override;
virtual void fromJSON(nlohmann::json j) override;

View file

@ -324,6 +324,20 @@ void AppWindow::SetInitialState()
}
}
void AppWindow::SetResetState()
{
modeHandler->closeModes();
auto vnaIndex = modeHandler->createMode("Vector Network Analyzer", Mode::Type::VNA);
modeHandler->createMode("Signal Generator", Mode::Type::SG);
modeHandler->createMode("Spectrum Analyzer", Mode::Type::SA);
for(auto m : modeHandler->getModes()) {
m->resetSettings();
}
modeHandler->setCurrentIndex(vnaIndex);
}
bool AppWindow::ConnectToDevice(QString serial, DeviceDriver *driver)
{
if(serial.isEmpty()) {
@ -487,15 +501,7 @@ void AppWindow::SetupSCPI()
return "LibreVNA,LibreVNA-GUI,dummy_serial,"+appVersion;
}));
scpi.add(new SCPICommand("*RST", [=](QStringList){
SetInitialState();
auto vna = dynamic_cast<VNA*>(modeHandler->getActiveMode());
if(vna) {
vna->Stop();
}
auto sa = dynamic_cast<SpectrumAnalyzer*>(modeHandler->getActiveMode());
if(sa) {
sa->Stop();
}
SetResetState();
ResetReference();
return SCPI::getResultName(SCPI::Result::Empty);
}, nullptr));

View file

@ -59,6 +59,7 @@ protected:
void closeEvent(QCloseEvent *event) override;
private slots:
void SetInitialState();
void SetResetState();
bool ConnectToDevice(QString serial = QString(), DeviceDriver *driver = nullptr);
void DisconnectDevice();
int UpdateDeviceList();

View file

@ -36,6 +36,8 @@ public:
static Type TypeFromName(QString s);
virtual Type getType() = 0;
virtual void resetSettings(){}
virtual void initializeDevice() = 0;
virtual void deviceDisconnected(){}