1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-09-04 14:17:50 -04:00

New scope: fix trigger (2)

This commit is contained in:
f4exb 2017-02-07 18:50:08 +01:00
parent ba67483b48
commit 199e915c62
5 changed files with 65 additions and 17 deletions

View File

@ -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); getInputMessageQueue()->push(cmd);
} }
@ -176,7 +176,7 @@ void ScopeVisNG::feed(const SampleVector::const_iterator& cbegin, const SampleVe
} }
else // look for trigger 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; bool trigger;
if (triggerCondition.m_triggerData.m_triggerBothEdges) { if (triggerCondition.m_triggerData.m_triggerBothEdges) {
@ -314,7 +314,7 @@ int ScopeVisNG::processTraces(int beginPointDelta, int endPointDelta, TraceBackB
if (projectionType == ProjectionMagLin) { if (projectionType == ProjectionMagLin) {
v = itCtl->m_projector->run(*begin)*itData->m_amp - itData->m_ofs - 1.0/itData->m_amp; 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 = 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; //v = itCtl->m_projector->run(*begin) * itData->m_amp - itData->m_ofs;
} else { } else {
@ -388,6 +388,7 @@ bool ScopeVisNG::handleMessage(const Message& message)
uint32_t traceSize = conf.getTraceSize(); uint32_t traceSize = conf.getTraceSize();
uint32_t timeOfsProMill = conf.getTimeOfsProMill(); uint32_t timeOfsProMill = conf.getTimeOfsProMill();
uint32_t triggerPre = conf.getTriggerPre();
bool freeRun = conf.getFreeRun(); bool freeRun = conf.getFreeRun();
if (m_traceSize != traceSize) 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) if (freeRun != m_freeRun)
{ {
m_freeRun = freeRun; m_freeRun = freeRun;
@ -419,6 +426,7 @@ bool ScopeVisNG::handleMessage(const Message& message)
qDebug() << "ScopeVisNG::handleMessage: MsgConfigureScopeVisNG:" qDebug() << "ScopeVisNG::handleMessage: MsgConfigureScopeVisNG:"
<< " m_traceSize: " << m_traceSize << " m_traceSize: " << m_traceSize
<< " m_timeOfsProMill: " << m_timeOfsProMill << " m_timeOfsProMill: " << m_timeOfsProMill
<< " m_preTriggerDelay: " << m_preTriggerDelay
<< " m_freeRun: " << m_freeRun; << " m_freeRun: " << m_freeRun;
return true; return true;

View File

@ -87,7 +87,7 @@ public:
virtual ~ScopeVisNG(); virtual ~ScopeVisNG();
void setSampleRate(int sampleRate); 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 addTrace(const TraceData& traceData);
void changeTrace(const TraceData& traceData, uint32_t traceIndex); void changeTrace(const TraceData& traceData, uint32_t traceIndex);
void removeTrace(uint32_t traceIndex); void removeTrace(uint32_t traceIndex);
@ -111,25 +111,30 @@ private:
static MsgConfigureScopeVisNG* create( static MsgConfigureScopeVisNG* create(
uint32_t traceSize, uint32_t traceSize,
uint32_t timeOfsProMill, uint32_t timeOfsProMill,
uint32_t triggerPre,
bool freeRun) bool freeRun)
{ {
return new MsgConfigureScopeVisNG(traceSize, timeOfsProMill, freeRun); return new MsgConfigureScopeVisNG(traceSize, timeOfsProMill, triggerPre, freeRun);
} }
uint32_t getTraceSize() const { return m_traceSize; } uint32_t getTraceSize() const { return m_traceSize; }
uint32_t getTimeOfsProMill() const { return m_timeOfsProMill; } uint32_t getTimeOfsProMill() const { return m_timeOfsProMill; }
uint32_t getTriggerPre() const { return m_triggerPre; }
bool getFreeRun() const { return m_freeRun; } bool getFreeRun() const { return m_freeRun; }
private: private:
uint32_t m_traceSize; uint32_t m_traceSize;
uint32_t m_timeOfsProMill; uint32_t m_timeOfsProMill;
uint32_t m_triggerPre;
bool m_freeRun; bool m_freeRun;
MsgConfigureScopeVisNG(uint32_t traceSize, MsgConfigureScopeVisNG(uint32_t traceSize,
uint32_t timeOfsProMill, uint32_t timeOfsProMill,
uint32_t triggerPre,
bool freeRun) : bool freeRun) :
m_traceSize(traceSize), m_traceSize(traceSize),
m_timeOfsProMill(timeOfsProMill), m_timeOfsProMill(timeOfsProMill),
m_triggerPre(triggerPre),
m_freeRun(freeRun) m_freeRun(freeRun)
{} {}
}; };
@ -664,7 +669,7 @@ private:
}; };
GLScopeNG* m_glScope; 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<TriggerCondition> m_triggerConditions; //!< Chain of triggers std::vector<TriggerCondition> m_triggerConditions; //!< Chain of triggers
int m_currentTriggerIndex; //!< Index of current index in the chain int m_currentTriggerIndex; //!< Index of current index in the chain
TriggerState m_triggerState; //!< Current trigger state TriggerState m_triggerState; //!< Current trigger state
@ -682,6 +687,21 @@ private:
bool m_freeRun; //!< True if free running (trigger globally disabled) bool m_freeRun; //!< True if free running (trigger globally disabled)
int m_maxTraceDelay; //!< Maximum trace delay 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 * Moves on to the next trigger if any or increments trigger count if in repeat mode
* - If not final it returns true * - If not final it returns true

View File

@ -335,7 +335,7 @@ void GLScopeNG::setTimeBase(int timeBase)
update(); update();
} }
void GLScopeNG::setTriggerPre(Real triggerPre) void GLScopeNG::setTriggerPre(uint32_t triggerPre)
{ {
m_triggerPre = triggerPre; m_triggerPre = triggerPre;
m_configChanged = true; m_configChanged = true;
@ -382,7 +382,8 @@ void GLScopeNG::applyConfig()
QFontMetrics fm(font()); QFontMetrics fm(font());
int M = fm.width("-"); 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; float t_len = ((float) m_traceSize / m_sampleRate) / (float) m_timeBase;
m_x1Scale.setRange(Unit::Time, t_start, t_start + t_len); // time scale m_x1Scale.setRange(Unit::Time, t_start, t_start + t_len); // time scale

View File

@ -57,7 +57,7 @@ public:
int getSampleRate() const { return m_sampleRate; } int getSampleRate() const { return m_sampleRate; }
int getTraceSize() const { return m_traceSize; } int getTraceSize() const { return m_traceSize; }
void setTriggerPre(Real triggerPre); void setTriggerPre(uint32_t triggerPre); //!< number of samples
void setTimeOfsProMill(int timeOfsProMill); void setTimeOfsProMill(int timeOfsProMill);
void setSampleRate(int sampleRate); void setSampleRate(int sampleRate);
void setTimeBase(int timeBase); void setTimeBase(int timeBase);
@ -82,7 +82,7 @@ private:
bool m_configChanged; bool m_configChanged;
int m_sampleRate; int m_sampleRate;
int m_timeOfsProMill; int m_timeOfsProMill;
Real m_triggerPre; uint32_t m_triggerPre;
int m_traceSize; int m_traceSize;
int m_timeBase; int m_timeBase;
int m_timeOffset; int m_timeOffset;

View File

@ -86,8 +86,15 @@ void GLScopeNGGUI::setBuddies(MessageQueue* messageQueue, ScopeVisNG* scopeVis,
ui->trigMode->clear(); ui->trigMode->clear();
fillProjectionCombo(ui->trigMode); fillProjectionCombo(ui->trigMode);
m_scopeVis->configure(2*m_traceLenMult*ScopeVisNG::m_traceChunkSize, m_timeOffset*10, ui->freerun->isChecked()); m_scopeVis->configure(2*m_traceLenMult*ScopeVisNG::m_traceChunkSize,
m_scopeVis->configure(m_traceLenMult*ScopeVisNG::m_traceChunkSize, m_timeOffset*10, ui->freerun->isChecked()); 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(); setTraceLenDisplay();
setTimeScaleDisplay(); setTimeScaleDisplay();
@ -228,7 +235,10 @@ void GLScopeNGGUI::on_timeOfs_valueChanged(int value)
m_timeOffset = value; m_timeOffset = value;
setTimeOfsDisplay(); 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) void GLScopeNGGUI::on_traceLen_valueChanged(int value)
@ -238,7 +248,10 @@ void GLScopeNGGUI::on_traceLen_valueChanged(int value)
} }
m_traceLenMult = 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(); setTraceLenDisplay();
setTimeScaleDisplay(); setTimeScaleDisplay();
setTimeOfsDisplay(); setTimeOfsDisplay();
@ -344,7 +357,10 @@ void GLScopeNGGUI::on_trigPre_valueChanged(int value)
void GLScopeNGGUI::on_trigOneShot_toggled(bool checked) 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) void GLScopeNGGUI::on_freerun_toggled(bool checked)
@ -359,7 +375,10 @@ void GLScopeNGGUI::on_freerun_toggled(bool checked)
ui->trigOneShot->setEnabled(true); 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() void GLScopeNGGUI::setTimeScaleDisplay()