20#include <units/dimensionless.h>
41 std::conjunction<std::is_convertible<Devices &, ParentDevice &>...>
51 std::map<uint32_t, std::unique_ptr<BaseStatusSignal>> _signalValues;
52 std::recursive_mutex _signalValuesLck;
57 std::shared_ptr<controls::ControlRequest> _controlReq = std::make_shared<controls::EmptyControl>();
58 std::mutex _controlReqLck;
61 StatusSignal<T> &LookupCommon(uint16_t spn, uint16_t mapper_iter, std::function<std::map<
int,
StatusSignal<T>>()> map_filler, std::string signalName,
bool reportOnConstruction)
66 std::lock_guard<std::recursive_mutex> lock{_signalValuesLck};
68 const uint32_t totalHash = spn | ((uint32_t)mapper_iter << 16);
70 auto iter = _signalValues.find(totalHash);
71 if (iter != _signalValues.end())
74 toFind = iter->second.get();
76 reportOnConstruction =
true;
88 map_filler, std::move(signalName)}});
93 _signalValues.emplace(totalHash, std::unique_ptr<StatusSignal<T>>{
new StatusSignal<T>{
96 std::move(signalName)}});
100 iter = _signalValues.find(totalHash);
101 toFind = iter->second.get();
106 StatusSignal<T> *ret =
dynamic_cast<StatusSignal<T> *
>(toFind);
117 ret->Refresh(reportOnConstruction);
203 return LookupStatusSignal<double>((uint16_t)signal,
"Generic",
true);
279 for (
auto device : devices) {
280 const auto err = device->OptimizeBusUtilization();
314 for (
auto device : devices) {
315 const auto err = device->OptimizeBusUtilization();
326 template <
typename T>
329 std::function<std::map<int, StatusSignal<T>>()> emptyMapFiller = []
331 return std::map<int, StatusSignal<T>>{};
333 return LookupCommon<T>(spn, 0, emptyMapFiller, std::move(signalName), reportOnConstruction);
336 template <
typename T>
339 return LookupCommon<T>(spn, mapper_iter, map_filler, std::move(signalName), reportOnConstruction);
343 template <
typename T,
typename U>
346 return StatusSignal<T>{LookupStatusSignal<U>(spn, std::move(signalName),
true)};
Cross the Road Electronics End User License Agreement This Software License or “Customer” and Cross The Road Electronics a Michigan based company with its principal place of business located at MI Terms Agreement means this End User License Agreement that forms the entire agreement between You and the Company regarding the use of the Software Leone USA Content refers to content such as or other information that can be linked to or otherwise made available by regardless of the form of that content Device means a hardware product or sold by Company Software means a collection of software supplied by Company that interacts with Devices and or simulates the behavior of Devices
Definition: CTRE_LICENSE.txt:22
@ OK
No Error.
Definition: StatusCodes.h:1169
@ InvalidParamValue
Incorrect argument passed into function/VI.
Definition: StatusCodes.h:1501
Class that provides operations to retrieve information about a status signal.
Definition: StatusSignal.hpp:45
Represents a status signal with data of type T, and operations available to retrieve information abou...
Definition: StatusSignal.hpp:626
Abstract Control Request class that other control requests extend for use.
Definition: ControlRequest.hpp:28
Definition: DeviceIdentifier.hpp:19
std::string model
Definition: DeviceIdentifier.hpp:22
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:30
const std::string & GetNetwork() const
Definition: ParentDevice.hpp:140
static constexpr bool is_all_device_v
Whether all types passed in are convertible to ParentDevice references.
Definition: ParentDevice.hpp:48
std::shared_ptr< controls::ControlRequest > GetAppliedControl()
Get the latest applied control.
Definition: ParentDevice.hpp:190
virtual ctre::phoenix::StatusCode SetControlPrivate(controls::ControlRequest &request)
DeviceIdentifier deviceIdentifier
Definition: ParentDevice.hpp:32
StatusSignal< T > & LookupStatusSignal(uint16_t spn, std::string signalName, bool reportOnConstruction)
Definition: ParentDevice.hpp:327
std::shared_ptr< const controls::ControlRequest > GetAppliedControl() const
Get the latest applied control.
Definition: ParentDevice.hpp:173
ctre::phoenix::StatusCode OptimizeBusUtilization(units::time::second_t timeoutSeconds=50_ms)
Optimizes the device's bus utilization by reducing the update frequencies of its status signals.
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:311
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:249
StatusSignal< double > & GetGenericSignal(uint32_t signal)
This is a reserved routine for internal testing.
Definition: ParentDevice.hpp:201
StatusSignal< T > LookupDimensionlessStatusSignal(uint16_t spn, std::string signalName)
Returns a unitless version of the StatusSignal by value.
Definition: ParentDevice.hpp:344
int GetDeviceID() const
Definition: ParentDevice.hpp:132
ParentDevice(int deviceID, std::string model, std::string canbus)
Definition: ParentDevice.hpp:123
uint64_t GetDeviceHash() const
Gets a number unique for this device's hardware type and ID.
Definition: ParentDevice.hpp:154
static constexpr double kDefaultControlRatePeriodsSec
Definition: ParentDevice.hpp:159
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:337
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:276
virtual void ReportIfTooOld()=0
Definition: ManualEvent.hpp:12
Type trait to verify that all types passed in are convertible to ParentDevice references.
Definition: ParentDevice.hpp:42