2015-10-14 22:05:19 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2023-11-19 00:43:20 -05:00
|
|
|
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
|
|
|
|
// written by Christian Daniel //
|
|
|
|
// Copyright (C) 2014 John Greb <hexameron@spam.no> //
|
|
|
|
// Copyright (C) 2015-2019, 2023 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
|
|
|
|
// Copyright (C) 2022 Jon Beniston, M7RCE <jon@beniston.com> //
|
2015-10-14 22:05:19 -04:00
|
|
|
// //
|
|
|
|
// 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 //
|
2019-04-11 08:32:15 -04:00
|
|
|
// (at your option) any later version. //
|
2015-10-14 22:05:19 -04:00
|
|
|
// //
|
|
|
|
// 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 INCLUDE_DSPDEVICEENGINE_H
|
|
|
|
#define INCLUDE_DSPDEVICEENGINE_H
|
|
|
|
|
2024-08-14 16:08:49 -04:00
|
|
|
#include <QObject>
|
2015-10-14 22:05:19 -04:00
|
|
|
#include <QTimer>
|
|
|
|
#include <QMutex>
|
|
|
|
#include <QWaitCondition>
|
|
|
|
#include "dsp/dsptypes.h"
|
|
|
|
#include "util/messagequeue.h"
|
2018-03-20 08:49:21 -04:00
|
|
|
#include "export.h"
|
2018-01-31 20:45:55 -05:00
|
|
|
#include "util/movingaverage.h"
|
2015-10-14 22:05:19 -04:00
|
|
|
|
2016-10-02 17:16:40 -04:00
|
|
|
class DeviceSampleSource;
|
2016-10-02 16:29:04 -04:00
|
|
|
class BasebandSampleSink;
|
2015-10-14 22:05:19 -04:00
|
|
|
|
2024-08-14 16:08:49 -04:00
|
|
|
class SDRBASE_API DSPDeviceSourceEngine : public QObject {
|
2015-10-14 22:05:19 -04:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2024-08-24 07:17:02 -04:00
|
|
|
enum class State {
|
2015-10-14 22:05:19 -04:00
|
|
|
StNotStarted, //!< engine is before initialization
|
|
|
|
StIdle, //!< engine is idle
|
|
|
|
StReady, //!< engine is ready to run
|
|
|
|
StRunning, //!< engine is running
|
|
|
|
StError //!< engine is in error
|
|
|
|
};
|
|
|
|
|
2024-08-14 11:24:21 -04:00
|
|
|
DSPDeviceSourceEngine(uint uid, QObject* parent = nullptr);
|
2024-08-24 07:17:02 -04:00
|
|
|
~DSPDeviceSourceEngine() final;
|
2015-10-14 22:05:19 -04:00
|
|
|
|
2016-05-11 13:14:23 -04:00
|
|
|
uint getUID() const { return m_uid; }
|
|
|
|
|
2015-10-14 22:05:19 -04:00
|
|
|
MessageQueue* getInputMessageQueue() { return &m_inputMessageQueue; }
|
|
|
|
|
2024-08-24 07:17:02 -04:00
|
|
|
bool initAcquisition() const; //!< Initialize acquisition sequence
|
2015-10-14 22:05:19 -04:00
|
|
|
bool startAcquisition(); //!< Start acquisition sequence
|
|
|
|
void stopAcquistion(); //!< Stop acquisition sequence
|
|
|
|
|
2016-10-02 17:16:40 -04:00
|
|
|
void setSource(DeviceSampleSource* source); //!< Set the sample source type
|
2015-10-14 22:05:19 -04:00
|
|
|
void setSourceSequence(int sequence); //!< Set the sample source sequence in type
|
2017-09-05 07:57:49 -04:00
|
|
|
DeviceSampleSource *getSource() { return m_deviceSampleSource; }
|
2015-10-14 22:05:19 -04:00
|
|
|
|
2016-10-02 16:29:04 -04:00
|
|
|
void addSink(BasebandSampleSink* sink); //!< Add a sample sink
|
|
|
|
void removeSink(BasebandSampleSink* sink); //!< Remove a sample sink
|
2015-10-14 22:05:19 -04:00
|
|
|
|
|
|
|
void configureCorrections(bool dcOffsetCorrection, bool iqImbalanceCorrection); //!< Configure DSP corrections
|
|
|
|
|
|
|
|
State state() const { return m_state; } //!< Return DSP engine current state
|
|
|
|
|
2024-08-14 11:24:21 -04:00
|
|
|
QString errorMessage() const; //!< Return the current error message
|
|
|
|
QString sourceDeviceDescription() const; //!< Return the source device description
|
2015-10-14 22:05:19 -04:00
|
|
|
|
|
|
|
private:
|
2016-05-11 13:14:23 -04:00
|
|
|
uint m_uid; //!< unique ID
|
|
|
|
|
2015-10-14 22:05:19 -04:00
|
|
|
MessageQueue m_inputMessageQueue; //<! Input message queue. Post here.
|
|
|
|
|
|
|
|
State m_state;
|
|
|
|
|
|
|
|
QString m_errorMessage;
|
|
|
|
QString m_deviceDescription;
|
|
|
|
|
2016-10-03 19:49:28 -04:00
|
|
|
DeviceSampleSource* m_deviceSampleSource;
|
2015-10-14 22:05:19 -04:00
|
|
|
int m_sampleSourceSequence;
|
|
|
|
|
2024-08-14 11:24:21 -04:00
|
|
|
using BasebandSampleSinks = std::list<BasebandSampleSink *>;
|
2016-10-03 19:49:28 -04:00
|
|
|
BasebandSampleSinks m_basebandSampleSinks; //!< sample sinks within main thread (usually spectrum, file output)
|
2015-10-14 22:05:19 -04:00
|
|
|
|
|
|
|
uint m_sampleRate;
|
|
|
|
quint64 m_centerFrequency;
|
2023-06-17 18:44:20 -04:00
|
|
|
bool m_realElseComplex;
|
2015-10-14 22:05:19 -04:00
|
|
|
|
|
|
|
bool m_dcOffsetCorrection;
|
|
|
|
bool m_iqImbalanceCorrection;
|
2024-08-14 11:24:21 -04:00
|
|
|
double m_iOffset;
|
|
|
|
double m_qOffset;
|
2018-02-04 12:20:16 -05:00
|
|
|
|
2018-01-31 20:45:55 -05:00
|
|
|
MovingAverageUtil<int32_t, int64_t, 1024> m_iBeta;
|
|
|
|
MovingAverageUtil<int32_t, int64_t, 1024> m_qBeta;
|
2018-02-04 12:20:16 -05:00
|
|
|
|
|
|
|
#if IMBALANCE_INT
|
|
|
|
// Fixed point DC + IQ corrections
|
|
|
|
MovingAverageUtil<int64_t, int64_t, 128> m_avgII;
|
|
|
|
MovingAverageUtil<int64_t, int64_t, 128> m_avgIQ;
|
|
|
|
MovingAverageUtil<int64_t, int64_t, 128> m_avgPhi;
|
|
|
|
MovingAverageUtil<int64_t, int64_t, 128> m_avgII2;
|
|
|
|
MovingAverageUtil<int64_t, int64_t, 128> m_avgQQ2;
|
|
|
|
MovingAverageUtil<int64_t, int64_t, 128> m_avgAmp;
|
|
|
|
|
|
|
|
#else
|
|
|
|
// Floating point DC + IQ corrections
|
2018-02-04 04:49:13 -05:00
|
|
|
MovingAverageUtil<float, double, 128> m_avgII;
|
|
|
|
MovingAverageUtil<float, double, 128> m_avgIQ;
|
|
|
|
MovingAverageUtil<float, double, 128> m_avgII2;
|
|
|
|
MovingAverageUtil<float, double, 128> m_avgQQ2;
|
|
|
|
MovingAverageUtil<double, double, 128> m_avgPhi;
|
|
|
|
MovingAverageUtil<double, double, 128> m_avgAmp;
|
2018-02-04 12:20:16 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
qint32 m_iRange;
|
2015-10-14 22:05:19 -04:00
|
|
|
qint32 m_qRange;
|
|
|
|
qint32 m_imbalance;
|
|
|
|
|
2018-01-31 20:45:55 -05:00
|
|
|
void iqCorrections(SampleVector::iterator begin, SampleVector::iterator end, bool imbalanceCorrection);
|
2015-10-14 22:05:19 -04:00
|
|
|
void dcOffset(SampleVector::iterator begin, SampleVector::iterator end);
|
|
|
|
void imbalance(SampleVector::iterator begin, SampleVector::iterator end);
|
|
|
|
void work(); //!< transfer samples from source to sinks if in running state
|
|
|
|
|
|
|
|
State gotoIdle(); //!< Go to the idle state
|
|
|
|
State gotoInit(); //!< Go to the acquisition init state from idle
|
|
|
|
State gotoRunning(); //!< Go to the running state from ready state
|
|
|
|
State gotoError(const QString& errorMsg); //!< Go to an error state
|
2022-08-27 05:18:17 -04:00
|
|
|
void setState(State state);
|
2015-10-14 22:05:19 -04:00
|
|
|
|
2016-10-02 17:16:40 -04:00
|
|
|
void handleSetSource(DeviceSampleSource* source); //!< Manage source setting
|
2024-08-14 11:24:21 -04:00
|
|
|
bool handleMessage(const Message& cmd);
|
2015-10-14 22:05:19 -04:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void handleData(); //!< Handle data when samples from source FIFO are ready to be processed
|
|
|
|
void handleInputMessages(); //!< Handle input message queue
|
2022-08-27 05:18:17 -04:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void stateChanged();
|
2024-10-10 08:57:11 -04:00
|
|
|
|
|
|
|
void acquistionStopped();
|
|
|
|
void sampleSet();
|
|
|
|
void sinkRemoved();
|
2015-10-14 22:05:19 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INCLUDE_DSPDEVICEENGINE_H
|