1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
/*
* The MIT License (MIT)
*
* Copyright (c) 2018 Matthias P. Braendli
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include <string.h>
#include <mutex>
#include <chrono>
#include <condition_variable>
#include <SoapySDR/Device.hpp>
#include <SoapySDR/Logger.hpp>
#include "CircBufferTimestamp.hpp"
class SoapyDummySession
{
public:
SoapyDummySession(void);
~SoapyDummySession(void);
};
class SoapyDummy : public SoapySDR::Device
{
public:
SoapyDummy( const SoapySDR::Kwargs & args );
SoapyDummy(const SoapyDummy& other) = delete;
SoapyDummy& operator=(const SoapyDummy& other) = delete;
~SoapyDummy( void );
/*******************************************************************
* Identification API
******************************************************************/
std::string getDriverKey( void ) const;
std::string getHardwareKey( void ) const;
SoapySDR::Kwargs getHardwareInfo( void ) const;
/*******************************************************************
* Channels API
******************************************************************/
size_t getNumChannels( const int ) const;
bool getFullDuplex( const int direction, const size_t channel ) const;
/*******************************************************************
* Stream API
******************************************************************/
std::vector<std::string> getStreamFormats(const int direction, const size_t channel) const;
std::string getNativeStreamFormat(const int direction, const size_t channel, double &fullScale) const;
SoapySDR::ArgInfoList getStreamArgsInfo(const int direction, const size_t channel) const;
SoapySDR::Stream *setupStream(
const int direction,
const std::string &format,
const std::vector<size_t> &channels = std::vector<size_t>(),
const SoapySDR::Kwargs &args = SoapySDR::Kwargs() );
void closeStream( SoapySDR::Stream *stream );
size_t getStreamMTU( SoapySDR::Stream *stream ) const;
int activateStream(
SoapySDR::Stream *stream,
const int flags = 0,
const long long timeNs = 0,
const size_t numElems = 0 );
int deactivateStream(
SoapySDR::Stream *stream,
const int flags = 0,
const long long timeNs = 0 );
int readStream(
SoapySDR::Stream *stream,
void * const *buffs,
const size_t numElems,
int &flags,
long long &timeNs,
const long timeoutUs = 100000 );
int writeStream(
SoapySDR::Stream *stream,
const void * const *buffs,
const size_t numElems,
int &flags,
const long long timeNs = 0,
const long timeoutUs = 100000);
int readStreamStatus(
SoapySDR::Stream *stream,
size_t &chanMask,
int &flags,
long long &timeNs,
const long timeoutUs
);
size_t getNumDirectAccessBuffers(SoapySDR::Stream *stream);
/*******************************************************************
* Settings API
******************************************************************/
SoapySDR::ArgInfoList getSettingInfo(void) const;
void writeSetting(const std::string &key, const std::string &value);
std::string readSetting(const std::string &key) const;
/*******************************************************************
* Antenna API
******************************************************************/
std::vector<std::string> listAntennas( const int direction, const size_t channel ) const;
void setAntenna( const int direction, const size_t channel, const std::string &name );
std::string getAntenna( const int direction, const size_t channel ) const;
/*******************************************************************
* Frontend corrections API
******************************************************************/
bool hasDCOffsetMode( const int direction, const size_t channel ) const;
/*******************************************************************
* Gain API
******************************************************************/
std::vector<std::string> listGains( const int direction, const size_t channel ) const;
void setGainMode( const int direction, const size_t channel, const bool automatic );
bool getGainMode( const int direction, const size_t channel ) const;
void setGain( const int direction, const size_t channel, const double value );
void setGain( const int direction, const size_t channel, const std::string &name, const double value );
double getGain( const int direction, const size_t channel, const std::string &name ) const;
SoapySDR::Range getGainRange( const int direction, const size_t channel, const std::string &name ) const;
/*******************************************************************
* Frequency API
******************************************************************/
void setFrequency( const int direction, const size_t channel, const std::string &name, const double frequency, const SoapySDR::Kwargs &args = SoapySDR::Kwargs() );
double getFrequency( const int direction, const size_t channel, const std::string &name ) const;
SoapySDR::ArgInfoList getFrequencyArgsInfo(const int direction, const size_t channel) const;
std::vector<std::string> listFrequencies( const int direction, const size_t channel ) const;
SoapySDR::RangeList getFrequencyRange( const int direction, const size_t channel, const std::string &name ) const;
/*******************************************************************
* Sample Rate API
******************************************************************/
void setSampleRate( const int direction, const size_t channel, const double rate );
double getSampleRate( const int direction, const size_t channel ) const;
std::vector<double> listSampleRates( const int direction, const size_t channel ) const;
void setBandwidth( const int direction, const size_t channel, const double bw );
double getBandwidth( const int direction, const size_t channel ) const;
std::vector<double> listBandwidths( const int direction, const size_t channel ) const;
/*******************************************************************
* Time API
******************************************************************/
virtual std::vector<std::string> listTimeSources(void) const;
virtual void setTimeSource(const std::string &source);
virtual std::string getTimeSource(void) const;
virtual bool hasHardwareTime(const std::string &what = "") const;
virtual long long getHardwareTime(const std::string &what = "") const;
virtual void setHardwareTime(const long long timeNs, const std::string &what = "");
/*******************************************************************
* Dummy callback
******************************************************************/
int dummy_tx_callback( int8_t *buffer, int32_t length );
int dummy_rx_callback( int8_t *buffer, int32_t length );
private:
struct DummyStream {
const size_t mtu = 1024;
bool active = false;
};
DummyStream m_rxstream;
DummyStream m_txstream;
SoapySDR::Stream* const TX_STREAM = (SoapySDR::Stream*) 0x1;
SoapySDR::Stream* const RX_STREAM = (SoapySDR::Stream*) 0x2;
CircularBuffer<std::complex<float> > m_circ_buffer;
SoapyDummySession m_session;
double m_samplerate = 0;
double m_frequency = 0;
long long m_time_epoch;
};
|