2019-05-07 22:30:40 +00:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2019 Edouard Griffiths, F4EXB //
// //
// 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 //
// (at your option) any later version. //
// //
// 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_DEVICE_DEVICEAPI_H_
# define SDRBASE_DEVICE_DEVICEAPI_H_
# include <QObject>
# include <QString>
# include <QTimer>
# include "export.h"
class BasebandSampleSink ;
class ThreadedBasebandSampleSink ;
2019-11-15 00:04:24 +00:00
class BasebandSampleSource ;
2019-09-04 03:00:22 +00:00
class MIMOChannel ;
2019-05-09 15:27:12 +00:00
class ChannelAPI ;
2019-05-07 22:30:40 +00:00
class DeviceSampleSink ;
class DeviceSampleSource ;
2019-05-18 04:30:37 +00:00
class DeviceSampleMIMO ;
2019-05-07 22:30:40 +00:00
class MessageQueue ;
class PluginInterface ;
class PluginInstanceGUI ;
class DSPDeviceSourceEngine ;
class DSPDeviceSinkEngine ;
2019-05-18 04:30:37 +00:00
class DSPDeviceMIMOEngine ;
2019-05-07 22:30:40 +00:00
class Preset ;
class SDRBASE_API DeviceAPI : public QObject {
Q_OBJECT
public :
enum StreamType //!< This is the same enum as in PluginInterface
{
StreamSingleRx , //!< Exposes a single input stream that can be one of the streams of a physical device
StreamSingleTx , //!< Exposes a single output stream that can be one of the streams of a physical device
2019-05-20 14:31:15 +00:00
StreamMIMO //!< May expose any number of input and/or output streams
2019-05-07 22:30:40 +00:00
} ;
enum EngineState {
StNotStarted , //!< engine is before initialization
StIdle , //!< engine is idle
StReady , //!< engine is ready to run
StRunning , //!< engine is running
StError //!< engine is in error
} ;
DeviceAPI (
StreamType streamType ,
int deviceTabIndex ,
DSPDeviceSourceEngine * deviceSourceEngine ,
2019-05-18 04:30:37 +00:00
DSPDeviceSinkEngine * deviceSinkEngine ,
DSPDeviceMIMOEngine * deviceMIMOEngine
2019-05-07 22:30:40 +00:00
) ;
~ DeviceAPI ( ) ;
2019-05-28 06:56:36 +00:00
void addAncillarySink ( BasebandSampleSink * sink , unsigned int index = 0 ) ; //!< Adds a sink to receive full baseband and that is not a channel (e.g. spectrum)
void removeAncillarySink ( BasebandSampleSink * sink , unsigned int index = 0 ) ; //!< Removes it
2019-05-19 08:23:18 +00:00
void setSpectrumSinkInput ( bool sourceElseSink = true , unsigned int index = 0 ) ; //!< Used in the MIMO case to select which stream is used as input to main spectrum
2019-05-07 22:30:40 +00:00
void addChannelSink ( ThreadedBasebandSampleSink * sink , int streamIndex = 0 ) ; //!< Add a channel sink (Rx)
void removeChannelSink ( ThreadedBasebandSampleSink * sink , int streamIndex = 0 ) ; //!< Remove a channel sink (Rx)
2019-11-15 00:04:24 +00:00
void addChannelSource ( BasebandSampleSource * sink , int streamIndex = 0 ) ; //!< Add a channel source (Tx)
void removeChannelSource ( BasebandSampleSource * sink , int streamIndex = 0 ) ; //!< Remove a channel source (Tx)
2019-09-04 03:00:22 +00:00
void addMIMOChannel ( MIMOChannel * channel ) ; //!< Add a MIMO channel (n Rx and m Tx combination)
void removeMIMOChannel ( MIMOChannel * channe ) ; //!< Remove a MIMO channel (n Rx and m Tx combination)
2019-05-07 22:30:40 +00:00
2019-05-09 15:27:12 +00:00
void addChannelSinkAPI ( ChannelAPI * channelAPI , int streamIndex = 0 ) ;
void removeChannelSinkAPI ( ChannelAPI * channelAPI , int streamIndex = 0 ) ;
void addChannelSourceAPI ( ChannelAPI * channelAPI , int streamIndex = 0 ) ;
void removeChannelSourceAPI ( ChannelAPI * channelAPI , int streamIndex = 0 ) ;
2019-09-04 03:00:22 +00:00
void addMIMOChannelAPI ( ChannelAPI * channelAPI ) ;
void removeMIMOChannelAPI ( ChannelAPI * channelAPI ) ;
2019-05-07 22:30:40 +00:00
void setSampleSource ( DeviceSampleSource * source ) ; //!< Set the device sample source (single Rx)
void setSampleSink ( DeviceSampleSink * sink ) ; //!< Set the device sample sink (single Tx)
2019-05-18 04:30:37 +00:00
void setSampleMIMO ( DeviceSampleMIMO * mimo ) ; //!< Set the device sample MIMO
2019-05-07 22:30:40 +00:00
DeviceSampleSource * getSampleSource ( ) ; //!< Return pointer to the device sample source (single Rx) or nullptr
DeviceSampleSink * getSampleSink ( ) ; //!< Return pointer to the device sample sink (single Tx) or nullptr
2019-05-18 04:30:37 +00:00
DeviceSampleMIMO * getSampleMIMO ( ) ; //!< Return pointer to the device sample MIMO or nullptr
2019-05-07 22:30:40 +00:00
2019-10-20 18:05:01 +00:00
bool initDeviceEngine ( int subsystemIndex = 0 ) ; //!< Init the device engine corresponding to the stream type
bool startDeviceEngine ( int subsystemIndex = 0 ) ; //!< Start the device engine corresponding to the stream type
void stopDeviceEngine ( int subsystemIndex = 0 ) ; //!< Stop the device engine corresponding to the stream type
EngineState state ( int subsystemIndex = 0 ) const ; //!< Return the state of the device engine corresponding to the stream type
QString errorMessage ( int subsystemIndex = 0 ) ; //!< Last error message from the device engine
2019-05-07 22:30:40 +00:00
uint getDeviceUID ( ) const ; //!< Return the current device engine unique ID
MessageQueue * getDeviceEngineInputMessageQueue ( ) ; //!< Device engine message queue
MessageQueue * getSamplingDeviceInputMessageQueue ( ) ; //!< Sampling device (ex: single Rx) input message queue
MessageQueue * getSamplingDeviceGUIMessageQueue ( ) ; //!< Sampling device (ex: single Tx) GUI input message queue
void configureCorrections ( bool dcOffsetCorrection , bool iqImbalanceCorrection , int streamIndex = 0 ) ; //!< Configure current device engine DSP corrections (Rx)
void setHardwareId ( const QString & id ) ;
2019-05-08 20:11:53 +00:00
void setSamplingDeviceId ( const QString & id ) { m_samplingDeviceId = id ; }
void resetSamplingDeviceId ( ) { m_samplingDeviceId . clear ( ) ; }
void setSamplingDeviceSerial ( const QString & serial ) { m_samplingDeviceSerial = serial ; }
void setSamplingDeviceDisplayName ( const QString & name ) { m_samplingDeviceDisplayName = name ; }
void setSamplingDeviceSequence ( int sequence ) { m_samplingDeviceSequence = sequence ; }
2019-06-13 16:43:06 +00:00
void setHardwareUserArguments ( const QString & userArguments ) { m_hardwareUserArguments = userArguments ; }
2019-05-07 22:30:40 +00:00
void setSamplingDevicePluginInterface ( PluginInterface * iface ) ;
void setSamplingDevicePluginInstanceGUI ( PluginInstanceGUI * gui ) ;
const QString & getHardwareId ( ) const { return m_hardwareId ; }
2019-05-08 20:11:53 +00:00
const QString & getSamplingDeviceId ( ) const { return m_samplingDeviceId ; }
const QString & getSamplingDeviceSerial ( ) const { return m_samplingDeviceSerial ; }
const QString & getSamplingDeviceDisplayName ( ) const { return m_samplingDeviceDisplayName ; }
uint32_t getSamplingDeviceSequence ( ) const { return m_samplingDeviceSequence ; }
2019-06-13 16:43:06 +00:00
const QString & getHardwareUserArguments ( ) const { return m_hardwareUserArguments ; }
2019-05-07 22:30:40 +00:00
2019-05-20 22:27:08 +00:00
void setDeviceNbItems ( uint32_t nbItems ) ;
void setDeviceItemIndex ( uint32_t index ) ;
uint32_t getDeviceNbItems ( ) const { return m_deviceNbItems ; }
uint32_t getDeviceItemIndex ( ) const { return m_deviceItemIndex ; }
2019-05-07 22:30:40 +00:00
int getDeviceSetIndex ( ) const { return m_deviceTabIndex ; }
PluginInterface * getPluginInterface ( ) { return m_pluginInterface ; }
2019-05-08 20:11:53 +00:00
PluginInstanceGUI * getSamplingDevicePluginInstanceGUI ( ) { return m_samplingDevicePluginInstanceUI ; }
2019-05-07 22:30:40 +00:00
// PluginInstanceGUI *getSampleSourcePluginInstanceGUI() { return m_sampleSourcePluginInstanceUI; }
// PluginInstanceGUI *getSampleSinkPluginInstanceGUI() { return m_sampleSinkPluginInstanceUI; }
void getDeviceEngineStateStr ( QString & state ) ;
2019-05-09 15:27:12 +00:00
ChannelAPI * getChanelSinkAPIAt ( int index , int streamIndex = 0 ) ;
ChannelAPI * getChanelSourceAPIAt ( int index , int streamIndex = 0 ) ;
2019-05-07 22:30:40 +00:00
int getNbSourceChannels ( ) const { return m_channelSourceAPIs . size ( ) ; }
int getNbSinkChannels ( ) const { return m_channelSinkAPIs . size ( ) ; }
void loadSamplingDeviceSettings ( const Preset * preset ) ;
// void loadSourceSettings(const Preset* preset);
// void loadSinkSettings(const Preset* preset);
void saveSamplingDeviceSettings ( Preset * preset ) ;
// void saveSourceSettings(Preset* preset);
// void saveSinkSettings(Preset* preset);
DSPDeviceSourceEngine * getDeviceSourceEngine ( ) { return m_deviceSourceEngine ; }
DSPDeviceSinkEngine * getDeviceSinkEngine ( ) { return m_deviceSinkEngine ; }
void addSourceBuddy ( DeviceAPI * buddy ) ;
void addSinkBuddy ( DeviceAPI * buddy ) ;
void removeSourceBuddy ( DeviceAPI * buddy ) ;
void removeSinkBuddy ( DeviceAPI * buddy ) ;
void clearBuddiesLists ( ) ;
void * getBuddySharedPtr ( ) const { return m_buddySharedPtr ; }
void setBuddySharedPtr ( void * ptr ) { m_buddySharedPtr = ptr ; }
bool isBuddyLeader ( ) const { return m_isBuddyLeader ; }
void setBuddyLeader ( bool isBuddyLeader ) { m_isBuddyLeader = isBuddyLeader ; }
const std : : vector < DeviceAPI * > & getSourceBuddies ( ) const { return m_sourceBuddies ; }
const std : : vector < DeviceAPI * > & getSinkBuddies ( ) const { return m_sinkBuddies ; }
2019-05-20 22:27:08 +00:00
void setNbSourceStreams ( uint32_t nbSourceStreams ) { m_nbSourceStreams = nbSourceStreams ; }
void setNbSinkStreams ( uint32_t nbSinkStreams ) { m_nbSinkStreams = nbSinkStreams ; }
uint32_t getNbSourceStreams ( ) const { return m_nbSourceStreams ; }
uint32_t getNbSinkStreams ( ) const { return m_nbSinkStreams ; }
2019-05-07 22:30:40 +00:00
const QTimer & getMasterTimer ( ) const { return m_masterTimer ; } //!< This is the DSPEngine master timer
protected :
// common
StreamType m_streamType ;
2019-05-08 20:11:53 +00:00
int m_deviceTabIndex ; //!< This is the tab index in the GUI and also the device set index
QString m_hardwareId ; //!< The internal id that identifies the type of hardware (i.e. HackRF, BladeRF, ...)
2019-05-20 22:27:08 +00:00
uint32_t m_deviceNbItems ; //!< Number of items in the physical device either Rx or Tx. Can be >1 for NxM devices (i.e. 2 for LimeSDR)
uint32_t m_deviceItemIndex ; //!< The item index inb the Rx or Tx side of the physical device. Can be >0 for NxM devices (i.e. 0 or 1 for LimeSDR)
uint32_t m_nbSourceStreams ; //!< The number of source streams in the logical device. 1 for Single Rx (SI) can be 0 or more for MIMO
uint32_t m_nbSinkStreams ; //!< The number of sink streams in the logical device. 1 for Single Tx (SO) can be 0 or more for MIMO
2019-05-07 22:30:40 +00:00
PluginInterface * m_pluginInterface ;
2019-05-08 20:11:53 +00:00
const QTimer & m_masterTimer ; //!< This is the DSPEngine master timer
QString m_samplingDeviceId ; //!< The internal plugin ID corresponding to the device (i.e. for HackRF input, for HackRF output ...)
QString m_samplingDeviceSerial ; //!< The device serial number defined by the vendor or a fake one (SDRplay)
QString m_samplingDeviceDisplayName ; //!< The human readable name identifying this instance
uint32_t m_samplingDeviceSequence ; //!< The device sequence. >0 when more than one device of the same type is connected
2019-06-13 16:43:06 +00:00
QString m_hardwareUserArguments ; //!< User given arguments to be used at hardware level i.e. for the hardware device and device sequence
2019-05-08 20:11:53 +00:00
PluginInstanceGUI * m_samplingDevicePluginInstanceUI ;
2019-05-07 22:30:40 +00:00
// Buddies (single Rx or single Tx)
std : : vector < DeviceAPI * > m_sourceBuddies ; //!< Device source APIs referencing the same physical device
std : : vector < DeviceAPI * > m_sinkBuddies ; //!< Device sink APIs referencing the same physical device
void * m_buddySharedPtr ;
bool m_isBuddyLeader ;
// Single Rx (i.e. source)
DSPDeviceSourceEngine * m_deviceSourceEngine ;
2019-05-09 15:27:12 +00:00
QList < ChannelAPI * > m_channelSinkAPIs ;
2019-05-07 22:30:40 +00:00
// Single Tx (i.e. sink)
DSPDeviceSinkEngine * m_deviceSinkEngine ;
2019-05-09 15:27:12 +00:00
QList < ChannelAPI * > m_channelSourceAPIs ;
2019-05-07 22:30:40 +00:00
2019-05-18 04:30:37 +00:00
// MIMO
DSPDeviceMIMOEngine * m_deviceMIMOEngine ;
2019-09-04 03:00:22 +00:00
QList < ChannelAPI * > m_mimoChannelAPIs ;
2019-05-18 04:30:37 +00:00
2019-05-07 22:30:40 +00:00
private :
void renumerateChannels ( ) ;
} ;
# endif // SDRBASE_DEVICE_DEVICEAPI_H_