CTRE Phoenix 6 C++ 24.3.0
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
14#include <units/time.h>
15#include <mutex>
16
17namespace ctre {
18namespace phoenix6 {
19namespace configs {
20
22 {
23 public:
24 /**
25 * \brief The default amount of time to wait for a config.
26 */
27 units::time::second_t DefaultTimeoutSeconds{0.050_s};
28
29 private:
30 hardware::DeviceIdentifier deviceIdentifier;
32
33 protected:
34 ParentConfigurator(hardware::DeviceIdentifier deviceIdentifier) : deviceIdentifier{std::move(deviceIdentifier)}
35 {
36 }
37
38 /* give child classes access to this, but not the typical user */
41
42 ctre::phoenix::StatusCode SetConfigsPrivate(const std::string &serializedString, units::time::second_t timeoutSeconds, bool futureProofConfigs, bool overrideIfDuplicate)
43 {
44 ctre::phoenix::StatusCode status;
45 {
46 std::lock_guard<std::mutex> lock{_m};
47
49 deviceIdentifier.network.c_str(),
50 deviceIdentifier.deviceHash,
51 timeoutSeconds.to<double>(),
52 serializedString,
53 futureProofConfigs,
54 overrideIfDuplicate);
55 }
56
57 if (!status.IsOK())
58 {
59 std::stringstream location;
60 location << this->deviceIdentifier.ToString() << " Apply Config";
61 c_ctre_phoenix_report_error(status.IsError(), status, 0, status.GetDescription(), location.str().c_str(), ctre::phoenix::platform::GetStackTrace(1).c_str());
62 }
63 return status;
64 }
65 ctre::phoenix::StatusCode GetConfigsPrivate(std::string &serializedString, units::time::second_t timeoutSeconds) const
66 {
67 ctre::phoenix::StatusCode status;
68 {
69 std::lock_guard<std::mutex> lock{_m};
70
72 deviceIdentifier.network.c_str(),
73 deviceIdentifier.deviceHash,
74 timeoutSeconds.to<double>(),
75 serializedString);
76 }
77
78 if (!status.IsOK())
79 {
80 std::stringstream location;
81 location << this->deviceIdentifier.ToString() << " Refresh Config";
82 c_ctre_phoenix_report_error(status.IsError(), status, 0, status.GetDescription(), location.str().c_str(), ctre::phoenix::platform::GetStackTrace(1).c_str());
83 }
84 return status;
85 }
86 };
87
88}
89}
90}
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
ctre::phoenix::StatusCode SetConfigsPrivate(const std::string &serializedString, units::time::second_t timeoutSeconds, bool futureProofConfigs, bool overrideIfDuplicate)
Definition: Configurator.hpp:42
ParentConfigurator & operator=(ParentConfigurator &&)=default
ParentConfigurator(hardware::DeviceIdentifier deviceIdentifier)
Definition: Configurator.hpp:34
ParentConfigurator(ParentConfigurator &&)=default
ctre::phoenix::StatusCode GetConfigsPrivate(std::string &serializedString, units::time::second_t timeoutSeconds) const
Definition: Configurator.hpp:65
units::time::second_t DefaultTimeoutSeconds
The default 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.
CTREXPORT std::string GetStackTrace(int offset)
Get a stack trace, ignoring the first "offset" symbols.
Definition: string_util.hpp:15