SoDaRadio-12.2.0-cut_dependencies:6c82803
Loading...
Searching...
No Matches
RTLSDRCtrl.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
45
46#include "RadioControl.hxx"
47#include "Params.hxx"
48#include "RTLSDRDev.hxx"
49#include <vector>
50#include <string>
51
52namespace SoDa {
53
54 class RTLSDRCtrl;
55 using RTLSDRCtrlPtr = std::shared_ptr<RTLSDRCtrl>;
56
57 class RTLSDRCtrl : public RadioControl {
58 protected:
60
61 public:
62 ~RTLSDRCtrl() = default;
63
65 auto ret = std::shared_ptr<RTLSDRCtrl>(new RTLSDRCtrl(dev_in, params));
66 ret->self = ret;
67 ret->registerThread(ret);
68 return ret;
69 }
70
71 RadioControlPtr getSelfPtr() override { return self.lock(); }
72
73 // ---------------------------------------------------------------
74 // RadioControl pure-virtual interface
75 // ---------------------------------------------------------------
76
77 bool isLOLocked(SoDa::RXTX rxtx) override;
78
79 double setLOFreq(double freq, SoDa::RXTX rxtx) override;
80 double getLOFreq(SoDa::RXTX rxtx) override;
81
82 float setRFGain(float gain, SoDa::RXTX rxtx) override;
83
84 void setSampleRate(float rate, SoDa::RXTX rxtx) override;
85 float getSampleRate(SoDa::RXTX rxtx) override;
86
87 std::string getHardwareDescription() override;
88
89 std::vector<std::string> listAntennas(SoDa::RXTX rxtx) override;
90 void setAntenna(const std::string & ant, SoDa::RXTX rxtx) override;
91 std::string getAntenna(SoDa::RXTX rxtx) override;
92
93 // TX is not supported — stubs only.
94 bool getTXEna() override { return false; }
95 bool getTXRelayOn() override { return false; }
96 void setTXEna(bool, bool) override { }
97
98 private:
99 static constexpr float HW_RATE = 2048000.0f;
100
102
103 double rx_lo_freq;
105
106 std::vector<int> gain_steps;
107 std::string hw_description;
108
109 std::weak_ptr<RTLSDRCtrl> self;
110
112 int sodaGainToRTL(float soda_gain) const;
113 };
114
115} // namespace SoDa
Shared RAII wrapper for an rtlsdr_dev_t handle.
Thread class that provides the common radio functions for any compatible radio.
RTLSDRCtrl(RTLSDRDevPtr dev_in, ParamsPtr params)
float setRFGain(float gain, SoDa::RXTX rxtx) override
set tain on the RX or TX side
double setLOFreq(double freq, SoDa::RXTX rxtx) override
static constexpr float HW_RATE
RTL2832U actual USB delivery rate (2.048 MSPS)
std::vector< std::string > listAntennas(SoDa::RXTX rxtx) override
report the antennas that are available.
RadioControlPtr getSelfPtr() override
void setAntenna(const std::string &ant, SoDa::RXTX rxtx) override
Set the antenna choice.
static RTLSDRCtrlPtr make(RTLSDRDevPtr dev_in, ParamsPtr params)
bool getTXEna() override
get the state of the TXEna bit
std::vector< int > gain_steps
valid tuner gains in tenths of dB
double getLOFreq(SoDa::RXTX rxtx) override
Return the current LO (front end) oscillator setting for RX or TX chain.
std::string getAntenna(SoDa::RXTX rxtx) override
Get the current selected antenna.
~RTLSDRCtrl()=default
void setSampleRate(float rate, SoDa::RXTX rxtx) override
Set the RX or TX sample rate.
std::string getHardwareDescription() override
report the model number and any other interesting features (like freq range) to be displayed on the U...
bool isLOLocked(SoDa::RXTX rxtx) override
Methods that ALL radios must implement.
void setTXEna(bool, bool) override
Enable or disable the transmit hardware chain, including the antenna relay and PA enable.
int sodaGainToRTL(float soda_gain) const
Map SoDaRadio gain (-30..0 dB) to the nearest discrete RTL gain step.
RTLSDRDevPtr rtl
std::weak_ptr< RTLSDRCtrl > self
double rx_lo_freq
last RX center frequency written (Hz)
std::string hw_description
float rx_sample_rate
current sample rate (Hz)
float getSampleRate(SoDa::RXTX rxtx) override
Get the current setting for the sample rate.
bool getTXRelayOn() override
get the state of the TX relay confirm bit
RadioControl(ParamsPtr params, const std::string &name)
Constructor Build a RadioControl thread.
std::shared_ptr< RadioControl > RadioControlPtr
RXTX
We often need to distinguis between the RX and TX device.
Definition SoDaBase.hxx:69
std::shared_ptr< RTLSDRDev > RTLSDRDevPtr
Definition RTLSDRDev.hxx:62
std::shared_ptr< Params > ParamsPtr
Definition Params.hxx:42
std::shared_ptr< RTLSDRCtrl > RTLSDRCtrlPtr