CTRE Phoenix Pro C++ 23.0.12
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 phoenixpro {
18namespace configs {
19
21 {
22 public:
23 /**
24 * \brief The default amount of time to wait for a config.
25 */
26 units::time::second_t defaultTimeoutSeconds{0.050_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
37 ctre::phoenix::StatusCode SetConfigsPrivate(const std::string &serializedString, units::time::second_t timeoutSeconds, bool futureProofConfigs, bool overrideIfDuplicate)
38 {
39 ctre::phoenix::StatusCode status;
40 {
41 std::lock_guard<std::mutex> lock{_m};
42
45 deviceIdentifier.network.c_str(),
46 deviceIdentifier.deviceHash,
47 timeoutSeconds.to<double>(),
48 serializedString,
49 futureProofConfigs,
50 overrideIfDuplicate);
51 }
52
53 if (!status.IsOK())
54 {
55 std::stringstream location;
56 location << this->deviceIdentifier.ToString() << " Apply Config";
57 c_ctre_phoenix_report_error(status.IsError(), status, 0, status.GetDescription(), location.str().c_str(), ctre::phoenix::platform::GetStackTrace(1).c_str());
58 }
59 return status;
60 }
61 ctre::phoenix::StatusCode GetConfigsPrivate(std::string &serializedString, units::time::second_t timeoutSeconds) const
62 {
63 ctre::phoenix::StatusCode status;
64 {
65 std::lock_guard<std::mutex> lock{_m};
66
69 deviceIdentifier.network.c_str(),
70 deviceIdentifier.deviceHash,
71 timeoutSeconds.to<double>(),
72 serializedString);
73 }
74
75 if (!status.IsOK())
76 {
77 std::stringstream location;
78 location << this->deviceIdentifier.ToString() << " Refresh Config";
79 c_ctre_phoenix_report_error(status.IsError(), status, 0, status.GetDescription(), location.str().c_str(), ctre::phoenix::platform::GetStackTrace(1).c_str());
80 }
81 return status;
82 }
83 };
84
85}
86}
87}
@ ContextAPI
Definition: Context.h:11
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 GetConfigsPrivate(std::string &serializedString, units::time::second_t timeoutSeconds) const
Definition: Configurator.hpp:61
units::time::second_t defaultTimeoutSeconds
The default amount of time to wait for a config.
Definition: Configurator.hpp:26
ParentConfigurator(hardware::DeviceIdentifier deviceIdentifier)
Definition: Configurator.hpp:33
ctre::phoenix::StatusCode SetConfigsPrivate(const std::string &serializedString, units::time::second_t timeoutSeconds, bool futureProofConfigs, bool overrideIfDuplicate)
Definition: Configurator.hpp:37
Definition: DeviceIdentifier.hpp:19
std::string network
Definition: DeviceIdentifier.hpp:21
std::string ToString() const
Definition: DeviceIdentifier.hpp:34
uint32_t deviceHash
Definition: DeviceIdentifier.hpp:24
static ctre::phoenix::StatusCode Device_GetConfigValues(Context context, const char *network, int deviceHash, double timeoutSeconds, std::string &serializedString)
Gets the config value of the device.
static ctre::phoenix::StatusCode Device_SetConfigValues(Context context, 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:14