Added single sweep functionality

This commit is contained in:
Jan Käberich 2022-05-17 20:07:40 +02:00
parent 53dcff8745
commit d84d3e80aa
8 changed files with 124 additions and 11 deletions

View file

@ -50,6 +50,7 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window, QString name)
central(new TileWidget(traceModel, window))
{
averages = 1;
singleSweep = false;
settings = {};
normalize.active = false;
normalize.measuring = false;
@ -83,6 +84,14 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window, QString name)
// Create menu entries and connections
// Sweep toolbar
auto tb_sweep = new QToolBar("Sweep");
auto bSingle = new QPushButton("Single");
bSingle->setToolTip("Single sweep");
bSingle->setCheckable(true);
connect(bSingle, &QPushButton::toggled, this, &SpectrumAnalyzer::SetSingleSweep);
connect(this, &SpectrumAnalyzer::singleSweepChanged, bSingle, &QPushButton::setChecked);
tb_sweep->addWidget(bSingle);
auto eStart = new SIUnitEdit("Hz", " kMG", 6);
// calculate width required with expected string length
auto width = QFontMetrics(eStart->font()).width("3.00000GHz") + 15;
@ -313,6 +322,7 @@ nlohmann::json SpectrumAnalyzer::toJSON()
freq["start"] = settings.f_start;
freq["stop"] = settings.f_stop;
sweep["frequency"] = freq;
sweep["single"] = singleSweep;
nlohmann::json acq;
acq["RBW"] = settings.RBW;
acq["window"] = WindowToString((Window) settings.WindowType).toStdString();
@ -414,6 +424,7 @@ void SpectrumAnalyzer::fromJSON(nlohmann::json j)
EnableNormalization(false);
}
}
SetSingleSweep(sweep.value("single", singleSweep));
}
}
@ -425,6 +436,19 @@ void SpectrumAnalyzer::NewDatapoint(Protocol::SpectrumAnalyzerResult d)
return;
}
if(changingSettings) {
// already setting new sweep settings, ignore incoming points from old settings
return;
}
if(singleSweep && average.getLevel() == averages) {
changingSettings = true;
// single sweep finished
window->getDevice()->SetIdle([=](Device::TransmissionResult){
changingSettings = false;
});
}
if(d.pointNum >= settings.pointNum) {
qWarning() << "Ignoring point with too large point number (" << d.pointNum << ")";
return;
@ -477,6 +501,7 @@ void SpectrumAnalyzer::NewDatapoint(Protocol::SpectrumAnalyzerResult d)
void SpectrumAnalyzer::SettingsChanged()
{
changingSettings = true;
if(settings.f_stop - settings.f_start >= 1000) {
settings.pointNum = 1001;
} else {
@ -529,7 +554,10 @@ void SpectrumAnalyzer::SettingsChanged()
}
if(window->getDevice() && Mode::getActiveMode() == this) {
window->getDevice()->Configure(settings);
window->getDevice()->Configure(settings, [=](Device::TransmissionResult res){
// device received command
changingSettings = false;
});
}
average.reset(settings.pointNum);
UpdateAverageCount();
@ -620,6 +648,15 @@ void SpectrumAnalyzer::SpanZoomOut()
ConstrainAndUpdateFrequencies();
}
void SpectrumAnalyzer::SetSingleSweep(bool single)
{
if(singleSweep != single) {
singleSweep = single;
emit singleSweepChanged(single);
}
SettingsChanged();
}
void SpectrumAnalyzer::SetRBW(double bandwidth)
{
if(bandwidth > Device::Info(window->getDevice()).limits_maxRBW) {
@ -923,6 +960,17 @@ void SpectrumAnalyzer::SetupSCPI()
}, [=](QStringList) -> QString {
return settings.SignalID ? "TRUE" : "FALSE";
}));
scpi_acq->add(new SCPICommand("SINGLE", [=](QStringList params) -> QString {
bool single;
if(!SCPI::paramToBool(params, 0, single)) {
return "ERROR";
} else {
SetSingleSweep(single);
return "";
}
}, [=](QStringList) -> QString {
return singleSweep ? "TRUE" : "FALSE";
}));
auto scpi_tg = new SCPINode("TRACKing");
SCPINode::add(scpi_tg);
scpi_tg->add(new SCPICommand("ENable", [=](QStringList params) -> QString {

View file

@ -63,6 +63,7 @@ private slots:
void SetFullSpan();
void SpanZoomIn();
void SpanZoomOut();
void SetSingleSweep(bool single);
// Acquisition control
void SetRBW(double bandwidth);
void SetWindow(Window w);
@ -88,7 +89,9 @@ private:
void StoreSweepSettings();
Protocol::SpectrumAnalyzerSettings settings;
bool changingSettings;
unsigned int averages;
bool singleSweep;
TraceModel traceModel;
TraceWidget *traceWidget;
MarkerModel *markerModel;
@ -122,6 +125,7 @@ signals:
void stopFreqChanged(double freq);
void centerFreqChanged(double freq);
void spanChanged(double span);
void singleSweepChanged(bool single);
void RBWChanged(double RBW);
void TGStateChanged(bool enabled);
void TGPortChanged(int port);