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"
148 return AddSchema(name, type, {(uint8_t
const *)schema.data(), schema.size()});
180 return WriteSchemaValue_Impl(name, schema, type, data, latencySeconds.value());
183#if __has_include("wpi/struct/Struct.h") || defined(_CTRE_DOCS_)
194 template <
typename T,
typename... I>
195 requires wpi::StructSerializable<T, I...>
198 using S = wpi::Struct<T, I...>;
200 auto const typeName = S::GetTypeName(info...);
203 if constexpr (wpi::HasNestedStruct<T, I...>) {
204 S::ForEachNested([](std::string_view typeName,
auto schema) {
205 if (typeName.starts_with(
"struct:")) {
206 typeName.remove_prefix(7);
216 if constexpr (
sizeof...(I) == 0) {
217 if constexpr (wpi::is_constexpr([] { S::GetSize(); })) {
218 std::array<uint8_t, S::GetSize()> data;
219 S::Pack(data, value);
224 wpi::SmallVector<uint8_t, 128> buf;
225 buf.resize_for_overwrite(S::GetSize(info...));
226 S::Pack(buf, value, info...);
240 template <
typename T,
typename... I>
241 requires wpi::StructSerializable<T, I...>
244 using S = wpi::Struct<T, I...>;
246 auto const typeName = MakeStructArrayTypeName<T, std::dynamic_extent>(info...);
249 wpi::ForEachStructSchema<T>([](std::string_view typeName,
auto schema) {
250 if (typeName.starts_with(
"struct:")) {
251 typeName.remove_prefix(7);
260 auto const size = S::GetSize(info...);
261 wpi::SmallVector<uint8_t, 256> buf;
262 buf.resize_for_overwrite(size * values.size());
264 uint8_t *out = buf.data();
265 for (
auto &&val : values) {
267 std::span<uint8_t>{out, size},
268 std::forward<decltype(val)>(val), info...
276#if __has_include("wpi/protobuf/Protobuf.h") || defined(_CTRE_DOCS_)
286 template <wpi::ProtobufSerializable T>
289 std::string_view
const typeName = wpi::Protobuf<std::remove_cvref_t<T>>::MessageStruct::msg_descriptor()->proto_name;
291 wpi::ProtobufMessage<T> proto;
293 proto.ForEachProtobufDescriptor(
294 [](std::string_view typeName) {
295 if (typeName.starts_with(
"proto:")) {
296 typeName.remove_prefix(6);
300 [](std::string_view typeName,
auto schema) {
301 if (typeName.starts_with(
"proto:")) {
302 typeName.remove_prefix(6);
310 wpi::SmallVector<uint8_t, 128> buf;
311 proto.Pack(buf, value);
327 return WriteRaw_Impl(name, data, latencySeconds.value());
340 return WriteBoolean_Impl(name, value, latencySeconds.value());
354 return WriteInteger_Impl(name, value, units, latencySeconds.value());
368 return WriteFloat_Impl(name, value, units, latencySeconds.value());
382 return WriteDouble_Impl(name, value, units, latencySeconds.value());
395 return WriteString_Impl(name, value, latencySeconds.value());
407 template <
typename U>
408 requires units::traits::is_unit_t_v<U>
411 return WriteDouble(name, value.value(), units::abbreviation(value), latencySeconds);
425 return WriteBooleanArray_Impl(name, values, latencySeconds.value());
438 return WriteBooleanArray_Impl(name, values, latencySeconds.value());
453 return WriteIntegerArray_Impl(name, values, units, latencySeconds.value());
468 return WriteFloatArray_Impl(name, values, units, latencySeconds.value());
483 return WriteDoubleArray_Impl(name, values, units, latencySeconds.value());
497 return WriteStringArray_Impl(name, values, latencySeconds.value());
510 return WriteStringArray_Impl(name, values, latencySeconds.value());
514 static ctre::phoenix::StatusCode WriteRaw_Impl(std::string_view name, std::span<uint8_t const> data,
double latencySeconds);
516 static ctre::phoenix::StatusCode WriteInteger_Impl(std::string_view name, int64_t value, std::string_view units,
double latencySeconds);
517 static ctre::phoenix::StatusCode WriteFloat_Impl(std::string_view name,
float value, std::string_view units,
double latencySeconds);
518 static ctre::phoenix::StatusCode WriteDouble_Impl(std::string_view name,
double value, std::string_view units,
double latencySeconds);
521 static ctre::phoenix::StatusCode WriteBooleanArray_Impl(std::string_view name, std::span<bool const> values,
double latencySeconds)
523 static_assert(
sizeof(bool) ==
sizeof(uint8_t),
"bool is not uint8_t");
524 return WriteBooleanArray_Impl(name, std::span{(uint8_t
const *)values.data(), values.size()}, latencySeconds);
526 static ctre::phoenix::StatusCode WriteBooleanArray_Impl(std::string_view name, std::span<uint8_t const> values,
double latencySeconds);
527 static ctre::phoenix::StatusCode WriteIntegerArray_Impl(std::string_view name, std::span<int64_t const> values, std::string_view units,
double latencySeconds);
528 static ctre::phoenix::StatusCode WriteFloatArray_Impl(std::string_view name, std::span<float const> values, std::string_view units,
double latencySeconds);
529 static ctre::phoenix::StatusCode WriteDoubleArray_Impl(std::string_view name, std::span<double const> values, std::string_view units,
double latencySeconds);
530 static ctre::phoenix::StatusCode WriteStringArray_Impl(std::string_view name, std::span<std::string_view const> values,
double latencySeconds);
531 static ctre::phoenix::StatusCode WriteStringArray_Impl(std::string_view name, std::span<std::string const> values,
double latencySeconds);
535#if __has_include("wpi/struct/Struct.h")
536 template <
typename T,
size_t N,
typename... I>
537 requires wpi::StructSerializable<T, I...>
538 static constexpr auto MakeStructArrayTypeName(I
const &... info) {
543 is_constexpr([&info...] { S::GetTypeName(info...); })
545 constexpr auto typeName = S::GetTypeName(info...);
546 using namespace literals;
547 if constexpr (N == std::dynamic_extent) {
549 ct_string<
char, std::char_traits<char>, typeName.size()>{typeName},
554 ct_string<
char, std::char_traits<char>, typeName.size()>{typeName},
555 "["_ct_string, NumToCtString<N>(),
"]"_ct_string
559 if constexpr (N == std::dynamic_extent) {
560 return fmt::format(
"{}[]", S::GetTypeName(info...));
562 return fmt::format(
"{}[{}]", S::GetTypeName(info...), N);
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:423
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:409
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:338
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:436
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:242
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:508
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:196
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:393
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:146
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:178
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:481
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:287
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:495
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:325
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:352
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:380
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:466
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:451
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:366
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