From 9fa737ec6723055318ffb10f5f41101ef22886cc Mon Sep 17 00:00:00 2001 From: f4exb Date: Mon, 13 Jul 2015 10:46:51 +0200 Subject: [PATCH] Prepare scope trigger #1 --- include-gpl/dsp/scopevis.h | 35 ++++++- include-gpl/gui/glscopegui.h | 3 + sdrbase/dsp/nullsink.cpp | 18 ---- sdrbase/dsp/scopevis.cpp | 57 +++++++---- sdrbase/gui/glscopegui.cpp | 5 +- sdrbase/gui/glscopegui.ui | 178 ++++++++++++++++++++++++++++++++++- 6 files changed, 250 insertions(+), 46 deletions(-) diff --git a/include-gpl/dsp/scopevis.h b/include-gpl/dsp/scopevis.h index 2e45915fa..7f4605fcc 100644 --- a/include-gpl/dsp/scopevis.h +++ b/include-gpl/dsp/scopevis.h @@ -3,6 +3,7 @@ #include "dsp/samplesink.h" #include "util/export.h" +#include "util/message.h" class GLScope; class MessageQueue; @@ -12,12 +13,15 @@ public: enum TriggerChannel { TriggerFreeRun, TriggerChannelI, - TriggerChannelQ + TriggerChannelQ, + TriggerMagLin, + TriggerMagDb, + TriggerPhase }; ScopeVis(GLScope* glScope = NULL); - void configure(MessageQueue* msgQueue, TriggerChannel triggerChannel, Real triggerLevelHigh, Real triggerLevelLow); + void configure(MessageQueue* msgQueue, TriggerChannel triggerChannel, Real triggerLevel, bool triggerPositiveEdge); void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); void start(); @@ -29,6 +33,32 @@ public: int getSampleRate() const { return m_sampleRate; } private: + class MsgConfigureScopeVis : public Message { + MESSAGE_CLASS_DECLARATION + + public: + int getTriggerChannel() const { return m_triggerChannel; } + Real getTriggerLevel() const { return m_triggerLevel; } + Real getTriggerPositiveEdge() const { return m_triggerPositiveEdge; } + + static MsgConfigureScopeVis* create(int triggerChannel, Real triggerLevel, bool triggerPositiveEdge) + { + return new MsgConfigureScopeVis(triggerChannel, triggerLevel, triggerPositiveEdge); + } + + private: + int m_triggerChannel; + Real m_triggerLevel; + bool m_triggerPositiveEdge; + + MsgConfigureScopeVis(int triggerChannel, Real triggerLevel, bool triggerPositiveEdge) : + Message(), + m_triggerChannel(triggerChannel), + m_triggerLevel(triggerLevel), + m_triggerPositiveEdge(triggerPositiveEdge) + { } + }; + enum TriggerState { Untriggered, Triggered, @@ -42,6 +72,7 @@ private: TriggerChannel m_triggerChannel; FixReal m_triggerLevelHigh; FixReal m_triggerLevelLow; + bool m_triggerPositiveEdge; int m_sampleRate; }; diff --git a/include-gpl/gui/glscopegui.h b/include-gpl/gui/glscopegui.h index 1cd62b9df..7f7ad2da6 100644 --- a/include-gpl/gui/glscopegui.h +++ b/include-gpl/gui/glscopegui.h @@ -47,6 +47,9 @@ private: qint32 m_amplification; qint32 m_ampOffset; int m_displayGridIntensity; + qint32 m_triggerChannel; + Real m_triggerLevel; + bool m_triggerPositiveEdge; static const qreal amps[11]; diff --git a/sdrbase/dsp/nullsink.cpp b/sdrbase/dsp/nullsink.cpp index d5c142742..fbc695de2 100644 --- a/sdrbase/dsp/nullsink.cpp +++ b/sdrbase/dsp/nullsink.cpp @@ -22,22 +22,4 @@ bool NullSink::handleMessage(Message* message) { message->completed(); return true; - /* - if(DSPSignalNotification::match(message)) { - DSPSignalNotification* signal = (DSPSignalNotification*)message; - m_sampleRate = signal->getSampleRate(); - message->completed(); - return true; - } else if(DSPConfigureScopeVis::match(message)) { - DSPConfigureScopeVis* conf = (DSPConfigureScopeVis*)message; - m_triggerState = Untriggered; - m_triggerChannel = (TriggerChannel)conf->getTriggerChannel(); - m_triggerLevelHigh = conf->getTriggerLevelHigh() * 32767; - m_triggerLevelLow = conf->getTriggerLevelLow() * 32767; - message->completed(); - return true; - } else { - return false; - } - */ } diff --git a/sdrbase/dsp/scopevis.cpp b/sdrbase/dsp/scopevis.cpp index 429e70fc0..4603062d8 100644 --- a/sdrbase/dsp/scopevis.cpp +++ b/sdrbase/dsp/scopevis.cpp @@ -5,6 +5,8 @@ #include +MESSAGE_CLASS_DEFINITION(ScopeVis::MsgConfigureScopeVis, Message) + ScopeVis::ScopeVis(GLScope* glScope) : m_glScope(glScope), m_trace(96000), @@ -13,20 +15,39 @@ ScopeVis::ScopeVis(GLScope* glScope) : m_triggerChannel(TriggerFreeRun), m_triggerLevelHigh(0.01 * 32768), m_triggerLevelLow(0.01 * 32768 - 1024), + m_triggerPositiveEdge(true), m_sampleRate(0) { } -void ScopeVis::configure(MessageQueue* msgQueue, TriggerChannel triggerChannel, Real triggerLevelHigh, Real triggerLevelLow) +void ScopeVis::configure(MessageQueue* msgQueue, TriggerChannel triggerChannel, Real triggerLevel, bool triggerPositiveEdge) { - Message* cmd = DSPConfigureScopeVis::create(triggerChannel, triggerLevelHigh, triggerLevelLow); + Message* cmd = MsgConfigureScopeVis::create(triggerChannel, triggerLevel, triggerPositiveEdge); cmd->submit(msgQueue, this); } void ScopeVis::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) { - while(begin < end) { - if(m_triggerChannel == TriggerChannelI) { + while(begin < end) + { + if (m_triggerChannel == TriggerFreeRun) + { + int count = end - begin; + if(count > (int)(m_trace.size() - m_fill)) + count = m_trace.size() - m_fill; + std::vector::iterator it = m_trace.begin() + m_fill; + for(int i = 0; i < count; ++i) { + *it++ = Complex(begin->real() / 32768.0, begin->imag() / 32768.0); + ++begin; + } + m_fill += count; + if(m_fill >= m_trace.size()) { + m_glScope->newTrace(m_trace, m_sampleRate); + m_fill = 0; + } + } + else if (m_triggerChannel == TriggerChannelI) + { if(m_triggerState == Untriggered) { while(begin < end) { if(begin->real() >= m_triggerLevelHigh) { @@ -61,7 +82,9 @@ void ScopeVis::feed(SampleVector::const_iterator begin, SampleVector::const_iter ++begin; } } - } else if(m_triggerChannel == TriggerChannelQ) { + } + else if (m_triggerChannel == TriggerChannelQ) + { if(m_triggerState == Untriggered) { while(begin < end) { if(begin->imag() >= m_triggerLevelHigh) { @@ -96,20 +119,6 @@ void ScopeVis::feed(SampleVector::const_iterator begin, SampleVector::const_iter ++begin; } } - } else { - int count = end - begin; - if(count > (int)(m_trace.size() - m_fill)) - count = m_trace.size() - m_fill; - std::vector::iterator it = m_trace.begin() + m_fill; - for(int i = 0; i < count; ++i) { - *it++ = Complex(begin->real() / 32768.0, begin->imag() / 32768.0); - ++begin; - } - m_fill += count; - if(m_fill >= m_trace.size()) { - m_glScope->newTrace(m_trace, m_sampleRate); - m_fill = 0; - } } } } @@ -129,13 +138,21 @@ bool ScopeVis::handleMessageKeep(Message* message) //fprintf(stderr, "ScopeVis::handleMessage @%x : %d samples/sec, %lld Hz offset\n", this, signal->getSampleRate(), signal->getFrequencyOffset()); m_sampleRate = signal->getSampleRate(); return true; + } else if(MsgConfigureScopeVis::match(message)) { + MsgConfigureScopeVis* conf = (MsgConfigureScopeVis*)message; + m_triggerState = Untriggered; + m_triggerChannel = (TriggerChannel) conf->getTriggerChannel(); + m_triggerLevelHigh = conf->getTriggerLevel() * 32767; + m_triggerPositiveEdge = conf->getTriggerPositiveEdge(); + return true; + /* } else if(DSPConfigureScopeVis::match(message)) { DSPConfigureScopeVis* conf = (DSPConfigureScopeVis*)message; m_triggerState = Untriggered; m_triggerChannel = (TriggerChannel)conf->getTriggerChannel(); m_triggerLevelHigh = conf->getTriggerLevelHigh() * 32767; m_triggerLevelLow = conf->getTriggerLevelLow() * 32767; - return true; + return true;*/ } else { return false; } diff --git a/sdrbase/gui/glscopegui.cpp b/sdrbase/gui/glscopegui.cpp index d322e196a..acd091672 100644 --- a/sdrbase/gui/glscopegui.cpp +++ b/sdrbase/gui/glscopegui.cpp @@ -24,7 +24,10 @@ GLScopeGUI::GLScopeGUI(QWidget* parent) : m_timeOffset(0), m_amplification(0), m_ampOffset(0), - m_displayGridIntensity(1) + m_displayGridIntensity(1), + m_triggerChannel(ScopeVis::TriggerFreeRun), + m_triggerLevel(0.0), + m_triggerPositiveEdge(true) { ui->setupUi(this); } diff --git a/sdrbase/gui/glscopegui.ui b/sdrbase/gui/glscopegui.ui index ad094d93a..5c1f4b13e 100644 --- a/sdrbase/gui/glscopegui.ui +++ b/sdrbase/gui/glscopegui.ui @@ -7,7 +7,7 @@ 0 0 807 - 34 + 50 @@ -30,7 +30,7 @@ 0 - + 3 @@ -72,7 +72,7 @@ - Grid intensity + Displayed data QComboBox::AdjustToContentsOnFirstShow @@ -253,7 +253,7 @@ Qt::Horizontal - QSlider::TicksBelow + QSlider::NoTicks 5 @@ -368,7 +368,7 @@ Qt::Horizontal - QSlider::TicksBelow + QSlider::NoTicks 1 @@ -459,6 +459,174 @@ + + + + Qt::Horizontal + + + + + + + 3 + + + 2 + + + 2 + + + 2 + + + 2 + + + + + + 8 + + + + Trig. + + + + + + + + 8 + + + + Trigger source + + + + Freerun + + + + + I (lin) + + + + + Q (lin) + + + + + Mag (lin) + + + + + Mag (dB) + + + + + Phi + + + + + + + + + + + 8 + + + + Trigger slope positive + + + + + + + + 16 + 16 + + + + true + + + true + + + + + + + + 8 + + + + Trigger slope negative + + + - + + + + 16 + 16 + + + + true + + + + + + + + + + 8 + + + + Trigger level + + + 100 + + + 1 + + + Qt::Horizontal + + + + + + + + 8 + + + + 0 + + + + +