CTRE Phoenix 6 C++ 26.2.0
Loading...
Searching...
No Matches
StatusSignalCollection.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) Cross The Road Electronics.  All rights reserved.
3 * License information can be found in CTRE_LICENSE.txt
4 * For support and suggestions contact support@ctr-electronics.com or file
5 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
6 */
7#pragma once
8
10#include <vector>
11
12namespace ctre {
13namespace phoenix6 {
14
15 /**
16 * \brief Class to manage bulk refreshing device status signals.
17 *
18 * This class does not own copies of the provided status signals. As a result,
19 * the usage of this class cannot outlive the lifetime of the status signals.
20 */
22 protected:
23 /** Signals stored by this collection */
24 std::vector<BaseStatusSignal *> _signals;
25
26 public:
27 /**
28 * \brief Creates a new collection of status signals, optionally
29 * adding the provided signals to the collection.
30 *
31 * This collection does not own copies of the provided status signals.
32 * As a result, the usage of this collection cannot outlive the lifetime
33 * of the status signals.
34 *
35 * \param signals Signals to add, passed as a comma-separated list of signal references
36 */
37 template <std::derived_from<BaseStatusSignal>... Signals>
38 StatusSignalCollection(Signals &... signals) :
39 _signals{(&signals)...}
40 {}
41 /**
42 * \brief Creates a new collection of status signals, adding the
43 * provided span of signals to the collection.
44 *
45 * This collection does not own copies of the provided status signals.
46 * As a result, the usage of this collection cannot outlive the lifetime
47 * of the status signals.
48 *
49 * \param signals Signals to add, passed as a span of signal pointers
50 */
51 StatusSignalCollection(std::span<BaseStatusSignal *const> signals) :
52 _signals(signals.begin(), signals.end())
53 {}
54
55 /**
56 * \brief Creates a new collection of status signals, reserving
57 * capacity for the specified number of signals.
58 *
59 * \param signalCount Number of signals to reserve space for
60 */
61 StatusSignalCollection(size_t signalCount)
62 {
63 _signals.reserve(signalCount);
64 }
65
66 /**
67 * \brief Adds the provided signals to the collection.
68 *
69 * This collection does not own copies of the provided status signals.
70 * As a result, the usage of this collection cannot outlive the lifetime
71 * of the status signals.
72 *
73 * \param signals Signals to add, passed as a comma-separated list of signal references
74 */
75 template <std::derived_from<BaseStatusSignal>... Signals>
76 void AddSignals(Signals &... signals)
77 {
78 return AddSignals(std::array<BaseStatusSignal *, sizeof...(Signals)>{(&signals)...});
79 }
80
81 /**
82 * \brief Adds the provided signals to the collection.
83 *
84 * This collection does not own copies of the provided status signals.
85 * As a result, the usage of this collection cannot outlive the lifetime
86 * of the status signals.
87 *
88 * \param signals Signals to add, passed as a span of signal pointers
89 */
90 void AddSignals(std::span<BaseStatusSignal *const> signals)
91 {
92 _signals.insert(_signals.end(), signals.begin(), signals.end());
93 }
94
95 /**
96 * \brief Waits for new data on all signals up to timeout.
97 * This API is typically used with CANivore Bus signals as they will be synced using the
98 * CANivore Timesync feature and arrive simultaneously. Signals on a roboRIO bus cannot
99 * be synced and may require a significantly longer blocking call to receive all signals.
100 *
101 * Note that CANivore Timesync requires Phoenix Pro.
102 *
103 * This can also be used with a timeout of zero to refresh many signals at once, which
104 * is faster than calling Refresh() on every signal. This is equivalent to calling #RefreshAll.
105 *
106 * If a signal arrives multiple times while waiting, such as when *not* using CANivore
107 * Timesync, the newest signal data is fetched. Additionally, if this function times out,
108 * the newest signal data is fetched for all signals (when possible). We recommend checking
109 * the individual status codes using BaseStatusSignal#GetStatus() when this happens.
110 *
111 * \param timeout Maximum time to wait for all the signals to arrive.
112 * Pass zero to refresh all signals without blocking.
113 * \return An InvalidParamValue if this signal collection is empty,
114 * InvalidNetwork if signals are on different CAN bus networks,
115 * RxTimeout if it took longer than timeoutSeconds to receive all the signals,
116 * MultiSignalNotSupported if using the roboRIO bus with more than one signal and a non-zero timeout.
117 * An OK status code means that all signals arrived within timeoutSeconds and they are all OK.
118 *
119 * Any other value represents the StatusCode of the first failed signal.
120 * Call GetStatus() on each signal to determine which ones failed.
121 */
122 ctre::phoenix::StatusCode WaitForAll(units::time::second_t timeout)
123 {
124 return BaseStatusSignal::WaitForAll(timeout, _signals);
125 }
126
127 /**
128 * \brief Performs a non-blocking refresh on all signals.
129 *
130 * This provides a performance improvement over separately calling Refresh() on each signal.
131 *
132 * \return An InvalidParamValue if this signal collection is empty,
133 * InvalidNetwork if signals are on different CAN bus networks.
134 * An OK status code means that all signals are OK.
135 *
136 * Any other value represents the StatusCode of the first failed signal.
137 * Call GetStatus() on each signal to determine which ones failed.
138 */
143
144 /**
145 * \brief Sets the update frequency of all status signals to the provided common frequency.
146 *
147 * A frequency of 0 Hz will turn off the signal. Otherwise, the minimum supported signal frequency
148 * is 4 Hz, and the maximum is 1000 Hz.
149 *
150 * If other StatusSignals in the same status frame have been set to an update frequency,
151 * the fastest requested update frequency will be applied to the frame.
152 *
153 * This will wait up to 0.100 seconds (100ms) for each signal.
154 *
155 * \param frequency Rate to publish the signal in Hz.
156 * \returns Status code of the first failed update frequency set call, or OK if all succeeded
157 */
158 ctre::phoenix::StatusCode SetUpdateFrequencyForAll(units::frequency::hertz_t frequency)
159 {
161 }
162
163 /**
164 * \brief Checks if all signals have an OK error code.
165 *
166 * \returns True if all signals are OK, false otherwise
167 */
168 bool IsAllGood() const
169 {
171 }
172 };
173
174}
175}
Class that provides operations to retrieve information about a status signal.
Definition StatusSignal.hpp:39
static ctre::phoenix::StatusCode WaitForAll(units::time::second_t timeoutSeconds, Signals &... signals)
Waits for new data on all provided signals up to timeout.
Definition StatusSignal.hpp:313
static bool IsAllGood(Signals const &... signals)
Checks if all signals have an OK error code.
Definition StatusSignal.hpp:397
static ctre::phoenix::StatusCode RefreshAll(Signals &... signals)
Performs a non-blocking refresh on all provided signals.
Definition StatusSignal.hpp:367
static ctre::phoenix::StatusCode SetUpdateFrequencyForAll(units::frequency::hertz_t frequencyHz, Signals &... signals)
Sets the update frequency of all specified status signals to the provided common frequency.
Definition StatusSignal.hpp:434
Class to manage bulk refreshing device status signals.
Definition StatusSignalCollection.hpp:21
void AddSignals(std::span< BaseStatusSignal *const > signals)
Adds the provided signals to the collection.
Definition StatusSignalCollection.hpp:90
ctre::phoenix::StatusCode RefreshAll()
Performs a non-blocking refresh on all signals.
Definition StatusSignalCollection.hpp:139
StatusSignalCollection(size_t signalCount)
Creates a new collection of status signals, reserving capacity for the specified number of signals.
Definition StatusSignalCollection.hpp:61
bool IsAllGood() const
Checks if all signals have an OK error code.
Definition StatusSignalCollection.hpp:168
void AddSignals(Signals &... signals)
Adds the provided signals to the collection.
Definition StatusSignalCollection.hpp:76
std::vector< BaseStatusSignal * > _signals
Signals stored by this collection.
Definition StatusSignalCollection.hpp:24
ctre::phoenix::StatusCode WaitForAll(units::time::second_t timeout)
Waits for new data on all signals up to timeout.
Definition StatusSignalCollection.hpp:122
StatusSignalCollection(Signals &... signals)
Creates a new collection of status signals, optionally adding the provided signals to the collection.
Definition StatusSignalCollection.hpp:38
StatusSignalCollection(std::span< BaseStatusSignal *const > signals)
Creates a new collection of status signals, adding the provided span of signals to the collection.
Definition StatusSignalCollection.hpp:51
ctre::phoenix::StatusCode SetUpdateFrequencyForAll(units::frequency::hertz_t frequency)
Sets the update frequency of all status signals to the provided common frequency.
Definition StatusSignalCollection.hpp:158
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
Definition motor_constants.h:14