SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
deviceapi.h
Go to the documentation of this file.
1 // Copyright (C) 2019 Edouard Griffiths, F4EXB //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #ifndef SDRBASE_DEVICE_DEVICEAPI_H_
19 #define SDRBASE_DEVICE_DEVICEAPI_H_
20 
21 #include <QObject>
22 #include <QString>
23 #include <QTimer>
24 
25 #include "export.h"
26 
27 class BasebandSampleSink;
30 class ChannelAPI;
31 class DeviceSampleSink;
32 class DeviceSampleSource;
33 class DeviceSampleMIMO;
34 class MessageQueue;
35 class PluginInterface;
36 class PluginInstanceGUI;
40 class Preset;
41 
42 class SDRBASE_API DeviceAPI : public QObject {
43  Q_OBJECT
44 public:
45  enum StreamType
46  {
49  StreamMIMO
50  };
51 
52  enum EngineState {
57  StError
58  };
59 
60  DeviceAPI(
61  StreamType streamType,
62  int deviceTabIndex,
63  DSPDeviceSourceEngine *deviceSourceEngine,
64  DSPDeviceSinkEngine *deviceSinkEngine,
65  DSPDeviceMIMOEngine *deviceMIMOEngine
66  );
67  ~DeviceAPI();
68 
69  // MIMO Engine baseband / channel lists management
70  void addSourceStream(bool connect);
71  void removeLastSourceStream();
72  void addSinkStream(bool connect);
73  void removeLastSinkStream();
74 
75  void addAncillarySink(BasebandSampleSink* sink, unsigned int index = 0);
76  void removeAncillarySink(BasebandSampleSink* sink, unsigned int index = 0);
77  void setSpectrumSinkInput(bool sourceElseSink = true, unsigned int index = 0);
78 
79  void addChannelSink(ThreadedBasebandSampleSink* sink, int streamIndex = 0);
80  void removeChannelSink(ThreadedBasebandSampleSink* sink, int streamIndex = 0);
81  void addChannelSource(ThreadedBasebandSampleSource* sink, int streamIndex = 0);
82  void removeChannelSource(ThreadedBasebandSampleSource* sink, int streamIndex = 0);
83 
84  void addChannelSinkAPI(ChannelAPI* channelAPI, int streamIndex = 0);
85  void removeChannelSinkAPI(ChannelAPI* channelAPI, int streamIndex = 0);
86  void addChannelSourceAPI(ChannelAPI* channelAPI, int streamIndex = 0);
87  void removeChannelSourceAPI(ChannelAPI* channelAPI, int streamIndex = 0);
88 
89  void setSampleSource(DeviceSampleSource* source);
90  void setSampleSink(DeviceSampleSink* sink);
91  void setSampleMIMO(DeviceSampleMIMO* mimo);
92  DeviceSampleSource *getSampleSource();
93  DeviceSampleSink *getSampleSink();
94  DeviceSampleMIMO *getSampleMIMO();
95 
96  bool initDeviceEngine();
97  bool startDeviceEngine();
98  void stopDeviceEngine();
99  EngineState state() const;
100  QString errorMessage();
101  uint getDeviceUID() const;
102 
103  MessageQueue *getDeviceEngineInputMessageQueue();
104  MessageQueue *getSamplingDeviceInputMessageQueue();
105  MessageQueue *getSamplingDeviceGUIMessageQueue();
106 
107  void configureCorrections(bool dcOffsetCorrection, bool iqImbalanceCorrection, int streamIndex = 0);
108 
109  void setHardwareId(const QString& id);
110  void setSamplingDeviceId(const QString& id) { m_samplingDeviceId = id; }
111  void resetSamplingDeviceId() { m_samplingDeviceId.clear(); }
112  void setSamplingDeviceSerial(const QString& serial) { m_samplingDeviceSerial = serial; }
113  void setSamplingDeviceDisplayName(const QString& name) { m_samplingDeviceDisplayName = name; }
114  void setSamplingDeviceSequence(int sequence) { m_samplingDeviceSequence = sequence; }
115  void setHardwareUserArguments(const QString& userArguments) { m_hardwareUserArguments = userArguments; }
116  void setSamplingDevicePluginInterface(PluginInterface *iface);
117  void setSamplingDevicePluginInstanceGUI(PluginInstanceGUI *gui);
118 
119  const QString& getHardwareId() const { return m_hardwareId; }
120  const QString& getSamplingDeviceId() const { return m_samplingDeviceId; }
121  const QString& getSamplingDeviceSerial() const { return m_samplingDeviceSerial; }
122  const QString& getSamplingDeviceDisplayName() const { return m_samplingDeviceDisplayName; }
123  uint32_t getSamplingDeviceSequence() const { return m_samplingDeviceSequence; }
124  const QString& getHardwareUserArguments() const { return m_hardwareUserArguments; }
125 
126  void setDeviceNbItems(uint32_t nbItems);
127  void setDeviceItemIndex(uint32_t index);
128  uint32_t getDeviceNbItems() const { return m_deviceNbItems; }
129  uint32_t getDeviceItemIndex() const { return m_deviceItemIndex; }
130 
131  int getDeviceSetIndex() const { return m_deviceTabIndex; }
132  PluginInterface *getPluginInterface() { return m_pluginInterface; }
133 
134  PluginInstanceGUI *getSamplingDevicePluginInstanceGUI() { return m_samplingDevicePluginInstanceUI; }
135  // PluginInstanceGUI *getSampleSourcePluginInstanceGUI() { return m_sampleSourcePluginInstanceUI; }
136  // PluginInstanceGUI *getSampleSinkPluginInstanceGUI() { return m_sampleSinkPluginInstanceUI; }
137 
138  void getDeviceEngineStateStr(QString& state);
139 
140  ChannelAPI *getChanelSinkAPIAt(int index, int streamIndex = 0);
141  ChannelAPI *getChanelSourceAPIAt(int index, int streamIndex = 0);
142 
143  int getNbSourceChannels() const { return m_channelSourceAPIs.size(); }
144  int getNbSinkChannels() const { return m_channelSinkAPIs.size(); }
145 
146  void loadSamplingDeviceSettings(const Preset* preset);
147  // void loadSourceSettings(const Preset* preset);
148  // void loadSinkSettings(const Preset* preset);
149  void saveSamplingDeviceSettings(Preset* preset);
150  // void saveSourceSettings(Preset* preset);
151  // void saveSinkSettings(Preset* preset);
152 
153  DSPDeviceSourceEngine *getDeviceSourceEngine() { return m_deviceSourceEngine; }
154  DSPDeviceSinkEngine *getDeviceSinkEngine() { return m_deviceSinkEngine; }
155 
156  void addSourceBuddy(DeviceAPI* buddy);
157  void addSinkBuddy(DeviceAPI* buddy);
158  void removeSourceBuddy(DeviceAPI* buddy);
159  void removeSinkBuddy(DeviceAPI* buddy);
160  void clearBuddiesLists();
161  void *getBuddySharedPtr() const { return m_buddySharedPtr; }
162  void setBuddySharedPtr(void *ptr) { m_buddySharedPtr = ptr; }
163  bool isBuddyLeader() const { return m_isBuddyLeader; }
164  void setBuddyLeader(bool isBuddyLeader) { m_isBuddyLeader = isBuddyLeader; }
165  const std::vector<DeviceAPI*>& getSourceBuddies() const { return m_sourceBuddies; }
166  const std::vector<DeviceAPI*>& getSinkBuddies() const { return m_sinkBuddies; }
167 
168  void setNbSourceStreams(uint32_t nbSourceStreams) { m_nbSourceStreams = nbSourceStreams; }
169  void setNbSinkStreams(uint32_t nbSinkStreams) { m_nbSinkStreams = nbSinkStreams; }
170  uint32_t getNbSourceStreams() const { return m_nbSourceStreams; }
171  uint32_t getNbSinkStreams() const { return m_nbSinkStreams; }
172 
173  const QTimer& getMasterTimer() const { return m_masterTimer; }
174 
175 protected:
176  // common
177 
180  QString m_hardwareId;
186  const QTimer& m_masterTimer;
193 
194  // Buddies (single Rx or single Tx)
195 
196  std::vector<DeviceAPI*> m_sourceBuddies;
197  std::vector<DeviceAPI*> m_sinkBuddies;
200 
201  // Single Rx (i.e. source)
202 
204  QList<ChannelAPI*> m_channelSinkAPIs;
205 
206  // Single Tx (i.e. sink)
207 
209  QList<ChannelAPI*> m_channelSourceAPIs;
210 
211  // MIMO
212 
214 
215 private:
216  void renumerateChannels();
217 };
218 #endif // SDRBASE_DEVICE_DEVICEAPI_H_
void setBuddyLeader(bool isBuddyLeader)
Definition: deviceapi.h:164
const QTimer & m_masterTimer
This is the DSPEngine master timer.
Definition: deviceapi.h:186
void setNbSourceStreams(uint32_t nbSourceStreams)
Definition: deviceapi.h:168
QString m_samplingDeviceId
The internal plugin ID corresponding to the device (i.e. for HackRF input, for HackRF output ...
Definition: deviceapi.h:187
uint32_t m_deviceNbItems
Number of items in the physical device either Rx or Tx. Can be >1 for NxM devices (i...
Definition: deviceapi.h:181
bool isBuddyLeader() const
Definition: deviceapi.h:163
const std::vector< DeviceAPI * > & getSinkBuddies() const
Definition: deviceapi.h:166
Exposes a single output stream that can be one of the streams of a physical device.
Definition: deviceapi.h:48
DSPDeviceSinkEngine * m_deviceSinkEngine
Definition: deviceapi.h:208
uint32_t getDeviceItemIndex() const
Definition: deviceapi.h:129
void setNbSinkStreams(uint32_t nbSinkStreams)
Definition: deviceapi.h:169
int m_deviceTabIndex
This is the tab index in the GUI and also the device set index.
Definition: deviceapi.h:179
const QTimer & getMasterTimer() const
This is the DSPEngine master timer.
Definition: deviceapi.h:173
PluginInstanceGUI * m_samplingDevicePluginInstanceUI
Definition: deviceapi.h:192
uint32_t m_deviceItemIndex
The item index inb the Rx or Tx side of the physical device. Can be >0 for NxM devices (i...
Definition: deviceapi.h:182
uint32_t getDeviceNbItems() const
Definition: deviceapi.h:128
void setSamplingDeviceSequence(int sequence)
Definition: deviceapi.h:114
const QString & getHardwareUserArguments() const
Definition: deviceapi.h:124
PluginInterface * m_pluginInterface
Definition: deviceapi.h:185
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...
Definition: deviceapi.h:183
Exposes a single input stream that can be one of the streams of a physical device.
Definition: deviceapi.h:47
unsigned int uint32_t
Definition: rtptypes_win.h:46
DSPDeviceSourceEngine * m_deviceSourceEngine
Definition: deviceapi.h:203
void setSamplingDeviceId(const QString &id)
Definition: deviceapi.h:110
QList< ChannelAPI * > m_channelSourceAPIs
Definition: deviceapi.h:209
engine is before initialization
Definition: deviceapi.h:53
void setSamplingDeviceDisplayName(const QString &name)
Definition: deviceapi.h:113
uint32_t getNbSinkStreams() const
Definition: deviceapi.h:171
int getDeviceSetIndex() const
Definition: deviceapi.h:131
engine is idle
Definition: deviceapi.h:54
void * getBuddySharedPtr() const
Definition: deviceapi.h:161
void * m_buddySharedPtr
Definition: deviceapi.h:198
DSPDeviceSourceEngine * getDeviceSourceEngine()
Definition: deviceapi.h:153
const QString & getSamplingDeviceId() const
Definition: deviceapi.h:120
QString m_hardwareUserArguments
User given arguments to be used at hardware level i.e. for the hardware device and device sequence...
Definition: deviceapi.h:191
DSPDeviceSinkEngine * getDeviceSinkEngine()
Definition: deviceapi.h:154
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...
Definition: deviceapi.h:184
QString m_samplingDeviceSerial
The device serial number defined by the vendor or a fake one (SDRplay)
Definition: deviceapi.h:188
Definition: preset.h:28
void setBuddySharedPtr(void *ptr)
Definition: deviceapi.h:162
QString m_hardwareId
The internal id that identifies the type of hardware (i.e. HackRF, BladeRF, ...)
Definition: deviceapi.h:180
QString m_samplingDeviceDisplayName
The human readable name identifying this instance.
Definition: deviceapi.h:189
DSPDeviceMIMOEngine * m_deviceMIMOEngine
Definition: deviceapi.h:213
StreamType
< This is the same enum as in PluginInterface
Definition: deviceapi.h:45
const QString & getSamplingDeviceSerial() const
Definition: deviceapi.h:121
PluginInterface * getPluginInterface()
Definition: deviceapi.h:132
std::vector< DeviceAPI * > m_sourceBuddies
Device source APIs referencing the same physical device.
Definition: deviceapi.h:196
StreamType m_streamType
Definition: deviceapi.h:178
PluginInstanceGUI * getSamplingDevicePluginInstanceGUI()
Definition: deviceapi.h:134
const QString & getHardwareId() const
Definition: deviceapi.h:119
int getNbSourceChannels() const
Definition: deviceapi.h:143
void setSamplingDeviceSerial(const QString &serial)
Definition: deviceapi.h:112
const std::vector< DeviceAPI * > & getSourceBuddies() const
Definition: deviceapi.h:165
uint32_t getNbSourceStreams() const
Definition: deviceapi.h:170
const QString & getSamplingDeviceDisplayName() const
Definition: deviceapi.h:122
void resetSamplingDeviceId()
Definition: deviceapi.h:111
std::vector< DeviceAPI * > m_sinkBuddies
Device sink APIs referencing the same physical device.
Definition: deviceapi.h:197
engine is running
Definition: deviceapi.h:56
bool m_isBuddyLeader
Definition: deviceapi.h:199
uint32_t m_samplingDeviceSequence
The device sequence. >0 when more than one device of the same type is connected.
Definition: deviceapi.h:190
#define SDRBASE_API
Definition: export.h:40
uint32_t getSamplingDeviceSequence() const
Definition: deviceapi.h:123
void setHardwareUserArguments(const QString &userArguments)
Definition: deviceapi.h:115
QList< ChannelAPI * > m_channelSinkAPIs
Definition: deviceapi.h:204
engine is ready to run
Definition: deviceapi.h:55
int getNbSinkChannels() const
Definition: deviceapi.h:144