2017-01-29 18:51:45 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2017 F4EXB //
|
|
|
|
// written by Edouard Griffiths //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef SDRBASE_DSP_SCOPEVISNG_H_
|
|
|
|
#define SDRBASE_DSP_SCOPEVISNG_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <boost/circular_buffer.hpp>
|
|
|
|
#include "dsp/dsptypes.h"
|
|
|
|
#include "dsp/basebandsamplesink.h"
|
|
|
|
#include "util/export.h"
|
|
|
|
#include "util/message.h"
|
|
|
|
#include "util/doublebuffer.h"
|
|
|
|
|
|
|
|
class GLScopeNG;
|
|
|
|
|
|
|
|
class SDRANGEL_API ScopeVisNG : public BasebandSampleSink {
|
|
|
|
|
|
|
|
public:
|
2017-01-31 07:26:13 +00:00
|
|
|
enum ProjectionType
|
|
|
|
{
|
|
|
|
ProjectionReal, //!< Extract real part
|
|
|
|
ProjectionImag, //!< Extract imaginary part
|
|
|
|
ProjectionMagLin, //!< Calculate linear magnitude or modulus
|
|
|
|
ProjectionMagDB, //!< Calculate logarithmic (dB) of squared magnitude
|
|
|
|
ProjectionPhase, //!< Calculate phase
|
|
|
|
ProjectionDPhase //!< Calculate phase derivative i.e. instantaneous frequency scaled to sample rate
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TraceData
|
|
|
|
{
|
2017-01-29 23:07:20 +00:00
|
|
|
ProjectionType m_projectionType; //!< Complex to real projection type
|
|
|
|
uint32_t m_inputIndex; //!< Input or feed index this trace is associated with
|
|
|
|
float m_amp; //!< Amplification factor
|
|
|
|
float m_ofs; //!< Offset factor
|
|
|
|
int m_traceDelay; //!< Trace delay in number of samples
|
|
|
|
|
|
|
|
TraceData() :
|
|
|
|
m_projectionType(ProjectionReal),
|
|
|
|
m_inputIndex(0),
|
|
|
|
m_amp(1.0f),
|
|
|
|
m_ofs(0.0f),
|
|
|
|
m_traceDelay(0)
|
|
|
|
{}
|
2017-01-31 07:26:13 +00:00
|
|
|
};
|
2017-01-29 23:07:20 +00:00
|
|
|
|
2017-01-31 07:26:13 +00:00
|
|
|
struct TriggerData
|
|
|
|
{
|
2017-01-29 23:07:20 +00:00
|
|
|
ProjectionType m_projectionType; //!< Complex to real projection type
|
|
|
|
uint32_t m_inputIndex; //!< Input or feed index this trigger is associated with
|
|
|
|
Real m_triggerLevel; //!< Level in real units
|
|
|
|
bool m_triggerPositiveEdge; //!< Trigger on the positive edge (else negative)
|
|
|
|
bool m_triggerBothEdges; //!< Trigger on both edges (else only one)
|
|
|
|
uint32_t m_triggerDelay; //!< Delay before the trigger is kicked off in number of samples
|
2017-02-01 17:31:16 +00:00
|
|
|
uint32_t m_triggerRepeat; //!< Number of trigger conditions before the final decisive trigger
|
2017-01-29 23:07:20 +00:00
|
|
|
|
|
|
|
TriggerData() :
|
|
|
|
m_projectionType(ProjectionReal),
|
|
|
|
m_inputIndex(0),
|
|
|
|
m_triggerLevel(0.0f),
|
|
|
|
m_triggerPositiveEdge(true),
|
|
|
|
m_triggerBothEdges(false),
|
|
|
|
m_triggerDelay(0),
|
2017-02-01 17:31:16 +00:00
|
|
|
m_triggerRepeat(0)
|
2017-01-29 23:07:20 +00:00
|
|
|
{}
|
2017-01-31 07:26:13 +00:00
|
|
|
};
|
2017-01-29 18:51:45 +00:00
|
|
|
|
|
|
|
static const uint m_traceChunkSize;
|
|
|
|
static const uint m_nbTriggers = 10;
|
|
|
|
|
|
|
|
ScopeVisNG(GLScopeNG* glScope = 0);
|
|
|
|
virtual ~ScopeVisNG();
|
|
|
|
|
2017-01-29 21:52:38 +00:00
|
|
|
void setSampleRate(int sampleRate);
|
2017-02-07 17:50:08 +00:00
|
|
|
void configure(uint32_t traceSize, uint32_t timeOfsProMill, uint32_t triggerPre, bool freeRun);
|
2017-01-29 23:36:27 +00:00
|
|
|
void addTrace(const TraceData& traceData);
|
|
|
|
void changeTrace(const TraceData& traceData, uint32_t traceIndex);
|
|
|
|
void removeTrace(uint32_t traceIndex);
|
|
|
|
void addTrigger(const TriggerData& triggerData);
|
|
|
|
void changeTrigger(const TriggerData& triggerData, uint32_t traceIndex);
|
|
|
|
void removeTrigger(uint32_t triggerIndex);
|
2017-01-29 18:51:45 +00:00
|
|
|
|
|
|
|
virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly);
|
|
|
|
virtual void start();
|
|
|
|
virtual void stop();
|
|
|
|
virtual bool handleMessage(const Message& message);
|
|
|
|
SampleVector::const_iterator getTriggerPoint() const { return m_triggerPoint; }
|
|
|
|
|
|
|
|
private:
|
2017-01-29 21:52:38 +00:00
|
|
|
// === messages ===
|
|
|
|
// ---------------------------------------------
|
2017-01-29 18:51:45 +00:00
|
|
|
class MsgConfigureScopeVisNG : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
static MsgConfigureScopeVisNG* create(
|
2017-02-05 03:41:32 +00:00
|
|
|
uint32_t traceSize,
|
2017-02-06 01:40:31 +00:00
|
|
|
uint32_t timeOfsProMill,
|
2017-02-07 17:50:08 +00:00
|
|
|
uint32_t triggerPre,
|
2017-02-06 01:40:31 +00:00
|
|
|
bool freeRun)
|
2017-01-29 18:51:45 +00:00
|
|
|
{
|
2017-02-07 17:50:08 +00:00
|
|
|
return new MsgConfigureScopeVisNG(traceSize, timeOfsProMill, triggerPre, freeRun);
|
2017-01-29 18:51:45 +00:00
|
|
|
}
|
|
|
|
|
2017-01-31 07:26:13 +00:00
|
|
|
uint32_t getTraceSize() const { return m_traceSize; }
|
2017-02-05 03:41:32 +00:00
|
|
|
uint32_t getTimeOfsProMill() const { return m_timeOfsProMill; }
|
2017-02-07 17:50:08 +00:00
|
|
|
uint32_t getTriggerPre() const { return m_triggerPre; }
|
2017-02-06 01:40:31 +00:00
|
|
|
bool getFreeRun() const { return m_freeRun; }
|
2017-01-31 07:26:13 +00:00
|
|
|
|
2017-01-29 18:51:45 +00:00
|
|
|
private:
|
|
|
|
uint32_t m_traceSize;
|
2017-02-05 03:41:32 +00:00
|
|
|
uint32_t m_timeOfsProMill;
|
2017-02-07 17:50:08 +00:00
|
|
|
uint32_t m_triggerPre;
|
2017-02-06 01:40:31 +00:00
|
|
|
bool m_freeRun;
|
2017-01-29 18:51:45 +00:00
|
|
|
|
2017-02-05 03:41:32 +00:00
|
|
|
MsgConfigureScopeVisNG(uint32_t traceSize,
|
2017-02-06 01:40:31 +00:00
|
|
|
uint32_t timeOfsProMill,
|
2017-02-07 17:50:08 +00:00
|
|
|
uint32_t triggerPre,
|
2017-02-06 01:40:31 +00:00
|
|
|
bool freeRun) :
|
2017-02-05 03:41:32 +00:00
|
|
|
m_traceSize(traceSize),
|
2017-02-06 01:40:31 +00:00
|
|
|
m_timeOfsProMill(timeOfsProMill),
|
2017-02-07 17:50:08 +00:00
|
|
|
m_triggerPre(triggerPre),
|
2017-02-06 01:40:31 +00:00
|
|
|
m_freeRun(freeRun)
|
2017-01-29 18:51:45 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2017-01-29 21:52:38 +00:00
|
|
|
// ---------------------------------------------
|
2017-01-29 18:51:45 +00:00
|
|
|
class MsgScopeVisNGAddTrigger : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
static MsgScopeVisNGAddTrigger* create(
|
2017-01-29 23:36:27 +00:00
|
|
|
const TriggerData& triggerData)
|
2017-01-29 18:51:45 +00:00
|
|
|
{
|
2017-01-29 23:36:27 +00:00
|
|
|
return new MsgScopeVisNGAddTrigger(triggerData);
|
2017-01-29 18:51:45 +00:00
|
|
|
}
|
|
|
|
|
2017-02-03 07:27:03 +00:00
|
|
|
const TriggerData& getTriggerData() const { return m_triggerData; }
|
|
|
|
|
2017-01-29 18:51:45 +00:00
|
|
|
private:
|
2017-01-29 23:36:27 +00:00
|
|
|
TriggerData m_triggerData;
|
2017-01-29 18:51:45 +00:00
|
|
|
|
2017-01-29 23:36:27 +00:00
|
|
|
MsgScopeVisNGAddTrigger(const TriggerData& triggerData) :
|
|
|
|
m_triggerData(triggerData)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
// ---------------------------------------------
|
|
|
|
class MsgScopeVisNGChangeTrigger : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
static MsgScopeVisNGChangeTrigger* create(
|
|
|
|
const TriggerData& triggerData, uint32_t triggerIndex)
|
|
|
|
{
|
|
|
|
return new MsgScopeVisNGChangeTrigger(triggerData, triggerIndex);
|
|
|
|
}
|
|
|
|
|
2017-02-03 07:27:03 +00:00
|
|
|
const TriggerData& getTriggerData() const { return m_triggerData; }
|
|
|
|
uint32_t getTriggerIndex() const { return m_triggerIndex; }
|
|
|
|
|
2017-01-29 23:36:27 +00:00
|
|
|
private:
|
|
|
|
TriggerData m_triggerData;
|
|
|
|
uint32_t m_triggerIndex;
|
|
|
|
|
|
|
|
MsgScopeVisNGChangeTrigger(const TriggerData& triggerData, uint32_t triggerIndex) :
|
|
|
|
m_triggerData(triggerData),
|
|
|
|
m_triggerIndex(triggerIndex)
|
2017-01-29 18:51:45 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2017-01-29 21:52:38 +00:00
|
|
|
// ---------------------------------------------
|
2017-01-29 18:51:45 +00:00
|
|
|
class MsgScopeVisNGRemoveTrigger : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
static MsgScopeVisNGRemoveTrigger* create(
|
|
|
|
uint32_t triggerIndex)
|
|
|
|
{
|
|
|
|
return new MsgScopeVisNGRemoveTrigger(triggerIndex);
|
|
|
|
}
|
|
|
|
|
2017-02-03 07:27:03 +00:00
|
|
|
uint32_t getTriggerIndex() const { return m_triggerIndex; }
|
|
|
|
|
2017-01-29 18:51:45 +00:00
|
|
|
private:
|
|
|
|
uint32_t m_triggerIndex;
|
|
|
|
|
|
|
|
MsgScopeVisNGRemoveTrigger(uint32_t triggerIndex) :
|
2017-01-31 07:26:13 +00:00
|
|
|
m_triggerIndex(triggerIndex)
|
2017-01-29 18:51:45 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2017-01-29 23:36:27 +00:00
|
|
|
// ---------------------------------------------
|
|
|
|
class MsgScopeVisNGAddTrace : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
static MsgScopeVisNGAddTrace* create(
|
|
|
|
const TraceData& traceData)
|
|
|
|
{
|
|
|
|
return new MsgScopeVisNGAddTrace(traceData);
|
|
|
|
}
|
|
|
|
|
2017-02-03 07:27:03 +00:00
|
|
|
const TraceData& getTraceData() const { return m_traceData; }
|
|
|
|
|
2017-01-29 23:36:27 +00:00
|
|
|
private:
|
|
|
|
TraceData m_traceData;
|
|
|
|
|
|
|
|
MsgScopeVisNGAddTrace(const TraceData& traceData) :
|
|
|
|
m_traceData(traceData)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
// ---------------------------------------------
|
|
|
|
class MsgScopeVisNGChangeTrace : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
static MsgScopeVisNGChangeTrace* create(
|
|
|
|
const TraceData& traceData, uint32_t traceIndex)
|
|
|
|
{
|
|
|
|
return new MsgScopeVisNGChangeTrace(traceData, traceIndex);
|
|
|
|
}
|
|
|
|
|
2017-02-03 07:27:03 +00:00
|
|
|
const TraceData& getTraceData() const { return m_traceData; }
|
|
|
|
uint32_t getTraceIndex() const { return m_traceIndex; }
|
|
|
|
|
2017-01-29 23:36:27 +00:00
|
|
|
private:
|
|
|
|
TraceData m_traceData;
|
|
|
|
uint32_t m_traceIndex;
|
|
|
|
|
|
|
|
MsgScopeVisNGChangeTrace(TraceData traceData, uint32_t traceIndex) :
|
|
|
|
m_traceData(traceData),
|
|
|
|
m_traceIndex(traceIndex)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
// ---------------------------------------------
|
|
|
|
class MsgScopeVisNGRemoveTrace : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
static MsgScopeVisNGRemoveTrace* create(
|
|
|
|
uint32_t traceIndex)
|
|
|
|
{
|
|
|
|
return new MsgScopeVisNGRemoveTrace(traceIndex);
|
|
|
|
}
|
|
|
|
|
2017-02-03 07:27:03 +00:00
|
|
|
uint32_t getTraceIndex() const { return m_traceIndex; }
|
|
|
|
|
2017-01-29 23:36:27 +00:00
|
|
|
private:
|
|
|
|
uint32_t m_traceIndex;
|
|
|
|
|
|
|
|
MsgScopeVisNGRemoveTrace(uint32_t traceIndex) :
|
|
|
|
m_traceIndex(traceIndex)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2017-01-29 21:52:38 +00:00
|
|
|
// === projectors ===
|
|
|
|
// ---------------------------------------------
|
2017-01-29 18:51:45 +00:00
|
|
|
class Projector
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Projector(ProjectionType projectionType) : m_projectionType(projectionType) {}
|
2017-02-05 03:41:32 +00:00
|
|
|
virtual ~Projector() {}
|
2017-01-29 18:51:45 +00:00
|
|
|
|
|
|
|
ProjectionType getProjectionType() const { return m_projectionType; }
|
2017-02-05 03:41:32 +00:00
|
|
|
virtual Real run(const Sample& s) = 0;
|
2017-01-29 18:51:45 +00:00
|
|
|
private:
|
|
|
|
ProjectionType m_projectionType;
|
|
|
|
};
|
|
|
|
|
2017-01-29 21:52:38 +00:00
|
|
|
// ---------------------------------------------
|
2017-01-29 18:51:45 +00:00
|
|
|
class ProjectorReal : public Projector
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ProjectorReal() : Projector(ProjectionReal) {}
|
2017-02-05 03:41:32 +00:00
|
|
|
virtual ~ProjectorReal() {}
|
2017-01-29 18:51:45 +00:00
|
|
|
virtual Real run(const Sample& s) { return s.m_real / 32768.0f; }
|
|
|
|
};
|
|
|
|
|
2017-01-29 21:52:38 +00:00
|
|
|
// ---------------------------------------------
|
2017-01-29 18:51:45 +00:00
|
|
|
class ProjectorImag : public Projector
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ProjectorImag() : Projector(ProjectionImag) {}
|
2017-02-05 03:41:32 +00:00
|
|
|
virtual ~ProjectorImag() {}
|
2017-01-29 18:51:45 +00:00
|
|
|
virtual Real run(const Sample& s) { return s.m_imag / 32768.0f; }
|
|
|
|
};
|
|
|
|
|
2017-01-29 21:52:38 +00:00
|
|
|
// ---------------------------------------------
|
2017-01-29 18:51:45 +00:00
|
|
|
class ProjectorMagLin : public Projector
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ProjectorMagLin() : Projector(ProjectionMagLin) {}
|
2017-02-05 03:41:32 +00:00
|
|
|
virtual ~ProjectorMagLin() {}
|
2017-01-29 18:51:45 +00:00
|
|
|
virtual Real run(const Sample& s)
|
|
|
|
{
|
|
|
|
uint32_t magsq = s.m_real*s.m_real + s.m_imag*s.m_imag;
|
|
|
|
return std::sqrt(magsq/1073741824.0f);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-01-29 21:52:38 +00:00
|
|
|
// ---------------------------------------------
|
2017-01-29 18:51:45 +00:00
|
|
|
class ProjectorMagDB : public Projector
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ProjectorMagDB() : Projector(ProjectionMagDB) {}
|
2017-02-05 03:41:32 +00:00
|
|
|
virtual ~ProjectorMagDB() {}
|
2017-01-29 18:51:45 +00:00
|
|
|
virtual Real run(const Sample& s)
|
|
|
|
{
|
|
|
|
uint32_t magsq = s.m_real*s.m_real + s.m_imag*s.m_imag;
|
2017-02-06 01:40:31 +00:00
|
|
|
//return mult * log2f(magsq/1073741824.0f);
|
2017-02-06 23:25:40 +00:00
|
|
|
return log10f(magsq/1073741824.0f) * 10.0f;
|
2017-01-29 18:51:45 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
static const Real mult;
|
|
|
|
};
|
|
|
|
|
2017-01-29 21:52:38 +00:00
|
|
|
// ---------------------------------------------
|
2017-01-29 18:51:45 +00:00
|
|
|
class ProjectorPhase : public Projector
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ProjectorPhase() : Projector(ProjectionPhase) {}
|
2017-02-05 03:41:32 +00:00
|
|
|
virtual ~ProjectorPhase() {}
|
2017-01-29 18:51:45 +00:00
|
|
|
virtual Real run(const Sample& s) { return std::atan2((float) s.m_imag, (float) s.m_real) / M_PI; }
|
|
|
|
};
|
|
|
|
|
2017-01-29 21:52:38 +00:00
|
|
|
// ---------------------------------------------
|
2017-01-29 18:51:45 +00:00
|
|
|
class ProjectorDPhase : public Projector
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ProjectorDPhase() : Projector(ProjectionDPhase), m_prevArg(0.0f) {}
|
2017-02-05 03:41:32 +00:00
|
|
|
virtual ~ProjectorDPhase() {}
|
2017-01-29 18:51:45 +00:00
|
|
|
virtual Real run(const Sample& s)
|
|
|
|
{
|
2017-02-06 01:40:31 +00:00
|
|
|
Real curArg = std::atan2((float) s.m_imag, (float) s.m_real);
|
2017-02-08 01:13:53 +00:00
|
|
|
Real dPhi = (curArg - m_prevArg) / M_PI;
|
2017-01-29 18:51:45 +00:00
|
|
|
m_prevArg = curArg;
|
|
|
|
|
2017-02-08 01:13:53 +00:00
|
|
|
if (dPhi < -1.0f) {
|
|
|
|
dPhi += 2.0f;
|
|
|
|
} else if (dPhi > 1.0f) {
|
|
|
|
dPhi -= 2.0f;
|
2017-01-29 18:51:45 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 01:13:53 +00:00
|
|
|
return dPhi;
|
2017-01-29 18:51:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Real m_prevArg;
|
|
|
|
};
|
|
|
|
|
2017-02-05 03:41:32 +00:00
|
|
|
static Projector *createProjector(ProjectionType projectionType)
|
|
|
|
{
|
|
|
|
//qDebug("ScopeVisNG::createProjector: projectionType: %d", projectionType);
|
|
|
|
switch (projectionType)
|
|
|
|
{
|
|
|
|
case ProjectionImag:
|
|
|
|
return new ProjectorImag();
|
|
|
|
case ProjectionMagLin:
|
|
|
|
return new ProjectorMagLin();
|
|
|
|
case ProjectionMagDB:
|
|
|
|
return new ProjectorMagDB();
|
|
|
|
case ProjectionPhase:
|
|
|
|
return new ProjectorPhase();
|
|
|
|
case ProjectionDPhase:
|
|
|
|
return new ProjectorDPhase();
|
|
|
|
case ProjectionReal:
|
|
|
|
default:
|
|
|
|
return new ProjectorReal();
|
|
|
|
}
|
|
|
|
}
|
2017-01-29 21:52:38 +00:00
|
|
|
|
2017-02-01 17:31:16 +00:00
|
|
|
/**
|
|
|
|
* Trigger stuff
|
|
|
|
*/
|
2017-01-29 18:51:45 +00:00
|
|
|
enum TriggerState
|
2017-01-31 07:26:13 +00:00
|
|
|
{
|
|
|
|
TriggerUntriggered, //!< Trigger is not kicked off yet (or trigger list is empty)
|
|
|
|
TriggerTriggered, //!< Trigger has been kicked off
|
|
|
|
TriggerWait, //!< In one shot mode trigger waits for manual re-enabling
|
|
|
|
TriggerDelay, //!< Trigger conditions have been kicked off but it is waiting for delay before final kick off
|
|
|
|
TriggerNewConfig, //!< Special condition when a new configuration has been received
|
|
|
|
};
|
2017-01-29 18:51:45 +00:00
|
|
|
|
|
|
|
struct TriggerCondition
|
|
|
|
{
|
|
|
|
public:
|
2017-02-05 03:41:32 +00:00
|
|
|
Projector *m_projector;
|
2017-01-31 07:26:13 +00:00
|
|
|
TriggerData m_triggerData; //!< Trigger data
|
2017-01-29 18:51:45 +00:00
|
|
|
bool m_prevCondition; //!< Condition (above threshold) at previous sample
|
|
|
|
uint32_t m_triggerDelayCount; //!< Counter of samples for delay
|
2017-01-29 23:07:20 +00:00
|
|
|
uint32_t m_triggerCounter; //!< Counter of trigger occurences
|
2017-01-29 18:51:45 +00:00
|
|
|
|
2017-01-31 07:26:13 +00:00
|
|
|
TriggerCondition(const TriggerData& triggerData) :
|
2017-02-05 03:41:32 +00:00
|
|
|
m_projector(0),
|
2017-01-31 07:26:13 +00:00
|
|
|
m_triggerData(triggerData),
|
|
|
|
m_prevCondition(false),
|
2017-01-29 18:51:45 +00:00
|
|
|
m_triggerDelayCount(0),
|
2017-01-29 23:07:20 +00:00
|
|
|
m_triggerCounter(0)
|
2017-01-31 07:26:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-02-05 03:41:32 +00:00
|
|
|
~TriggerCondition()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-02-10 01:45:49 +00:00
|
|
|
void initProjector()
|
2017-02-05 03:41:32 +00:00
|
|
|
{
|
|
|
|
m_projector = createProjector(m_triggerData.m_projectionType);
|
|
|
|
}
|
2017-01-31 07:26:13 +00:00
|
|
|
|
2017-02-10 01:45:49 +00:00
|
|
|
void releaseProjector()
|
|
|
|
{
|
|
|
|
delete m_projector;
|
|
|
|
}
|
|
|
|
|
2017-01-31 07:26:13 +00:00
|
|
|
void setData(const TriggerData& triggerData)
|
|
|
|
{
|
|
|
|
m_triggerData = triggerData;
|
|
|
|
|
|
|
|
if (m_projector->getProjectionType() != m_triggerData.m_projectionType)
|
|
|
|
{
|
|
|
|
delete m_projector;
|
2017-02-05 03:41:32 +00:00
|
|
|
m_projector = createProjector(m_triggerData.m_projectionType);
|
2017-01-31 07:26:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_prevCondition = false;
|
|
|
|
m_triggerDelayCount = 0;
|
|
|
|
m_triggerCounter = 0;
|
|
|
|
}
|
2017-01-29 18:51:45 +00:00
|
|
|
};
|
|
|
|
|
2017-02-01 17:31:16 +00:00
|
|
|
/**
|
|
|
|
* Complex trace stuff
|
|
|
|
*/
|
|
|
|
typedef DoubleBufferSimple<Sample> TraceBuffer;
|
|
|
|
|
|
|
|
struct TraceBackBuffer
|
|
|
|
{
|
|
|
|
TraceBuffer m_traceBuffer;
|
|
|
|
SampleVector::iterator m_endPoint;
|
|
|
|
|
|
|
|
TraceBackBuffer()
|
|
|
|
{
|
|
|
|
m_endPoint = m_traceBuffer.getCurrent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void resize(uint32_t size)
|
|
|
|
{
|
|
|
|
m_traceBuffer.resize(size);
|
|
|
|
}
|
|
|
|
|
2017-02-02 07:27:49 +00:00
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
m_traceBuffer.reset();
|
|
|
|
}
|
|
|
|
|
2017-02-01 17:31:16 +00:00
|
|
|
void write(const SampleVector::const_iterator begin, const SampleVector::const_iterator end)
|
|
|
|
{
|
|
|
|
m_traceBuffer.write(begin, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int absoluteFill() const {
|
|
|
|
return m_traceBuffer.absoluteFill();
|
|
|
|
}
|
|
|
|
|
|
|
|
SampleVector::iterator current() { return m_traceBuffer.getCurrent(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TraceBackDiscreteMemory
|
|
|
|
{
|
|
|
|
std::vector<TraceBackBuffer> m_traceBackBuffers;
|
|
|
|
uint32_t m_memSize;
|
|
|
|
uint32_t m_currentMemIndex;
|
2017-02-06 01:40:31 +00:00
|
|
|
uint32_t m_traceSize;
|
2017-02-01 17:31:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Give memory size in number of traces
|
|
|
|
*/
|
2017-02-06 01:40:31 +00:00
|
|
|
TraceBackDiscreteMemory(uint32_t size) : m_memSize(size), m_currentMemIndex(0), m_traceSize(0)
|
2017-02-01 17:31:16 +00:00
|
|
|
{
|
|
|
|
m_traceBackBuffers.resize(m_memSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resize all trace buffers in memory
|
|
|
|
*/
|
|
|
|
void resize(uint32_t size)
|
|
|
|
{
|
2017-02-06 01:40:31 +00:00
|
|
|
m_traceSize = size;
|
|
|
|
|
2017-02-01 17:31:16 +00:00
|
|
|
for (std::vector<TraceBackBuffer>::iterator it = m_traceBackBuffers.begin(); it != m_traceBackBuffers.end(); ++it)
|
|
|
|
{
|
2017-02-06 01:40:31 +00:00
|
|
|
it->resize(4*m_traceSize);
|
2017-02-01 17:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move index forward by one position and return reference to the trace at this position
|
2017-02-06 01:40:31 +00:00
|
|
|
* Copy a trace length of samples into the new memory slot
|
2017-02-01 17:31:16 +00:00
|
|
|
*/
|
|
|
|
TraceBackBuffer &store()
|
|
|
|
{
|
2017-02-06 01:40:31 +00:00
|
|
|
uint32_t nextMemIndex = m_currentMemIndex < (m_memSize-1) ? m_currentMemIndex+1 : 0;
|
|
|
|
m_traceBackBuffers[nextMemIndex].reset();
|
|
|
|
m_traceBackBuffers[nextMemIndex].write(m_traceBackBuffers[m_currentMemIndex].m_endPoint - m_traceSize,
|
|
|
|
m_traceBackBuffers[m_currentMemIndex].m_endPoint);
|
|
|
|
m_currentMemIndex = nextMemIndex;
|
2017-02-01 17:31:16 +00:00
|
|
|
return m_traceBackBuffers[m_currentMemIndex]; // new trace
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recalls trace at shift positions back. Therefore 0 is current. Wraps around memory size.
|
|
|
|
*/
|
|
|
|
TraceBackBuffer& recall(uint32_t shift)
|
|
|
|
{
|
|
|
|
int index = (m_currentMemIndex + (m_memSize - (shift % m_memSize))) % m_memSize;
|
|
|
|
return m_traceBackBuffers[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return trace at current memory position
|
|
|
|
*/
|
|
|
|
TraceBackBuffer& current()
|
|
|
|
{
|
|
|
|
return m_traceBackBuffers[m_currentMemIndex];
|
|
|
|
}
|
2017-02-06 01:40:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return current memory index
|
|
|
|
*/
|
|
|
|
uint32_t currentIndex() const { return m_currentMemIndex; }
|
2017-02-01 17:31:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displayable trace stuff
|
|
|
|
*/
|
2017-02-06 01:40:31 +00:00
|
|
|
struct TraceControl
|
2017-01-29 18:51:45 +00:00
|
|
|
{
|
2017-01-31 07:26:13 +00:00
|
|
|
Projector *m_projector; //!< Projector transform from complex trace to real (displayable) trace
|
2017-02-06 01:40:31 +00:00
|
|
|
int m_traceCount[2]; //!< Count of samples processed (double buffered)
|
2017-01-31 07:26:13 +00:00
|
|
|
|
2017-02-06 01:40:31 +00:00
|
|
|
TraceControl() : m_projector(0)
|
2017-01-31 07:26:13 +00:00
|
|
|
{
|
2017-02-06 01:40:31 +00:00
|
|
|
reset();
|
2017-01-31 07:26:13 +00:00
|
|
|
}
|
|
|
|
|
2017-02-06 01:40:31 +00:00
|
|
|
~TraceControl()
|
2017-01-31 07:26:13 +00:00
|
|
|
{
|
2017-02-05 03:41:32 +00:00
|
|
|
if (m_projector) delete m_projector;
|
|
|
|
}
|
|
|
|
|
2017-02-06 01:40:31 +00:00
|
|
|
void init(ProjectionType projectionType)
|
|
|
|
{
|
|
|
|
if (m_projector) delete m_projector;
|
|
|
|
m_projector = createProjector(projectionType);
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
m_traceCount[0] = 0;
|
|
|
|
m_traceCount[1] = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Traces
|
|
|
|
{
|
|
|
|
std::vector<TraceControl> m_tracesControl; //!< Corresponding traces control data
|
|
|
|
std::vector<TraceData> m_tracesData; //!< Corresponding traces data
|
|
|
|
std::vector<float *> m_traces[2]; //!< Double buffer of traces processed by glScope
|
|
|
|
int m_traceSize; //!< Current size of a trace in buffer
|
|
|
|
int m_maxTraceSize; //!< Maximum Size of a trace in buffer
|
|
|
|
bool evenOddIndex; //!< Even (true) or odd (false) index
|
|
|
|
|
|
|
|
Traces() : evenOddIndex(true), m_traceSize(0), m_maxTraceSize(0) {}
|
|
|
|
|
|
|
|
~Traces()
|
|
|
|
{
|
|
|
|
std::vector<float *>::iterator it0 = m_traces[0].begin();
|
|
|
|
std::vector<float *>::iterator it1 = m_traces[1].begin();
|
|
|
|
|
|
|
|
for (; it0 != m_traces[0].end(); ++it0, ++it1)
|
|
|
|
{
|
|
|
|
delete[] (*it0);
|
|
|
|
delete[] (*it1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void addTrace(const TraceData& traceData, int traceSize)
|
2017-02-05 03:41:32 +00:00
|
|
|
{
|
2017-02-06 01:40:31 +00:00
|
|
|
resize(traceSize);
|
|
|
|
|
|
|
|
m_tracesData.push_back(traceData);
|
|
|
|
m_tracesControl.push_back(TraceControl());
|
|
|
|
m_tracesControl.back().init(traceData.m_projectionType);
|
|
|
|
float *x0 = new float[2*m_traceSize];
|
|
|
|
float *x1 = new float[2*m_traceSize];
|
|
|
|
m_traces[0].push_back(x0);
|
|
|
|
m_traces[1].push_back(x1);
|
2017-01-31 07:26:13 +00:00
|
|
|
}
|
|
|
|
|
2017-02-06 01:40:31 +00:00
|
|
|
void changeTrace(const TraceData& traceData, uint32_t traceIndex)
|
2017-01-31 07:26:13 +00:00
|
|
|
{
|
2017-02-06 01:40:31 +00:00
|
|
|
if (traceIndex < m_tracesControl.size()) {
|
|
|
|
m_tracesControl[traceIndex].init(traceData.m_projectionType);
|
|
|
|
m_tracesData[traceIndex] = traceData;
|
|
|
|
}
|
|
|
|
}
|
2017-01-31 07:26:13 +00:00
|
|
|
|
2017-02-06 01:40:31 +00:00
|
|
|
void removeTrace(uint32_t traceIndex)
|
|
|
|
{
|
|
|
|
if (traceIndex < m_tracesControl.size())
|
2017-01-31 07:26:13 +00:00
|
|
|
{
|
2017-02-06 01:40:31 +00:00
|
|
|
m_tracesControl.erase(m_tracesControl.begin() + traceIndex);
|
|
|
|
m_tracesData.erase(m_tracesData.begin() + traceIndex);
|
|
|
|
delete[] (m_traces[0])[traceIndex];
|
|
|
|
delete[] (m_traces[1])[traceIndex];
|
|
|
|
m_traces[0].erase(m_traces[0].begin() + traceIndex);
|
|
|
|
m_traces[1].erase(m_traces[1].begin() + traceIndex);
|
2017-01-31 07:26:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void resize(int traceSize)
|
|
|
|
{
|
|
|
|
m_traceSize = traceSize;
|
|
|
|
|
|
|
|
if (m_traceSize > m_maxTraceSize)
|
|
|
|
{
|
2017-02-06 01:40:31 +00:00
|
|
|
std::vector<float *>::iterator it0 = m_traces[0].begin();
|
|
|
|
std::vector<float *>::iterator it1 = m_traces[1].begin();
|
|
|
|
|
|
|
|
for (; it0 != m_traces[0].end(); ++it0, ++it1)
|
|
|
|
{
|
|
|
|
delete[] (*it0);
|
|
|
|
delete[] (*it1);
|
|
|
|
*it0 = new float[2*m_traceSize];
|
|
|
|
*it1 = new float[2*m_traceSize];
|
|
|
|
}
|
|
|
|
|
2017-01-31 07:26:13 +00:00
|
|
|
m_maxTraceSize = m_traceSize;
|
|
|
|
}
|
|
|
|
}
|
2017-02-02 07:27:49 +00:00
|
|
|
|
2017-02-06 01:40:31 +00:00
|
|
|
uint32_t currentBufferIndex() const { return evenOddIndex? 0 : 1; }
|
|
|
|
uint32_t size() const { return m_tracesControl.size(); }
|
|
|
|
|
|
|
|
void switchBuffer()
|
2017-02-02 07:27:49 +00:00
|
|
|
{
|
2017-02-06 01:40:31 +00:00
|
|
|
evenOddIndex = !evenOddIndex;
|
|
|
|
|
|
|
|
for (std::vector<TraceControl>::iterator it = m_tracesControl.begin(); it != m_tracesControl.end(); ++it)
|
|
|
|
{
|
|
|
|
it->m_traceCount[currentBufferIndex()] = 0;
|
|
|
|
}
|
2017-02-02 07:27:49 +00:00
|
|
|
}
|
2017-01-29 18:51:45 +00:00
|
|
|
};
|
|
|
|
|
2017-02-08 01:13:53 +00:00
|
|
|
class TriggerComparator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TriggerComparator() : m_level(0), m_reset(true)
|
|
|
|
{
|
|
|
|
computeLevels();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool triggered(const Sample& s, TriggerCondition& triggerCondition)
|
|
|
|
{
|
|
|
|
if (triggerCondition.m_triggerData.m_triggerLevel != m_level)
|
|
|
|
{
|
|
|
|
m_level = triggerCondition.m_triggerData.m_triggerLevel;
|
|
|
|
computeLevels();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool condition, trigger;
|
|
|
|
|
|
|
|
if (triggerCondition.m_projector->getProjectionType() == ProjectionMagDB) {
|
|
|
|
condition = triggerCondition.m_projector->run(s) > m_levelPwoerDB;
|
|
|
|
} else if (triggerCondition.m_projector->getProjectionType() == ProjectionMagLin) {
|
|
|
|
condition = triggerCondition.m_projector->run(s) > m_levelPowerLin;
|
|
|
|
} else {
|
|
|
|
condition = triggerCondition.m_projector->run(s) > m_level;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_reset)
|
|
|
|
{
|
|
|
|
triggerCondition.m_prevCondition = condition;
|
|
|
|
m_reset = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (triggerCondition.m_triggerData.m_triggerBothEdges) {
|
|
|
|
trigger = triggerCondition.m_prevCondition ? !condition : condition; // This is a XOR between bools
|
|
|
|
} else if (triggerCondition.m_triggerData.m_triggerPositiveEdge) {
|
|
|
|
trigger = !triggerCondition.m_prevCondition && condition;
|
|
|
|
} else {
|
|
|
|
trigger = triggerCondition.m_prevCondition && !condition;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if (trigger) {
|
|
|
|
// qDebug("ScopeVisNG::triggered: %s/%s %f/%f",
|
|
|
|
// triggerCondition.m_prevCondition ? "T" : "F",
|
|
|
|
// condition ? "T" : "F",
|
|
|
|
// triggerCondition.m_projector->run(s),
|
|
|
|
// triggerCondition.m_triggerData.m_triggerLevel);
|
|
|
|
// }
|
|
|
|
|
|
|
|
triggerCondition.m_prevCondition = condition;
|
|
|
|
return trigger;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
m_reset = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void computeLevels()
|
|
|
|
{
|
|
|
|
m_levelPowerLin = m_level + 1.0f;
|
|
|
|
m_levelPwoerDB = (100.0f * (m_level - 1.0f));
|
|
|
|
}
|
|
|
|
|
|
|
|
Real m_level;
|
|
|
|
Real m_levelPwoerDB;
|
|
|
|
Real m_levelPowerLin;
|
|
|
|
bool m_reset;
|
|
|
|
};
|
|
|
|
|
2017-01-29 18:51:45 +00:00
|
|
|
GLScopeNG* m_glScope;
|
2017-02-07 17:50:08 +00:00
|
|
|
uint32_t m_preTriggerDelay; //!< Pre-trigger delay in number of samples
|
2017-01-29 18:51:45 +00:00
|
|
|
std::vector<TriggerCondition> m_triggerConditions; //!< Chain of triggers
|
2017-02-01 17:31:16 +00:00
|
|
|
int m_currentTriggerIndex; //!< Index of current index in the chain
|
|
|
|
TriggerState m_triggerState; //!< Current trigger state
|
2017-02-06 01:40:31 +00:00
|
|
|
Traces m_traces; //!< Displayable traces
|
2017-02-01 17:31:16 +00:00
|
|
|
int m_traceSize; //!< Size of traces in number of samples
|
2017-02-09 00:58:54 +00:00
|
|
|
int m_nbSamples; //!< Number of samples yet to process in one complex trace
|
2017-02-01 17:31:16 +00:00
|
|
|
int m_timeOfsProMill; //!< Start trace shift in 1/1000 trace size
|
|
|
|
bool m_traceStart; //!< Trace is at start point
|
|
|
|
int m_traceFill; //!< Count of samples accumulated into trace
|
|
|
|
int m_zTraceIndex; //!< Index of the trace used for Z input (luminance or false colors)
|
|
|
|
SampleVector::const_iterator m_triggerPoint; //!< Trigger start location in the samples vector
|
2017-01-29 21:52:38 +00:00
|
|
|
int m_sampleRate;
|
2017-02-01 17:31:16 +00:00
|
|
|
TraceBackDiscreteMemory m_traceDiscreteMemory; //!< Complex trace memory for triggered states TODO: vectorize when more than on input is allowed
|
2017-02-06 01:40:31 +00:00
|
|
|
bool m_freeRun; //!< True if free running (trigger globally disabled)
|
|
|
|
int m_maxTraceDelay; //!< Maximum trace delay
|
2017-02-08 01:13:53 +00:00
|
|
|
TriggerComparator m_triggerComparator; //!< Compares sample level to trigger level
|
2017-02-07 17:50:08 +00:00
|
|
|
|
2017-02-02 17:18:37 +00:00
|
|
|
/**
|
|
|
|
* Moves on to the next trigger if any or increments trigger count if in repeat mode
|
|
|
|
* - If not final it returns true
|
|
|
|
* - If final i.e. signal is actually triggerd it returns false
|
|
|
|
*/
|
|
|
|
bool nextTrigger(); //!< Returns true if not final
|
|
|
|
|
2017-02-08 21:22:27 +00:00
|
|
|
/**
|
|
|
|
* Process a sample trace which length is at most the trace length (m_traceSize)
|
|
|
|
*/
|
2017-02-09 01:16:43 +00:00
|
|
|
void processTrace(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, int& triggerPointToEnd);
|
2017-02-08 21:22:27 +00:00
|
|
|
|
2017-02-02 17:18:37 +00:00
|
|
|
/**
|
|
|
|
* Process traces from complex trace memory buffer.
|
|
|
|
* - if finished it returns the number of unprocessed samples left in the buffer
|
|
|
|
* - if not finished it returns -1
|
|
|
|
*/
|
2017-02-08 23:11:10 +00:00
|
|
|
int processTraces(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool traceBack = false);
|
2017-02-06 01:40:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get maximum trace delay
|
|
|
|
*/
|
|
|
|
void updateMaxTraceDelay();
|
2017-02-05 03:41:32 +00:00
|
|
|
|
|
|
|
/**
|
2017-02-06 01:40:31 +00:00
|
|
|
* Initialize trace buffers
|
2017-02-05 03:41:32 +00:00
|
|
|
*/
|
2017-02-06 01:40:31 +00:00
|
|
|
void initTraceBuffers();
|
2017-01-29 18:51:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* SDRBASE_DSP_SCOPEVISNG_H_ */
|