SatNOGS-COMMS
4.1.0
A COMMS subsystem for CubeSats
Toggle main menu visibility
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
22
#include <
satnogs-comms-lib/board.hpp
>
23
#include <
satnogs-comms-lib/rf_frontend.hpp
>
24
25
namespace
satnogs::comms::lib
26
{
27
28
rf_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 */
37
set_filter
(
filter::NARROW
);
38
}
39
44
void
45
rf_frontend::set_filter
(
filter
f)
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
63
rf_frontend::filter
64
rf_frontend::get_filter
()
const
65
{
66
if
(
m_filt_sel
.get()) {
67
return
filter::NARROW
;
68
}
69
return
filter::WIDE
;
70
}
71
77
rf_frontend::dir
78
rf_frontend::direction
()
const
79
{
80
return
m_dir
;
81
}
82
89
void
90
rf_frontend::set_rx_gain
(
const
rx_gain_params
&gain)
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
122
bool
123
rf_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
board.hpp
satnogs::comms::io
Definition
io.hpp:47
satnogs::comms::lib::inval_arg_exception
Generic exception indicating an invalid argument.
Definition
exception.hpp:180
satnogs::comms::lib::power
Manages power supplies and monitors subsystem status.
Definition
power.hpp:43
satnogs::comms::lib::rf_frontend::io_conf
Definition
rf_frontend.hpp:72
satnogs::comms::lib::rf_frontend::params
RF frontend initialization settings.
Definition
rf_frontend.hpp:50
satnogs::comms::lib::rf_frontend::rx_gain_params
RX gain settings for the two different gain stages. Gain0 stage corresponds to the first stage (close...
Definition
rf_frontend.hpp:112
satnogs::comms::lib::rf_frontend::rx_gain_params::gain0_mode
gain_mode gain0_mode
Definition
rf_frontend.hpp:114
satnogs::comms::lib::rf_frontend::rx_gain_params::gain0
union satnogs::comms::lib::rf_frontend::rx_gain_params::@057170116231345201073375110000256144366370046377 gain0
satnogs::comms::lib::rf_frontend::rx_gain_params::tgt
float tgt
Target signal level for the AGC [-60, -35].
Definition
rf_frontend.hpp:117
satnogs::comms::lib::rf_frontend::rx_gain_params::gain
float gain
Fixed gain value in dB [-6, 29.5].
Definition
rf_frontend.hpp:118
satnogs::comms::lib::rf_frontend::m_agc
ad8318 m_agc
Definition
rf_frontend.hpp:166
satnogs::comms::lib::rf_frontend::direction
dir direction() const
Definition
rf_frontend.cpp:78
satnogs::comms::lib::rf_frontend::m_dac
bsp::dac & m_dac
Definition
rf_frontend.hpp:164
satnogs::comms::lib::rf_frontend::filter
filter
Definition
rf_frontend.hpp:99
satnogs::comms::lib::rf_frontend::filter::NARROW
@ NARROW
Definition
rf_frontend.hpp:101
satnogs::comms::lib::rf_frontend::filter::WIDE
@ WIDE
Definition
rf_frontend.hpp:100
satnogs::comms::lib::rf_frontend::set_rx_gain
void set_rx_gain(const rx_gain_params &gain)
Sets the RX gain parameters.
Definition
rf_frontend.cpp:90
satnogs::comms::lib::rf_frontend::m_dir
dir m_dir
Definition
rf_frontend.hpp:167
satnogs::comms::lib::rf_frontend::m_pwr
power & m_pwr
Definition
rf_frontend.hpp:165
satnogs::comms::lib::rf_frontend::set_filter
virtual void set_filter(filter f)
Definition
rf_frontend.cpp:45
satnogs::comms::lib::rf_frontend::gain_mode::MANUAL
@ MANUAL
Definition
rf_frontend.hpp:95
satnogs::comms::lib::rf_frontend::gain_mode::AUTO
@ AUTO
Definition
rf_frontend.hpp:94
satnogs::comms::lib::rf_frontend::get_filter
virtual filter get_filter() const
Definition
rf_frontend.cpp:64
satnogs::comms::lib::rf_frontend::frequency_valid
bool frequency_valid(dir d, uint32_t freq) const
Checks if a frequency is within the permissible range.
Definition
rf_frontend.cpp:123
satnogs::comms::lib::rf_frontend::rf_frontend
rf_frontend(const params &init_params, io_conf &&io, power &pwr)
Definition
rf_frontend.cpp:28
satnogs::comms::lib::rf_frontend::m_params
const params m_params
Definition
rf_frontend.hpp:162
satnogs::comms::lib::rf_frontend::m_filt_sel
bsp::gpio & m_filt_sel
Definition
rf_frontend.hpp:163
satnogs::comms::lib::rf_frontend::dir
dir
Definition
rf_frontend.hpp:83
satnogs::comms::lib::rf_frontend::dir::TX
@ TX
Definition
rf_frontend.hpp:85
satnogs::comms::lib::rf_frontend::dir::RX
@ RX
Definition
rf_frontend.hpp:84
satnogs::comms::lib
Definition
ad8318.hpp:30
rf_frontend.hpp
libsatnogs-comms
src
rf_frontend.cpp
Generated by
1.17.0