19 #ifndef SDRBASE_DSP_SCOPEVISNG_H_ 20 #define SDRBASE_DSP_SCOPEVISNG_H_ 32 #include <boost/circular_buffer.hpp> 41 #define M_PI 3.14159265358979323846 70 m_projectionType(
Projector::ProjectionReal),
78 m_traceDelayCoarse(0),
80 m_triggerDisplayLevel(2.0),
81 m_traceColor(255,255,64),
82 m_hasTextOverlay(false),
85 setColor(m_traceColor);
92 m_traceColor.getRgbF(&r, &g, &b, &a);
121 m_projectionType(
Projector::ProjectionReal),
123 m_triggerLevel(0.0f),
124 m_triggerLevelCoarse(0),
125 m_triggerLevelFine(0),
126 m_triggerPositiveEdge(true),
127 m_triggerBothEdges(false),
130 m_triggerDelayMult(0.0),
131 m_triggerDelayCoarse(0),
132 m_triggerDelayFine(0),
134 m_triggerColor(0,255,0)
136 setColor(m_triggerColor);
141 m_triggerColor = color;
143 m_triggerColor.getRgbF(&r, &g, &b, &a);
158 void setLiveRate(
int sampleRate);
159 void setLiveRateLog2Decim(
int log2Decim);
161 void addTrace(
const TraceData& traceData);
163 void removeTrace(
uint32_t traceIndex);
164 void moveTrace(
uint32_t traceIndex,
bool upElseDown);
165 void focusOnTrace(
uint32_t traceIndex);
168 void removeTrigger(
uint32_t triggerIndex);
169 void moveTrigger(
uint32_t triggerIndex,
bool upElseDown);
170 void focusOnTrigger(
uint32_t triggerIndex);
171 void setOneShot(
bool oneShot);
172 void setMemoryIndex(
uint32_t memoryIndex);
181 QByteArray buffer = m_traceDiscreteMemory.serialize();
197 uint32_t traceSize, preTriggerDelay;
200 bool traceDiscreteMemorySuccess;
202 d.
readU32(1, &traceSize, m_traceChunkSize);
203 d.
readU32(2, &preTriggerDelay, 0);
205 setSampleRate(sampleRate);
206 setTraceSize(traceSize,
true);
207 setPreTriggerDelay(preTriggerDelay,
true);
209 traceDiscreteMemorySuccess = m_traceDiscreteMemory.deserialize(buf);
211 if (traceDiscreteMemorySuccess && (m_glScope) && (m_currentTraceMemoryIndex > 0)) {
212 processMemoryTrace();
215 return traceDiscreteMemorySuccess;
225 if (triggerIndex < m_triggerConditions.size())
227 triggerData = m_triggerConditions[triggerIndex]->m_triggerData;
233 if (traceIndex < m_traces.m_tracesData.size())
235 traceData = m_traces.m_tracesData[traceIndex];
240 const std::vector<TraceData>&
getTracesData()
const {
return m_traces.m_tracesData; }
243 virtual void feed(
const SampleVector::const_iterator& begin,
const SampleVector::const_iterator& end,
bool positiveOnly);
244 virtual void start();
246 virtual bool handleMessage(
const Message& message);
284 m_traceSize(traceSize),
285 m_timeBase(timeBase),
286 m_timeOfsProMill(timeOfsProMill),
287 m_triggerPre(triggerPre),
309 m_triggerData(triggerData)
332 m_triggerData(triggerData),
333 m_triggerIndex(triggerIndex)
354 m_triggerIndex(triggerIndex)
378 m_triggerIndex(triggerIndex),
379 m_moveUpElseDown(moveUpElseDown)
400 m_triggerIndex(triggerIndex)
421 m_traceData(traceData)
444 m_traceData(traceData),
445 m_traceIndex(traceIndex)
466 m_traceIndex(traceIndex)
490 m_traceIndex(traceIndex),
491 m_moveUpElseDown(moveUpElseDown)
512 m_traceIndex(traceIndex)
554 m_memoryIndex(memoryIndex)
584 m_triggerData(triggerData),
585 m_prevCondition(false),
586 m_triggerDelayCount(0),
608 m_triggerData = triggerData;
615 m_prevCondition =
false;
616 m_triggerDelayCount = 0;
617 m_triggerCounter = 0;
645 m_traceBuffer.
resize(size);
650 m_traceBuffer.
reset();
653 void write(
const SampleVector::const_iterator begin,
const SampleVector::const_iterator end)
655 m_traceBuffer.
write(begin, end);
668 QByteArray buffer = m_traceBuffer.
serialize();
669 unsigned int endDelta = m_endPoint - m_traceBuffer.
begin();
686 unsigned int tmpUInt;
692 m_endPoint = m_traceBuffer.
begin() + tmpUInt;
715 m_traceBackBuffers.resize(m_memSize);
725 for (std::vector<TraceBackBuffer>::iterator it = m_traceBackBuffers.begin(); it != m_traceBackBuffers.end(); ++it)
727 it->resize(2*m_traceSize);
738 uint32_t nextMemIndex = m_currentMemIndex < (m_memSize-1) ? m_currentMemIndex+1 : 0;
739 m_traceBackBuffers[nextMemIndex].
reset();
740 m_traceBackBuffers[nextMemIndex].write(m_traceBackBuffers[m_currentMemIndex].m_endPoint - samplesToReport,
741 m_traceBackBuffers[m_currentMemIndex].m_endPoint);
742 m_currentMemIndex = nextMemIndex;
743 return m_traceBackBuffers[m_currentMemIndex];
751 int index = (m_currentMemIndex + (m_memSize - (shift % m_memSize))) % m_memSize;
752 return m_traceBackBuffers[index];
760 return m_traceBackBuffers[m_currentMemIndex];
768 return m_traceBackBuffers[index];
787 for (
unsigned int i = 0;
i < m_memSize;
i++)
789 QByteArray buffer = m_traceBackBuffers[
i].serialize();
810 d.
readU32(2, &m_currentMemIndex, 0);
813 m_traceBackBuffers.resize(m_memSize);
815 if (traceSize != m_traceSize) {
819 for (
unsigned int i = 0;
i < m_memSize;
i++)
823 m_traceBackBuffers[
i].deserialize(buffer);
878 std::vector<float *> m_traces[2];
894 for (std::vector<TraceControl*>::iterator it = m_tracesControl.begin(); it != m_tracesControl.end(); ++it) {
911 return (m_tracesData[traceIndex].m_projectionType != traceData.
m_projectionType)
912 || (m_tracesData[traceIndex].m_amp != traceData.
m_amp)
913 || (m_tracesData[traceIndex].m_ofs != traceData.
m_ofs 914 || (m_tracesData[traceIndex].m_traceColor != traceData.
m_traceColor));
919 if (m_traces[0].size() < m_maxNbTraces)
921 qDebug(
"ScopeVis::addTrace");
922 m_traces[0].push_back(0);
923 m_traces[1].push_back(0);
924 m_tracesData.push_back(traceData);
935 if (traceIndex < m_tracesControl.size()) {
936 TraceControl *traceControl = m_tracesControl[traceIndex];
939 m_tracesData[traceIndex] = traceData;
945 if (traceIndex < m_tracesControl.size())
947 qDebug(
"ScopeVis::removeTrace");
948 m_traces[0].erase(m_traces[0].begin() + traceIndex);
949 m_traces[1].erase(m_traces[1].begin() + traceIndex);
950 TraceControl *traceControl = m_tracesControl[traceIndex];
952 m_tracesControl.erase(m_tracesControl.begin() + traceIndex);
953 m_tracesData.erase(m_tracesData.begin() + traceIndex);
962 if ((!upElseDown) && (traceIndex == 0)) {
966 int nextControlIndex = (traceIndex + (upElseDown ? 1 : -1)) % (m_tracesControl.size());
967 int nextDataIndex = (traceIndex + (upElseDown ? 1 : -1)) % (m_tracesData.size());
969 TraceControl *traceControl = m_tracesControl[traceIndex];
970 TraceControl *nextTraceControl = m_tracesControl[nextControlIndex];
975 m_tracesControl[nextControlIndex] = traceControl;
976 m_tracesControl[traceIndex] = nextTraceControl;
978 TraceData nextData = m_tracesData[nextDataIndex];
979 m_tracesData[nextDataIndex] = m_tracesData[traceIndex];
980 m_tracesData[traceIndex] = nextData;
982 traceControl = m_tracesControl[traceIndex];
983 nextTraceControl = m_tracesControl[nextControlIndex];
985 traceControl->
initProjector(m_tracesData[traceIndex].m_projectionType);
986 nextTraceControl->
initProjector(m_tracesData[nextDataIndex].m_projectionType);
991 m_traceSize = traceSize;
993 if (m_traceSize > m_maxTraceSize)
997 m_x0 =
new float[2*m_traceSize*m_maxNbTraces];
998 m_x1 =
new float[2*m_traceSize*m_maxNbTraces];
1000 m_maxTraceSize = m_traceSize;
1003 std::fill_n(m_x0, 2*m_traceSize*m_traces[0].size(), 0.0f);
1004 std::fill_n(m_x1, 2*m_traceSize*m_traces[0].size(), 0.0f);
1006 for (
unsigned int i = 0;
i < m_traces[0].size();
i++)
1008 (m_traces[0])[
i] = &m_x0[2*m_traceSize*
i];
1009 (m_traces[1])[
i] = &m_x1[2*m_traceSize*
i];
1018 evenOddIndex = !evenOddIndex;
1020 for (std::vector<TraceControl*>::iterator it = m_tracesControl.begin(); it != m_tracesControl.end(); ++it)
1022 (*it)->m_traceCount[currentBufferIndex()] = 0;
1047 bool condition, trigger;
1050 condition = triggerCondition.
m_projector.
run(s) > m_levelPowerDB;
1052 condition = triggerCondition.
m_projector.
run(s) > m_levelPowerLin;
1111 m_levelPowerLin = m_level + 1.0f;
1112 m_levelPowerDB = (100.0f * (m_level - 1.0f));
1160 void processTrace(
const SampleVector::const_iterator& begin,
const SampleVector::const_iterator& end,
int& triggerPointToEnd);
1165 void processMemoryTrace();
1172 int processTraces(
const SampleVector::const_iterator& begin,
const SampleVector::const_iterator& end,
bool traceBack =
false);
1177 void updateMaxTraceDelay();
1182 void initTraceBuffers();
1191 void computeDisplayTriggerLevels();
1198 void updateGLScopeDisplay();
1203 void setSampleRate(
int sampleRate);
1208 void setTraceSize(
uint32_t traceSize,
bool emitSignal =
false);
1213 void setPreTriggerDelay(
uint32_t preTriggerDelay,
bool emitSignal =
false);
uint32_t getTriggerIndex() const
MsgScopeVisNGMoveTrace(uint32_t traceIndex, bool moveUpElseDown)
uint32_t m_triggerRepeat
Number of trigger conditions before the final decisive trigger.
TriggerData m_triggerData
void addTrace(const TraceData &traceData, int traceSize)
const TraceData & getTraceData() const
uint32_t currentBufferIndex() const
bool m_viewTrace
Trace visibility.
void getTraceData(TraceData &traceData, uint32_t traceIndex)
static MsgScopeVisNGChangeTrigger * create(const TriggerData &triggerData, uint32_t triggerIndex)
bool m_triggerPositiveEdge
Trigger on the positive edge (else negative)
MsgScopeVisNGAddTrace(const TraceData &traceData)
static MsgScopeVisNGRemoveTrigger * create(uint32_t triggerIndex)
void write(const SampleVector::const_iterator begin, const SampleVector::const_iterator end)
double m_sumPow
Cumulative power over the current trace for MagDB overlay display.
TraceBackDiscreteMemory(uint32_t size)
MsgScopeVisNGFocusOnTrace(uint32_t traceIndex)
std::vector< TraceControl * > m_tracesControl
Corresponding traces control data.
uint32_t m_focusedTriggerIndex
Index of the trigger that has focus.
uint32_t getTraceIndex() const
bool m_triggerWaitForReset
In one shot mode suspended until reset by UI.
int m_liveSampleRate
Sample rate in live mode.
MsgScopeVisNGChangeTrigger(const TriggerData &triggerData, uint32_t triggerIndex)
std::vector< TraceData > m_tracesData
Corresponding traces data.
Calculate logarithmic (dB) of squared magnitude.
MsgScopeVisNGMoveTrigger(uint32_t triggerIndex, bool moveUpElseDown)
const TriggerData & getTriggerData() const
MsgScopeVisNGAddTrigger(const TriggerData &triggerData)
TraceBackBuffer & current()
QByteArray serializeMemory() const
TraceBuffer m_traceBuffer
uint32_t getTriggerIndex() const
SampleVector::iterator current()
void writeBlob(quint32 id, const QByteArray &value)
double m_maxPow
Maximum power over the current trace for MagDB overlay display.
void getTriggerData(TriggerData &triggerData, uint32_t triggerIndex)
QColor m_traceColor
Trace display color.
float m_traceColorR
Trace display color - red shortcut.
std::vector< T >::const_iterator begin() const
void setColor(QColor color)
uint32_t currentIndex() const
float m_triggerDisplayLevel
Displayable trigger display level in -1:+1 scale. Off scale if not displayable.
bool readU32(quint32 id, quint32 *result, quint32 def=0) const
int m_focusedTraceIndex
Index of the trace that has focus.
float m_traceColorG
Trace display color - green shortcut.
Trigger is not kicked off yet (or trigger list is empty)
Gives the number of projections in the enum.
std::vector< TraceBackBuffer > m_traceBackBuffers
uint32_t m_timeOfsProMill
Start trace shift in 1/1000 trace size.
QString m_textOverlay
Text overlay to display.
bool deserialize(const QByteArray &data)
int m_traceSize
Current size of a trace in buffer.
Trigger conditions have been kicked off but it is waiting for delay before final kick off...
bool deserialize(const QByteArray &data)
int m_traceDelay
Trace delay in number of samples.
static MsgScopeVisNGFocusOnTrace * create(uint32_t traceIndex)
const TriggerData & getTriggerData() const
bool m_prevCondition
Condition (above threshold) at previous sample.
uint32_t getTriggerIndex() const
uint32_t m_trues
Count of true conditions for holdoff processing.
int m_traceDelayCoarse
Coarse delay slider value.
static MsgScopeVisNGMoveTrigger * create(uint32_t triggerIndex, bool moveUpElseDown)
int m_traceDelayFine
Fine delay slider value.
float m_triggerColorR
Trigger line display color - red shortcut.
uint32_t m_triggerCounter
Counter of trigger occurrences.
static MsgScopeVisNGMoveTrace * create(uint32_t traceIndex, bool moveUpElseDown)
bool readS32(quint32 id, qint32 *result, qint32 def=0) const
TriggerData m_triggerData
uint32_t m_traceSize
Size of traces in number of samples.
uint32_t m_livePreTriggerDelay
Pre-trigger delay in number of samples in live mode.
bool readBlob(quint32 id, QByteArray *result, const QByteArray &def=QByteArray()) const
uint32_t m_liveTraceSize
Size of traces in number of samples in live mode.
static MsgScopeVisNGFocusOnTrigger * create(uint32_t triggerIndex)
void setData(const TriggerData &triggerData)
#define MESSAGE_CLASS_DECLARATION
bool m_triggerBothEdges
Trigger on both edges (else only one)
int getTriggerLocation() const
uint32_t m_triggerHoldoff
Trigger holdoff in number of samples.
int m_liveLog2Decim
Sample rate decimation log2 in live mode.
static MsgScopeVisNGMemoryTrace * create(uint32_t memoryIndex)
TraceBackBuffer & at(int index)
float m_traceColorB
Trace display color - blue shortcut.
uint32_t m_triggerDelayCount
Counter of samples for delay.
MsgScopeVisNGRemoveTrace(uint32_t traceIndex)
TraceBackBuffer & store(int samplesToReport)
bool deserialize(const QByteArray &data)
void write(const typename std::vector< T >::const_iterator &begin, const typename std::vector< T >::const_iterator &cend)
QColor m_triggerColor
Trigger line display color.
uint32_t m_timeBase
Trace display time divisor.
int m_triggerLocation
Trigger location from end point.
int m_maxTraceDelay
Maximum trace delay.
uint32_t m_currentTriggerIndex
Index of current index in the chain.
static MsgScopeVisNGOneShot * create(bool oneShot)
bool deserializeMemory(const QByteArray &data)
int m_ofsFine
Fine offset slider value.
Real m_triggerLevel
Level in real units.
uint32_t m_falses
Count of false conditions for holdoff processing.
MsgScopeVisNGRemoveTrigger(uint32_t triggerIndex)
Calculate linear magnitude or modulus.
void operator=(const TriggerCondition &other)
bool m_hasTextOverlay
True if a text overlay has to be displayed.
void writeS32(quint32 id, qint32 value)
TriggerData m_triggerData
Trigger data.
static MsgScopeVisNGChangeTrace * create(const TraceData &traceData, uint32_t traceIndex)
quint32 getVersion() const
unsigned int absoluteFill() const
bool m_traceStart
Trace is at start point.
uint32_t m_currentMemIndex
Projector::ProjectionType m_projectionType
Complex to real projection type.
float m_amp
Amplification factor.
static const uint32_t m_traceChunkSize
void settProjectionType(ProjectionType projectionType)
MsgScopeVisNGOneShot(bool oneShot)
void resize(uint32_t size)
void writeU32(quint32 id, quint32 value)
bool triggered(const Sample &s, TriggerCondition &triggerCondition)
uint32_t m_preTriggerDelay
Pre-trigger delay in number of samples.
Traces m_traces
Displayable traces.
bool evenOddIndex
Even (true) or odd (false) index.
int m_maxTraceSize
Maximum Size of a trace in buffer.
MsgScopeVisNGFocusOnTrigger(uint32_t triggerIndex)
void changeTrace(const TraceData &traceData, uint32_t traceIndex)
uint32_t getMemoryIndex() const
uint32_t getTraceIndex() const
uint32_t getTriggerIndex() const
MsgScopeVisNGMemoryTrace(uint32_t memoryIndex)
SampleVector::iterator m_endPoint
ProjectionType getProjectionType() const
TraceBackBuffer & recall(uint32_t shift)
uint32_t m_inputIndex
Input or feed index this trace is associated with.
Trigger has been kicked off.
int m_nbPow
Number of power samples over the current trace for MagDB overlay display.
QByteArray serialize() const
const TraceData & getTraceData() const
uint32_t getNbTriggers() const
static MsgScopeVisNGRemoveTrace * create(uint32_t traceIndex)
DoubleBufferSimple< Sample > TraceBuffer
Projector::ProjectionType m_projectionType
Complex to real projection type.
uint32_t m_triggerDelay
Delay before the trigger is kicked off in number of samples (trigger delay)
int m_nbSamples
Number of samples yet to process in one complex trace.
void resize(int traceSize)
uint32_t m_currentTraceMemoryIndex
The current index of trace in memory (0: current)
const std::vector< TraceData > & getTracesData() const
static MsgScopeVisNGAddTrace * create(const TraceData &traceData)
std::vector< TriggerCondition * > m_triggerConditions
Chain of triggers.
unsigned int absoluteFill() const
void resize(uint32_t size)
void moveTrace(uint32_t traceIndex, bool upElseDown)
bool isVerticalDisplayChange(const TraceData &traceData, uint32_t traceIndex)
void initProjector(Projector::ProjectionType projectionType)
TriggerComparator m_triggerComparator
Compares sample level to trigger level.
uint32_t m_ampIndex
Index in list of amplification factors.
TraceBackDiscreteMemory m_traceDiscreteMemory
Complex trace memory for triggered states TODO: vectorize when more than on input is allowed...
uint32_t m_inputIndex
Input or feed index this trigger is associated with.
TriggerState m_triggerState
Current trigger state.
float m_triggerColorB
Trigger line display color - blue shortcut.
uint32_t getTraceIndex() const
const QByteArray & final()
float m_triggerColorG
Trigger line display color - green shortcut.
bool m_triggerOneShot
True when one shot mode is active.
std::vector< T >::iterator getCurrent() const
void setColor(QColor color)
QByteArray serialize() const
uint32_t getTraceIndex() const
float m_ofs
Offset factor.
int m_sampleRate
Actual sample rate being used.
const TriggerData & getTriggerData(uint32_t triggerIndex) const
static MsgScopeVisNGAddTrigger * create(const TriggerData &triggerData)
void removeTrace(uint32_t traceIndex)
MsgScopeVisNGChangeTrace(TraceData traceData, uint32_t traceIndex)
TriggerCondition(const TriggerData &triggerData)
Projector m_projector
Projector transform from complex trace to real (displayable) trace.
int m_ofsCoarse
Coarse offset slider value.
bool m_freeRun
True if free running (trigger globally disabled)
Real run(const Sample &s)
double m_triggerDelayMult
Trigger delay as a multiplier of trace length.
QByteArray serialize() const