SoDaRadio-12.2.0-cut_dependencies:6c82803
Loading...
Searching...
No Matches
USRPCtrl.hxx
Go to the documentation of this file.
1#pragma once
2
3/*
4Copyright (c) 2012, 2026 Matthew H. Reilly (kb1vc)
5All rights reserved.
6
7Redistribution and use in source and binary forms, with or without
8modification, are permitted provided that the following conditions are
9met:
10
11 Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13 Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in
15 the documentation and/or other materials provided with the
16 distribution.
17
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*/
30
39
40#include "SoDaBase.hxx"
41#include "SoDaThread.hxx"
42#include "Command.hxx"
43#include "Params.hxx"
44#include "USRPTRControl.hxx"
45#include "RadioControl.hxx"
46#include "USRPPropTree.hxx"
47#include <uhd/version.hpp>
48#include <uhd/utils/thread.hpp>
49
50#include <uhd/utils/safe_main.hpp>
51#include <uhd/usrp/multi_usrp.hpp>
52#include <uhd/usrp/dboard_base.hpp>
53#include <uhd/types/tune_request.hpp>
54#include <uhd/types/tune_result.hpp>
55
56#include <SoDa/MailBox.hxx>
57
58#include <memory>
59
60namespace SoDa {
61 class USRPCtrl;
62 typedef std::shared_ptr<USRPCtrl> USRPCtrlPtr;
63
75 protected:
81
82 public:
84 auto ret = std::shared_ptr<USRPCtrl>(new USRPCtrl(params));
85 ret->self = ret;
86 ret->registerThread(ret);
87 return ret;
88 }
89
93 uhd::usrp::multi_usrp::sptr getUSRP() { return usrp; }
94
102
135 double setLOFreq(double freq, SoDa::RXTX rxtx);
136
142 double getLOFreq(SoDa::RXTX rxtx);
143
151 float setRFGain(float gain, SoDa::RXTX rxtx);
152
159 void setSampleRate(float rate, SoDa::RXTX rxtx);
160
168
169
177
190
191
200
206 RadioControlPtr getSelfPtr() { return self.lock(); }
207
208 void setTXEna(bool enable, bool full_duplex) override {
209 tx_on = enable; // update RadioControl::tx_on so setRFGain(TX) guard works
210 locSetTXEna(enable);
211 }
212
213 protected:
215
220 bool is_B210;
221
222
228 uhd::tune_result_t checkLock(uhd::tune_request_t & req,
229 char sel,
230 uhd::tune_result_t & cur);
231
241 std::vector<std::string> listAntennas(SoDa::RXTX rxtx);
242
243
244
251 void setAntenna(const std::string & ant, SoDa::RXTX rxtx);
252
259 std::string getAntenna(SoDa::RXTX rxtx);
260
261
262
263 private:
264
265 // USRP stuff.
266 uhd::usrp::multi_usrp::sptr usrp;
267 uhd::usrp::dboard_iface::sptr dboard;
268 // need this for TX/RX enable.
270 // need this for TX/RX enable.
272
273 // what controls and widgets do we have for the two front-ends?
274
279
280
281 // Capability Flags --
283
284 // parallel IO to turn on RX ena and TX ena
285 // specific to WBX right now.
286
290
293 bool getTXEna();
299 void locSetTXEna(bool val);
300
304 void setTXFrontEndEnable(bool val);
305
308 static const unsigned int TX_RELAY_CTL;
309 static const unsigned int TX_RELAY_MON;
310
311 uhd::tune_result_t last_rx_tune_result;
312 uhd::tune_result_t last_tx_tune_result;
313 uhd::tune_result_t saved_rx_tune_result;
314
316
317 // gain settings
318 double rx_rf_gain;
319 double tx_rf_gain;
320
321 uhd::gain_range_t rx_rf_gain_range;
322 uhd::gain_range_t tx_rf_gain_range;
323
324 uhd::freq_range_t rx_rf_freq_range;
325 uhd::freq_range_t tx_rf_freq_range;
326
327 // state of the box
328 bool tx_on;
329
331
332 // we horse the TX tuning around when we switch to RX
333 // to move the transmit birdie out of band.
334 double tx_freq;
336 static const double rxmode_offset;
337
339 std::string tx_ant;
340
341 std::string motherboard_name;
342
343 // enables verbose messages
345
346 // integer tuning mode is helped by a map of LO capabilities.
347
354 void applyTargetFreqCorrection(double target_freq,
355 double avoid_freq,
356 uhd::tune_request_t * tune_req);
357
358
362 void testIntNMode(bool force_int_N, bool force_frac_N);
363
368
371
373 std::weak_ptr<USRPCtrl> self;
374 };
375}
376
377
Thread class that provides the common radio functions for any compatible radio.
The Baseclass for all SoDa objects, and useful commonly used classes.
The Baseclass for all SoDa thread objects.
ClockSource
some radios support two sources for the master oscillator reference.
Definition Command.hxx:71
Though libuhd is designed to be re-entrant, there are some indications that all control functions (se...
Though libuhd is designed to be re-entrant, there are some indications that all control functions (se...
Definition USRPCtrl.hxx:74
bool isLOLocked(SoDa::RXTX rxtx)
is the identified (rx or tx) front-end LO locked?
double first_gettime
timestamps are relative to the first timestamp.
Definition USRPCtrl.hxx:315
void initControlGPIO()
Initialize the GPIO control registers to set the direction and enables for the TX/RX relay output and...
double last_rx_req_freq
remember the last setting – useful for "calibration check"
Definition USRPCtrl.hxx:330
Command::ClockSource getClockSource()
Some radios support multiple choices for the main reference clock source.
uhd::tune_result_t saved_rx_tune_result
previous RX tune result – used for transverter LO "calibration" function
Definition USRPCtrl.hxx:313
uhd::tune_result_t last_rx_tune_result
RX tune result – actual LO and DSP freq.
Definition USRPCtrl.hxx:311
bool supports_IntN_Mode
if true, this unit can tune the front-end LO
Definition USRPCtrl.hxx:364
static USRPCtrlPtr make(ParamsPtr params)
Definition USRPCtrl.hxx:83
float getSampleRate(SoDa::RXTX rxtx)
Get the current setting for the sample rate.
SoDa::USRPPropTree * tx_fe_subtree
property tree from daughtercard module
Definition USRPCtrl.hxx:269
uhd::usrp::dboard_iface::sptr dboard
the daughterboard we're controlling
Definition USRPCtrl.hxx:267
double tx_samp_rate
sample rate to USRP TX chain.
Definition USRPCtrl.hxx:338
void setSampleRate(float rate, SoDa::RXTX rxtx)
Set the RX or TX sample rate.
RadioControlPtr getSelfPtr()
get a pointer to myself (for things like exception handlers.)
Definition USRPCtrl.hxx:206
double tx_freq
remember current tx freq
Definition USRPCtrl.hxx:334
static const unsigned int TX_RELAY_CTL
we use TX_IO bit 12 to turn on the TX relay we use TX_IO bit 11 to monitor the TX relay
Definition USRPCtrl.hxx:308
bool getTXRelayOn()
get the state of the TX relay confirm bit
bool tx_on
if true, we are transmitting.
Definition USRPCtrl.hxx:328
std::weak_ptr< USRPCtrl > self
Definition USRPCtrl.hxx:373
SoDa::USRPPropTree * rx_fe_subtree
property tree from daughtercard module
Definition USRPCtrl.hxx:271
double getLOFreq(SoDa::RXTX rxtx)
Return the current LO (front end) oscillator setting for RX or TX chain.
uhd::tune_result_t last_tx_tune_result
TX tune result.
Definition USRPCtrl.hxx:312
SoDa::USRPTRControl * tr_control
external control widget for TR switching and other things.
Definition USRPCtrl.hxx:370
void testIntNMode(bool force_int_N, bool force_frac_N)
Test for support for integer-N synthesis.
void applyTargetFreqCorrection(double target_freq, double avoid_freq, uhd::tune_request_t *tune_req)
applyTargetFreqCorrection adjusts the requested frequency, if necessary, to avoid a birdie caused by ...
ParamsPtr params
Definition USRPCtrl.hxx:214
double rx_rf_gain
rf gain for RX front end amp/attenuator
Definition USRPCtrl.hxx:318
uhd::freq_range_t tx_rf_freq_range
property of the device – what is the min/maximum TX frequency?
Definition USRPCtrl.hxx:325
bool debug_mode
print stuff when we are in debug mode
Definition USRPCtrl.hxx:344
double tx_freq_rxmode_offset
when in RX mode, move tx off frequency to put the tx birdie out of band, when in TX mode,...
Definition USRPCtrl.hxx:335
bool getTXEna()
get the state of the TXEna bit
static const unsigned int TX_RELAY_MON
mask for RELAY sense bit
Definition USRPCtrl.hxx:309
bool setClockSource(Command::ClockSource src)
Some radios support multiple choices for the main reference clock source.
void setAntenna(const std::string &ant, SoDa::RXTX rxtx)
Set the antenna choice.
uhd::usrp::multi_usrp::sptr usrp
to which USRP unit is this connected?
Definition USRPCtrl.hxx:266
uhd::gain_range_t rx_rf_gain_range
property of the device – what is the min/maximum RX gain setting?
Definition USRPCtrl.hxx:321
std::string getHardwareDescription()
report the model number and any other interesting features (like freq range) to be displayed on the U...
uhd::usrp::multi_usrp::sptr getUSRP()
return a pointer to the multi_usrp object – used by RX and TX processes to find the associated USRP w...
Definition USRPCtrl.hxx:93
uhd::freq_range_t rx_rf_freq_range
property of the device – what is the min/maximum RX frequency?
Definition USRPCtrl.hxx:324
bool is_B210
the B210 has two tx channels – use the second for a Transverter LO – see USRPLO
Definition USRPCtrl.hxx:220
std::string motherboard_name
The model name of the USRP unit.
Definition USRPCtrl.hxx:341
std::vector< std::string > listAntennas(SoDa::RXTX rxtx)
report the antennas that are available.
static const double rxmode_offset
tx offset when in RX mode
Definition USRPCtrl.hxx:336
void setTXEna(bool enable, bool full_duplex) override
Enable or disable the transmit hardware chain, including the antenna relay and PA enable.
Definition USRPCtrl.hxx:208
std::string getAntenna(SoDa::RXTX rxtx)
Get the current selected antenna.
uhd::tune_result_t checkLock(uhd::tune_request_t &req, char sel, uhd::tune_result_t &cur)
is the identified (rx or tx) front-end LO locked?
bool tx_has_lo_locked_sensor
does the tx frond end have an lo_locked sensor?
Definition USRPCtrl.hxx:277
bool is_B2xx
The B200 and B210 need some special handling, as they don't have frontend lock indications (as of 3....
Definition USRPCtrl.hxx:219
bool rx_fe_has_enable
can we access rx_fe_subtree/enabled ?
Definition USRPCtrl.hxx:276
void locSetTXEna(bool val)
hardware-level TX relay and front-end control
uhd::gain_range_t tx_rf_gain_range
property of the device – what is the min/maximum TX gain setting?
Definition USRPCtrl.hxx:322
double tx_rf_gain
rf gain for final TX amp
Definition USRPCtrl.hxx:319
std::string tx_ant
TX antenna choice (usually has to be TX or TX/RX1?
Definition USRPCtrl.hxx:339
void setTXFrontEndEnable(bool val)
set TX enable property on front-end module – not present in all daughtercards...
bool tx_fe_has_enable
can we access tx_fe_subtree/enabled ?
Definition USRPCtrl.hxx:275
bool supports_tx_gpio
does this unit support GPIO signals? (B2xx does not as of 3.7.0)
Definition USRPCtrl.hxx:282
bool rx_has_lo_locked_sensor
does the rx frond end have an lo_locked sensor?
Definition USRPCtrl.hxx:278
double setLOFreq(double freq, SoDa::RXTX rxtx)
Set the front-end (LO + DDS) frequency to 'freq' This includes setting the PLL front end synthesizer ...
float setRFGain(float gain, SoDa::RXTX rxtx)
set tain on the RX or TX side
USRPCtrl(ParamsPtr params)
Constructor Build a USRPCtrl thread.
USRPPropTree class encapsulates the USRP property tree functions to allow better trap and error recov...
Generic Control class to activate T/R switching, band switching, and other control functions.
std::shared_ptr< RadioControl > RadioControlPtr
RXTX
We often need to distinguis between the RX and TX device.
Definition SoDaBase.hxx:69
std::shared_ptr< Params > ParamsPtr
Definition Params.hxx:42
std::shared_ptr< USRPCtrl > USRPCtrlPtr
Definition USRPCtrl.hxx:62