14#include <units/time.h>
31 mutable std::mutex _m;
34 mutable units::second_t _lastConfigTime = _creationTime;
35 mutable units::second_t _freqConfigStart = 0_s;
48 auto lastConfigTime = _lastConfigTime;
49 _lastConfigTime = currentTime;
51 if (currentTime - _creationTime < 5_s) {
56 if (currentTime - lastConfigTime < 1_s) {
58 if (_freqConfigStart == 0_s) {
60 _freqConfigStart = lastConfigTime;
64 _freqConfigStart = 0_s;
67 if (_freqConfigStart > 0_s && currentTime - _freqConfigStart > 3_s) {
71 std::stringstream location;
72 location << this->deviceIdentifier.
ToString() <<
" Config";
81 std::lock_guard<std::mutex> lock{_m};
84 deviceIdentifier.
network.c_str(),
86 timeoutSeconds.to<
double>(),
95 std::stringstream location;
96 location << this->deviceIdentifier.
ToString() <<
" Apply Config";
105 std::lock_guard<std::mutex> lock{_m};
108 deviceIdentifier.
network.c_str(),
110 timeoutSeconds.to<
double>(),
116 if (!status.
IsOK()) {
117 std::stringstream location;
118 location << this->deviceIdentifier.
ToString() <<
" Refresh Config";
CTREXPORT void c_ctre_phoenix_report_error(int isError, int32_t errorCode, int isLVCode, const char *details, const char *location, const char *callStack)
Definition Configurator.hpp:22
void ReportIfFrequent() const
Definition Configurator.hpp:45
ctre::phoenix::StatusCode SetConfigsPrivate(const std::string &serializedString, units::time::second_t timeoutSeconds, bool futureProofConfigs, bool overrideIfDuplicate)
Definition Configurator.hpp:77
ParentConfigurator(hardware::DeviceIdentifier deviceIdentifier)
Definition Configurator.hpp:38
ParentConfigurator(ParentConfigurator const &)=delete
ctre::phoenix::StatusCode GetConfigsPrivate(std::string &serializedString, units::time::second_t timeoutSeconds) const
Definition Configurator.hpp:101
ParentConfigurator & operator=(ParentConfigurator const &)=delete
units::time::second_t DefaultTimeoutSeconds
The default maximum amount of time to wait for a config.
Definition Configurator.hpp:27
Definition DeviceIdentifier.hpp:19
std::string ToString() const
Definition DeviceIdentifier.hpp:34
uint32_t deviceHash
Definition DeviceIdentifier.hpp:24
std::string network
Definition DeviceIdentifier.hpp:21
static ctre::phoenix::StatusCode Device_GetConfigValues(const char *network, int deviceHash, double timeoutSeconds, std::string &serializedString)
Gets the config value of the device.
static ctre::phoenix::StatusCode Device_SetConfigValues(const char *network, int deviceHash, double timeoutSeconds, const std::string &serializedString, bool futureProofConfigs, bool overrideIfDuplicate)
Sets the config value of the device.
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
constexpr const char * GetDescription() const
Gets the description of this StatusCode.
Definition StatusCodes.h:1066
static constexpr int FrequentConfigCalls
Do not apply or refresh configs periodically, as configs are blocking.
Definition StatusCodes.h:632
constexpr bool IsOK() const
Definition StatusCodes.h:859
static constexpr int TimeoutCannotBeZero
Blocking operations, such as configs, cannot have a timeout of 0.
Definition StatusCodes.h:776
constexpr bool IsError() const
Definition StatusCodes.h:851
units::second_t GetCurrentTime()
Get the current timestamp.
Definition Utils.hpp:29
Definition StatusCodes.h:18