SoDaRadio-12.2.0-cut_dependencies:6c82803
Loading...
Searching...
No Matches
SoDa::PlutoCtrl Class Reference

Concrete RadioControl for the ADALM-PLUTO SDR (AD9361 transceiver). More...

#include <PlutoCtrl.hxx>

Inheritance diagram for SoDa::PlutoCtrl:
SoDa::RadioControl SoDa::Thread SoDa::Base SoDa::Debug

Public Member Functions

 ~PlutoCtrl ()
RadioControlPtr getSelfPtr () override
void init () override
 Set hardware sample rate before PlutoTX/PlutoRX create their DMA buffers.
bool isLOLocked (SoDa::RXTX rxtx) override
 Methods that ALL radios must implement.
double setLOFreq (double freq, SoDa::RXTX rxtx) override
double getLOFreq (SoDa::RXTX rxtx) override
 Return the current LO (front end) oscillator setting for RX or TX chain.
float setRFGain (float gain, SoDa::RXTX rxtx) override
 set tain on the RX or TX side
void setSampleRate (float rate, SoDa::RXTX rxtx) override
 Set the RX or TX sample rate.
float getSampleRate (SoDa::RXTX rxtx) override
 Get the current setting for the sample rate.
std::string getHardwareDescription () override
 report the model number and any other interesting features (like freq range) to be displayed on the UI and such.
std::vector< std::string > listAntennas (SoDa::RXTX rxtx) override
 report the antennas that are available.
void setAntenna (const std::string &ant, SoDa::RXTX rxtx) override
 Set the antenna choice.
std::string getAntenna (SoDa::RXTX rxtx) override
 Get the current selected antenna.
bool getTXEna () override
 get the state of the TXEna bit
bool getTXRelayOn () override
 get the state of the TX relay confirm bit
void setTXEna (bool enable, bool full_duplex) override
 Enable or disable the transmit hardware chain, including the antenna relay and PA enable.
Public Member Functions inherited from SoDa::RadioControl
 RadioControl (ParamsPtr params, const std::string &name)
 Constructor Build a RadioControl thread.
void run () final
 start the thread
void subscribeToMailBoxes (const std::vector< MailBoxBasePtr > &mailboxes)
 implement the subscription method
Public Member Functions inherited from SoDa::Thread
void registerThread (SoDa::ThreadPtr me)
void operator() ()
void start ()
 Execute the thread's run loop.
void join ()
 more properly "Wait for this thread to exit its run loop".
void execCommand (CommandPtr cmd)
 Execute (dispatch) a message removed from the command stream to one of the basic Command handler functions.
virtual void shutDown ()
 optional method that performs cleanup – may not delete.
void sleep_ms (unsigned int milliseconds)
void sleep_us (unsigned int microseconds)
uint32_t getID ()
 Get the process/thread ID for this thread – helps with figuring out who caused a segfault.
Public Member Functions inherited from SoDa::Base
 Base (const std::string &oname)
 The constructor – pass a name for the object.
void registerSelf (BasePtr ptr)
std::string & getObjName ()
 get the name of this object
BasePtr findSoDaObject (const std::string &oname)
 find a SoDa Object by name.
double getTime ()
 Get a time stamp in nS resolution that monotonically increases and that is very inexpensive (typically < 100nS).
BasePtr getSelfPtr ()
 get a pointer to myself.
Public Member Functions inherited from SoDa::Debug
 Debug (std::string _unit_name=std::string("UNKNOWN"))
 Debug (const char *_unit_name_cstr)
 Debug (unsigned int _debug_level, std::string _unit_name=std::string("UNKNOWN"))
 Debug (unsigned int _debug_level, const char *_unit_name_cstr)
void debugMsg (const std::string &msg, unsigned int threshold=1)
void debugMsg (const SoDa::Format &fmt, unsigned int threshold=1)
void debugMsg (const char *msg, unsigned int threshold=1)
void setDebugLevel (unsigned int v)
unsigned int getDebugLevel ()

Static Public Member Functions

static PlutoCtrlPtr make (ParamsPtr params)
Static Public Member Functions inherited from SoDa::Debug
static void setDefaultLevel (unsigned int v)
static unsigned int getDefaultLevel ()
static void setGlobalLevel (unsigned int v)
static unsigned int getGlobalLevel ()

Protected Member Functions

 PlutoCtrl (ParamsPtr params)
Protected Member Functions inherited from SoDa::RadioControl
virtual void execCommand (CommandPtr cmd) final
 Parse an incoming command and dispatch.
virtual void execGetCommand (CommandPtr cmd) final
 Parse an incoming GET command and dispatch.
void execSetCommand (CommandPtr cmd) final
 Parse an incoming SET command and dispatch.
void execRepCommand (CommandPtr cmd) final
 Parse an incoming REPort command and dispatch.
double getTime ()
 get the number of seconds since the "Epoch"
void setFreq (double freq, SoDa::RXTX rxtx)
 Set the recieve or transmit frequency to 'freq' This includes setting the PLL front end synthesizer, the FPGA resident digital synthesizer (if it exists) and the RX baseband or TX baseband oscillator.
void setTXRXMode (Command::RxTxState rxtxst, bool full_duplex)
 Initiate the actions that will turn on the transmitter and (optionally) disable the receiver.
virtual bool setClockSource (Command::ClockSource src)
 Some radios support multiple choices for the main reference clock source.
virtual Command::ClockSource getClockSource ()
 Some radios support multiple choices for the main reference clock source.
double findGoodRXLO (double freq, double cur_lo_freq)
 see setFreq - this is a helper to find a good LO frequency that puts the IF in a range that is convenient for the spectrum display.
Protected Member Functions inherited from SoDa::Thread
 Thread (const std::string &oname, const std::string &version=std::string("12.2.0"))
 make the thread object.
Protected Member Functions inherited from SoDa::Debug
std::string curDateTime ()

Private Member Functions

void writeHWTXGain (double gain_db)
 Write TX hardware gain (dB, range TX_GAIN_MIN..0) to IIO, clamping first.
void writeHWRXGain (double gain_db)
 Write RX hardware gain (dB, range 0..RX_GAIN_MAX) to IIO, clamping first.

Private Attributes

iio_context * ctx
 IIO context (network, USB, or local)
iio_device * phy
 ad9361-phy control device
iio_channel * rx_lo_chan
 altvoltage0: RX PLL oscillator
iio_channel * tx_lo_chan
 altvoltage1: TX PLL oscillator
iio_channel * rx_phy_chan
 voltage0 (input direction): RX path config
iio_channel * tx_phy_chan
 voltage0 (output direction): TX path config
double rx_lo_freq
 last RX LO written to hardware (Hz)
double tx_lo_freq
 last TX LO written to hardware (Hz)
float rx_samp_rate_hw
 RX sample rate read back from hardware.
float tx_samp_rate_hw
 TX sample rate read back from hardware.
std::string rx_antenna_name
std::string tx_antenna_name
std::string hw_description
 cached string for getHardwareDescription()
std::weak_ptr< PlutoCtrlself

Static Private Attributes

static constexpr double RX_GAIN_MAX = 73.0
 dB maximum RX hardware gain
static constexpr double TX_GAIN_MIN = -89.75
 dB most-negative TX gain (= max atten)
static constexpr double FREQ_MIN = 70.0e6
 Hz (software-extended lower limit)
static constexpr double FREQ_MAX = 6.0e9
 Hz (software-extended upper limit)
static constexpr float PLUTO_SAMPLE_RATE = 2500000.0f

Additional Inherited Members

Static Public Attributes inherited from SoDa::Debug
static std::mutex debug_msg_mutex
Protected Attributes inherited from SoDa::RadioControl
ParamsPtr params
CmdMBoxPtr cmd_stream
 command stream channel
CmdMBox::Subscription cmd_subs
 subscriber ID for this thread's connection to the command channel
double first_gettime
 timestamps are relative to the first timestamp.
double rx_rf_gain
 rf gain for RX front end amp/attenuator
double tx_rf_gain
 rf gain for final TX amp
bool tx_on
 if true, we are transmitting.
double cur_rx_lo_freq
 The current receiver LO frequency.
double cur_rx_if_freq
 difference between rx
double cur_tx_lo_freq
 The current requested transmitter LO frequency.
double cur_tx_if_freq
 the TX LO frequency reported by the RadioTX front end.
double tx_samp_rate
 sample rate to TX chain.
std::string tx_ant
 TX antenna choice (usually has to be TX or TX/RX1?
std::string motherboard_name
 The model name of the radio.
bool tvrt_lo_capable
 if true, this unit can implement a local transverter oscillator.
bool tvrt_lo_mode
 if true, set the transmit frequency, with some knowledge of the tvrt LO.
double tvrt_lo_gain
 output power for the second transmit channel (used for transverter LO)
double tvrt_lo_freq
 the frequency of the second transmit channel oscillator
double tvrt_lo_fe_freq
 the frequency of the second transmit channel front-end oscillator
bool debug_mode
 print stuff when we are in debug mode
Protected Attributes inherited from SoDa::Thread
std::weak_ptr< Threadself
 A pointer to ourself.
Protected Attributes inherited from SoDa::Debug
std::string unit_name
 the name of the unit reporting status
unsigned int debug_level
 the debug level (threshold) for messages
Static Protected Attributes inherited from SoDa::RadioControl
static const double tx_freq_rxmode_offset
 tx offset when in RX mode
Static Protected Attributes inherited from SoDa::Debug
static unsigned int default_debug_level
static unsigned int global_debug_level

Detailed Description

Concrete RadioControl for the ADALM-PLUTO SDR (AD9361 transceiver).

All frequency, gain, and sample-rate commands arrive on the command stream and are dispatched by RadioControl::run(). This class provides the hardware-specific implementations of those virtual methods.

TX/RX switching is handled by asserting maximum TX attenuation when the transmitter is disabled — the Pluto has no external relay GPIO.

Definition at line 78 of file PlutoCtrl.hxx.

Constructor & Destructor Documentation

◆ PlutoCtrl()

SoDa::PlutoCtrl::PlutoCtrl ( ParamsPtr params)
protected

References SoDa::RadioControl::params.

Referenced by make().

◆ ~PlutoCtrl()

SoDa::PlutoCtrl::~PlutoCtrl ( )

Member Function Documentation

◆ getAntenna()

std::string SoDa::PlutoCtrl::getAntenna ( SoDa::RXTX rxtx)
overridevirtual

Get the current selected antenna.

Parameters
rxtxrx/tx selection
Returns
a string corresponding to the chosen antenna. It will be in the list returned by listAntennas.

Implements SoDa::RadioControl.

◆ getHardwareDescription()

std::string SoDa::PlutoCtrl::getHardwareDescription ( )
overridevirtual

report the model number and any other interesting features (like freq range) to be displayed on the UI and such.

Returns
a string describing the hardware.

Implements SoDa::RadioControl.

◆ getLOFreq()

double SoDa::PlutoCtrl::getLOFreq ( SoDa::RXTX rxtx)
overridevirtual

Return the current LO (front end) oscillator setting for RX or TX chain.

Parameters
rxtxselect receiver or transmitter
Returns
frequency (Analog LO and DDS/FPGA)

Implements SoDa::RadioControl.

◆ getSampleRate()

float SoDa::PlutoCtrl::getSampleRate ( SoDa::RXTX rxtx)
overridevirtual

Get the current setting for the sample rate.

Parameters
rxtxchoose RX chain or TX chain
Returns
the sample rate (samples/sec)

Implements SoDa::RadioControl.

◆ getSelfPtr()

RadioControlPtr SoDa::PlutoCtrl::getSelfPtr ( )
inlineoverridevirtual

Implements SoDa::RadioControl.

Definition at line 92 of file PlutoCtrl.hxx.

References self.

◆ getTXEna()

bool SoDa::PlutoCtrl::getTXEna ( )
overridevirtual

get the state of the TXEna bit

Returns
true if the TX relay is activated.

Implements SoDa::RadioControl.

◆ getTXRelayOn()

bool SoDa::PlutoCtrl::getTXRelayOn ( )
overridevirtual

get the state of the TX relay confirm bit

Returns
true if the TX relay sense input is asserted

Implements SoDa::RadioControl.

◆ init()

void SoDa::PlutoCtrl::init ( )
overridevirtual

Set hardware sample rate before PlutoTX/PlutoRX create their DMA buffers.

iio_buffer_push() silently fails if the DMA buffer is created before the ad9361-phy sampling_frequency attribute is written. This override ensures the rate is written during PlutoRadio::init() (ctrl→rx→tx order) so that PlutoTX::init() sees a correctly configured DMA engine.

Reimplemented from SoDa::RadioControl.

◆ isLOLocked()

bool SoDa::PlutoCtrl::isLOLocked ( SoDa::RXTX rxtx)
overridevirtual

Methods that ALL radios must implement.

is the identified (rx or tx) front-end LO locked? If not, set the tuning frequency to "the right thing"

Parameters
rxtxRX, TX

Implements SoDa::RadioControl.

◆ listAntennas()

std::vector< std::string > SoDa::PlutoCtrl::listAntennas ( SoDa::RXTX rxtx)
overridevirtual

report the antennas that are available.

we'll use this to let the GUI know what the choices are.

Parameters
rxtxselect which port RX, or TX
Returns
list of antennas for rx/tx This will later be used in the RadioControl initialization command sequence from "reportModes"

Implements SoDa::RadioControl.

◆ make()

PlutoCtrlPtr SoDa::PlutoCtrl::make ( ParamsPtr params)
inlinestatic

Definition at line 85 of file PlutoCtrl.hxx.

References PlutoCtrl(), and SoDa::RadioControl::params.

◆ setAntenna()

void SoDa::PlutoCtrl::setAntenna ( const std::string & ant,
SoDa::RXTX rxtx )
overridevirtual

Set the antenna choice.

Use "ant" if it is in the list of alternatives. Otherwise, choose the first alternative.

Parameters
antthe requested antenna
rxtxrx/tx selection

Implements SoDa::RadioControl.

◆ setLOFreq()

double SoDa::PlutoCtrl::setLOFreq ( double freq,
SoDa::RXTX rxtx )
overridevirtual
   @brief Set the front-end (LO + DDS) frequency to 'freq'
   This includes setting the PLL front end synthesizer
   as well as the FPGA resident digital synthesizer.

   @param freq targeto frequency (analog LO and DDS in the FPGA)
   @param rxtx select receiver or transmitter

   @return The actual LO frequency.

   The actual LO frequency may differ from the requested frequency by a small
   margin. Some radios may have a tuning step that is more than a few Hz. In this
   case we adjust the LO in the RX and TX objects. (This may be a bigger deal for the
   TX object as we like to do all the modulation there at baseband and assume the
   hardware takes care of the carrier frequency. 

   Typically, the call for a receive request would look like this:

   actual_lo_freq = setLOFreq(144.215e6, SoDa::RX)

   If the target LO can tune in 20 kHz intervals, the actual LO would be 144.100e6 and
   the if_freq would be 115e3 Hz. This would allow a "clean" window from 144.115 Mhz to

g * 144.325 MHz in the spectrogram display. The LO would need to be changed if the next frequency was greater than 144.240 or less than 144.205 (I think)

On the transmit side, the offset may be dictated by the frequency stepping increment in the front-end LO.

To keep everything civilized, setLOFreq should never be called by any other agent than the RadioControl object. (Not even its sub-classes.)

Implements SoDa::RadioControl.

◆ setRFGain()

float SoDa::PlutoCtrl::setRFGain ( float gain,
SoDa::RXTX rxtx )
overridevirtual

set tain on the RX or TX side

The radio implementation is responsible for mapping the gain to the appropriate control settings.

The range for gain is -30 to 0 in dB. 0 is maximum power or maximum front end RX gain. The device may support a more limited range, say -15 to 0 dB. In this case, any gain value less than -15 is treated as -15. For devices that support a greater range, the supported range is still -30 to 0.

Parameters
gaingain - if not in range, we'll pick something good
rxtxreceive or transmit?
Returns
the actual gain setting

Implements SoDa::RadioControl.

◆ setSampleRate()

void SoDa::PlutoCtrl::setSampleRate ( float rate,
SoDa::RXTX rxtx )
overridevirtual

Set the RX or TX sample rate.

Parameters
ratesample rate (in samples/sec)
rxtxchoose RX chain or TX chain

Implements SoDa::RadioControl.

◆ setTXEna()

void SoDa::PlutoCtrl::setTXEna ( bool tx_on,
bool full_duplex )
overridevirtual

Enable or disable the transmit hardware chain, including the antenna relay and PA enable.

In half-duplex mode the RX chain should also be muted.

Parameters
tx_onif true, enable the TX hardware; if false, disable it.
full_duplexif true, leave the RX chain active while transmitting.

Implements SoDa::RadioControl.

◆ writeHWRXGain()

void SoDa::PlutoCtrl::writeHWRXGain ( double gain_db)
private

Write RX hardware gain (dB, range 0..RX_GAIN_MAX) to IIO, clamping first.

◆ writeHWTXGain()

void SoDa::PlutoCtrl::writeHWTXGain ( double gain_db)
private

Write TX hardware gain (dB, range TX_GAIN_MIN..0) to IIO, clamping first.

Member Data Documentation

◆ ctx

iio_context* SoDa::PlutoCtrl::ctx
private

IIO context (network, USB, or local)

Definition at line 130 of file PlutoCtrl.hxx.

◆ FREQ_MAX

double SoDa::PlutoCtrl::FREQ_MAX = 6.0e9
staticconstexprprivate

Hz (software-extended upper limit)

Definition at line 153 of file PlutoCtrl.hxx.

◆ FREQ_MIN

double SoDa::PlutoCtrl::FREQ_MIN = 70.0e6
staticconstexprprivate

Hz (software-extended lower limit)

Definition at line 152 of file PlutoCtrl.hxx.

◆ hw_description

std::string SoDa::PlutoCtrl::hw_description
private

cached string for getHardwareDescription()

Definition at line 147 of file PlutoCtrl.hxx.

◆ phy

iio_device* SoDa::PlutoCtrl::phy
private

ad9361-phy control device

Definition at line 131 of file PlutoCtrl.hxx.

◆ PLUTO_SAMPLE_RATE

float SoDa::PlutoCtrl::PLUTO_SAMPLE_RATE = 2500000.0f
staticconstexprprivate

Definition at line 157 of file PlutoCtrl.hxx.

◆ rx_antenna_name

std::string SoDa::PlutoCtrl::rx_antenna_name
private

Definition at line 144 of file PlutoCtrl.hxx.

◆ RX_GAIN_MAX

double SoDa::PlutoCtrl::RX_GAIN_MAX = 73.0
staticconstexprprivate

dB maximum RX hardware gain

Definition at line 150 of file PlutoCtrl.hxx.

◆ rx_lo_chan

iio_channel* SoDa::PlutoCtrl::rx_lo_chan
private

altvoltage0: RX PLL oscillator

Definition at line 133 of file PlutoCtrl.hxx.

◆ rx_lo_freq

double SoDa::PlutoCtrl::rx_lo_freq
private

last RX LO written to hardware (Hz)

Definition at line 139 of file PlutoCtrl.hxx.

◆ rx_phy_chan

iio_channel* SoDa::PlutoCtrl::rx_phy_chan
private

voltage0 (input direction): RX path config

Definition at line 135 of file PlutoCtrl.hxx.

◆ rx_samp_rate_hw

float SoDa::PlutoCtrl::rx_samp_rate_hw
private

RX sample rate read back from hardware.

Definition at line 141 of file PlutoCtrl.hxx.

◆ self

std::weak_ptr<PlutoCtrl> SoDa::PlutoCtrl::self
private

Definition at line 159 of file PlutoCtrl.hxx.

Referenced by getSelfPtr().

◆ tx_antenna_name

std::string SoDa::PlutoCtrl::tx_antenna_name
private

Definition at line 145 of file PlutoCtrl.hxx.

◆ TX_GAIN_MIN

double SoDa::PlutoCtrl::TX_GAIN_MIN = -89.75
staticconstexprprivate

dB most-negative TX gain (= max atten)

Definition at line 151 of file PlutoCtrl.hxx.

◆ tx_lo_chan

iio_channel* SoDa::PlutoCtrl::tx_lo_chan
private

altvoltage1: TX PLL oscillator

Definition at line 134 of file PlutoCtrl.hxx.

◆ tx_lo_freq

double SoDa::PlutoCtrl::tx_lo_freq
private

last TX LO written to hardware (Hz)

Definition at line 140 of file PlutoCtrl.hxx.

◆ tx_phy_chan

iio_channel* SoDa::PlutoCtrl::tx_phy_chan
private

voltage0 (output direction): TX path config

Definition at line 136 of file PlutoCtrl.hxx.

◆ tx_samp_rate_hw

float SoDa::PlutoCtrl::tx_samp_rate_hw
private

TX sample rate read back from hardware.

Definition at line 142 of file PlutoCtrl.hxx.


The documentation for this class was generated from the following file: