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;
51 std::recursive_mutex _signalValuesLck;
56 std::shared_ptr<controls::ControlRequest> _controlReq = std::make_shared<controls::EmptyControl>();
57 std::mutex _controlReqLck;
61 bool _isInitialized =
false;
68 void ReportIfTooOld();
80 std::lock_guard<std::recursive_mutex>
lock{_signalValuesLck};
83 auto iter = _signalValues.find(spn);
84 if (
iter != _signalValues.end()) {
92 _signalValues.emplace(spn,
95 [
this] { ReportIfTooOld(); },
100 _signalValues.emplace(spn,
103 [
this] { ReportIfTooOld(); },
110 iter = _signalValues.find(spn);
118 if (
ret ==
nullptr) {
135 _isInitialized =
true;
422 for (
auto device : devices) {
461 for (
auto device : devices) {
515 for (
auto device : devices) {
516 const auto err = device->ResetSignalFrequencies();
540 for (
auto device : devices) {
541 const auto err = device->ResetSignalFrequencies();
552 template <
typename T>
558 template <
typename T>
565 template <
typename T,
typename U>
bool HasUpdated()
Check whether the signal has been updated since the last check.
Definition StatusSignal.hpp:608
const Timestamp & GetTimestamp() const
Get the most accurate timestamp available for this signal.
Definition StatusSignal.hpp:593
Represents a status signal with data of type T, and operations available to retrieve information abou...
Definition StatusSignal.hpp:657
StatusSignal< T > & Refresh(bool ReportOnError=true)
Refreshes the value of this status signal.
Definition StatusSignal.hpp:786
units::time::second_t GetLatency() const
Get the latency of this timestamp compared to now.
Definition Timestamp.hpp:115
Abstract Control Request class that other control requests extend for use.
Definition ControlRequest.hpp:29
Generic Empty Control class used to do nothing.
Definition ControlRequest.hpp:72
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:154
static ctre::phoenix::StatusCode ResetSignalFrequenciesForAll(const std::array< ParentDevice *, N > &devices)
Resets the update frequencies of all the devices' status signals to the defaults.
Definition ParentDevice.hpp:537
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:202
StatusSignal< T > LookupDimensionlessStatusSignal(uint16_t spn, std::string signalName, bool refresh)
Returns a unitless version of the StatusSignal by value.
Definition ParentDevice.hpp:566
DeviceIdentifier deviceIdentifier
Definition ParentDevice.hpp:33
StatusSignal< T > & LookupStatusSignal(uint16_t spn, std::string signalName, bool reportOnConstruction, bool refresh)
Definition ParentDevice.hpp:553
ParentDevice(ParentDevice const &)=delete
static ctre::phoenix::StatusCode ResetSignalFrequenciesForAll(const std::vector< ParentDevice * > &devices)
Resets the update frequencies of all the devices' status signals to the defaults.
Definition ParentDevice.hpp:512
bool IsConnected(units::second_t maxLatencySeconds=500_ms)
Returns whether the device is still connected to the robot.
Definition ParentDevice.hpp:234
std::function< bool()> GetResetOccurredChecker() const
Definition ParentDevice.hpp:218
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:458
virtual ctre::phoenix::StatusCode SetControlPrivate(const controls::ControlRequest &request)
std::shared_ptr< const controls::ControlRequest > GetAppliedControl() const
Get the latest applied control.
Definition ParentDevice.hpp:185
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:356
ctre::phoenix::StatusCode OptimizeBusUtilization(units::frequency::hertz_t optimizedFreqHz=0_Hz, units::time::second_t timeoutSeconds=100_ms)
Optimizes the device's bus utilization by reducing the update frequencies of its status signals.
static ctre::phoenix::StatusCode ResetSignalFrequenciesForAll(Devices &... devices)
Resets the update frequencies of all the devices' status signals to the defaults.
Definition ParentDevice.hpp:495
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:299
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:388
ctre::phoenix::StatusCode ResetSignalFrequencies(units::time::second_t timeoutSeconds=100_ms)
Resets the update frequencies of all the device's status signals to the defaults.
StatusSignal< T > & LookupStatusSignal(uint16_t spn, std::function< std::map< uint16_t, std::string >()> mapFiller, std::string signalName, bool reportOnConstruction, bool refresh)
Definition ParentDevice.hpp:559
int GetDeviceID() const
Definition ParentDevice.hpp:146
ParentDevice(int deviceID, std::string model, std::string canbus)
Definition ParentDevice.hpp:131
uint64_t GetDeviceHash() const
Gets a number unique for this device's hardware type and ID.
Definition ParentDevice.hpp:168
virtual ~ParentDevice()=default
bool HasResetOccurred()
Definition ParentDevice.hpp:210
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:327
StatusSignal< double > & GetGenericSignal(uint32_t signal, bool refresh=true)
This is a reserved routine for internal testing.
Definition ParentDevice.hpp:246
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:419
ParentDevice & operator=(ParentDevice const &)=delete
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
static constexpr int OK
No Error.
Definition StatusCodes.h:34
static constexpr int InvalidParamValue
An invalid argument was passed into the function/VI, such as a null pointer.
Definition StatusCodes.h:368
static constexpr int CouldNotRetrieveV6Firmware
Device firmware could not be retrieved.
Definition StatusCodes.h:721
CTREXPORT double GetCurrentTimeSeconds()
Get the current timestamp in seconds.
Definition StatusCodes.h:18
Type trait to verify that all types passed in are subclasses of ParentDevice.
Definition ParentDevice.hpp:41