From edec4d9ec506c7816718aa359f770789add0fed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=A4berich?= Date: Wed, 22 Jun 2022 23:50:21 +0200 Subject: [PATCH] handle zero span data throughout the application --- .../PC_Application/CustomWidgets/csvimport.cpp | 1 + .../PC_Application/Traces/Math/expression.cpp | 4 ++++ .../Traces/Math/expressiondialog.ui | 15 +++++++++++++-- .../PC_Application/Traces/Math/tracemath.cpp | 2 ++ Software/PC_Application/Traces/trace.cpp | 2 ++ .../PC_Application/Traces/tracecsvexport.cpp | 3 ++- .../PC_Application/Traces/traceeditdialog.cpp | 3 +++ Software/PC_Application/Traces/traceplot.h | 8 ++++---- .../PC_Application/Traces/tracewaterfall.cpp | 17 +++++++++++++---- Software/PC_Application/Traces/tracewaterfall.h | 6 +++--- Software/PC_Application/Traces/tracexyplot.h | 2 +- .../Application/Communication/Protocol.hpp | 2 +- 12 files changed, 49 insertions(+), 16 deletions(-) diff --git a/Software/PC_Application/CustomWidgets/csvimport.cpp b/Software/PC_Application/CustomWidgets/csvimport.cpp index 6ceab43..3ccc000 100644 --- a/Software/PC_Application/CustomWidgets/csvimport.cpp +++ b/Software/PC_Application/CustomWidgets/csvimport.cpp @@ -96,6 +96,7 @@ void CSVImport::evaluateFile() ui->to->setUnit("Hz"); break; case Trace::DataType::Time: + case Trace::DataType::TimeZeroSpan: ui->from->setUnit("s"); ui->to->setUnit("s"); break; diff --git a/Software/PC_Application/Traces/Math/expression.cpp b/Software/PC_Application/Traces/Math/expression.cpp index 6f8a6c1..b9d7418 100644 --- a/Software/PC_Application/Traces/Math/expression.cpp +++ b/Software/PC_Application/Traces/Math/expression.cpp @@ -50,6 +50,7 @@ void Math::Expression::edit() case DataType::Frequency: ui->stackedWidget->setCurrentIndex(0); break; case DataType::Time: ui->stackedWidget->setCurrentIndex(1); break; case DataType::Power: ui->stackedWidget->setCurrentIndex(2); break; + case DataType::TimeZeroSpan: ui->stackedWidget->setCurrentIndex(3); break; default: break; } @@ -129,6 +130,9 @@ void Math::Expression::expressionChanged() case DataType::Power: parser->DefineVar("P", Variable(&P)); break; + case DataType::TimeZeroSpan: + parser->DefineVar("t", Variable(&t)); + break; default: break; } diff --git a/Software/PC_Application/Traces/Math/expressiondialog.ui b/Software/PC_Application/Traces/Math/expressiondialog.ui index 9210faf..82702b1 100644 --- a/Software/PC_Application/Traces/Math/expressiondialog.ui +++ b/Software/PC_Application/Traces/Math/expressiondialog.ui @@ -44,7 +44,7 @@ - <html><head/><body><p>Available variables:</p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">x: the S parameter as a (complex) voltage vector. </li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">f: measurement frequency in Hz</li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">w: angular measurement frequency (w = 2πf)</li></ul><p>Examples:<br/>Add 10db to the trace (10db = exp10(10/20) = sqrt(10)):</p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">x * sqrt(10)</li></ul><p>Clip trace at 0db (0db = exp10(0/20) = 1) while preserving phase:</p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">abs(x) &lt; 1 ? x : exp(i*arg(x))</li></ul></body></html> + <html><head/><body><p>Available variables:</p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">x: the S parameter as a (complex) voltage ratio vector. </li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">f: measurement frequency in Hz</li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">w: angular measurement frequency (w = 2πf)</li></ul><p>Examples:<br/>Add 10db to the trace (10db = exp10(10/20) = sqrt(10)):</p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">x * sqrt(10)</li></ul><p>Clip trace at 0db (0db = exp10(0/20) = 1) while preserving phase:</p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">abs(x) &lt; 1 ? x : exp(i*arg(x))</li></ul></body></html> @@ -66,7 +66,7 @@ - <html><head/><body><p>Available variables:</p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">x: the S parameter as a (complex) voltage vector. </li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">P: power of the stimulus signal in dBm</li></ul><p>Examples:<br/>Add 10db to the trace (10db = exp10(10/20) = sqrt(10)):</p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">x * sqrt(10)</li></ul><p>Clip trace at 0db (0db = exp10(0/20) = 1) while preserving phase:</p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">abs(x) &lt; 1 ? x : exp(i*arg(x))</li></ul></body></html> + <html><head/><body><p>Available variables:</p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">x: the S parameter as a (complex) voltage ratio vector. </li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">P: power of the stimulus signal in dBm</li></ul><p>Examples:<br/>Add 10db to the trace (10db = exp10(10/20) = sqrt(10)):</p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">x * sqrt(10)</li></ul><p>Clip trace at 0db (0db = exp10(0/20) = 1) while preserving phase:</p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">abs(x) &lt; 1 ? x : exp(i*arg(x))</li></ul></body></html> true @@ -75,6 +75,17 @@ + + + + + + <html><head/><body><p>Available variables:</p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">x: the S parameter as a (complex) voltage ratio vector. </li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">t: time in seconds</li></ul><p><br/></p></body></html> + + + + + diff --git a/Software/PC_Application/Traces/Math/tracemath.cpp b/Software/PC_Application/Traces/Math/tracemath.cpp index b15c8ba..f1f258e 100644 --- a/Software/PC_Application/Traces/Math/tracemath.cpp +++ b/Software/PC_Application/Traces/Math/tracemath.cpp @@ -146,6 +146,8 @@ QString TraceMath::dataTypeToString(TraceMath::DataType type) return "Power"; case DataType::Time: return "Time"; + case DataType::TimeZeroSpan: + return "Time (Zero Span)"; default: return "Invalid"; } diff --git a/Software/PC_Application/Traces/trace.cpp b/Software/PC_Application/Traces/trace.cpp index a038e1d..ba1a4fd 100644 --- a/Software/PC_Application/Traces/trace.cpp +++ b/Software/PC_Application/Traces/trace.cpp @@ -228,6 +228,8 @@ QString Trace::fillFromCSV(CSV &csv, unsigned int parameter) domain = DataType::Time; } else if(csv.getHeader(0).compare("power", Qt::CaseInsensitive) == 0) { domain = DataType::Power; + } else if(csv.getHeader(0).compare("time (zero span)", Qt::CaseInsensitive) == 0) { + domain = DataType::TimeZeroSpan; } else { domain = DataType::Frequency; } diff --git a/Software/PC_Application/Traces/tracecsvexport.cpp b/Software/PC_Application/Traces/tracecsvexport.cpp index a0d9080..d005a59 100644 --- a/Software/PC_Application/Traces/tracecsvexport.cpp +++ b/Software/PC_Application/Traces/tracecsvexport.cpp @@ -26,7 +26,7 @@ TraceCSVExport::TraceCSVExport(TraceModel &traceModel, QWidget *parent) : if(traces.size() == 0) { ui->listColumns->clear(); } else if(ui->listColumns->count() == 0) { - // first trace has bee selected, fill column selection + // first trace has been selected, fill column selection auto t = traces.front(); auto domain = t->outputType(); auto Xaxis = XAxis::Type::Last; @@ -34,6 +34,7 @@ TraceCSVExport::TraceCSVExport(TraceModel &traceModel, QWidget *parent) : case Trace::DataType::Frequency: Xaxis = XAxis::Type::Frequency; break; case Trace::DataType::Power: Xaxis = XAxis::Type::Power; break; case Trace::DataType::Time: Xaxis = XAxis::Type::Time; break; + case Trace::DataType::TimeZeroSpan: Xaxis = XAxis::Type::TimeZeroSpan; break; } if(Xaxis == XAxis::Type::Last) { // invalid axis selection diff --git a/Software/PC_Application/Traces/traceeditdialog.cpp b/Software/PC_Application/Traces/traceeditdialog.cpp index d49c625..c0e209f 100644 --- a/Software/PC_Application/Traces/traceeditdialog.cpp +++ b/Software/PC_Application/Traces/traceeditdialog.cpp @@ -351,7 +351,10 @@ QVariant MathModel::data(const QModelIndex &index, int role) const return "Frequency"; case TraceMath::DataType::Power: return "Power"; + case TraceMath::DataType::TimeZeroSpan: + return "Time (Zero Span)"; case TraceMath::DataType::Invalid: + default: return "Invalid"; } } diff --git a/Software/PC_Application/Traces/traceplot.h b/Software/PC_Application/Traces/traceplot.h index 0ce662f..32178e1 100644 --- a/Software/PC_Application/Traces/traceplot.h +++ b/Software/PC_Application/Traces/traceplot.h @@ -47,11 +47,11 @@ protected: void initializeTraceInfo(); std::vector activeTraces(); // changes the graph settings to make it possible to display a specific trace. The trace is not aded yet - virtual bool configureForTrace(Trace *t) { Q_UNUSED(t) return false; }; // default implementation fails for all traces + virtual bool configureForTrace(Trace *t) { Q_UNUSED(t) return false; } // default implementation fails for all traces void contextMenuEvent(QContextMenuEvent *event) override; void paintEvent(QPaintEvent *event) override; - virtual void updateContextMenu(){}; - virtual void replot(){update();}; + virtual void updateContextMenu(){} + virtual void replot(){update();} virtual void draw(QPainter& p) = 0; virtual bool supported(Trace *t) = 0; std::map traces; @@ -79,7 +79,7 @@ protected: void dropEvent(QDropEvent *event) override; void dragLeaveEvent(QDragLeaveEvent *event) override; virtual void traceDropped(Trace *t, QPoint position); - virtual QString mouseText(QPoint pos) {Q_UNUSED(pos) return QString();}; + virtual QString mouseText(QPoint pos) {Q_UNUSED(pos) return QString();} protected slots: void newTraceAvailable(Trace *t); diff --git a/Software/PC_Application/Traces/tracewaterfall.cpp b/Software/PC_Application/Traces/tracewaterfall.cpp index 3ef3df4..0dfca68 100644 --- a/Software/PC_Application/Traces/tracewaterfall.cpp +++ b/Software/PC_Application/Traces/tracewaterfall.cpp @@ -49,6 +49,9 @@ void TraceWaterfall::enableTrace(Trace *t, bool enabled) trace = t; connect(t, &Trace::dataChanged, this, &TraceWaterfall::traceDataChanged); } else { + if(trace) { + disconnect(trace, &Trace::dataChanged, this, &TraceWaterfall::traceDataChanged); + } trace = nullptr; } @@ -130,14 +133,18 @@ bool TraceWaterfall::configureForTrace(Trace *t) xAxis.set(XAxis::Type::Frequency, false, true, 0, 1, 0.1); yAxis.set(YAxis::Type::Magnitude, false, true, 0, 1, 1.0); break; - case Trace::DataType::Time: - xAxis.set(XAxis::Type::Time, false, true, 0, 1, 0.1); - yAxis.set(YAxis::Type::ImpulseMag, false, true, 0, 1, 1.0); - break; +// case Trace::DataType::Time: +// xAxis.set(XAxis::Type::Time, false, true, 0, 1, 0.1); +// yAxis.set(YAxis::Type::ImpulseMag, false, true, 0, 1, 1.0); +// break; case Trace::DataType::Power: xAxis.set(XAxis::Type::Power, false, true, 0, 1, 0.1); yAxis.set(YAxis::Type::Magnitude, false, true, 0, 1, 1.0); break; +// case Trace::DataType::TimeZeroSpan: +// xAxis.set(XAxis::Type::Power, false, true, 0, 1, 0.1); +// yAxis.set(YAxis::Type::Magnitude, false, true, 0, 1, 1.0); +// break; case Trace::DataType::Invalid: // unable to add return false; @@ -156,6 +163,8 @@ bool TraceWaterfall::domainMatch(Trace *t) return t->outputType() == Trace::DataType::Time; case XAxis::Type::Power: return t->outputType() == Trace::DataType::Power; + case XAxis::Type::TimeZeroSpan: + return t->outputType() == Trace::DataType::TimeZeroSpan; case XAxis::Type::Last: return false; } diff --git a/Software/PC_Application/Traces/tracewaterfall.h b/Software/PC_Application/Traces/tracewaterfall.h index 50174af..b8ce15f 100644 --- a/Software/PC_Application/Traces/tracewaterfall.h +++ b/Software/PC_Application/Traces/tracewaterfall.h @@ -12,12 +12,12 @@ class TraceWaterfall : public TracePlot friend class WaterfallAxisDialog; Q_OBJECT public: - TraceWaterfall(TraceModel &model, QWidget *parent = 0);; + TraceWaterfall(TraceModel &model, QWidget *parent = 0); virtual void enableTrace(Trace *t, bool enabled) override; void replot() override; - virtual Type getType() override { return Type::Waterfall;}; + virtual Type getType() override { return Type::Waterfall;} void fromJSON(nlohmann::json j) override; nlohmann::json toJSON() override; @@ -33,7 +33,7 @@ protected: bool domainMatch(Trace *t); virtual bool supported(Trace *t) override; - virtual QPoint markerToPixel(Marker *m) override { Q_UNUSED(m) return QPoint(0,0);}; + virtual QPoint markerToPixel(Marker *m) override { Q_UNUSED(m) return QPoint(0,0);} virtual double nearestTracePoint(Trace *t, QPoint pixel, double *distance = nullptr) override; virtual QString mouseText(QPoint pos) override; diff --git a/Software/PC_Application/Traces/tracexyplot.h b/Software/PC_Application/Traces/tracexyplot.h index 422f968..daca0d7 100644 --- a/Software/PC_Application/Traces/tracexyplot.h +++ b/Software/PC_Application/Traces/tracexyplot.h @@ -74,7 +74,7 @@ public: void updateSpan(double min, double max) override; void replot() override; - virtual Type getType() override { return Type::XYPlot;}; + virtual Type getType() override { return Type::XYPlot;} virtual nlohmann::json toJSON() override; virtual void fromJSON(nlohmann::json j) override; diff --git a/Software/VNA_embedded/Application/Communication/Protocol.hpp b/Software/VNA_embedded/Application/Communication/Protocol.hpp index 4aa34ba..8e31400 100644 --- a/Software/VNA_embedded/Application/Communication/Protocol.hpp +++ b/Software/VNA_embedded/Application/Communication/Protocol.hpp @@ -4,7 +4,7 @@ namespace Protocol { -static constexpr uint16_t Version = 10; +static constexpr uint16_t Version = 11; #pragma pack(push, 1)