16#include <unordered_map>
32 std::unordered_map<uint32_t, std::unique_ptr<BaseStatusSignal>> _signalValues;
33 std::recursive_mutex _signalValuesLck;
38 std::shared_ptr<controls::ControlRequest> _controlReq = std::make_shared<controls::EmptyControl>();
39 mutable std::mutex _controlReqLck;
41 struct FirmwareVersChecker {
54 void ReportIfTooOld();
57 std::shared_ptr<FirmwareVersChecker> _versChecker;
62 uint16_t spn, std::string signalName,
63 std::function<std::map<uint16_t, std::string>()> mapFiller,
64 bool reportOnConstruction,
bool refresh)
68 BaseStatusSignal *toFind;
71 std::lock_guard<std::recursive_mutex> lock{_signalValuesLck};
74 auto iter = _signalValues.find(spn);
75 if (iter != _signalValues.end()) {
77 toFind = iter->second.get();
79 reportOnConstruction =
true;
83 iter = _signalValues.emplace(spn,
84 std::unique_ptr<StatusSignal<T>>{
new StatusSignal<T>{
86 std::move(signalName),
87 [versChecker=_versChecker]()
mutable {
88 versChecker->ReportIfTooOld();
93 iter = _signalValues.emplace(spn,
94 std::unique_ptr<StatusSignal<T>>{
new StatusSignal<T>{
96 std::move(signalName),
97 [versChecker=_versChecker]()
mutable {
98 versChecker->ReportIfTooOld();
106 toFind = iter->second.get();
111 StatusSignal<T> *ret =
dynamic_cast<StatusSignal<T> *
>(toFind);
113 if (ret ==
nullptr) {
119 ret->Refresh(reportOnConstruction);
184 std::lock_guard<std::mutex> lock{_controlReqLck};
202 std::lock_guard<std::mutex> lock{_controlReqLck};
211 return _resetSignal.Refresh(
false).HasUpdated();
219 return [resetSignal=_resetSignal]()
mutable {
220 return resetSignal.Refresh(
false).HasUpdated();
233 bool IsConnected(wpi::units::second_t maxLatencySeconds = 500_ms)
final
235 return _versChecker->_compliancy.Refresh(
false).GetTimestamp().GetLatency() <= maxLatencySeconds;
249 return [compliancy=_versChecker->_compliancy, maxLatencySeconds]()
mutable {
250 return compliancy.Refresh(
false).GetTimestamp().GetLatency() <= maxLatencySeconds;
314 template <std::derived_from<traits::CommonDevice>... Devices>
375 template <std::derived_from<traits::CommonDevice>... Devices>
410 for (
auto device : devices) {
411 auto const err = device->OptimizeBusUtilization(optimizedFreqHz);
443 template <std::derived_from<traits::CommonDevice>... Devices>
464 for (
auto device : devices) {
465 auto const err = device->ResetSignalFrequencies();
478 template <
typename T>
481 return LookupCommon<T>(spn, std::move(signalName),
nullptr, reportOnConstruction, refresh);
484 template <
typename T>
487 return LookupCommon<T>(spn, std::move(signalName), std::move(mapFiller), reportOnConstruction, refresh);
Collection of objects that can report alerts.
Definition Alertable.hpp:109
Class for getting information about an available CAN bus.
Definition CANBus.hpp:142
Persistent alert with debouncing.
Definition Alerts.hpp:24
Interface for all types that can report a Phoenix alert.
Definition Alertable.hpp:21
Represents a status signal with data of type T, and operations available to retrieve information abou...
Definition StatusSignal.hpp:523
Common interface implemented by all control requests.
Definition ControlRequest.hpp:27
Generic Empty Control class used to do nothing.
Definition ControlRequest.hpp:65
The unique identifier for a device.
Definition DeviceIdentifier.hpp:19
virtual ctre::phoenix::StatusCode SetControlPrivate(controls::ControlRequest const &request)
CANBus GetNetwork() const final
Definition ParentDevice.hpp:143
StatusSignal< T > & LookupStatusSignal(uint16_t spn, std::string signalName, std::function< std::map< uint16_t, std::string >()> mapFiller, bool reportOnConstruction, bool refresh)
Definition ParentDevice.hpp:485
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll(wpi::units::hertz_t optimizedFreqHz, Devices &... devices)
Optimizes the bus utilization of the provided devices by reducing the update frequencies of their sta...
Definition ParentDevice.hpp:376
static ctre::phoenix::StatusCode ResetSignalFrequenciesForAll(Devices &... devices)
Resets the update frequencies of all the devices' status signals to the defaults.
Definition ParentDevice.hpp:444
DeviceIdentifier deviceIdentifier
Definition ParentDevice.hpp:29
StatusSignal< T > & LookupStatusSignal(uint16_t spn, std::string signalName, bool reportOnConstruction, bool refresh)
Definition ParentDevice.hpp:479
ParentDevice(ParentDevice const &)=delete
ctre::phoenix::StatusCode ResetSignalFrequencies(wpi::units::second_t timeoutSeconds=100_ms) final
Resets the update frequencies of all the device's status signals to the defaults.
static ctre::phoenix::StatusCode ResetSignalFrequenciesForAll(std::span< traits::CommonDevice *const > devices)
Resets the update frequencies of all the devices' status signals to the defaults.
Definition ParentDevice.hpp:461
std::string ToString() const override
Definition ParentDevice.hpp:165
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:315
static constexpr controls::EmptyControl _emptyControl
Definition ParentDevice.hpp:27
bool IsConnected(wpi::units::second_t maxLatencySeconds=500_ms) final
Returns whether the device is still connected to the robot.
Definition ParentDevice.hpp:233
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll(std::span< traits::CommonDevice *const > devices)
Optimizes the bus utilization of the provided devices by reducing the update frequencies of their sta...
Definition ParentDevice.hpp:344
uint32_t GetDeviceHash() const final
Gets a number unique for this device's hardware type and ID.
Definition ParentDevice.hpp:157
std::function< bool()> GetIsConnectedChecker(wpi::units::second_t maxLatencySeconds=500_ms) const final
Gets a function that checks whether the device is still connected to the robot.
Definition ParentDevice.hpp:247
virtual ~ParentDevice()=0
int GetDeviceID() const final
Definition ParentDevice.hpp:135
ParentDevice(int deviceID, std::string model, CANBus canbus)
ctre::phoenix::StatusCode OptimizeBusUtilization(wpi::units::hertz_t optimizedFreqHz=4_Hz, wpi::units::second_t timeoutSeconds=100_ms) final
Optimizes the device's bus utilization by reducing the update frequencies of its status signals.
std::function< bool()> GetResetOccurredChecker() const final
Definition ParentDevice.hpp:217
std::shared_ptr< controls::ControlRequest const > GetAppliedControl() const final
Get the latest applied control.
Definition ParentDevice.hpp:182
StatusSignal< double > & GetGenericSignal(uint16_t signal, bool refresh=true)
This is a reserved routine for internal testing.
Definition ParentDevice.hpp:261
static ctre::phoenix::StatusCode OptimizeBusUtilizationForAll(wpi::units::hertz_t optimizedFreqHz, std::span< traits::CommonDevice *const > devices)
Optimizes the bus utilization of the provided devices by reducing the update frequencies of their sta...
Definition ParentDevice.hpp:407
std::shared_ptr< controls::ControlRequest > GetAppliedControl() final
Get the latest applied control.
Definition ParentDevice.hpp:200
ParentDevice & operator=(ParentDevice const &)=delete
void RegisterAlerts(AlertableCollection &collection) override
Registers all alerts for this type to the provided collection.
bool HasResetOccurred() final
Definition ParentDevice.hpp:209
Contains everything common between Phoenix 6 devices.
Definition CommonDevice.hpp:23
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
static constexpr int OK
No Error.
Definition StatusCodes.h:35
static constexpr int InvalidParamValue
An invalid argument was passed into the function/VI, such as a null pointer.
Definition StatusCodes.h:370
static constexpr int CouldNotRetrieveV6Firmware
Device firmware could not be retrieved.
Definition StatusCodes.h:725
constexpr bool IsOK() const
Definition StatusCodes.h:860
Definition ExternalFeedbackConfigs.hpp:17
CTREXPORT double GetCurrentTimeSeconds()
Get the current timestamp in seconds.
Definition ExternalFeedbackConfigs.hpp:16
Definition motor_constants.h:14