From 199e915c622bd2caf063c76648968ac5f9100ad4 Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 7 Feb 2017 18:50:08 +0100 Subject: [PATCH] New scope: fix trigger (2) --- sdrbase/dsp/scopevisng.cpp | 16 ++++++++++++---- sdrbase/dsp/scopevisng.h | 26 +++++++++++++++++++++++--- sdrbase/gui/glscopeng.cpp | 5 +++-- sdrbase/gui/glscopeng.h | 4 ++-- sdrbase/gui/glscopenggui.cpp | 31 +++++++++++++++++++++++++------ 5 files changed, 65 insertions(+), 17 deletions(-) diff --git a/sdrbase/dsp/scopevisng.cpp b/sdrbase/dsp/scopevisng.cpp index f8cc2d1b8..96f56fded 100644 --- a/sdrbase/dsp/scopevisng.cpp +++ b/sdrbase/dsp/scopevisng.cpp @@ -67,9 +67,9 @@ void ScopeVisNG::setSampleRate(int sampleRate) } } -void ScopeVisNG::configure(uint32_t traceSize, uint32_t timeOfsProMill, bool freeRun) +void ScopeVisNG::configure(uint32_t traceSize, uint32_t timeOfsProMill, uint32_t triggerPre, bool freeRun) { - Message* cmd = MsgConfigureScopeVisNG::create(traceSize, timeOfsProMill, freeRun); + Message* cmd = MsgConfigureScopeVisNG::create(traceSize, timeOfsProMill, triggerPre, freeRun); getInputMessageQueue()->push(cmd); } @@ -176,7 +176,7 @@ void ScopeVisNG::feed(const SampleVector::const_iterator& cbegin, const SampleVe } else // look for trigger { - bool condition = triggerCondition.m_projector->run(*begin) > triggerCondition.m_triggerData.m_triggerLevel; + bool condition = compareTrigger(*begin, triggerCondition); // triggerCondition.m_projector->run(*begin) > triggerCondition.m_triggerData.m_triggerLevel; bool trigger; if (triggerCondition.m_triggerData.m_triggerBothEdges) { @@ -314,7 +314,7 @@ int ScopeVisNG::processTraces(int beginPointDelta, int endPointDelta, TraceBackB if (projectionType == ProjectionMagLin) { v = itCtl->m_projector->run(*begin)*itData->m_amp - itData->m_ofs - 1.0/itData->m_amp; - } else if (projectionType == ProjectionMagDB) { + } else if (projectionType == ProjectionMagDB) { // TODO: optimize computation using a specialized projector (2 projectors: value and trace) v = 1.0f + 2.0f*(((itCtl->m_projector->run(*begin))/100.0f) - itData->m_ofs) + 1.0f - 1.0f/itData->m_amp; //v = itCtl->m_projector->run(*begin) * itData->m_amp - itData->m_ofs; } else { @@ -388,6 +388,7 @@ bool ScopeVisNG::handleMessage(const Message& message) uint32_t traceSize = conf.getTraceSize(); uint32_t timeOfsProMill = conf.getTimeOfsProMill(); + uint32_t triggerPre = conf.getTriggerPre(); bool freeRun = conf.getFreeRun(); if (m_traceSize != traceSize) @@ -411,6 +412,12 @@ bool ScopeVisNG::handleMessage(const Message& message) } } + if (m_preTriggerDelay != triggerPre) + { + m_preTriggerDelay = triggerPre; + m_glScope->setTriggerPre(m_preTriggerDelay); + } + if (freeRun != m_freeRun) { m_freeRun = freeRun; @@ -419,6 +426,7 @@ bool ScopeVisNG::handleMessage(const Message& message) qDebug() << "ScopeVisNG::handleMessage: MsgConfigureScopeVisNG:" << " m_traceSize: " << m_traceSize << " m_timeOfsProMill: " << m_timeOfsProMill + << " m_preTriggerDelay: " << m_preTriggerDelay << " m_freeRun: " << m_freeRun; return true; diff --git a/sdrbase/dsp/scopevisng.h b/sdrbase/dsp/scopevisng.h index 466f9d9df..896bafb81 100644 --- a/sdrbase/dsp/scopevisng.h +++ b/sdrbase/dsp/scopevisng.h @@ -87,7 +87,7 @@ public: virtual ~ScopeVisNG(); void setSampleRate(int sampleRate); - void configure(uint32_t traceSize, uint32_t timeOfsProMill, bool freeRun); + void configure(uint32_t traceSize, uint32_t timeOfsProMill, uint32_t triggerPre, bool freeRun); void addTrace(const TraceData& traceData); void changeTrace(const TraceData& traceData, uint32_t traceIndex); void removeTrace(uint32_t traceIndex); @@ -111,25 +111,30 @@ private: static MsgConfigureScopeVisNG* create( uint32_t traceSize, uint32_t timeOfsProMill, + uint32_t triggerPre, bool freeRun) { - return new MsgConfigureScopeVisNG(traceSize, timeOfsProMill, freeRun); + return new MsgConfigureScopeVisNG(traceSize, timeOfsProMill, triggerPre, freeRun); } uint32_t getTraceSize() const { return m_traceSize; } uint32_t getTimeOfsProMill() const { return m_timeOfsProMill; } + uint32_t getTriggerPre() const { return m_triggerPre; } bool getFreeRun() const { return m_freeRun; } private: uint32_t m_traceSize; uint32_t m_timeOfsProMill; + uint32_t m_triggerPre; bool m_freeRun; MsgConfigureScopeVisNG(uint32_t traceSize, uint32_t timeOfsProMill, + uint32_t triggerPre, bool freeRun) : m_traceSize(traceSize), m_timeOfsProMill(timeOfsProMill), + m_triggerPre(triggerPre), m_freeRun(freeRun) {} }; @@ -664,7 +669,7 @@ private: }; GLScopeNG* m_glScope; - int m_preTriggerDelay; //!< Pre-trigger delay in number of samples + uint32_t m_preTriggerDelay; //!< Pre-trigger delay in number of samples std::vector m_triggerConditions; //!< Chain of triggers int m_currentTriggerIndex; //!< Index of current index in the chain TriggerState m_triggerState; //!< Current trigger state @@ -682,6 +687,21 @@ private: bool m_freeRun; //!< True if free running (trigger globally disabled) int m_maxTraceDelay; //!< Maximum trace delay + /** + * Test sample against trigger level. Returns true if sample is above level. + * TODO: optimize power level computation by storing value when it changes + */ + bool compareTrigger(const Sample& s, TriggerCondition& triggerCondition) + { + if (triggerCondition.m_projector->getProjectionType() == ProjectionMagDB) { + return triggerCondition.m_projector->run(s) > (100.0f * (triggerCondition.m_triggerData.m_triggerLevel - 1.0f)); + } else if (triggerCondition.m_projector->getProjectionType() == ProjectionMagLin) { + return triggerCondition.m_projector->run(s) > triggerCondition.m_triggerData.m_triggerLevel + 1.0f; + } else { + return triggerCondition.m_projector->run(s) > triggerCondition.m_triggerData.m_triggerLevel; + } + } + /** * Moves on to the next trigger if any or increments trigger count if in repeat mode * - If not final it returns true diff --git a/sdrbase/gui/glscopeng.cpp b/sdrbase/gui/glscopeng.cpp index eb2e4dd10..a44708bf7 100644 --- a/sdrbase/gui/glscopeng.cpp +++ b/sdrbase/gui/glscopeng.cpp @@ -335,7 +335,7 @@ void GLScopeNG::setTimeBase(int timeBase) update(); } -void GLScopeNG::setTriggerPre(Real triggerPre) +void GLScopeNG::setTriggerPre(uint32_t triggerPre) { m_triggerPre = triggerPre; m_configChanged = true; @@ -382,7 +382,8 @@ void GLScopeNG::applyConfig() QFontMetrics fm(font()); int M = fm.width("-"); - float t_start = ((m_timeOfsProMill / 1000.0) - m_triggerPre) * ((float) m_traceSize / m_sampleRate); + //float t_start = ((m_timeOfsProMill / 1000.0) * ((float) m_traceSize / m_sampleRate)) - ((float) m_triggerPre / m_sampleRate); + float t_start = (((m_timeOfsProMill / 1000.0f) * (float) m_traceSize) / m_sampleRate) - ((float) m_triggerPre / m_sampleRate); float t_len = ((float) m_traceSize / m_sampleRate) / (float) m_timeBase; m_x1Scale.setRange(Unit::Time, t_start, t_start + t_len); // time scale diff --git a/sdrbase/gui/glscopeng.h b/sdrbase/gui/glscopeng.h index 07cbff8be..edba9460b 100644 --- a/sdrbase/gui/glscopeng.h +++ b/sdrbase/gui/glscopeng.h @@ -57,7 +57,7 @@ public: int getSampleRate() const { return m_sampleRate; } int getTraceSize() const { return m_traceSize; } - void setTriggerPre(Real triggerPre); + void setTriggerPre(uint32_t triggerPre); //!< number of samples void setTimeOfsProMill(int timeOfsProMill); void setSampleRate(int sampleRate); void setTimeBase(int timeBase); @@ -82,7 +82,7 @@ private: bool m_configChanged; int m_sampleRate; int m_timeOfsProMill; - Real m_triggerPre; + uint32_t m_triggerPre; int m_traceSize; int m_timeBase; int m_timeOffset; diff --git a/sdrbase/gui/glscopenggui.cpp b/sdrbase/gui/glscopenggui.cpp index 9d1707fe0..d3cd1c31c 100644 --- a/sdrbase/gui/glscopenggui.cpp +++ b/sdrbase/gui/glscopenggui.cpp @@ -86,8 +86,15 @@ void GLScopeNGGUI::setBuddies(MessageQueue* messageQueue, ScopeVisNG* scopeVis, ui->trigMode->clear(); fillProjectionCombo(ui->trigMode); - m_scopeVis->configure(2*m_traceLenMult*ScopeVisNG::m_traceChunkSize, m_timeOffset*10, ui->freerun->isChecked()); - m_scopeVis->configure(m_traceLenMult*ScopeVisNG::m_traceChunkSize, m_timeOffset*10, ui->freerun->isChecked()); + m_scopeVis->configure(2*m_traceLenMult*ScopeVisNG::m_traceChunkSize, + m_timeOffset*10, + (uint32_t) (m_glScope->getTraceSize() * (ui->trigPre->value()/100.0f)), + ui->freerun->isChecked()); + + m_scopeVis->configure(m_traceLenMult*ScopeVisNG::m_traceChunkSize, + m_timeOffset*10, + (uint32_t) (m_glScope->getTraceSize() * (ui->trigPre->value()/100.0f)), + ui->freerun->isChecked()); setTraceLenDisplay(); setTimeScaleDisplay(); @@ -228,7 +235,10 @@ void GLScopeNGGUI::on_timeOfs_valueChanged(int value) m_timeOffset = value; setTimeOfsDisplay(); - m_scopeVis->configure(m_traceLenMult*ScopeVisNG::m_traceChunkSize, m_timeOffset*10, ui->freerun->isChecked()); + m_scopeVis->configure(m_traceLenMult*ScopeVisNG::m_traceChunkSize, + m_timeOffset*10, + (uint32_t) (m_glScope->getTraceSize() * (ui->trigPre->value()/100.0f)), + ui->freerun->isChecked()); } void GLScopeNGGUI::on_traceLen_valueChanged(int value) @@ -238,7 +248,10 @@ void GLScopeNGGUI::on_traceLen_valueChanged(int value) } m_traceLenMult = value; - m_scopeVis->configure(m_traceLenMult*ScopeVisNG::m_traceChunkSize, m_timeOffset*10, ui->freerun->isChecked()); + m_scopeVis->configure(m_traceLenMult*ScopeVisNG::m_traceChunkSize, + m_timeOffset*10, + (uint32_t) (m_glScope->getTraceSize() * (ui->trigPre->value()/100.0f)), + ui->freerun->isChecked()); setTraceLenDisplay(); setTimeScaleDisplay(); setTimeOfsDisplay(); @@ -344,7 +357,10 @@ void GLScopeNGGUI::on_trigPre_valueChanged(int value) void GLScopeNGGUI::on_trigOneShot_toggled(bool checked) { - m_scopeVis->configure(m_traceLenMult*ScopeVisNG::m_traceChunkSize, m_timeOffset*10, ui->freerun->isChecked()); // TODO: implement one shot feature + m_scopeVis->configure(m_traceLenMult*ScopeVisNG::m_traceChunkSize, + m_timeOffset*10, + (uint32_t) (m_glScope->getTraceSize() * (ui->trigPre->value()/100.0f)), + ui->freerun->isChecked()); // TODO: implement one shot feature } void GLScopeNGGUI::on_freerun_toggled(bool checked) @@ -359,7 +375,10 @@ void GLScopeNGGUI::on_freerun_toggled(bool checked) ui->trigOneShot->setEnabled(true); } - m_scopeVis->configure(m_traceLenMult*ScopeVisNG::m_traceChunkSize, m_timeOffset*10, ui->freerun->isChecked()); // TODO: implement one shot feature + m_scopeVis->configure(m_traceLenMult*ScopeVisNG::m_traceChunkSize, + m_timeOffset*10, + (uint32_t) (m_glScope->getTraceSize() * (ui->trigPre->value()/100.0f)), + ui->freerun->isChecked()); // TODO: implement one shot feature } void GLScopeNGGUI::setTimeScaleDisplay()