CTRE Phoenix 6 C++ 26.0.0-beta-1
Loading...
Searching...
No Matches
ctre::phoenix6::StatusSignalCollection Class Reference

Class to manage bulk refreshing device status signals. More...

#include <ctre/phoenix6/StatusSignalCollection.hpp>

Public Member Functions

template<std::derived_from< BaseStatusSignal >... Signals>
 StatusSignalCollection (Signals &... signals)
 Creates a new collection of status signals, optionally adding the provided signals to the collection.
 
 StatusSignalCollection (std::span< BaseStatusSignal *const > signals)
 Creates a new collection of status signals, adding the provided span of signals to the collection.
 
template<std::derived_from< BaseStatusSignal >... Signals>
void AddSignals (Signals &... signals)
 Adds the provided signals to the collection.
 
void AddSignals (std::span< BaseStatusSignal *const > signals)
 Adds the provided signals to the collection.
 
ctre::phoenix::StatusCode WaitForAll (units::time::second_t timeout)
 Waits for new data on all signals up to timeout.
 
ctre::phoenix::StatusCode RefreshAll ()
 Performs a non-blocking refresh on all signals.
 
ctre::phoenix::StatusCode SetUpdateFrequencyForAll (units::frequency::hertz_t frequency)
 Sets the update frequency of all status signals to the provided common frequency.
 
bool IsAllGood () const
 Checks if all signals have an OK error code.
 

Protected Attributes

std::vector< BaseStatusSignal * > _signals
 Signals stored by this collection.
 

Detailed Description

Class to manage bulk refreshing device status signals.

This class does not own copies of the provided status signals. As a result, the usage of this class cannot outlive the lifetime of the status signals.

Constructor & Destructor Documentation

◆ StatusSignalCollection() [1/2]

template<std::derived_from< BaseStatusSignal >... Signals>
ctre::phoenix6::StatusSignalCollection::StatusSignalCollection ( Signals &... signals)
inline

Creates a new collection of status signals, optionally adding the provided signals to the collection.

This collection does not own copies of the provided status signals. As a result, the usage of this collection cannot outlive the lifetime of the status signals.

Parameters
signalsSignals to add, passed as a comma-separated list of signal references

◆ StatusSignalCollection() [2/2]

ctre::phoenix6::StatusSignalCollection::StatusSignalCollection ( std::span< BaseStatusSignal *const > signals)
inline

Creates a new collection of status signals, adding the provided span of signals to the collection.

This collection does not own copies of the provided status signals. As a result, the usage of this collection cannot outlive the lifetime of the status signals.

Parameters
signalsSignals to add, passed as a span of signal pointers

Member Function Documentation

◆ AddSignals() [1/2]

template<std::derived_from< BaseStatusSignal >... Signals>
void ctre::phoenix6::StatusSignalCollection::AddSignals ( Signals &... signals)
inline

Adds the provided signals to the collection.

This collection does not own copies of the provided status signals. As a result, the usage of this collection cannot outlive the lifetime of the status signals.

Parameters
signalsSignals to add, passed as a comma-separated list of signal references

◆ AddSignals() [2/2]

void ctre::phoenix6::StatusSignalCollection::AddSignals ( std::span< BaseStatusSignal *const > signals)
inline

Adds the provided signals to the collection.

This collection does not own copies of the provided status signals. As a result, the usage of this collection cannot outlive the lifetime of the status signals.

Parameters
signalsSignals to add, passed as a span of signal pointers

◆ IsAllGood()

bool ctre::phoenix6::StatusSignalCollection::IsAllGood ( ) const
inline

Checks if all signals have an OK error code.

Returns
True if all signals are OK, false otherwise

◆ RefreshAll()

ctre::phoenix::StatusCode ctre::phoenix6::StatusSignalCollection::RefreshAll ( )
inline

Performs a non-blocking refresh on all signals.

This provides a performance improvement over separately calling Refresh() on each signal.

Returns
An InvalidParamValue if this signal collection is empty, InvalidNetwork if signals are on different CAN bus networks. An OK status code means that all signals are OK.

Any other value represents the StatusCode of the first failed signal. Call GetStatus() on each signal to determine which ones failed.

◆ SetUpdateFrequencyForAll()

ctre::phoenix::StatusCode ctre::phoenix6::StatusSignalCollection::SetUpdateFrequencyForAll ( units::frequency::hertz_t frequency)
inline

Sets the update frequency of all status signals to the provided common frequency.

A frequency of 0 Hz will turn off the signal. Otherwise, the minimum supported signal frequency is 4 Hz, and the maximum is 1000 Hz.

If other StatusSignals in the same status frame have been set to an update frequency, the fastest requested update frequency will be applied to the frame.

This will wait up to 0.100 seconds (100ms) for each signal.

Parameters
frequencyRate to publish the signal in Hz.
Returns
Status code of the first failed update frequency set call, or OK if all succeeded

◆ WaitForAll()

ctre::phoenix::StatusCode ctre::phoenix6::StatusSignalCollection::WaitForAll ( units::time::second_t timeout)
inline

Waits for new data on all signals up to timeout.

This API is typically used with CANivore Bus signals as they will be synced using the CANivore Timesync feature and arrive simultaneously. Signals on a roboRIO bus cannot be synced and may require a significantly longer blocking call to receive all signals.

Note that CANivore Timesync requires Phoenix Pro.

This can also be used with a timeout of zero to refresh many signals at once, which is faster than calling Refresh() on every signal. This is equivalent to calling RefreshAll.

If a signal arrives multiple times while waiting, such as when not using CANivore Timesync, the newest signal data is fetched. Additionally, if this function times out, the newest signal data is fetched for all signals (when possible). We recommend checking the individual status codes using BaseStatusSignal::GetStatus() when this happens.

Parameters
timeoutMaximum time to wait for all the signals to arrive. Pass zero to refresh all signals without blocking.
Returns
An InvalidParamValue if this signal collection is empty, InvalidNetwork if signals are on different CAN bus networks, RxTimeout if it took longer than timeoutSeconds to receive all the signals, MultiSignalNotSupported if using the roboRIO bus with more than one signal and a non-zero timeout. An OK status code means that all signals arrived within timeoutSeconds and they are all OK.

Any other value represents the StatusCode of the first failed signal. Call GetStatus() on each signal to determine which ones failed.

Member Data Documentation

◆ _signals

std::vector<BaseStatusSignal *> ctre::phoenix6::StatusSignalCollection::_signals
protected

Signals stored by this collection.


The documentation for this class was generated from the following file: