SoDaRadio-12.2.0-cut_dependencies:6c82803
Loading...
Searching...
No Matches
PlutoCtrl.hxx
Go to the documentation of this file.
1#pragma once
2/*
3Copyright (c) 2026 Matthew H. Reilly (kb1vc)
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are
8met:
9
10 Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the
15 distribution.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
51
52#include "SoDaBase.hxx"
53#include "SoDaThread.hxx"
54#include "Command.hxx"
55#include "Params.hxx"
56#include "RadioControl.hxx"
57#include <iio.h>
58#include <memory>
59#include <string>
60#include <vector>
61
62namespace SoDa {
63 class PlutoCtrl;
64 typedef std::shared_ptr<PlutoCtrl> PlutoCtrlPtr;
65
79 protected:
81
82 public:
84
86 auto ret = std::shared_ptr<PlutoCtrl>(new PlutoCtrl(params));
87 ret->self = ret;
88 ret->registerThread(ret);
89 return ret;
90 }
91
92 RadioControlPtr getSelfPtr() override { return self.lock(); }
93
102 void init() override;
103
104 // ---------------------------------------------------------------
105 // RadioControl pure-virtual interface
106 // ---------------------------------------------------------------
107
108 bool isLOLocked(SoDa::RXTX rxtx) override;
109
110 double setLOFreq(double freq, SoDa::RXTX rxtx) override;
111 double getLOFreq(SoDa::RXTX rxtx) override;
112
113 float setRFGain(float gain, SoDa::RXTX rxtx) override;
114
115 void setSampleRate(float rate, SoDa::RXTX rxtx) override;
116 float getSampleRate(SoDa::RXTX rxtx) override;
117
118 std::string getHardwareDescription() override;
119
120 std::vector<std::string> listAntennas(SoDa::RXTX rxtx) override;
121 void setAntenna(const std::string & ant, SoDa::RXTX rxtx) override;
122 std::string getAntenna(SoDa::RXTX rxtx) override;
123
124 bool getTXEna() override;
125 bool getTXRelayOn() override;
126 void setTXEna(bool enable, bool full_duplex) override;
127
128 private:
129 // IIO objects
130 iio_context * ctx;
131 iio_device * phy;
132
133 iio_channel * rx_lo_chan;
134 iio_channel * tx_lo_chan;
135 iio_channel * rx_phy_chan;
136 iio_channel * tx_phy_chan;
137
138 // Cached hardware state
139 double rx_lo_freq;
140 double tx_lo_freq;
143
144 std::string rx_antenna_name;
145 std::string tx_antenna_name;
146
147 std::string hw_description;
148
149 // AD9361 limits
150 static constexpr double RX_GAIN_MAX = 73.0;
151 static constexpr double TX_GAIN_MIN = -89.75;
152 static constexpr double FREQ_MIN = 70.0e6;
153 static constexpr double FREQ_MAX = 6.0e9;
154
155 // PlutoRX and PlutoTX each decimate/interpolate 4:1, so the Pluto hardware
156 // always runs at 4 * 625k = 2.5 MSPS regardless of what Params requests.
157 static constexpr float PLUTO_SAMPLE_RATE = 2500000.0f;
158
159 std::weak_ptr<PlutoCtrl> self;
160
162 void writeHWTXGain(double gain_db);
164 void writeHWRXGain(double gain_db);
165 };
166}
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.
Concrete RadioControl for the ADALM-PLUTO SDR (AD9361 transceiver).
Definition PlutoCtrl.hxx:78
iio_context * ctx
IIO context (network, USB, or local)
double tx_lo_freq
last TX LO written to hardware (Hz)
PlutoCtrl(ParamsPtr params)
float setRFGain(float gain, SoDa::RXTX rxtx) override
set tain on the RX or TX side
void writeHWTXGain(double gain_db)
Write TX hardware gain (dB, range TX_GAIN_MIN..0) to IIO, clamping first.
iio_channel * tx_lo_chan
altvoltage1: TX PLL oscillator
iio_channel * tx_phy_chan
voltage0 (output direction): TX path config
std::string getHardwareDescription() override
report the model number and any other interesting features (like freq range) to be displayed on the U...
void setSampleRate(float rate, SoDa::RXTX rxtx) override
Set the RX or TX sample rate.
void writeHWRXGain(double gain_db)
Write RX hardware gain (dB, range 0..RX_GAIN_MAX) to IIO, clamping first.
iio_device * phy
ad9361-phy control device
double getLOFreq(SoDa::RXTX rxtx) override
Return the current LO (front end) oscillator setting for RX or TX chain.
std::vector< std::string > listAntennas(SoDa::RXTX rxtx) override
report the antennas that are available.
bool getTXEna() override
get the state of the TXEna bit
static constexpr double FREQ_MIN
Hz (software-extended lower limit)
static constexpr double FREQ_MAX
Hz (software-extended upper limit)
void setAntenna(const std::string &ant, SoDa::RXTX rxtx) override
Set the antenna choice.
static constexpr float PLUTO_SAMPLE_RATE
static constexpr double RX_GAIN_MAX
dB maximum RX hardware gain
iio_channel * rx_phy_chan
voltage0 (input direction): RX path config
std::string tx_antenna_name
bool isLOLocked(SoDa::RXTX rxtx) override
Methods that ALL radios must implement.
std::string hw_description
cached string for getHardwareDescription()
double rx_lo_freq
last RX LO written to hardware (Hz)
std::string rx_antenna_name
bool getTXRelayOn() override
get the state of the TX relay confirm bit
std::weak_ptr< PlutoCtrl > self
float tx_samp_rate_hw
TX sample rate read back from hardware.
void init() override
Set hardware sample rate before PlutoTX/PlutoRX create their DMA buffers.
float rx_samp_rate_hw
RX sample rate read back from hardware.
iio_channel * rx_lo_chan
altvoltage0: RX PLL oscillator
static PlutoCtrlPtr make(ParamsPtr params)
Definition PlutoCtrl.hxx:85
void setTXEna(bool enable, bool full_duplex) override
Enable or disable the transmit hardware chain, including the antenna relay and PA enable.
RadioControlPtr getSelfPtr() override
Definition PlutoCtrl.hxx:92
static constexpr double TX_GAIN_MIN
dB most-negative TX gain (= max atten)
float getSampleRate(SoDa::RXTX rxtx) override
Get the current setting for the sample rate.
double setLOFreq(double freq, SoDa::RXTX rxtx) override
std::string getAntenna(SoDa::RXTX rxtx) override
Get the current selected antenna.
Though libuhd is designed to be re-entrant, there are some indications that all control functions (se...
std::shared_ptr< RadioControl > RadioControlPtr
RXTX
We often need to distinguis between the RX and TX device.
Definition SoDaBase.hxx:69
std::shared_ptr< PlutoCtrl > PlutoCtrlPtr
Definition PlutoCtrl.hxx:64
std::shared_ptr< Params > ParamsPtr
Definition Params.hxx:42