CTRE Phoenix 6 C++ 24.50.0-alpha-2
Configurator.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) Cross The Road Electronics.  All rights reserved.
3 * License information can be found in CTRE_LICENSE.txt
4 * For support and suggestions contact support@ctr-electronics.com or file
5 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
6 */
7#pragma once
8
13#include <units/time.h>
14#include <mutex>
15
16namespace ctre {
17namespace phoenix6 {
18namespace configs {
19
21 {
22 public:
23 /**
24 * \brief The default maximum amount of time to wait for a config.
25 */
26 units::time::second_t DefaultTimeoutSeconds{0.100_s};
27
28 private:
29 hardware::DeviceIdentifier deviceIdentifier;
30 mutable std::mutex _m;
31
32 protected:
33 ParentConfigurator(hardware::DeviceIdentifier deviceIdentifier) : deviceIdentifier{std::move(deviceIdentifier)}
34 {
35 }
36
39
40 ctre::phoenix::StatusCode SetConfigsPrivate(const std::string &serializedString, units::time::second_t timeoutSeconds, bool futureProofConfigs, bool overrideIfDuplicate)
41 {
43 {
44 std::lock_guard<std::mutex> lock{_m};
45
47 deviceIdentifier.network.c_str(),
48 deviceIdentifier.deviceHash,
49 timeoutSeconds.to<double>(),
50 serializedString,
51 futureProofConfigs,
52 overrideIfDuplicate);
53 }
54
56 {
57 std::stringstream location;
58 location << this->deviceIdentifier.ToString() << " Apply Config";
59 c_ctre_phoenix_report_error(status.IsError(), status, 0, status.GetDescription(), location.str().c_str(), ctre::phoenix::platform::GetStackTrace(1).c_str());
60 }
61 return status;
62 }
63 ctre::phoenix::StatusCode GetConfigsPrivate(std::string &serializedString, units::time::second_t timeoutSeconds) const
64 {
66 {
67 std::lock_guard<std::mutex> lock{_m};
68
70 deviceIdentifier.network.c_str(),
71 deviceIdentifier.deviceHash,
72 timeoutSeconds.to<double>(),
73 serializedString);
74 }
75
76 if (!status.IsOK())
77 {
78 std::stringstream location;
79 location << this->deviceIdentifier.ToString() << " Refresh Config";
80 c_ctre_phoenix_report_error(status.IsError(), status, 0, status.GetDescription(), location.str().c_str(), ctre::phoenix::platform::GetStackTrace(1).c_str());
81 }
82 return status;
83 }
84 };
85
86}
87}
88}
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:21
ctre::phoenix::StatusCode SetConfigsPrivate(const std::string &serializedString, units::time::second_t timeoutSeconds, bool futureProofConfigs, bool overrideIfDuplicate)
Definition: Configurator.hpp:40
ParentConfigurator(hardware::DeviceIdentifier deviceIdentifier)
Definition: Configurator.hpp:33
ParentConfigurator(ParentConfigurator const &)=delete
ctre::phoenix::StatusCode GetConfigsPrivate(std::string &serializedString, units::time::second_t timeoutSeconds) const
Definition: Configurator.hpp:63
ParentConfigurator & operator=(ParentConfigurator const &)=delete
units::time::second_t DefaultTimeoutSeconds
The default maximum amount of time to wait for a config.
Definition: Configurator.hpp:26
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:1061
constexpr bool IsOK() const
Definition: StatusCodes.h:855
static constexpr int TimeoutCannotBeZero
Blocking operations, such as configs, cannot have a timeout of 0.
Definition: StatusCodes.h:772
constexpr bool IsError() const
Definition: StatusCodes.h:847
CTREXPORT std::string GetStackTrace(int offset)
Get a stack trace, ignoring the first "offset" symbols.
Represents the state of one swerve module.
Definition: StatusCodes.h:18
Definition: span.hpp:401