CTRE Phoenix 6 C++ 26.0.0-beta-1
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 Adds the provided signals to the collection.
57 *
58 * This collection does not own copies of the provided status signals.
59 * As a result, the usage of this collection cannot outlive the lifetime
60 * of the status signals.
61 *
62 * \param signals Signals to add, passed as a comma-separated list of signal references
63 */
64 template <std::derived_from<BaseStatusSignal>... Signals>
65 void AddSignals(Signals &... signals)
66 {
67 return AddSignals(std::array<BaseStatusSignal *, sizeof...(Signals)>{(&signals)...});
68 }
69
70 /**
71 * \brief Adds the provided signals to the collection.
72 *
73 * This collection does not own copies of the provided status signals.
74 * As a result, the usage of this collection cannot outlive the lifetime
75 * of the status signals.
76 *
77 * \param signals Signals to add, passed as a span of signal pointers
78 */
79 void AddSignals(std::span<BaseStatusSignal *const> signals)
80 {
81 _signals.insert(_signals.end(), signals.begin(), signals.end());
82 }
83
84 /**
85 * \brief Waits for new data on all signals up to timeout.
86 * This API is typically used with CANivore Bus signals as they will be synced using the
87 * CANivore Timesync feature and arrive simultaneously. Signals on a roboRIO bus cannot
88 * be synced and may require a significantly longer blocking call to receive all signals.
89 *
90 * Note that CANivore Timesync requires Phoenix Pro.
91 *
92 * This can also be used with a timeout of zero to refresh many signals at once, which
93 * is faster than calling Refresh() on every signal. This is equivalent to calling #RefreshAll.
94 *
95 * If a signal arrives multiple times while waiting, such as when *not* using CANivore
96 * Timesync, the newest signal data is fetched. Additionally, if this function times out,
97 * the newest signal data is fetched for all signals (when possible). We recommend checking
98 * the individual status codes using BaseStatusSignal#GetStatus() when this happens.
99 *
100 * \param timeout Maximum time to wait for all the signals to arrive.
101 * Pass zero to refresh all signals without blocking.
102 * \return An InvalidParamValue if this signal collection is empty,
103 * InvalidNetwork if signals are on different CAN bus networks,
104 * RxTimeout if it took longer than timeoutSeconds to receive all the signals,
105 * MultiSignalNotSupported if using the roboRIO bus with more than one signal and a non-zero timeout.
106 * An OK status code means that all signals arrived within timeoutSeconds and they are all OK.
107 *
108 * Any other value represents the StatusCode of the first failed signal.
109 * Call GetStatus() on each signal to determine which ones failed.
110 */
111 ctre::phoenix::StatusCode WaitForAll(units::time::second_t timeout)
112 {
113 return BaseStatusSignal::WaitForAll(timeout, _signals);
114 }
115
116 /**
117 * \brief Performs a non-blocking refresh on all signals.
118 *
119 * This provides a performance improvement over separately calling Refresh() on each signal.
120 *
121 * \return An InvalidParamValue if this signal collection is empty,
122 * InvalidNetwork if signals are on different CAN bus networks.
123 * An OK status code means that all signals are OK.
124 *
125 * Any other value represents the StatusCode of the first failed signal.
126 * Call GetStatus() on each signal to determine which ones failed.
127 */
132
133 /**
134 * \brief Sets the update frequency of all status signals to the provided common frequency.
135 *
136 * A frequency of 0 Hz will turn off the signal. Otherwise, the minimum supported signal frequency
137 * is 4 Hz, and the maximum is 1000 Hz.
138 *
139 * If other StatusSignals in the same status frame have been set to an update frequency,
140 * the fastest requested update frequency will be applied to the frame.
141 *
142 * This will wait up to 0.100 seconds (100ms) for each signal.
143 *
144 * \param frequency Rate to publish the signal in Hz.
145 * \returns Status code of the first failed update frequency set call, or OK if all succeeded
146 */
147 ctre::phoenix::StatusCode SetUpdateFrequencyForAll(units::frequency::hertz_t frequency)
148 {
150 }
151
152 /**
153 * \brief Checks if all signals have an OK error code.
154 *
155 * \returns True if all signals are OK, false otherwise
156 */
157 bool IsAllGood() const
158 {
160 }
161 };
162
163}
164}
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:318
static bool IsAllGood(Signals const &... signals)
Checks if all signals have an OK error code.
Definition StatusSignal.hpp:405
static ctre::phoenix::StatusCode RefreshAll(Signals &... signals)
Performs a non-blocking refresh on all provided signals.
Definition StatusSignal.hpp:374
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:442
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:79
ctre::phoenix::StatusCode RefreshAll()
Performs a non-blocking refresh on all signals.
Definition StatusSignalCollection.hpp:128
bool IsAllGood() const
Checks if all signals have an OK error code.
Definition StatusSignalCollection.hpp:157
void AddSignals(Signals &... signals)
Adds the provided signals to the collection.
Definition StatusSignalCollection.hpp:65
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:111
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:147
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
Definition motor_constants.h:14