11#include <units/time.h>
16#if __has_include("wpi/struct/Struct.h")
17#include "wpi/struct/Struct.h"
18#include "wpi/SmallVector.h"
20#if __has_include("wpi/protobuf/Protobuf.h")
21#include "wpi/protobuf/Protobuf.h"
22#include "wpi/SmallVector.h"
146 return AddSchema(name, type, {(uint8_t
const *)schema.data(), schema.size()});
178 return WriteSchemaValue_Impl(name, schema, type, data, latencySeconds.value());
181#if __has_include("wpi/struct/Struct.h") || defined(_CTRE_DOCS_)
192 template <
typename T,
typename... I>
193 requires wpi::StructSerializable<T, I...>
196 using S = wpi::Struct<T, I...>;
198 wpi::ForEachStructSchema<T>([](std::string_view typeName,
auto schema) {
199 if (typeName.starts_with(
"struct:")) {
200 typeName.remove_prefix(7);
207 if constexpr (
sizeof...(I) == 0) {
208 if constexpr (wpi::is_constexpr([] { S::GetSize(); })) {
209 std::array<uint8_t, S::GetSize()> data;
210 S::Pack(data, value);
215 wpi::SmallVector<uint8_t, 128> buf;
216 buf.resize_for_overwrite(S::GetSize(info...));
217 S::Pack(buf, value, info...);
231 template <
typename T,
typename... I>
232 requires wpi::StructSerializable<T, I...>
235 using S = wpi::Struct<T, I...>;
237 auto const typeName = wpi::MakeStructArrayTypeName<T, std::dynamic_extent>(info...);
240 wpi::ForEachStructSchema<T>([](std::string_view typeName,
auto schema) {
241 if (typeName.starts_with(
"struct:")) {
242 typeName.remove_prefix(7);
251 auto const size = S::GetSize(info...);
252 wpi::SmallVector<uint8_t, 256> buf;
253 buf.resize_for_overwrite(size * values.size());
255 uint8_t *out = buf.data();
256 for (
auto &&val : values) {
258 std::span<uint8_t>{out, size},
259 std::forward<decltype(val)>(val), info...
267#if __has_include("wpi/protobuf/Protobuf.h") || defined(_CTRE_DOCS_)
277 template <wpi::ProtobufSerializable T>
280 std::string_view
const typeName = wpi::Protobuf<std::remove_cvref_t<T>>::MessageStruct::msg_descriptor()->proto_name;
282 wpi::ProtobufMessage<T> proto;
283 proto.ForEachProtobufDescriptor(
284 [](std::string_view typeName) {
285 if (typeName.starts_with(
"proto:")) {
286 typeName.remove_prefix(6);
290 [](std::string_view typeName,
auto schema) {
291 if (typeName.starts_with(
"proto:")) {
292 typeName.remove_prefix(6);
299 wpi::SmallVector<uint8_t, 128> buf;
300 proto.Pack(buf, value);
316 return WriteRaw_Impl(name, data, latencySeconds.value());
329 return WriteBoolean_Impl(name, value, latencySeconds.value());
343 return WriteInteger_Impl(name, value, units, latencySeconds.value());
357 return WriteFloat_Impl(name, value, units, latencySeconds.value());
371 return WriteDouble_Impl(name, value, units, latencySeconds.value());
384 return WriteString_Impl(name, value, latencySeconds.value());
396 template <
typename U>
397 requires units::traits::is_unit_t_v<U>
400 return WriteDouble(name, value.value(), units::abbreviation(value), latencySeconds);
414 return WriteBooleanArray_Impl(name, values, latencySeconds.value());
427 return WriteBooleanArray_Impl(name, values, latencySeconds.value());
442 return WriteIntegerArray_Impl(name, values, units, latencySeconds.value());
457 return WriteFloatArray_Impl(name, values, units, latencySeconds.value());
472 return WriteDoubleArray_Impl(name, values, units, latencySeconds.value());
486 return WriteStringArray_Impl(name, values, latencySeconds.value());
499 return WriteStringArray_Impl(name, values, latencySeconds.value());
503 static ctre::phoenix::StatusCode WriteRaw_Impl(std::string_view name, std::span<uint8_t const> data,
double latencySeconds);
505 static ctre::phoenix::StatusCode WriteInteger_Impl(std::string_view name, int64_t value, std::string_view units,
double latencySeconds);
506 static ctre::phoenix::StatusCode WriteFloat_Impl(std::string_view name,
float value, std::string_view units,
double latencySeconds);
507 static ctre::phoenix::StatusCode WriteDouble_Impl(std::string_view name,
double value, std::string_view units,
double latencySeconds);
510 static ctre::phoenix::StatusCode WriteBooleanArray_Impl(std::string_view name, std::span<bool const> values,
double latencySeconds)
512 static_assert(
sizeof(bool) ==
sizeof(uint8_t),
"bool is not uint8_t");
513 return WriteBooleanArray_Impl(name, std::span{(uint8_t
const *)values.data(), values.size()}, latencySeconds);
515 static ctre::phoenix::StatusCode WriteBooleanArray_Impl(std::string_view name, std::span<uint8_t const> values,
double latencySeconds);
516 static ctre::phoenix::StatusCode WriteIntegerArray_Impl(std::string_view name, std::span<int64_t const> values, std::string_view units,
double latencySeconds);
517 static ctre::phoenix::StatusCode WriteFloatArray_Impl(std::string_view name, std::span<float const> values, std::string_view units,
double latencySeconds);
518 static ctre::phoenix::StatusCode WriteDoubleArray_Impl(std::string_view name, std::span<double const> values, std::string_view units,
double latencySeconds);
519 static ctre::phoenix::StatusCode WriteStringArray_Impl(std::string_view name, std::span<std::string_view const> values,
double latencySeconds);
520 static ctre::phoenix::StatusCode WriteStringArray_Impl(std::string_view name, std::span<std::string const> values,
double latencySeconds);
Static class for controlling the Phoenix 6 signal logger.
Definition SignalLogger.hpp:43
static ctre::phoenix::StatusCode WriteBooleanArray(std::string_view name, std::span< bool const > values, units::time::second_t latencySeconds=0_s)
Writes the array of booleans to the log file.
Definition SignalLogger.hpp:412
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:398
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:327
static ctre::phoenix::StatusCode WriteBooleanArray(std::string_view name, std::span< uint8_t const > values, units::time::second_t latencySeconds=0_s)
Writes the array of booleans to the log file.
Definition SignalLogger.hpp:425
static ctre::phoenix::StatusCode WriteStructArray(std::string_view name, std::span< T const > values, I const &... info, units::time::second_t latencySeconds=0_s)
Writes the array of WPILib Structs to the log file.
Definition SignalLogger.hpp:233
static bool HasSchema(std::string_view name, HootSchemaType type)
Checks if the schema has already been added to the log files.
static ctre::phoenix::StatusCode WriteStringArray(std::string_view name, std::span< std::string const > values, units::time::second_t latencySeconds=0_s)
Writes the array of strings to the log file.
Definition SignalLogger.hpp:497
static ctre::phoenix::StatusCode WriteStruct(std::string_view name, T const &value, I const &... info, units::time::second_t latencySeconds=0_s)
Writes the WPILib Struct to the log file.
Definition SignalLogger.hpp:194
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:382
static ctre::phoenix::StatusCode SetPath(const char *path)
Sets the destination for logging, restarting logger if the path changed.
static ctre::phoenix::StatusCode AddSchema(std::string_view name, HootSchemaType type, std::string_view schema)
Adds the schema to the log file.
Definition SignalLogger.hpp:144
static ctre::phoenix::StatusCode WriteSchemaValue(std::string_view name, std::string_view schema, HootSchemaType type, std::span< uint8_t const > data, units::time::second_t latencySeconds=0_s)
Writes the schema-serialized bytes to the log file.
Definition SignalLogger.hpp:176
static ctre::phoenix::StatusCode WriteDoubleArray(std::string_view name, std::span< double const > values, std::string_view units="", units::time::second_t latencySeconds=0_s)
Writes the array of doubles to the log file.
Definition SignalLogger.hpp:470
static ctre::phoenix::StatusCode WriteProtobuf(std::string_view name, T const &value, units::time::second_t latencySeconds=0_s)
Writes the protobuf to the log file.
Definition SignalLogger.hpp:278
static ctre::phoenix::StatusCode WriteStringArray(std::string_view name, std::span< std::string_view const > values, units::time::second_t latencySeconds=0_s)
Writes the array of strings to the log file.
Definition SignalLogger.hpp:484
static ctre::phoenix::StatusCode WriteRaw(std::string_view name, std::span< uint8_t const > data, units::time::second_t latencySeconds=0_s)
Writes the raw data bytes to the log file.
Definition SignalLogger.hpp:314
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:341
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:369
static ctre::phoenix::StatusCode Stop()
Stops logging status signals.
static ctre::phoenix::StatusCode WriteFloatArray(std::string_view name, std::span< float const > values, std::string_view units="", units::time::second_t latencySeconds=0_s)
Writes the array of floats to the log file.
Definition SignalLogger.hpp:455
static ctre::phoenix::StatusCode WriteIntegerArray(std::string_view name, std::span< int64_t const > values, std::string_view units="", units::time::second_t latencySeconds=0_s)
Writes the array of integers to the log file.
Definition SignalLogger.hpp:440
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:355
static ctre::phoenix::StatusCode EnableAutoLogging(bool enable)
Enables or disables auto logging.
static ctre::phoenix::StatusCode Start()
Starts logging status signals.
static ctre::phoenix::StatusCode AddSchema(std::string_view name, HootSchemaType type, std::span< uint8_t const > schema)
Adds the schema to the log file.
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
HootSchemaType
Supported schema types for a hoot user signal.
Definition HootSchemaType.hpp:15
@ Struct
Serialize using the WPILib Struct format.
@ Protobuf
Serialize using the Protobuf format.
Definition motor_constants.h:14