SatNOGS-COMMS  4.1.0
A COMMS subsystem for CubeSats
Loading...
Searching...
No Matches
rf_frontend.cpp
Go to the documentation of this file.
1/*
2 * SatNOGS-COMMS control library
3 *
4 * Copyright (C) 2022-2023, Libre Space Foundation <http://libre.space>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * SPDX-License-Identifier: GNU General Public License v3.0 or later
20 */
21
24
25namespace satnogs::comms::lib
26{
27
28rf_frontend::rf_frontend(const params &init_params, io_conf &&io, power &pwr)
29 : m_params(init_params),
30 m_filt_sel(io.flt_sel),
31 m_dac(io.agc_vset),
32 m_pwr(pwr),
33 m_agc(io.en_agc),
34 m_dir(dir::RX)
35{
36 /* By default select the narrow filter */
38}
39
44void
46{
47 switch (f) {
48 case filter::WIDE:
49 m_filt_sel.set(false);
50 break;
51 case filter::NARROW:
52 m_filt_sel.set(true);
53 break;
54 default:
55 throw inval_arg_exception(__FILE__, __LINE__);
56 }
57}
58
65{
66 if (m_filt_sel.get()) {
67 return filter::NARROW;
68 }
69 return filter::WIDE;
70}
71
79{
80 return m_dir;
81}
82
89void
91{
92 switch (gain.gain0_mode) {
93 case gain_mode::AUTO: {
94 m_agc.enable(true);
95 m_dac.start();
96 float x = etl::clamp(gain.gain0.tgt, m_params.agc0_range.first,
97 m_params.agc0_range.second);
98 m_dac.set_voltage(m_params.agc0_calib.first * x +
99 m_params.agc0_calib.second);
100 } break;
101 case gain_mode::MANUAL: {
102 m_agc.enable(false);
103 m_dac.start();
104 float x = etl::clamp(gain.gain0.gain, m_params.gain0_range.first,
105 m_params.gain0_range.second);
106 m_dac.set_voltage(m_params.gain0_calib.first * x +
107 m_params.gain0_calib.second);
108 } break;
109 default:
110 throw inval_arg_exception(__FILE__, __LINE__);
111 }
112}
113
122bool
123rf_frontend::frequency_valid(dir d, uint32_t freq) const
124{
125 switch (d) {
126 case dir::RX:
127 if (freq < m_params.rx_range.first || freq > m_params.rx_range.second) {
128 return false;
129 }
130 return true;
131 case dir::TX:
132 if (freq < m_params.tx_range.first || freq > m_params.tx_range.second) {
133 return false;
134 }
135 return true;
136 default:
137 throw inval_arg_exception(__FILE__, __LINE__);
138 }
139}
140
141} // namespace satnogs::comms::lib
Generic exception indicating an invalid argument.
Manages power supplies and monitors subsystem status.
Definition power.hpp:43
RF frontend initialization settings.
RX gain settings for the two different gain stages. Gain0 stage corresponds to the first stage (close...
union satnogs::comms::lib::rf_frontend::rx_gain_params::@057170116231345201073375110000256144366370046377 gain0
float tgt
Target signal level for the AGC [-60, -35].
float gain
Fixed gain value in dB [-6, 29.5].
void set_rx_gain(const rx_gain_params &gain)
Sets the RX gain parameters.
virtual void set_filter(filter f)
virtual filter get_filter() const
bool frequency_valid(dir d, uint32_t freq) const
Checks if a frequency is within the permissible range.
rf_frontend(const params &init_params, io_conf &&io, power &pwr)