19#include <units/dimensionless.h>
38 template <
typename... Devices>
40 std::conjunction<std::is_base_of<ParentDevice, std::remove_reference_t<Devices>>...>
46 template <
typename... Devices>
50 std::map<uint32_t, std::unique_ptr<BaseStatusSignal>> _signalValues;
56 std::shared_ptr<controls::ControlRequest> _controlReq = std::make_shared<controls::EmptyControl>();
61 bool _isInitialized =
false;
65 StatusSignal<int> _compliancy{LookupStatusSignal<int>(ctre::phoenix6::spns::SpnValue::Compliancy_Version,
"Compliancy",
false)};
66 StatusSignal<int> _resetSignal{LookupStatusSignal<int>(ctre::phoenix6::spns::SpnValue::Startup_ResetFlags,
"ResetFlags",
false)};
68 void ReportIfTooOld();
71 StatusSignal<T> &LookupCommon(uint16_t spn, uint16_t mapper_iter, std::function<std::map<
int, StatusSignal<T>>()> map_filler, std::string signalName,
bool reportOnConstruction)
73 BaseStatusSignal *toFind;
76 std::lock_guard<std::recursive_mutex> lock{_signalValuesLck};
78 const uint32_t totalHash = spn | ((uint32_t)mapper_iter << 16);
80 auto iter = _signalValues.find(totalHash);
81 if (iter != _signalValues.end())
84 toFind = iter->second.get();
86 reportOnConstruction =
true;
95 _signalValues.emplace(totalHash, std::unique_ptr<StatusSignal<T>>{
new StatusSignal<T>{
97 { ReportIfTooOld(); },
98 map_filler, std::move(signalName)}});
103 _signalValues.emplace(totalHash, std::unique_ptr<StatusSignal<T>>{
new StatusSignal<T>{
105 { ReportIfTooOld(); },
106 std::move(signalName)}});
110 iter = _signalValues.find(totalHash);
111 toFind = iter->second.get();
116 StatusSignal<T> *ret =
dynamic_cast<StatusSignal<T> *
>(toFind);
127 ret->Refresh(reportOnConstruction);
137 _isInitialized =
true;
222 return [resetSignal=_resetSignal]()
mutable {
223 return resetSignal.Refresh(
false).HasUpdated();
235 return LookupStatusSignal<double>((uint16_t)signal,
"Generic",
true);
259 ctre::phoenix::StatusCode
OptimizeBusUtilization(units::frequency::hertz_t optimizedFreqHz = 0_Hz, units::time::second_t timeoutSeconds = 50_ms);
283 template <
typename... Devices,
typename = std::enable_if_t<
is_all_device_v<Devices...>>>
369 template <
typename... Devices,
typename = std::enable_if_t<
is_all_device_v<Devices...>>>
403 for (
auto device : devices) {
404 const auto err = device->OptimizeBusUtilization(optimizedFreqHz);
441 for (
auto device : devices) {
442 const auto err = device->OptimizeBusUtilization(optimizedFreqHz);
453 template <
typename T>
456 std::function<std::map<int, StatusSignal<T>>()> emptyMapFiller = []
458 return std::map<int, StatusSignal<T>>{};
460 return LookupCommon<T>(spn, 0, emptyMapFiller, std::move(signalName), reportOnConstruction);
463 template <
typename T>
466 return LookupCommon<T>(spn, mapper_iter, map_filler, std::move(signalName), reportOnConstruction);
470 template <
typename T,
typename U>
473 return StatusSignal<T>{LookupStatusSignal<U>(spn, std::move(signalName),
true)};
@ OK
No Error.
Definition: StatusCodes.h:1196
@ CouldNotRetrieveV6Firmware
Device firmware could not be retrieved.
Definition: StatusCodes.h:1878
@ InvalidParamValue
An invalid argument was passed into the function/VI, such as a null pointer.
Definition: StatusCodes.h:1529
bool HasUpdated()
Check whether the signal has been updated since the last check.
Definition: StatusSignal.hpp:579
StatusSignal< T > & Refresh(bool ReportOnError=true)
Refreshes the value of this status signal.
Definition: StatusSignal.hpp:810
Abstract Control Request class that other control requests extend for use.
Definition: ControlRequest.hpp:28
Generic Empty Control class used to do nothing.
Definition: ControlRequest.hpp:71
Definition: DeviceIdentifier.hpp:19
int deviceID
Definition: DeviceIdentifier.hpp:23
uint32_t deviceHash
Definition: DeviceIdentifier.hpp:24
std::string network
Definition: DeviceIdentifier.hpp:21
Parent class for all devices.
Definition: ParentDevice.hpp:29
static controls::EmptyControl _emptyControl
Definition: ParentDevice.hpp:31
const std::string & GetNetwork() const
Definition: ParentDevice.hpp:156
static constexpr bool is_all_device_v
Whether all types passed in are subclasses of ParentDevice.
Definition: ParentDevice.hpp:47
std::shared_ptr< controls::ControlRequest > GetAppliedControl()
Get the latest applied control.
Definition: ParentDevice.hpp:204
virtual ctre::phoenix::StatusCode SetControlPrivate(controls::ControlRequest &request)
DeviceIdentifier deviceIdentifier
Definition: ParentDevice.hpp:33
StatusSignal< T > & LookupStatusSignal(uint16_t spn, std::string signalName, bool reportOnConstruction)
Definition: ParentDevice.hpp:454
std::function< bool()> GetResetOccurredChecker() const
Definition: ParentDevice.hpp:220
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll(units::frequency::hertz_t optimizedFreqHz, const std::array< ParentDevice *, N > &devices)
Optimizes the bus utilization of the provided devices by reducing the update frequencies of their sta...
Definition: ParentDevice.hpp:438
ParentDevice & operator=(ParentDevice &&)=default
ctre::phoenix::StatusCode OptimizeBusUtilization(units::frequency::hertz_t optimizedFreqHz=0_Hz, units::time::second_t timeoutSeconds=50_ms)
Optimizes the device's bus utilization by reducing the update frequencies of its status signals.
std::shared_ptr< const controls::ControlRequest > GetAppliedControl() const
Get the latest applied control.
Definition: ParentDevice.hpp:187
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll(const std::array< ParentDevice *, N > &devices)
Optimizes the bus utilization of the provided devices by reducing the update frequencies of their sta...
Definition: ParentDevice.hpp:339
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll(Devices &... devices)
Optimizes the bus utilization of the provided devices by reducing the update frequencies of their sta...
Definition: ParentDevice.hpp:284
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll(units::frequency::hertz_t optimizedFreqHz, Devices &... devices)
Optimizes the bus utilization of the provided devices by reducing the update frequencies of their sta...
Definition: ParentDevice.hpp:370
StatusSignal< double > & GetGenericSignal(uint32_t signal)
This is a reserved routine for internal testing.
Definition: ParentDevice.hpp:233
StatusSignal< T > LookupDimensionlessStatusSignal(uint16_t spn, std::string signalName)
Returns a unitless version of the StatusSignal by value.
Definition: ParentDevice.hpp:471
int GetDeviceID() const
Definition: ParentDevice.hpp:148
ParentDevice(int deviceID, std::string model, std::string canbus)
Definition: ParentDevice.hpp:133
ParentDevice(ParentDevice &&)=default
uint64_t GetDeviceHash() const
Gets a number unique for this device's hardware type and ID.
Definition: ParentDevice.hpp:170
virtual ~ParentDevice()=default
bool HasResetOccurred()
Definition: ParentDevice.hpp:212
StatusSignal< T > & LookupStatusSignal(uint16_t spn, uint16_t mapper_iter, std::function< std::map< int, StatusSignal< T > >()> map_filler, std::string signalName, bool reportOnConstruction)
Definition: ParentDevice.hpp:464
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll(const std::vector< ParentDevice * > &devices)
Optimizes the bus utilization of the provided devices by reducing the update frequencies of their sta...
Definition: ParentDevice.hpp:311
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll(units::frequency::hertz_t optimizedFreqHz, const std::vector< ParentDevice * > &devices)
Optimizes the bus utilization of the provided devices by reducing the update frequencies of their sta...
Definition: ParentDevice.hpp:400
CTREXPORT double GetCurrentTimeSeconds()
Get the current timestamp in seconds.
Definition: string_util.hpp:15
Type trait to verify that all types passed in are subclasses of ParentDevice.
Definition: ParentDevice.hpp:41