aboutsummaryrefslogtreecommitdiffstats
path: root/Dummy_Settings.cpp
blob: d449329dce4f792e4a8e8491045bad21f9056613 (plain)
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/*
 * 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.
 */

#include "SoapyDummy.hpp"


SoapyDummy::SoapyDummy( const SoapySDR::Kwargs &args )
    : m_circ_buffer(1000000)
{
    // On startup, initialise our epoch to current time, so that
    // it appears the counter just started counting
    using namespace std::chrono;
    const auto now = steady_clock::now();
    m_time_epoch = duration_cast<nanoseconds>(now.time_since_epoch()).count();
}

SoapyDummy::~SoapyDummy( void )
{
}

/*******************************************************************
 * Identification API
 ******************************************************************/
std::string SoapyDummy::getDriverKey( void ) const
{
    return("Dummy");
}

std::string SoapyDummy::getHardwareKey( void ) const
{
    return "DummyHWKey";
}

SoapySDR::Kwargs SoapyDummy::getHardwareInfo( void ) const
{
    SoapySDR::Kwargs info;
    info["version"] = "1";
    info["clock source"] = "fictious";
    return info;
}

/*******************************************************************
 * Channels API
 ******************************************************************/
size_t SoapyDummy::getNumChannels( const int dir ) const
{
    return 1;
}


bool SoapyDummy::getFullDuplex( const int direction, const size_t channel ) const
{
    return true;
}

/*******************************************************************
 * Settings API
 ******************************************************************/
SoapySDR::ArgInfoList SoapyDummy::getSettingInfo(void) const
{
    SoapySDR::ArgInfoList setArgs;

    /* example setting from hackrf
    SoapySDR::ArgInfo biastxArg;
    biastxArg.key="bias_tx";
    biastxArg.value="false";
    biastxArg.name="Antenna Bias";
    biastxArg.description="Antenna port power control.";
    biastxArg.type=SoapySDR::ArgInfo::BOOL;
    setArgs.push_back(biastxArg);
    */

    return setArgs;
}

void SoapyDummy::writeSetting(const std::string &key, const std::string &value)
{
    /*
    if(key=="bias_tx"){
        std::lock_guard<std::mutex> lock(_device_mutex);
        _tx_stream.bias=(value=="true") ? true : false;
        int ret=hackrf_set_antenna_enable(_dev,_tx_stream.bias);
        if(ret!=HACKRF_SUCCESS){

            SoapySDR_logf(SOAPY_SDR_INFO,"Failed to apply antenna bias voltage");

        }
    }
    */
}

std::string SoapyDummy::readSetting(const std::string &key) const
{
    /*
    if (key == "bias_tx") {
        return _tx_stream.bias?"true":"false";
    }
    */
    return "";
}

/*******************************************************************
 * Antenna API
 ******************************************************************/
std::vector<std::string> SoapyDummy::listAntennas( const int direction, const size_t channel ) const
{
    std::vector<std::string> options;
    if ( direction == SOAPY_SDR_RX ) {
        options.push_back("RX");
    }
    else {
        options.push_back("TX");
    }
    return options;
}

void SoapyDummy::setAntenna( const int direction, const size_t channel, const std::string &name )
{
    /* TODO delete this function or throw if name != RX... */
}

std::string SoapyDummy::getAntenna( const int direction, const size_t channel ) const
{
    if ( direction == SOAPY_SDR_RX ) {
        return "RX";
    }
    else {
        return "TX";
    }
}

/*******************************************************************
 * Frontend corrections API
 ******************************************************************/
bool SoapyDummy::hasDCOffsetMode( const int direction, const size_t channel ) const
{
    return false;
}


/*******************************************************************
 * Gain API
 ******************************************************************/
std::vector<std::string> SoapyDummy::listGains( const int direction, const size_t channel ) const
{
    std::vector<std::string> options;
    options.push_back( "GAIN" );

    return options;
}


void SoapyDummy::setGainMode( const int direction, const size_t channel, const bool automatic )
{
    /* enable AGC if the hardware supports it, or remove this function */
}


bool SoapyDummy::getGainMode( const int direction, const size_t channel ) const
{
    return false;
}


void SoapyDummy::setGain( const int direction, const size_t channel, const double value )
{
    if ( direction == SOAPY_SDR_RX ) {
    }
    else if ( direction == SOAPY_SDR_TX ) {
    }
}

void SoapyDummy::setGain( const int direction, const size_t channel, const std::string &name, const double value )
{

}


double SoapyDummy::getGain( const int direction, const size_t channel, const std::string &name ) const
{
    return 10.0;
}


SoapySDR::Range SoapyDummy::getGainRange( const int direction, const size_t channel, const std::string &name ) const
{
    if (name == "GAIN") {
        return(SoapySDR::Range( 0, 60 ) );
    }
    return(SoapySDR::Range( 0, 0 ) );
}


/*******************************************************************
 * Frequency API
 ******************************************************************/
void SoapyDummy::setFrequency( const int direction, const size_t channel, const std::string &name, const double frequency, const SoapySDR::Kwargs &args )
{
    if ( name != "RF" ) {
        throw std::runtime_error( "setFrequency(" + name + ") unknown name" );
    }

    if (direction==SOAPY_SDR_RX){
        m_frequency = frequency;
    }
    else if (direction==SOAPY_SDR_TX){
        m_frequency = frequency;
    }
}


double SoapyDummy::getFrequency( const int direction, const size_t channel, const std::string &name ) const
{
    if ( name != "RF" ) {
        throw std::runtime_error( "getFrequency(" + name + ") unknown name" );
    }

    double freq = 0.0;

    if (direction==SOAPY_SDR_RX){
        freq = m_frequency;
    }
    else if (direction==SOAPY_SDR_TX){
        freq = m_frequency;
    }
    return freq;
}

SoapySDR::ArgInfoList SoapyDummy::getFrequencyArgsInfo(const int direction, const size_t channel) const
{
    SoapySDR::ArgInfoList freqArgs;
    return freqArgs;
}

std::vector<std::string> SoapyDummy::listFrequencies( const int direction, const size_t channel ) const
{
    std::vector<std::string> names;
    names.push_back( "RF" );
    return names;
}

SoapySDR::RangeList SoapyDummy::getFrequencyRange( const int direction, const size_t channel, const std::string &name ) const
{
    if ( name != "RF" )
        throw std::runtime_error( "getFrequencyRange(" + name + ") unknown name" );
    return(SoapySDR::RangeList( 1, SoapySDR::Range( 0, 7250000000ull ) ) );
}

/*******************************************************************
 * Sample Rate API
 ******************************************************************/
void SoapyDummy::setSampleRate( const int direction, const size_t channel, const double rate )
{
    m_samplerate = rate;

    // ticks are in nanoseconds
    m_circ_buffer.set_ticks_per_sample(std::lrint(1e9 / rate));
}

double SoapyDummy::getSampleRate( const int direction, const size_t channel ) const
{
    return m_samplerate;
}

std::vector<double> SoapyDummy::listSampleRates( const int direction, const size_t channel ) const
{
    std::vector<double> options;
    for ( double r = 1e6; r <= 20e6; r += 1e6 ) {
        options.push_back( r );
    }
    return options;
}


void SoapyDummy::setBandwidth( const int direction, const size_t channel, const double bw )
{
}


double SoapyDummy::getBandwidth( const int direction, const size_t channel ) const
{
    return 8000000;
}

std::vector<double> SoapyDummy::listBandwidths( const int direction, const size_t channel ) const
{
    std::vector<double> options;
    options.push_back( 8000000 );
    return(options);
}