ReduxLib C++ 2024.1.1-beta0
Loading...
Searching...
No Matches
redux::canand::CanandSettingsManager< T > Class Template Reference

#include <CanandSettingsManager.h>

Public Member Functions

 CanandSettingsManager (CanandDevice &dev)
 
GetSettings (units::second_t timeout, units::second_t missingTimeout, uint32_t missingAttempts)
 
std::vector< uint8_t > FetchMissingSettings (units::second_t timeout, int attempts)
 
void StartFetchSettings ()
 
SetSettings (T &settings, units::second_t timeout, int attempts)
 
bool SetSettings (T &settings, units::second_t timeout)
 
SendReceiveSettingCommand (uint8_t cmd, units::second_t timeout, bool clearKnown)
 
GetKnownSettings ()
 
void HandleSetting (CanandMessage &msg)
 
void SetSettingById (uint8_t settingId, uint8_t *value, uint8_t length, uint8_t flags)
 
void SetSettingById (uint8_t settingId, uint64_t value, uint8_t flags)
 
SettingResult ConfirmSetSetting (uint8_t settingIdx, uint8_t *payload, uint8_t length, units::second_t timeout, uint8_t flags)
 
SettingResult FetchSetting (uint8_t settingIdx, units::second_t timeout)
 
void SendSettingCommand (uint8_t settingCmdIdx)
 

Detailed Description

template<class T>
requires std::is_base_of<CanandSettings, T>
class redux::canand::CanandSettingsManager< T >

Common logic for settings management for CanandDevices.

This class holds a CanandSettings cache of known settings received from the CAN bus, and offers a series of helper functions that provide common logic for bulk settings operations.

Constructor & Destructor Documentation

◆ CanandSettingsManager()

template<class T >
redux::canand::CanandSettingsManager< T >::CanandSettingsManager ( CanandDevice dev)
inline

Constructor.

Parameters
devthe CanandDevice to associate with.

Member Function Documentation

◆ ConfirmSetSetting()

template<class T >
SettingResult redux::canand::CanandSettingsManager< T >::ConfirmSetSetting ( uint8_t  settingIdx,
uint8_t *  payload,
uint8_t  length,
units::second_t  timeout,
uint8_t  flags 
)
inline

Potentially blocking operation to send a setting and wait for a report setting message to be received to confirm the operation.

Parameters
settingIdxSetting index to set and listen for
payloadthe bytes to send.
lengththe length of the payload.
timeoutthe timeout to wait before giving up in seconds. Passing in 0 will return instantly (not block)
flagsoptional flags to send to the device specifying how the setting will be set.
Returns
the value received by the report setting packet if existent or kTimeout otherwise. If timeout = 0, return "payload" (assume success)

◆ FetchMissingSettings()

template<class T >
std::vector< uint8_t > redux::canand::CanandSettingsManager< T >::FetchMissingSettings ( units::second_t  timeout,
int  attempts 
)
inline

Attempt to fill out the known settings with the set of settings it is missing.

Parameters
timeoutmaximum timeout per setting index (seconds)
attemptsnumber of attempts to fetch a setting index (should be at least 1)
Returns
a std::vector of setting indexes that were not able to be received despite attempts/timeout

◆ FetchSetting()

template<class T >
SettingResult redux::canand::CanandSettingsManager< T >::FetchSetting ( uint8_t  settingIdx,
units::second_t  timeout 
)
inline

Fetches a setting from the device and returns the received result.

Parameters
settingIdxSetting index to fetch
timeouttimeout to wait before giving up in seconds. Passing in 0 will return a timeout.
Returns
SettingResult representing the setting result.

◆ GetKnownSettings()

template<class T >
T redux::canand::CanandSettingsManager< T >::GetKnownSettings ( )
inline

Return a CanandSettings of known settings. The object returned is a copy of this object's internal copy.

Returns
known settings

◆ GetSettings()

template<class T >
T redux::canand::CanandSettingsManager< T >::GetSettings ( units::second_t  timeout,
units::second_t  missingTimeout,
uint32_t  missingAttempts 
)
inline

Fetches the device's current configuration in a blocking manner.

This function will block for at least timeout seconds waiting for the device to reply, so it is best to put this in a teleop or autonomous init function, rather than the main loop.

Parameters
timeoutmaximum number of seconds to wait for settings before giving up
missingTimeoutmaximum number of seconds to wait for each settings retry before giving up
missingAttemptsif >0, lists how many times to attempt fetching missing settings.
Returns
CanandSettings representing what has been received of the device's configuration.

◆ HandleSetting()

template<class T >
void redux::canand::CanandSettingsManager< T >::HandleSetting ( CanandMessage msg)
inline

Setting handler to put in CanandDevice::HandleMessage

Parameters
msgthe CanandMessage containing settings data.

◆ SendReceiveSettingCommand()

template<class T >
T redux::canand::CanandSettingsManager< T >::SendReceiveSettingCommand ( uint8_t  cmd,
units::second_t  timeout,
bool  clearKnown 
)
inline

Runs a setting command that may mutate all settings and trigger a response.

Typically used with "reset factory default" type commands

Parameters
cmdsetting index
timeouttotal timeout for all settings to be returned
clearKnownwhether to clear the set of known settings
Returns
the set of known settings.

◆ SendSettingCommand()

template<class T >
void redux::canand::CanandSettingsManager< T >::SendSettingCommand ( uint8_t  settingCmdIdx)
inline

Sends a setting command with no arguments.

Parameters
settingCmdIdxthe index of the setting command to send.

◆ SetSettingById() [1/2]

template<class T >
void redux::canand::CanandSettingsManager< T >::SetSettingById ( uint8_t  settingId,
uint64_t  value,
uint8_t  flags 
)
inline

Directly sends a CAN message to the associated CanandDevice to set a setting by index. This function does not block nor check if a report settings message is sent in response.

Device subclasses will usually have a more user-friendly settings interface, eliminating the need to call this function directly in the vast majority of cases.

Parameters
settingIdsetting id to use
value48-bit long
flagsflags

◆ SetSettingById() [2/2]

template<class T >
void redux::canand::CanandSettingsManager< T >::SetSettingById ( uint8_t  settingId,
uint8_t *  value,
uint8_t  length,
uint8_t  flags 
)
inline

Directly sends a CAN message to the associated CanandDevice to set a setting by index. This function does not block nor check if a report settings message is sent in response.

Device subclasses will usually have a more user-friendly settings interface, eliminating the need to call this function directly in the vast majority of cases.

Parameters
settingIdthe setting id
valuethe raw numerical value. Only the first 6 bytes will be used.
lengththe length of the buffer specified.
flagsoptional flags to send to the device specifying how the setting will be set.

◆ SetSettings() [1/2]

template<class T >
bool redux::canand::CanandSettingsManager< T >::SetSettings ( T &  settings,
units::second_t  timeout 
)
inline

Applies the settings from a CanandSettings to the device.

Parameters
settingsthe CanandSettings to update the device with
timeoutmaximum time in seconds to wait for each setting to be confirmed. Set to 0 to not check (and not block).
Returns
true if successful, false if a setting operation failed

◆ SetSettings() [2/2]

template<class T >
T redux::canand::CanandSettingsManager< T >::SetSettings ( T &  settings,
units::second_t  timeout,
int  attempts 
)
inline

Applies the settings from a CanandSettings to the device, with fine grained control over failure-handling.

This overload allows specifiyng the number of retries per setting as well as the confirmation timeout. Additionally, it returns a CanandSettings object of settings that were not able to be successfully applied.

Parameters
settingsthe CanandSettings to update the device with
timeoutmaximum time in seconds to wait for each setting to be confirmed. Set to 0 to not check (and not block).
attemptsthe maximum number of attempts to write each individual setting
Returns
a CanandSettings object of unsuccessfully set settings.

◆ StartFetchSettings()

template<class T >
void redux::canand::CanandSettingsManager< T >::StartFetchSettings ( )
inline

Tells the device to begin transmitting its settings. Once they are all transmitted (typically after ~200-300ms), the values can be retrieved from GetKnownSettings()


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