SoDaRadio-5.0.3-master:8901fb5
USRPCtrl.hxx
Go to the documentation of this file.
1 /*
2 Copyright (c) 2012, Matthew H. Reilly (kb1vc)
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8 
9  Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in
13  the documentation and/or other materials provided with the
14  distribution.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
37 
38 #ifndef USRPCTRL_HDR
39 #define USRPCTRL_HDR
40 #include "SoDaBase.hxx"
41 #include "MultiMBox.hxx"
42 #include "Command.hxx"
43 #include "Params.hxx"
44 #include "TRControl.hxx"
45 #include "PropTree.hxx"
46 
47 #include <uhd/utils/thread_priority.hpp>
48 #include <uhd/utils/safe_main.hpp>
49 #include <uhd/usrp/multi_usrp.hpp>
50 #include <uhd/usrp/dboard_base.hpp>
51 #include <uhd/types/tune_request.hpp>
52 #include <uhd/types/tune_result.hpp>
53 #include <uhd/utils/msg.hpp>
54 
55 namespace SoDa {
56 
57 
68  class USRPCtrl : public SoDaThread {
69  public:
75  USRPCtrl(Params * params, CmdMBox * _cmd_stream);
77  void run();
78 
82  uhd::usrp::multi_usrp::sptr getUSRP() { return usrp; }
83 
84 
86  static void normal_message_handler(uhd::msg::type_t type, const std::string & msg);
87 
92 
93  private:
95 
99  bool is_B2xx;
100  bool is_B210;
101 
104  void execCommand(Command * cmd);
107  void execGetCommand(Command * cmd);
110  void execSetCommand(Command * cmd);
113  void execRepCommand(Command * cmd);
114 
117  double getTime();
118 
124  uhd::tune_result_t checkLock(uhd::tune_request_t & req,
125  char sel,
126  uhd::tune_result_t & cur);
127 
131  void reportAntennas();
132 
136  void reportModes();
137 
141  void reportAFFilters();
142 
149  void setAntenna(const std::string & ant, char sel);
150 
158  void set1stLOFreq(double freq, char sel, bool set_if_freq = false);
159 
160 
162  unsigned int subid;
163 
164  // USRP stuff.
165  uhd::usrp::multi_usrp::sptr usrp;
166  uhd::usrp::dboard_iface::sptr dboard;
167  // need this for TX/RX enable.
169  // need this for TX/RX enable.
171 
172  // what controls and widgets do we have for the two front-ends?
173 
178 
179 
180  // Capability Flags --
182 
183  // parallel IO to turn on RX ena and TX ena
184  // specific to WBX right now.
185 
188  void initControlGPIO();
189 
192  bool getTXEna();
195  bool getTXRelayOn();
198  void setTXEna(bool val);
199 
203  void setTXFrontEndEnable(bool val);
204 
207  void setTransverterLOFreqPower(double freq, double power);
208  void enableTransverterLO();
209  void disableTransverterLO();
210 
213  static const unsigned int TX_RELAY_CTL;
214  static const unsigned int TX_RELAY_MON;
215 
216  uhd::tune_result_t last_rx_tune_result;
217  uhd::tune_result_t last_tx_tune_result;
218  uhd::tune_result_t saved_rx_tune_result;
219 
220  double first_gettime;
221 
222  // gain settings
223  double rx_rf_gain;
224  double tx_rf_gain;
225 
226  uhd::gain_range_t rx_rf_gain_range;
227  uhd::gain_range_t tx_rf_gain_range;
228 
229  uhd::freq_range_t rx_rf_freq_range;
230  uhd::freq_range_t tx_rf_freq_range;
231 
232  // state of the box
233  bool tx_on;
234 
236 
237  // we horse the TX tuning around when we switch to RX
238  // to move the transmit birdie out of band.
239  double tx_freq;
241  static const double rxmode_offset;
242 
243  double tx_samp_rate;
244  std::string tx_ant;
245 
246  std::string motherboard_name;
247 
248  // transverter local oscillator support.
251  double tvrt_lo_gain;
252  double tvrt_lo_freq;
254 
255  // enables verbose messages
256  bool debug_mode;
257 
258  // integer tuning mode is helped by a map of LO capabilities.
259 
266  void applyTargetFreqCorrection(double target_freq,
267  double avoid_freq,
268  uhd::tune_request_t * tune_req);
269 
270 
274  void testIntNMode(bool force_int_N, bool force_frac_N);
275 
277 
283  };
284 }
285 
286 
287 #endif
uhd::usrp::multi_usrp::sptr usrp
to which USRP unit is this connected?
Definition: USRPCtrl.hxx:165
bool rx_fe_has_enable
can we access rx_fe_subtree/enabled ?
Definition: USRPCtrl.hxx:175
The Baseclass for all SoDa objects, and useful commonly used classes.
SoDa::PropTree * tx_fe_subtree
property tree from daughtercard module
Definition: USRPCtrl.hxx:168
static SoDa::USRPCtrl * singleton_ctrl_obj
This is a singleton object – the last (and only, we hope) such object to be created sets a static po...
Definition: USRPCtrl.hxx:91
bool is_B2xx
The B200 and B210 need some special handling, as they don&#39;t have frontend lock indications (as of 3...
Definition: USRPCtrl.hxx:99
The Thread baseclass for all SoDa thread objects.
Definition: SoDaBase.hxx:284
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 ...
Definition: USRPCtrl.hxx:82
double tvrt_lo_fe_freq
the frequency of the second transmit channel front-end oscillator
Definition: USRPCtrl.hxx:253
SoDa::TRControl * tr_control
external control widget for TR switching and other things.
Definition: USRPCtrl.hxx:282
uhd::tune_result_t last_tx_tune_result
TX tune result.
Definition: USRPCtrl.hxx:217
bool tx_has_lo_locked_sensor
does the tx frond end have an lo_locked sensor?
Definition: USRPCtrl.hxx:176
void disableTransverterLO()
Definition: USRPCtrl.cxx:856
Though libuhd is designed to be re-entrant, there are some indications that all control functions (se...
Definition: USRPCtrl.hxx:68
std::string motherboard_name
The model name of the USRP unit.
Definition: USRPCtrl.hxx:246
void execGetCommand(Command *cmd)
Dispatch an incoming GET command.
Definition: USRPCtrl.cxx:634
static const double rxmode_offset
tx offset when in RX mode
Definition: USRPCtrl.hxx:241
double tx_samp_rate
sample rate to USRP TX chain.
Definition: USRPCtrl.hxx:243
bool getTXRelayOn()
get the state of the TX relay confirm bit
Definition: USRPCtrl.cxx:807
uhd::tune_result_t saved_rx_tune_result
previous RX tune result – used for transverter LO "calibration" function
Definition: USRPCtrl.hxx:218
void enableTransverterLO()
Definition: USRPCtrl.cxx:832
uhd::freq_range_t tx_rf_freq_range
property of the device – what is the min/maximum TX frequency?
Definition: USRPCtrl.hxx:230
This class handles command line parameters and built-ins.
Definition: Params.hxx:42
double rx_rf_gain
rf gain for RX front end amp/attenuator
Definition: USRPCtrl.hxx:223
Generic Control class to activate T/R switching, band switching, and other control functions...
Definition: TRControl.hxx:51
PropTree class encapsulates the USRP property tree functions to allow better trap and error recovery ...
Definition: PropTree.hxx:44
bool supports_IntN_Mode
if true, this unit can tune the front-end LO
Definition: USRPCtrl.hxx:276
bool tvrt_lo_capable
if true, this unit can implement a local transverter oscillator.
Definition: USRPCtrl.hxx:249
double getTime()
get the number of seconds since the "Epoch"
Definition: USRPCtrl.cxx:260
bool tx_on
if true, we are transmitting.
Definition: USRPCtrl.hxx:233
uhd::tune_result_t last_rx_tune_result
RX tune result – actual LO and DSP freq.
Definition: USRPCtrl.hxx:216
void set1stLOFreq(double freq, char sel, bool set_if_freq=false)
Set the front-end (LO + DDS) frequency to &#39;freq&#39; This includes setting the PLL front end synthesizer ...
Definition: USRPCtrl.cxx:312
static void normal_message_handler(uhd::msg::type_t type, const std::string &msg)
This is the more permanent message handler...
Definition: USRPCtrl.cxx:925
void reportAntennas()
report the antennas that are available, send the report on cmd_stream
Definition: USRPCtrl.cxx:1048
double tx_freq
remember current tx freq
Definition: USRPCtrl.hxx:239
void setTXEna(bool val)
turn TX on/off
Definition: USRPCtrl.cxx:745
This is a list of all the commands that can "do something" to one or more components in the SoDa radi...
Definition: Command.hxx:47
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 ...
Definition: USRPCtrl.cxx:864
double tx_rf_gain
rf gain for final TX amp
Definition: USRPCtrl.hxx:224
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:240
bool debug_mode
print stuff when we are in debug mode
Definition: USRPCtrl.hxx:256
bool tx_fe_has_enable
can we access tx_fe_subtree/enabled ?
Definition: USRPCtrl.hxx:174
void setTransverterLOFreqPower(double freq, double power)
set the transverter LO frequency and power This code does not work for libUHD after 3...
Definition: USRPCtrl.cxx:817
uhd::gain_range_t tx_rf_gain_range
property of the device – what is the min/maximum TX gain setting?
Definition: USRPCtrl.hxx:227
void reportAFFilters()
report the audio filters that are implemented, send the report on cmd_stream
Definition: USRPCtrl.cxx:1033
bool supports_tx_gpio
does this unit support GPIO signals? (B2xx does not as of 3.7.0)
Definition: USRPCtrl.hxx:181
bool getTXEna()
get the state of the TXEna bit
Definition: USRPCtrl.cxx:796
uhd::usrp::dboard_iface::sptr dboard
the daughterboard we&#39;re controlling
Definition: USRPCtrl.hxx:166
double first_gettime
timestamps are relative to the first timestamp.
Definition: USRPCtrl.hxx:220
static const unsigned int TX_RELAY_MON
mask for RELAY sense bit
Definition: USRPCtrl.hxx:214
void initControlGPIO()
Initialize the GPIO control registers to set the direction and enables for the TX/RX relay output and...
Definition: USRPCtrl.cxx:702
void testIntNMode(bool force_int_N, bool force_frac_N)
Test for support for integer-N synthesis.
Definition: USRPCtrl.cxx:940
double last_rx_req_freq
remember the last setting – useful for "calibration check"
Definition: USRPCtrl.hxx:235
Params * params
Definition: USRPCtrl.hxx:94
void reportModes()
report the modulation modes that are implemented, send the report on cmd_stream
Definition: USRPCtrl.cxx:1015
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:213
bool tvrt_lo_mode
if true, set the transmit frequency, with some knowledge of the tvrt LO.
Definition: USRPCtrl.hxx:250
void setTXFrontEndEnable(bool val)
set TX enable property on front-end module – not present in all daughtercards... ...
Definition: USRPCtrl.cxx:781
double tvrt_lo_freq
the frequency of the second transmit channel oscillator
Definition: USRPCtrl.hxx:252
unsigned int subid
subscriber ID for this thread&#39;s connection to the command channel
Definition: USRPCtrl.hxx:162
bool rx_has_lo_locked_sensor
does the rx frond end have an lo_locked sensor?
Definition: USRPCtrl.hxx:177
double tvrt_lo_gain
output power for the second transmit channel (used for transverter LO)
Definition: USRPCtrl.hxx:251
uhd::freq_range_t rx_rf_freq_range
property of the device – what is the min/maximum RX frequency?
Definition: USRPCtrl.hxx:229
std::string tx_ant
TX antenna choice (usually has to be TX or TX/RX1?
Definition: USRPCtrl.hxx:244
void run()
start the thread
Definition: USRPCtrl.cxx:209
CmdMBox * cmd_stream
command stream channel
Definition: USRPCtrl.hxx:161
SoDa::PropTree * rx_fe_subtree
property tree from daughtercard module
Definition: USRPCtrl.hxx:170
USRPCtrl(Params *params, CmdMBox *_cmd_stream)
Constructor Build a USRPCtrl thread.
Definition: USRPCtrl.cxx:55
uhd::gain_range_t rx_rf_gain_range
property of the device – what is the min/maximum RX gain setting?
Definition: USRPCtrl.hxx:226
void execRepCommand(Command *cmd)
Dispatch an incoming REPort command.
Definition: USRPCtrl.cxx:694
void setAntenna(const std::string &ant, char sel)
Set the antenna choice.
Definition: USRPCtrl.cxx:1067
void execSetCommand(Command *cmd)
Dispatch an incoming SET command.
Definition: USRPCtrl.cxx:447
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? If not, set the tuning frequency to "the right thin...
Definition: USRPCtrl.cxx:286
void execCommand(Command *cmd)
Parse an incoming command and dispatch.
Definition: USRPCtrl.cxx:269
bool is_B210
the B210 has two tx channels – use the second for a Transverter LO – see USRPLO ...
Definition: USRPCtrl.hxx:100