SatNOGS-COMMS  4.1.0
A COMMS subsystem for CubeSats
Loading...
Searching...
No Matches
satnogs::comms::settings Class Reference

Store and retrieve reliably persistent settings. More...

#include <settings.hpp>

Classes

struct  agc1
struct  fsk
struct  basic_param_info
 Extensible parameter descriptor. More...
struct  is_param_info
struct  is_param_info< basic_param_info< Types... > >

Public Types

enum class  param : uint16_t {
  BOOT_COUNT , UHF_TX_FREQ , UHF_RX_FREQ , SBAND_TX_FREQ ,
  SBAND_RX_FREQ , UHF_TX_EN , SBAND_TX_EN , UHF_TX_GAIN ,
  SBAND_TX_GAIN , IO_WDG_PERIOD_MINS , SBAND_RX_RANGE_MIN , SBAND_RX_RANGE_MAX ,
  SBAND_TX_RANGE_MIN , SBAND_TX_RANGE_MAX , SBAND_AGC0_RANGE_MIN , SBAND_AGC0_RANGE_MAX ,
  SBAND_GAIN0_RANGE_MIN , SBAND_GAIN0_RANGE_MAX , SBAND_AGC0_CALIB_SLOPE , SBAND_AGC0_CALIB_INTRCPT ,
  SBAND_GAIN0_CALIB_SLOPE , SBAND_GAIN0_CALIB_INTRCPT , UHF_RX_RANGE_MIN , UHF_RX_RANGE_MAX ,
  UHF_TX_RANGE_MIN , UHF_TX_RANGE_MAX , UHF_AGC0_RANGE_MIN , UHF_AGC0_RANGE_MAX ,
  UHF_GAIN0_RANGE_MIN , UHF_GAIN0_RANGE_MAX , UHF_AGC0_CALIB_SLOPE , UHF_AGC0_CALIB_INTRCPT ,
  UHF_GAIN0_CALIB_SLOPE , UHF_GAIN0_CALIB_INTRCPT , PLL_REF_CLK_SRC , UHF_FILTER ,
  SBAND_FILTER , UHF_ENABLE , UHF_GAIN0_MODE , UHF_GAIN1_MODE ,
  UHF_GAIN0_TGT , UHF_GAIN0_GAIN , UHF_GAIN1_AGC , UHF_GAIN1_GAIN ,
  UHF_TX_MODULATION , UHF_FSK_TX , UHF_RX_MODULATION , UHF_FSK_RX ,
  SBAND_ENABLE , SBAND_GAIN0_MODE , SBAND_GAIN1_MODE , SBAND_GAIN0_TGT ,
  SBAND_GAIN0_GAIN , SBAND_GAIN1_AGC , SBAND_GAIN1_GAIN , SBAND_TX_MODULATION ,
  SBAND_FSK_TX , SBAND_RX_MODULATION , SBAND_FSK_RX , THERMAL_UHF_SHUTDOWN_TEMP ,
  THERMAL_UHF_ENABLE_TEMP , THERMAL_SBAND_SHUTDOWN_TEMP , THERMAL_SBAND_ENABLE_TEMP , THERMAL_PCB_SHUTDOWN_TEMP ,
  THERMAL_PCB_ENABLE_TEMP , THERMAL_MIN_VALID_TEMP , THERMAL_MAX_VALID_TEMP , UHF_TRX_TURNAROUND_MS ,
  SBAND_TRX_TURNAROUND_MS , UHF_RX_ON_SECS , UHF_RX_OFF_SECS , SBAND_RX_ON_SECS ,
  SBAND_RX_OFF_SECS , FPGA_BOOT_MODE , UHF_TX_WAIT_MS , SBAND_TX_WAIT_MS ,
  _COUNT
}
 Specific setting identifier. More...
using param_info = basic_param_info<>

Public Member Functions

 settings (settings const &)=delete
void operator= (settings const &)=delete
void incr_boot_cnt ()
 Increments the current boot count and stores it at the persistent storage.
bool deployed ()
 Retrieves the information regarding if this is the first time that the system deploys.
void get_tx_conf (lib::radio::interface iface, lib::radio::tx_conf &cnf)
 Retrieve the TX configuration parameters for a specific interface.
void get_rx_conf (lib::radio::interface iface, lib::radio::rx_conf &cnf)
 Retrieve the TX configuration parameters for a specific interface.
lib::radio::clk_src radio_clk_src ()
 Returns the current radio clock source.
template<const auto Key, const auto & Map, auto & RuntimeMap, typename T, typename = std::enable_if_t<!std::is_same_v<decltype(Key), param>, void>>
void set (T x)
 Sets a mission-defined setting in RAM shadow table.
template<const auto Key, typename T, typename = std::enable_if_t<std::is_same_v<decltype(Key), param>, void>>
void set (T x)
 Sets a specific core setting in RAM shadow table.
template<const auto Key, const auto & Map, auto & RuntimeMap>
void reset ()
 Reset a mission specific setting in RAM shadow table.
template<param P>
void reset ()
 Reset a specific core setting in RAM shadow table.
template<param P>
auto get ()
 Get a specific core setting from RAM shadow table.
template<const auto Key, const auto & Map, const auto & RuntimeMap>
auto get ()
 Get a mission-defined setting in RAM shadow table.
template<const auto Key, const auto & Map, auto & RuntimeMap>
void load_one ()
 Load a mission-defined setting from FLASH to the RAM shadow table.
template<param P>
void load_one ()
 Load a core setting from FLASH to the RAM shadow table.
template<param P>
void save_one ()
 Save a core setting from RAM shadow table to FLASH.
template<const auto Key, const auto & Map, auto & RuntimeMap>
void save_one ()
 Save a mission specific setting from RAM shadow table to FLASH.
void reset_all ()
 Resets all the settings to their default values.
void load ()
 Loads all the core settings from FLASH to the RAM shadow table.
void save ()
 Save all the core settings from the RAM shadow table to FLASH.
template<const auto & Map, auto & RuntimeMap>
constexpr void load ()
 Load ALL mission-defined settings from FLASH to the RAM shadow table.
template<const auto & Map, auto & RuntimeMap>
constexpr void reset_all ()
 Reset ALL mission-defined settings.
template<const auto & Map, auto & RuntimeMap>
constexpr void save ()
 Save ALL mission-defined settings from the RAM shadow table to FLASH.

Static Public Member Functions

static settingsget_instance ()
 Get a singleton access to the settings subsystem.
template<const auto Key, const auto & Map>
static constexpr auto defaults ()
 Returns the default value of a mission-defined setting.
template<param P>
static constexpr auto defaults ()
 Returns the default value of a specific setting.

Static Public Attributes

static constexpr uint32_t TRUE_MAGIC = 0xA17E3C5D
static constexpr uint32_t FALSE_MAGIC = 0x0CF18BE2
static constexpr std::size_t TABLE_SIZE
template<typename T>
static constexpr bool is_param_info_v = is_param_info<T>::value

Protected Member Functions

 settings ()
 Construct a new settings::settings object and mounts the LittleFS partition.

Detailed Description

Store and retrieve reliably persistent settings.

The settings subsystem utilizes LittleFS to store reliably all the settings that should be persistent across power cycles. It uses the internal flash of the MCU.

All settings are mirrored to RAM for fast access via a runtime shadow table. Default values are applied on first boot or when data is missing.

Access to the subsystem itself is achieved using the singleton design pattern. All read or write operations are thread-safe.

To add a new setting, first a new file should be defined. All files should defined under the /lfs1 directory. In addition, a default setting value should be set, so it can be applied in case the flash area is formatted or has been previously erased.

Definition at line 59 of file settings.hpp.

Member Typedef Documentation

◆ param_info

Backward-compatible alias — zero extra types.

Definition at line 202 of file settings.hpp.

Member Enumeration Documentation

◆ param

enum class satnogs::comms::settings::param : uint16_t
strong

Specific setting identifier.

To efficiently discriminate between the available settings parameters, indexing is performed via this enumeration

Enumerator
BOOT_COUNT 
UHF_TX_FREQ 
UHF_RX_FREQ 
SBAND_TX_FREQ 
SBAND_RX_FREQ 
UHF_TX_EN 
SBAND_TX_EN 
UHF_TX_GAIN 
SBAND_TX_GAIN 
IO_WDG_PERIOD_MINS 
SBAND_RX_RANGE_MIN 
SBAND_RX_RANGE_MAX 
SBAND_TX_RANGE_MIN 
SBAND_TX_RANGE_MAX 
SBAND_AGC0_RANGE_MIN 
SBAND_AGC0_RANGE_MAX 
SBAND_GAIN0_RANGE_MIN 
SBAND_GAIN0_RANGE_MAX 
SBAND_AGC0_CALIB_SLOPE 
SBAND_AGC0_CALIB_INTRCPT 
SBAND_GAIN0_CALIB_SLOPE 
SBAND_GAIN0_CALIB_INTRCPT 
UHF_RX_RANGE_MIN 
UHF_RX_RANGE_MAX 
UHF_TX_RANGE_MIN 
UHF_TX_RANGE_MAX 
UHF_AGC0_RANGE_MIN 
UHF_AGC0_RANGE_MAX 
UHF_GAIN0_RANGE_MIN 
UHF_GAIN0_RANGE_MAX 
UHF_AGC0_CALIB_SLOPE 
UHF_AGC0_CALIB_INTRCPT 
UHF_GAIN0_CALIB_SLOPE 
UHF_GAIN0_CALIB_INTRCPT 
PLL_REF_CLK_SRC 
UHF_FILTER 
SBAND_FILTER 
UHF_ENABLE 
UHF_GAIN0_MODE 
UHF_GAIN1_MODE 
UHF_GAIN0_TGT 
UHF_GAIN0_GAIN 
UHF_GAIN1_AGC 
UHF_GAIN1_GAIN 
UHF_TX_MODULATION 
UHF_FSK_TX 
UHF_RX_MODULATION 
UHF_FSK_RX 
SBAND_ENABLE 
SBAND_GAIN0_MODE 
SBAND_GAIN1_MODE 
SBAND_GAIN0_TGT 
SBAND_GAIN0_GAIN 
SBAND_GAIN1_AGC 
SBAND_GAIN1_GAIN 
SBAND_TX_MODULATION 
SBAND_FSK_TX 
SBAND_RX_MODULATION 
SBAND_FSK_RX 
THERMAL_UHF_SHUTDOWN_TEMP 
THERMAL_UHF_ENABLE_TEMP 
THERMAL_SBAND_SHUTDOWN_TEMP 
THERMAL_SBAND_ENABLE_TEMP 
THERMAL_PCB_SHUTDOWN_TEMP 
THERMAL_PCB_ENABLE_TEMP 
THERMAL_MIN_VALID_TEMP 
THERMAL_MAX_VALID_TEMP 
UHF_TRX_TURNAROUND_MS 
SBAND_TRX_TURNAROUND_MS 
UHF_RX_ON_SECS 
UHF_RX_OFF_SECS 
SBAND_RX_ON_SECS 
SBAND_RX_OFF_SECS 
FPGA_BOOT_MODE 
UHF_TX_WAIT_MS 
SBAND_TX_WAIT_MS 
_COUNT 

Definition at line 70 of file settings.hpp.

Constructor & Destructor Documentation

◆ settings() [1/2]

satnogs::comms::settings::settings ( settings const & )
delete

◆ settings() [2/2]

satnogs::comms::settings::settings ( )
protected

Construct a new settings::settings object and mounts the LittleFS partition.

Definition at line 46 of file settings.cpp.

Member Function Documentation

◆ defaults() [1/2]

template<param P>
constexpr auto satnogs::comms::settings::defaults ( )
inlinestaticconstexpr

Returns the default value of a specific setting.

Template Parameters
Pthe settings::param setting
Returns
constexpr auto default value of the given setting

Definition at line 262 of file settings.hpp.

◆ defaults() [2/2]

template<const auto Key, const auto & Map>
constexpr auto satnogs::comms::settings::defaults ( )
inlinestaticconstexpr

Returns the default value of a mission-defined setting.

Template Parameters
Keythe specific setting to get the default value
&Mapthe constexpr map containing the mission defined settings
Returns
constexpr auto default value of the given setting

Definition at line 244 of file settings.hpp.

◆ deployed()

bool satnogs::comms::settings::deployed ( )

Retrieves the information regarding if this is the first time that the system deploys.

Returns
true has already deployed
false if this is the first time that the system powers up
Note
Internally this is implemented by checking the boot counter

Definition at line 93 of file settings.cpp.

◆ get() [1/2]

template<const auto Key, const auto & Map, const auto & RuntimeMap>
auto satnogs::comms::settings::get ( )
inline

Get a mission-defined setting in RAM shadow table.

Template Parameters
paramthe specific setting to set
&Mapthe constexpr map containing the mission defined settings
&RuntimeMapthe runtime map that holds the mission-defined settings stored in RAM
Returns
std::variant<float, uint32_t, bool> the value of the mission-defined setting

Definition at line 366 of file settings.hpp.

◆ get() [2/2]

template<param P>
auto satnogs::comms::settings::get ( )
inline

Get a specific core setting from RAM shadow table.

Template Parameters
paramthe specific setting to set

Definition at line 348 of file settings.hpp.

◆ get_instance()

settings & satnogs::comms::settings::get_instance ( )
inlinestatic

Get a singleton access to the settings subsystem.

Returns
settings& singleton access to the settings subsystem

Definition at line 210 of file settings.hpp.

◆ get_rx_conf()

void satnogs::comms::settings::get_rx_conf ( lib::radio::interface iface,
lib::radio::rx_conf & cnf )

Retrieve the TX configuration parameters for a specific interface.

Parameters
ifacethe desired interface
cnfreference to a TX configuration, to store the retrieved parameters

Definition at line 139 of file settings.cpp.

◆ get_tx_conf()

void satnogs::comms::settings::get_tx_conf ( lib::radio::interface iface,
lib::radio::tx_conf & cnf )

Retrieve the TX configuration parameters for a specific interface.

Parameters
ifacethe desired interface
cnfreference to a TX configuration, to store the retrieved parameters

Definition at line 105 of file settings.cpp.

◆ incr_boot_cnt()

void satnogs::comms::settings::incr_boot_cnt ( )

Increments the current boot count and stores it at the persistent storage.

Warning
this method is not thread-safe

Definition at line 76 of file settings.cpp.

◆ load() [1/2]

template<const auto & Map, auto & RuntimeMap>
void satnogs::comms::settings::load ( )
inlineconstexpr

Load ALL mission-defined settings from FLASH to the RAM shadow table.

Template Parameters
&Mapthe constexpr map containing the mission defined settings
&RuntimeMapthe runtime map that holds the mission-defined settings stored in RAM

Definition at line 532 of file settings.hpp.

◆ load() [2/2]

void satnogs::comms::settings::load ( )

Loads all the core settings from FLASH to the RAM shadow table.

Warning
This method does not load any mission-defined settings. Only the core settings are loaded. One must call the load<MISSION_SPECIFIC_SETTINGS_MAP>() method to load the mission-defined settings

Definition at line 239 of file settings.cpp.

◆ load_one() [1/2]

template<param P>
void satnogs::comms::settings::load_one ( )
inline

Load a core setting from FLASH to the RAM shadow table.

Template Parameters
paramthe specific setting to set
Note
If the parameter is a boolean value, the value in flash is expected to be one of the magic constants TRUE_MAGIC or FALSE_MAGIC. Any other pattern is treated as flash corruption and the setting reverts to the default parameter.

Definition at line 425 of file settings.hpp.

◆ load_one() [2/2]

template<const auto Key, const auto & Map, auto & RuntimeMap>
void satnogs::comms::settings::load_one ( )
inline

Load a mission-defined setting from FLASH to the RAM shadow table.

Template Parameters
Keythe specific setting to load
&Mapthe constexpr map containing the mission defined settings
&RuntimeMapthe runtime map that holds the mission-defined settings stored in RAM
Note
If the parameter is a boolean value, the value in flash is expected to be one of the magic constants TRUE_MAGIC or FALSE_MAGIC. Any other pattern is treated as flash corruption and the setting reverts to the default parameter.

Definition at line 387 of file settings.hpp.

◆ operator=()

void satnogs::comms::settings::operator= ( settings const & )
delete

◆ radio_clk_src()

radio::clk_src satnogs::comms::settings::radio_clk_src ( )

Returns the current radio clock source.

Returns
radio::clk_src the current radio clock source

Definition at line 205 of file settings.cpp.

◆ reset() [1/2]

template<param P>
void satnogs::comms::settings::reset ( )
inline

Reset a specific core setting in RAM shadow table.

Template Parameters
paramthe specific setting to set

Definition at line 337 of file settings.hpp.

◆ reset() [2/2]

template<const auto Key, const auto & Map, auto & RuntimeMap>
void satnogs::comms::settings::reset ( )
inline

Reset a mission specific setting in RAM shadow table.

Template Parameters
Keythe specific setting to set
&Mapthe constexpr map containing the mission specific settings
&RuntimeMapthe runtime map that holds the mission-defined settings stored in RAM

Definition at line 321 of file settings.hpp.

◆ reset_all() [1/2]

template<const auto & Map, auto & RuntimeMap>
void satnogs::comms::settings::reset_all ( )
inlineconstexpr

Reset ALL mission-defined settings.

Template Parameters
&Mapthe constexpr map containing the mission defined settings
&RuntimeMapthe runtime map that holds the mission-defined settings stored in RAM

Definition at line 545 of file settings.hpp.

◆ reset_all() [2/2]

void satnogs::comms::settings::reset_all ( )

Resets all the settings to their default values.

Warning
This method does not reset any mission-defined settings. Only the core settings are reset.

Definition at line 225 of file settings.cpp.

◆ save() [1/2]

template<const auto & Map, auto & RuntimeMap>
void satnogs::comms::settings::save ( )
inlineconstexpr

Save ALL mission-defined settings from the RAM shadow table to FLASH.

Template Parameters
&Mapthe constexpr map containing the mission defined settings
&RuntimeMapthe runtime map that holds the mission-defined settings stored in RAM

Definition at line 559 of file settings.hpp.

◆ save() [2/2]

void satnogs::comms::settings::save ( )

Save all the core settings from the RAM shadow table to FLASH.

Warning
This method does not load any mission-defined settings. Only the core settings are loaded. One must call the save<MISSION_SPECIFIC_SETTINGS_MAP>() method to save the mission-defined settings

Definition at line 253 of file settings.cpp.

◆ save_one() [1/2]

template<const auto Key, const auto & Map, auto & RuntimeMap>
void satnogs::comms::settings::save_one ( )
inline

Save a mission specific setting from RAM shadow table to FLASH.

Template Parameters
Keythe specific setting to load
&Mapthe constexpr map containing the mission defined settings
&RuntimeMapthe runtime map that holds the mission-defined settings stored in RAM
Note
If the underlying type of the parameter is boolean, the value is first converted to the 32-bit magic patterns TRUE_MAGIC and FALSE_MAGIC. This guards against silent bit flips due to flash corruption that could otherwise erroneously flip a critical boolean (e.g. TX-inhibit) on the next boot without any warning.

Definition at line 494 of file settings.hpp.

◆ save_one() [2/2]

template<param P>
void satnogs::comms::settings::save_one ( )
inline

Save a core setting from RAM shadow table to FLASH.

Template Parameters
Keythe specific setting to load
&Mapthe constexpr map containing the mission defined settings
Note
If the underlying type of the parameter is boolean, the value is first converted to the 32-bit magic patterns TRUE_MAGIC and FALSE_MAGIC. This guards against silent bit flips due to flash corruption that could otherwise erroneously flip a critical boolean (e.g. TX-inhibit) on the next boot without any warning.

Definition at line 464 of file settings.hpp.

◆ set() [1/2]

template<const auto Key, typename T, typename = std::enable_if_t<std::is_same_v<decltype(Key), param>, void>>
void satnogs::comms::settings::set ( T x)
inline

Sets a specific core setting in RAM shadow table.

Template Parameters
paramthe specific setting to set
Parameters
xthe value to set

Definition at line 303 of file settings.hpp.

◆ set() [2/2]

template<const auto Key, const auto & Map, auto & RuntimeMap, typename T, typename = std::enable_if_t<!std::is_same_v<decltype(Key), param>, void>>
void satnogs::comms::settings::set ( T x)
inline

Sets a mission-defined setting in RAM shadow table.

Template Parameters
Keythe specific setting to set
&Mapthe constexpr map containing the mission specific settings
&RuntimeMapthe runtime map that holds the mission-defined settings stored in RAM
Parameters
xthe value to set

Definition at line 281 of file settings.hpp.

Member Data Documentation

◆ FALSE_MAGIC

uint32_t satnogs::comms::settings::FALSE_MAGIC = 0x0CF18BE2
staticconstexpr

Definition at line 63 of file settings.hpp.

◆ is_param_info_v

template<typename T>
bool satnogs::comms::settings::is_param_info_v = is_param_info<T>::value
staticconstexpr

Definition at line 199 of file settings.hpp.

◆ TABLE_SIZE

std::size_t satnogs::comms::settings::TABLE_SIZE
staticconstexpr
Initial value:
=
static_cast<std::size_t>(param::_COUNT)

Definition at line 151 of file settings.hpp.

◆ TRUE_MAGIC

uint32_t satnogs::comms::settings::TRUE_MAGIC = 0xA17E3C5D
staticconstexpr

Definition at line 62 of file settings.hpp.


The documentation for this class was generated from the following files: