CTRE Phoenix 6 C++ 24.3.0
SignalLogger.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 <units/time.h>
11#include <array>
12#include <vector>
13
14namespace ctre {
15namespace phoenix6 {
16
17/**
18 * \brief Static class for controlling the Phoenix 6 signal logger.
19 *
20 * This logs all the signals from the CAN buses into .hoot files. Each file name starts with the
21 * CANivore serial number or "rio" for the roboRIO CAN bus, followed by the timestamp. In the
22 * header of a hoot file, the CANivore name and firmware version are logged in plain text.
23 *
24 * During an FRC match, the log file will be renamed to include the event name, match type, and
25 * match number at the start of the file name. The match type will be 'P' for practice matches,
26 * 'Q' for qualification matches, and 'E' for elimination matches.
27 */
29{
30public:
31 /**
32 * \brief Sets the destination for logging, restarting logger if the path changed.
33 *
34 * If this is not called or the path is left empty, the default path will be used. The
35 * default path on the roboRIO is a logs folder on the first USB flash drive found, or
36 * /home/lvuser/logs if none is available. The default path on all other platforms is
37 * a logs folder in the current working directory.
38 *
39 * Typical use for this routine is to use a removable USB flash drive for logging.
40 *
41 * \param path Folder path for the log files; path must exist
42 * \returns Status of setting the path and restarting the log
43 */
44 static ctre::phoenix::StatusCode SetPath(const char *path);
45 /**
46 * \brief Starts logging status signals. Starts regardless of auto logging status.
47 *
48 * If using a roboRIO 1, we recommend setting the logging path to an external drive
49 * using #SetPath to avoid running out of internal storage space.
50 *
51 * \details If auto logging is enabled, the log will be stopped at the end of the match.
52 *
53 * \returns Status of starting the logger
54 */
55 static ctre::phoenix::StatusCode Start();
56 /**
57 * \brief Stops logging status signals. Stops regardless of auto logging status.
58 *
59 * \returns Status of stopping the logger
60 */
61 static ctre::phoenix::StatusCode Stop();
62 /**
63 * \brief Enables or disables auto logging.
64 *
65 * Auto logging is only supported on the roboRIO. When auto logging is enabled,
66 * logging is started at the beginning of an FRC match and stopped at the end.
67 *
68 * \param enable Whether to enable auto logging
69 * \returns Status of auto logging enable/disable
70 */
71 static ctre::phoenix::StatusCode EnableAutoLogging(bool enable);
72
73 /**
74 * \brief Writes the raw data bytes to the log file. The data cannot exceed 64 bytes.
75 *
76 * \param name Name of the signal
77 * \param data Raw data bytes
78 * \param size Size of the raw data (in bytes)
79 * \param latencySeconds Latency of the signal in seconds; this value is subtracted
80 * from the current time to get the timestamp written to the log
81 * \returns Status of writing the data
82 */
83 static ctre::phoenix::StatusCode WriteRaw(std::string_view name, uint8_t const *data, uint8_t size, units::time::second_t latencySeconds = 0_s)
84 {
85 return WriteRaw_Impl(name, data, size, latencySeconds.value());
86 }
87 /**
88 * \brief Writes the boolean to the log file.
89 *
90 * \param name Name of the signal
91 * \param value Value to write
92 * \param latencySeconds Latency of the signal in seconds; this value is subtracted
93 * from the current time to get the timestamp written to the log
94 * \returns Status of writing the data
95 */
96 static ctre::phoenix::StatusCode WriteBoolean(std::string_view name, bool value, units::time::second_t latencySeconds = 0_s)
97 {
98 return WriteBoolean_Impl(name, value, latencySeconds.value());
99 }
100 /**
101 * \brief Writes the integer to the log file.
102 *
103 * \param name Name of the signal
104 * \param value Value to write
105 * \param units Units of the signal
106 * \param latencySeconds Latency of the signal in seconds; this value is subtracted
107 * from the current time to get the timestamp written to the log
108 * \returns Status of writing the data
109 */
110 static ctre::phoenix::StatusCode WriteInteger(std::string_view name, int64_t value, std::string_view units = "", units::time::second_t latencySeconds = 0_s)
111 {
112 return WriteInteger_Impl(name, value, units, latencySeconds.value());
113 }
114 /**
115 * \brief Writes the float to the log file.
116 *
117 * \param name Name of the signal
118 * \param value Value to write
119 * \param units Units of the signal
120 * \param latencySeconds Latency of the signal in seconds; this value is subtracted
121 * from the current time to get the timestamp written to the log
122 * \returns Status of writing the data
123 */
124 static ctre::phoenix::StatusCode WriteFloat(std::string_view name, float value, std::string_view units = "", units::time::second_t latencySeconds = 0_s)
125 {
126 return WriteFloat_Impl(name, value, units, latencySeconds.value());
127 }
128 /**
129 * \brief Writes the double to the log file.
130 *
131 * \param name Name of the signal
132 * \param value Value to write
133 * \param units Units of the signal
134 * \param latencySeconds Latency of the signal in seconds; this value is subtracted
135 * from the current time to get the timestamp written to the log
136 * \returns Status of writing the data
137 */
138 static ctre::phoenix::StatusCode WriteDouble(std::string_view name, double value, std::string_view units = "", units::time::second_t latencySeconds = 0_s)
139 {
140 return WriteDouble_Impl(name, value, units, latencySeconds.value());
141 }
142 /**
143 * \brief Writes the string to the log file. The string cannot exceed 64 characters.
144 *
145 * \param name Name of the signal
146 * \param value Value to write
147 * \param latencySeconds Latency of the signal in seconds; this value is subtracted
148 * from the current time to get the timestamp written to the log
149 * \returns Status of writing the data
150 */
151 static ctre::phoenix::StatusCode WriteString(std::string_view name, std::string_view value, units::time::second_t latencySeconds = 0_s)
152 {
153 return WriteString_Impl(name, value, latencySeconds.value());
154 }
155
156 /**
157 * \brief Writes the unit value to the log file.
158 *
159 * \param name Name of the signal
160 * \param value Value to write
161 * \param latencySeconds Latency of the signal in seconds; this value is subtracted
162 * from the current time to get the timestamp written to the log
163 * \returns Status of writing the data
164 */
165 template <typename U, typename = std::enable_if_t<units::traits::is_unit_t_v<U>>>
166 static ctre::phoenix::StatusCode WriteValue(std::string_view name, U value, units::time::second_t latencySeconds = 0_s)
167 {
168 return WriteDouble(name, value.value(), units::abbreviation(value), latencySeconds);
169 }
170
171 /**
172 * \brief Writes the array of booleans to the log file. The array cannot exceed 64 elements.
173 *
174 * \param name Name of the signal
175 * \param values Array of values to write
176 * \param latencySeconds Latency of the signal in seconds; this value is subtracted
177 * from the current time to get the timestamp written to the log
178 * \returns Status of writing the data
179 */
180 template <size_t N, typename = std::enable_if_t<(N <= 64U)>>
181 static ctre::phoenix::StatusCode WriteBooleanArray(std::string_view name, std::array<bool, N> const &values, units::time::second_t latencySeconds = 0_s)
182 {
183 static_assert(sizeof(bool) == sizeof(uint8_t), "bool is not uint8_t");
184 return WriteBooleanArray_Impl(name, values.data(), values.size(), latencySeconds.value());
185 }
186 /**
187 * \brief Writes the array of booleans to the log file. The array cannot exceed 64 elements.
188 *
189 * \param name Name of the signal
190 * \param values Array of values to write, passed as an array of bytes
191 * \param latencySeconds Latency of the signal in seconds; this value is subtracted
192 * from the current time to get the timestamp written to the log
193 * \returns Status of writing the data
194 */
195 template <size_t N, typename = std::enable_if_t<(N <= 64U)>>
196 static ctre::phoenix::StatusCode WriteBooleanArray(std::string_view name, std::array<uint8_t, N> const &values, units::time::second_t latencySeconds = 0_s)
197 {
198 return WriteBooleanArray_Impl(name, values.data(), values.size(), latencySeconds.value());
199 }
200 /**
201 * \brief Writes the array of booleans to the log file. The array cannot exceed 64 elements.
202 *
203 * \param name Name of the signal
204 * \param values Vector of values to write; since vector<bool> is not a boolean array,
205 * this is passed as a vector<uint8_t> instead
206 * \param latencySeconds Latency of the signal in seconds; this value is subtracted
207 * from the current time to get the timestamp written to the log
208 * \returns Status of writing the data
209 */
210 static ctre::phoenix::StatusCode WriteBooleanArray(std::string_view name, std::vector<uint8_t> const &values, units::time::second_t latencySeconds = 0_s)
211 {
212 if (values.size() > 64) {
214 }
215 return WriteBooleanArray_Impl(name, values.data(), values.size(), latencySeconds.value());
216 }
217
218 /**
219 * \brief Writes the array of integers to the log file. The array cannot exceed 8 elements.
220 *
221 * \param name Name of the signal
222 * \param values Array of values to write
223 * \param units Units of the signals
224 * \param latencySeconds Latency of the signal in seconds; this value is subtracted
225 * from the current time to get the timestamp written to the log
226 * \returns Status of writing the data
227 */
228 template <size_t N, typename = std::enable_if_t<(N <= 8U)>>
229 static ctre::phoenix::StatusCode WriteIntegerArray(std::string_view name, std::array<int64_t, N> const &values, std::string_view units = "", units::time::second_t latencySeconds = 0_s)
230 {
231 return WriteIntegerArray_Impl(name, values.data(), values.size(), units, latencySeconds.value());
232 }
233 /**
234 * \brief Writes the array of integers to the log file. The array cannot exceed 8 elements.
235 *
236 * \param name Name of the signal
237 * \param values Vector of values to write
238 * \param units Units of the signals
239 * \param latencySeconds Latency of the signal in seconds; this value is subtracted
240 * from the current time to get the timestamp written to the log
241 * \returns Status of writing the data
242 */
243 static ctre::phoenix::StatusCode WriteIntegerArray(std::string_view name, std::vector<int64_t> const &values, std::string_view units = "", units::time::second_t latencySeconds = 0_s)
244 {
245 if (values.size() > 8) {
247 }
248 return WriteIntegerArray_Impl(name, values.data(), values.size(), units, latencySeconds.value());
249 }
250
251 /**
252 * \brief Writes the array of floats to the log file. The array cannot exceed 16 elements.
253 *
254 * \param name Name of the signal
255 * \param values Array of values to write
256 * \param units Units of the signals
257 * \param latencySeconds Latency of the signal in seconds; this value is subtracted
258 * from the current time to get the timestamp written to the log
259 * \returns Status of writing the data
260 */
261 template <size_t N, typename = std::enable_if_t<(N <= 16U)>>
262 static ctre::phoenix::StatusCode WriteFloatArray(std::string_view name, std::array<float, N> const &values, std::string_view units = "", units::time::second_t latencySeconds = 0_s)
263 {
264 return WriteFloatArray_Impl(name, values.data(), values.size(), units, latencySeconds.value());
265 }
266 /**
267 * \brief Writes the array of floats to the log file. The array cannot exceed 16 elements.
268 *
269 * \param name Name of the signal
270 * \param values Vector of values to write
271 * \param units Units of the signals
272 * \param latencySeconds Latency of the signal in seconds; this value is subtracted
273 * from the current time to get the timestamp written to the log
274 * \returns Status of writing the data
275 */
276 static ctre::phoenix::StatusCode WriteFloatArray(std::string_view name, std::vector<float> const &values, std::string_view units = "", units::time::second_t latencySeconds = 0_s)
277 {
278 if (values.size() > 16) {
280 }
281 return WriteFloatArray_Impl(name, values.data(), values.size(), units, latencySeconds.value());
282 }
283
284 /**
285 * \brief Writes the array of doubles to the log file. The array cannot exceed 8 elements.
286 *
287 * \param name Name of the signal
288 * \param values Array of values to write
289 * \param units Units of the signals
290 * \param latencySeconds Latency of the signal in seconds; this value is subtracted
291 * from the current time to get the timestamp written to the log
292 * \returns Status of writing the data
293 */
294 template <size_t N, typename = std::enable_if_t<(N <= 8U)>>
295 static ctre::phoenix::StatusCode WriteDoubleArray(std::string_view name, std::array<double, N> const &values, std::string_view units = "", units::time::second_t latencySeconds = 0_s)
296 {
297 return WriteDoubleArray_Impl(name, values.data(), values.size(), units, latencySeconds.value());
298 }
299 /**
300 * \brief Writes the array of doubles to the log file. The array cannot exceed 8 elements.
301 *
302 * \param name Name of the signal
303 * \param values Vector of values to write
304 * \param units Units of the signals
305 * \param latencySeconds Latency of the signal in seconds; this value is subtracted
306 * from the current time to get the timestamp written to the log
307 * \returns Status of writing the data
308 */
309 static ctre::phoenix::StatusCode WriteDoubleArray(std::string_view name, std::vector<double> const &values, std::string_view units = "", units::time::second_t latencySeconds = 0_s)
310 {
311 if (values.size() > 8) {
313 }
314 return WriteDoubleArray_Impl(name, values.data(), values.size(), units, latencySeconds.value());
315 }
316
317private:
318 static ctre::phoenix::StatusCode WriteRaw_Impl(std::string_view name, uint8_t const *data, uint8_t size, double latencySeconds);
319 static ctre::phoenix::StatusCode WriteBoolean_Impl(std::string_view name, bool value, double latencySeconds);
320 static ctre::phoenix::StatusCode WriteInteger_Impl(std::string_view name, int64_t value, std::string_view units, double latencySeconds);
321 static ctre::phoenix::StatusCode WriteFloat_Impl(std::string_view name, float value, std::string_view units, double latencySeconds);
322 static ctre::phoenix::StatusCode WriteDouble_Impl(std::string_view name, double value, std::string_view units, double latencySeconds);
323 static ctre::phoenix::StatusCode WriteString_Impl(std::string_view name, std::string_view value, double latencySeconds);
324
325 static ctre::phoenix::StatusCode WriteBooleanArray_Impl(std::string_view name, uint8_t const *values, uint8_t count, double latencySeconds);
326 static ctre::phoenix::StatusCode WriteIntegerArray_Impl(std::string_view name, int64_t const *values, uint8_t count, std::string_view units, double latencySeconds);
327 static ctre::phoenix::StatusCode WriteFloatArray_Impl(std::string_view name, float const *values, uint8_t count, std::string_view units, double latencySeconds);
328 static ctre::phoenix::StatusCode WriteDoubleArray_Impl(std::string_view name, double const *values, uint8_t count, std::string_view units, double latencySeconds);
329};
330
331}
332}
@ InvalidSize
Size is invalid.
Definition: StatusCodes.h:1852
Static class for controlling the Phoenix 6 signal logger.
Definition: SignalLogger.hpp:29
static ctre::phoenix::StatusCode WriteBoolean(std::string_view name, bool value, units::time::second_t latencySeconds=0_s)
Writes the boolean to the log file.
Definition: SignalLogger.hpp:96
static ctre::phoenix::StatusCode WriteString(std::string_view name, std::string_view value, units::time::second_t latencySeconds=0_s)
Writes the string to the log file.
Definition: SignalLogger.hpp:151
static ctre::phoenix::StatusCode SetPath(const char *path)
Sets the destination for logging, restarting logger if the path changed.
static ctre::phoenix::StatusCode WriteValue(std::string_view name, U value, units::time::second_t latencySeconds=0_s)
Writes the unit value to the log file.
Definition: SignalLogger.hpp:166
static ctre::phoenix::StatusCode WriteRaw(std::string_view name, uint8_t const *data, uint8_t size, units::time::second_t latencySeconds=0_s)
Writes the raw data bytes to the log file.
Definition: SignalLogger.hpp:83
static ctre::phoenix::StatusCode WriteInteger(std::string_view name, int64_t value, std::string_view units="", units::time::second_t latencySeconds=0_s)
Writes the integer to the log file.
Definition: SignalLogger.hpp:110
static ctre::phoenix::StatusCode WriteDouble(std::string_view name, double value, std::string_view units="", units::time::second_t latencySeconds=0_s)
Writes the double to the log file.
Definition: SignalLogger.hpp:138
static ctre::phoenix::StatusCode Stop()
Stops logging status signals.
static ctre::phoenix::StatusCode WriteFloat(std::string_view name, float value, std::string_view units="", units::time::second_t latencySeconds=0_s)
Writes the float to the log file.
Definition: SignalLogger.hpp:124
static ctre::phoenix::StatusCode EnableAutoLogging(bool enable)
Enables or disables auto logging.
static ctre::phoenix::StatusCode Start()
Starts logging status signals.
Definition: string_util.hpp:15