SatNOGS-COMMS  4.1.0
A COMMS subsystem for CubeSats
Loading...
Searching...
No Matches
settings.cpp
Go to the documentation of this file.
1/*
2 * SatNOGS-COMMS MCU software
3 *
4 * Copyright (C) 2024-2025, 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 "settings.hpp"
23#include "dsp/ccsds.hpp"
24#include "error_handler.hpp"
25#include "memory_monitor.hpp"
27#include <zephyr/drivers/flash.h>
28
29namespace scl = satnogs::comms::lib;
31
32static const struct device *const flash = DEVICE_DT_GET(DT_NODELABEL(flash));
33static constexpr size_t size = DT_REG_SIZE(DT_NODELABEL(lfs1_partition));
34constexpr off_t offset = DT_REG_ADDR(DT_NODELABEL(lfs1_partition));
35
36FS_FSTAB_DECLARE_ENTRY(DT_NODELABEL(lfs1));
37struct fs_mount_t *mountpoint = &FS_FSTAB_ENTRY(DT_NODELABEL(lfs1));
38namespace satnogs::comms
39{
40
46settings::settings() : m_runtime_settings_map{}
47{
48 k_mutex_init(&m_mtx);
49 /*
50 * If mount fails, it probably means that a double ECC flash error occured in
51 * the directory header, erase the partition, reboot, and try to mount again.
52 */
53 try {
54 if (fs_mount(mountpoint) < 0) {
55 flash_erase(flash, offset, size);
56 throw flash_read_exception(__FILE__, __LINE__);
57 }
58 } catch (const flash_read_exception &e) {
59 auto &err = error_handler::get_instance();
60 err.handle(e);
61 }
62
63 for (auto key : m_settings_map.keys()) {
64 m_runtime_settings_map.insert({key, m_settings_map[key].default_value});
65 }
66 load();
67}
68
75void
82
92bool
94{
95 return get<param::BOOT_COUNT>() > 0;
96}
97
104void
106{
107 cnf.sync = dsp::ccsds::ASM;
108 switch (iface) {
110 cnf.preamble_len = 16;
114 cnf.fsk.rate = fsk.baudrate;
115 cnf.fsk.mod_idx = fsk.mod_idx;
116 cnf.fsk.excess_bw = fsk.shaping;
117 } break;
119 cnf.preamble_len = 32;
123 cnf.fsk.rate = fsk.baudrate;
124 cnf.fsk.mod_idx = fsk.mod_idx;
125 cnf.fsk.excess_bw = fsk.shaping;
126 } break;
127 default:
128 throw lib::inval_arg_exception(__FILE__, __LINE__);
129 }
130}
131
138void
140{
141 cnf.preamble_len = 16;
142 cnf.sync = dsp::ccsds::ASM;
143 switch (iface) {
148
151 } else {
153 }
154
157 cnf.gain.gain1.agc.avgs = agc1.avg;
158 cnf.gain.gain1.agc.input = agc1.input;
159 cnf.gain.gain1.agc.tgt = agc1.tgt;
160 } else {
162 }
164 cnf.fsk.rate = fsk.baudrate;
165 cnf.fsk.mod_idx = fsk.mod_idx;
166 cnf.fsk.excess_bw = fsk.mod_idx;
168 } break;
173
176 } else {
178 }
179
182 cnf.gain.gain1.agc.avgs = agc1.avg;
183 cnf.gain.gain1.agc.input = agc1.input;
184 cnf.gain.gain1.agc.tgt = agc1.tgt;
185 } else {
187 }
189 cnf.fsk.rate = fsk.baudrate;
190 cnf.fsk.mod_idx = fsk.mod_idx;
191 cnf.fsk.excess_bw = fsk.mod_idx;
193 } break;
194 default:
195 throw lib::inval_arg_exception(__FILE__, __LINE__);
196 }
197}
198
206{
208 switch (x) {
209 case static_cast<uint32_t>(radio::clk_src::INTERNAL):
211 case static_cast<uint32_t>(radio::clk_src::EXTERNAL):
213 default:
215 }
216}
217
224void
226{
227 reset_sequence(std::make_index_sequence<m_settings_map.size()>{});
228}
229
238void
240{
241 load_sequence(std::make_index_sequence<m_settings_map.size()>{});
242}
243
252void
254{
255 save_sequence(std::make_index_sequence<m_settings_map.size()>{});
256}
257
258} // namespace satnogs::comms
static constexpr uint32_t ASM
CCSDS frame synchronization marker.
Definition ccsds.hpp:41
static error_handler & get_instance()
Singleton access to the error_handler subsystem.
Generic exception indicating an invalid argument.
at86rf215_fsk_srate_t rate
FSK data rate.
Definition radio.hpp:261
float excess_bw
FSK 3-dB bandwidth of the shaping filter.
Definition radio.hpp:265
RX configuration parameters.
Definition radio.hpp:299
fsk_conf fsk
FSK parameters.
Definition radio.hpp:304
uint32_t sync
The synchronization word.
Definition radio.hpp:303
rf_frontend::filter filter
Hardware filter selection.
Definition radio.hpp:306
uint32_t freq
The desired RX frequency to set.
Definition radio.hpp:301
rf_frontend::rx_gain_params gain
Gain settings to set.
Definition radio.hpp:305
uint8_t preamble_len
The length of the preamble in bytes.
Definition radio.hpp:302
uint32_t sync
The synchronization word.
Definition radio.hpp:314
fsk_conf fsk
FSK parameters.
Definition radio.hpp:315
uint32_t freq
The desired RX frequency to set.
Definition radio.hpp:312
uint8_t preamble_len
The length of the preamble in bytes.
Definition radio.hpp:313
Radio subsystem providing TX/RX functionality on UHF and S-Band.
Definition radio.hpp:127
interface
Radio interface identifier.
Definition radio.hpp:177
clk_src
PLL Reference Clock identifier.
Definition radio.hpp:167
@ INTERNAL
Internal Crystal Oscillator.
Definition radio.hpp:168
@ EXTERNAL
External Reference Clock (TCXO).
Definition radio.hpp:169
union satnogs::comms::lib::rf_frontend::rx_gain_params::@057170116231345201073375110000256144366370046377 gain0
float tgt
Target signal level for the AGC [-60, -35].
union satnogs::comms::lib::rf_frontend::rx_gain_params::@215011014006014333052114215072331261330071377362 gain1
float gain
Fixed gain value in dB [-6, 29.5].
void save()
Save all the core settings from the RAM shadow table to FLASH.
Definition settings.cpp:253
void save_one()
Save a core setting from RAM shadow table to FLASH.
Definition settings.hpp:464
settings()
Construct a new settings::settings object and mounts the LittleFS partition.
Definition settings.cpp:46
void set(T x)
Sets a mission-defined setting in RAM shadow table.
Definition settings.hpp:281
void get_tx_conf(lib::radio::interface iface, lib::radio::tx_conf &cnf)
Retrieve the TX configuration parameters for a specific interface.
Definition settings.cpp:105
void get_rx_conf(lib::radio::interface iface, lib::radio::rx_conf &cnf)
Retrieve the TX configuration parameters for a specific interface.
Definition settings.cpp:139
auto get()
Get a specific core setting from RAM shadow table.
Definition settings.hpp:348
bool deployed()
Retrieves the information regarding if this is the first time that the system deploys.
Definition settings.cpp:93
void reset_all()
Resets all the settings to their default values.
Definition settings.cpp:225
lib::radio::clk_src radio_clk_src()
Returns the current radio clock source.
Definition settings.cpp:205
void incr_boot_cnt()
Increments the current boot count and stores it at the persistent storage.
Definition settings.cpp:76
void load()
Loads all the core settings from FLASH to the RAM shadow table.
Definition settings.cpp:239
FS_FSTAB_DECLARE_ENTRY(DT_NODELABEL(lfs1))
struct fs_mount_t * mountpoint
Definition settings.cpp:37
scl::radio radio
Definition settings.cpp:30
constexpr off_t offset
Definition settings.cpp:34
at86rf215_agc_avgs_t avg
Definition settings.hpp:158
at86rf215_agc_tgt_t tgt
Definition settings.hpp:157
at86rf215_fsk_srate_t baudrate
Definition settings.hpp:164