LibreVNA/Software/PC_Application/VNA/vna.h

188 lines
5.3 KiB
C
Raw Normal View History

#ifndef VNA_H
#define VNA_H
#include "appwindow.h"
#include "mode.h"
#include "CustomWidgets/tilewidget.h"
#include "Device/device.h"
#include "Deembedding/deembedding.h"
#include "scpi.h"
#include "Traces/tracewidget.h"
2021-10-21 19:00:34 +08:00
#include <QObject>
#include <QWidget>
#include <functional>
2022-04-04 05:34:18 +08:00
class VNA : public Mode
{
Q_OBJECT
2021-07-10 04:26:44 +08:00
public:
2022-04-04 05:34:18 +08:00
VNA(AppWindow *window, QString name = "Vector Network Analyzer");
void deactivate() override;
void initializeDevice() override;
2020-09-14 00:01:32 +08:00
void deviceDisconnected() override;
void shutdown() override;
2020-12-05 06:49:52 +08:00
2022-04-04 05:34:18 +08:00
virtual Type getType() override { return Type::VNA;}
2020-12-05 06:49:52 +08:00
// 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;
void updateGraphColors();
2021-12-02 05:11:50 +08:00
void setAveragingMode(Averaging::Mode mode);
2021-07-10 04:26:44 +08:00
enum class SweepType {
Frequency = 0,
Power = 1,
Last,
2021-07-10 04:26:44 +08:00
};
static QString SweepTypeToString(SweepType sw);
static SweepType SweepTypeFromString(QString s);
2022-03-07 06:01:11 +08:00
class Settings {
public:
2022-03-17 19:53:13 +08:00
Settings()
: sweepType(SweepType::Frequency)
, Freq({.start=1000000, .stop=6000000000, .excitation_power=-10, .logSweep=false})
, Power({.start=-40, .stop=-10, .frequency=1000000000})
, npoints(501), bandwidth(1000), excitingPort1(true), excitingPort2(true)
, segments(1), activeSegment(0){}
2021-07-10 04:26:44 +08:00
SweepType sweepType;
struct {
double start;
double stop;
double excitation_power;
2022-01-05 23:01:51 +08:00
bool logSweep;
2021-07-10 04:26:44 +08:00
} Freq;
struct {
double start;
double stop;
double frequency;
} Power;
int npoints;
double bandwidth;
bool excitingPort1;
bool excitingPort2;
2022-03-07 06:01:11 +08:00
// if the number of points is higher than supported by the hardware, the sweep has to be segmented into multiple parts
int segments;
int activeSegment;
2021-07-10 04:26:44 +08:00
};
public slots:
bool LoadCalibration(QString filename);
private slots:
void NewDatapoint(Protocol::Datapoint d);
void StartImpedanceMatching();
// Sweep control
2021-07-10 04:26:44 +08:00
void SetSweepType(SweepType sw);
void SetStartFreq(double freq);
void SetStopFreq(double freq);
void SetCenterFreq(double freq);
void SetSpan(double span);
void SetFullSpan();
void SpanZoomIn();
void SpanZoomOut();
2022-01-05 23:01:51 +08:00
void SetLogSweep(bool log);
// Acquisition control
void SetSourceLevel(double level);
2021-07-10 04:26:44 +08:00
// Power sweep settings
void SetStartPower(double level);
void SetStopPower(double level);
void SetPowerSweepFrequency(double freq);
void SetPoints(unsigned int points);
void SetIFBandwidth(double bandwidth);
void SetAveraging(unsigned int averages);
void ExcitationRequired(bool port1, bool port2);
// Calibration
void DisableCalibration(bool force = false);
void ApplyCalibration(Calibration::Type type);
void StartCalibrationMeasurements(std::set<Calibration::Measurement> m);
signals:
void CalibrationMeasurementsComplete(std::set<Calibration::Measurement> m);
void graphColorsChanged();
private:
2021-04-16 01:24:11 +08:00
bool CalibrationMeasurementActive() { return calWaitFirst || calMeasuring; }
void SetupSCPI();
2020-10-23 17:39:07 +08:00
void UpdateAverageCount();
2022-03-07 06:01:11 +08:00
void SettingsChanged(bool resetTraces = true, std::function<void (Device::TransmissionResult)> cb = nullptr);
void ConstrainAndUpdateFrequencies();
void LoadSweepSettings();
void StoreSweepSettings();
void StopSweep();
void StartCalibrationDialog(Calibration::Type type = Calibration::Type::None);
void UpdateCalWidget();
private slots:
void EnableDeembedding(bool enable);
void UpdateStatusbar();
2022-05-18 02:07:40 +08:00
void SetSingleSweep(bool single);
private:
2021-07-10 04:26:44 +08:00
Settings settings;
unsigned int averages;
TraceModel traceModel;
TraceWidget *traceWidget;
MarkerModel *markerModel;
Averaging average;
2022-05-18 02:07:40 +08:00
bool singleSweep;
// Calibration
Calibration cal;
bool changingSettings;
bool calValid;
bool calEdited;
std::set<Calibration::Measurement> calMeasurements;
bool calMeasuring;
bool calWaitFirst;
QProgressDialog calDialog;
2021-07-10 04:26:44 +08:00
Calibration::InterpolationType getCalInterpolation();
2020-12-07 23:04:59 +08:00
QString getCalStyle();
QString getCalToolTip();
2020-09-14 00:01:32 +08:00
QMenu *defaultCalMenu;
QAction *assignDefaultCal, *removeDefaultCal;
QAction *saveCal;
2020-09-14 00:01:32 +08:00
Deembedding deembedding;
QAction *enableDeembeddingAction;
bool deembedding_active;
2020-10-31 23:52:59 +08:00
// Status Labels
QLabel *lAverages;
QLabel *calLabel;
TileWidget *central;
signals:
void dataChanged();
2021-07-10 04:26:44 +08:00
void sweepTypeChanged(SweepType sw);
void startFreqChanged(double freq);
void stopFreqChanged(double freq);
void centerFreqChanged(double freq);
void spanChanged(double span);
2022-01-05 23:01:51 +08:00
void logSweepChanged(bool log);
2022-05-18 02:07:40 +08:00
void singleSweepChanged(bool single);
void sourceLevelChanged(double level);
void pointsChanged(unsigned int points);
void IFBandwidthChanged(double bandwidth);
void averagingChanged(unsigned int averages);
2021-07-10 04:26:44 +08:00
void startPowerChanged(double level);
void stopPowerChanged(double level);
void powerSweepFrequencyChanged(double freq);
void CalibrationDisabled();
void CalibrationApplied(Calibration::Type type);
};
#endif // VNA_H