ReduxLib C++ 2024.3.2
|
#include <CanandSettingsManager.h>
Public Member Functions | |
CanandSettingsManager (CanandDevice &dev) | |
T | 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 () |
T | SetSettings (T &settings, units::second_t timeout, int attempts) |
bool | SetSettings (T &settings, units::second_t timeout) |
T | SendReceiveSettingCommand (uint8_t cmd, units::second_t timeout, bool clearKnown) |
T | 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 | ConfirmSetSetting (uint8_t settingIdx, uint64_t payload, units::second_t timeout, uint8_t flags) |
SettingResult | FetchSetting (uint8_t settingIdx, units::second_t timeout) |
void | SendSettingCommand (uint8_t settingCmdIdx) |
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.
|
inline |
Constructor.
dev | the CanandDevice to associate with. |
|
inline |
Potentially blocking operation to send a setting and wait for a report setting message to be received to confirm the operation.
settingIdx | Setting index to set and listen for |
payload | the 48 bits to send. |
timeout | the timeout to wait before giving up in seconds. Passing in 0 will return instantly (not block) |
flags | optional flags to send to the device specifying how the setting will be set. |
|
inline |
Potentially blocking operation to send a setting and wait for a report setting message to be received to confirm the operation.
settingIdx | Setting index to set and listen for |
payload | the bytes to send. |
length | the length of the payload. |
timeout | the timeout to wait before giving up in seconds. Passing in 0 will return instantly (not block) |
flags | optional flags to send to the device specifying how the setting will be set. |
|
inline |
Attempt to fill out the known settings with the set of settings it is missing.
timeout | maximum timeout per setting index (seconds) |
attempts | number of attempts to fetch a setting index (should be at least 1) |
|
inline |
Fetches a setting from the device and returns the received result.
settingIdx | Setting index to fetch |
timeout | timeout to wait before giving up in seconds. Passing in 0 will return a timeout. |
|
inline |
Return a CanandSettings of known settings. The object returned is a copy of this object's internal copy.
|
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.
timeout | maximum number of seconds to wait for settings before giving up |
missingTimeout | maximum number of seconds to wait for each settings retry before giving up |
missingAttempts | if >0, lists how many times to attempt fetching missing settings. |
|
inline |
Setting handler to put in CanandDevice::HandleMessage
msg | the CanandMessage containing settings data. |
|
inline |
Runs a setting command that may mutate all settings and trigger a response.
Typically used with "reset factory default" type commands
cmd | setting index |
timeout | total timeout for all settings to be returned |
clearKnown | whether to clear the set of known settings |
|
inline |
Sends a setting command with no arguments.
settingCmdIdx | the index of the setting command to send. |
|
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.
settingId | setting id to use |
value | 48-bit long |
flags | 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.
settingId | the setting id |
value | the raw numerical value. Only the first 6 bytes will be used. |
length | the length of the buffer specified. |
flags | optional flags to send to the device specifying how the setting will be set. |
|
inline |
Applies the settings from a CanandSettings to the device.
settings | the CanandSettings to update the device with |
timeout | maximum time in seconds to wait for each setting to be confirmed. Set to 0 to not check (and not block). |
|
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.
settings | the CanandSettings to update the device with |
timeout | maximum time in seconds to wait for each setting to be confirmed. Set to 0 to not check (and not block). |
attempts | the maximum number of attempts to write each individual setting |
|
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()