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 auto const typeName = S::GetTypeName(info...);
201 if constexpr (wpi::HasNestedStruct<T, I...>) {
202 S::ForEachNested([](std::string_view typeName,
auto schema) {
203 if (typeName.starts_with(
"struct:")) {
204 typeName.remove_prefix(7);
214 if constexpr (
sizeof...(I) == 0) {
215 if constexpr (wpi::is_constexpr([] { S::GetSize(); })) {
216 std::array<uint8_t, S::GetSize()> data;
217 S::Pack(data, value);
222 wpi::SmallVector<uint8_t, 128> buf;
223 buf.resize_for_overwrite(S::GetSize(info...));
224 S::Pack(buf, value, info...);
238 template <
typename T,
typename... I>
239 requires wpi::StructSerializable<T, I...>
242 using S = wpi::Struct<T, I...>;
244 auto const typeName = MakeStructArrayTypeName<T, std::dynamic_extent>(info...);
247 wpi::ForEachStructSchema<T>([](std::string_view typeName,
auto schema) {
248 if (typeName.starts_with(
"struct:")) {
249 typeName.remove_prefix(7);
258 auto const size = S::GetSize(info...);
259 wpi::SmallVector<uint8_t, 256> buf;
260 buf.resize_for_overwrite(size * values.size());
262 uint8_t *out = buf.data();
263 for (
auto &&val : values) {
265 std::span<uint8_t>{out, size},
266 std::forward<decltype(val)>(val), info...
274#if __has_include("wpi/protobuf/Protobuf.h") || defined(_CTRE_DOCS_)
284 template <wpi::ProtobufSerializable T>
287 std::string_view
const typeName = wpi::Protobuf<std::remove_cvref_t<T>>::MessageStruct::msg_descriptor()->proto_name;
289 wpi::ProtobufMessage<T> proto;
291 proto.ForEachProtobufDescriptor(
292 [](std::string_view typeName) {
293 if (typeName.starts_with(
"proto:")) {
294 typeName.remove_prefix(6);
298 [](std::string_view typeName,
auto schema) {
299 if (typeName.starts_with(
"proto:")) {
300 typeName.remove_prefix(6);
308 wpi::SmallVector<uint8_t, 128> buf;
309 proto.Pack(buf, value);
325 return WriteRaw_Impl(name, data, latencySeconds.value());
338 return WriteBoolean_Impl(name, value, latencySeconds.value());
352 return WriteInteger_Impl(name, value, units, latencySeconds.value());
366 return WriteFloat_Impl(name, value, units, latencySeconds.value());
380 return WriteDouble_Impl(name, value, units, latencySeconds.value());
393 return WriteString_Impl(name, value, latencySeconds.value());
405 template <
typename U>
406 requires units::traits::is_unit_t_v<U>
409 return WriteDouble(name, value.value(), units::abbreviation(value), latencySeconds);
423 return WriteBooleanArray_Impl(name, values, latencySeconds.value());
436 return WriteBooleanArray_Impl(name, values, latencySeconds.value());
451 return WriteIntegerArray_Impl(name, values, units, latencySeconds.value());
466 return WriteFloatArray_Impl(name, values, units, latencySeconds.value());
481 return WriteDoubleArray_Impl(name, values, units, latencySeconds.value());
495 return WriteStringArray_Impl(name, values, latencySeconds.value());
508 return WriteStringArray_Impl(name, values, latencySeconds.value());
512 static ctre::phoenix::StatusCode WriteRaw_Impl(std::string_view name, std::span<uint8_t const> data,
double latencySeconds);
514 static ctre::phoenix::StatusCode WriteInteger_Impl(std::string_view name, int64_t value, std::string_view units,
double latencySeconds);
515 static ctre::phoenix::StatusCode WriteFloat_Impl(std::string_view name,
float value, std::string_view units,
double latencySeconds);
516 static ctre::phoenix::StatusCode WriteDouble_Impl(std::string_view name,
double value, std::string_view units,
double latencySeconds);
519 static ctre::phoenix::StatusCode WriteBooleanArray_Impl(std::string_view name, std::span<bool const> values,
double latencySeconds)
521 static_assert(
sizeof(bool) ==
sizeof(uint8_t),
"bool is not uint8_t");
522 return WriteBooleanArray_Impl(name, std::span{(uint8_t
const *)values.data(), values.size()}, latencySeconds);
524 static ctre::phoenix::StatusCode WriteBooleanArray_Impl(std::string_view name, std::span<uint8_t const> values,
double latencySeconds);
525 static ctre::phoenix::StatusCode WriteIntegerArray_Impl(std::string_view name, std::span<int64_t const> values, std::string_view units,
double latencySeconds);
526 static ctre::phoenix::StatusCode WriteFloatArray_Impl(std::string_view name, std::span<float const> values, std::string_view units,
double latencySeconds);
527 static ctre::phoenix::StatusCode WriteDoubleArray_Impl(std::string_view name, std::span<double const> values, std::string_view units,
double latencySeconds);
528 static ctre::phoenix::StatusCode WriteStringArray_Impl(std::string_view name, std::span<std::string_view const> values,
double latencySeconds);
529 static ctre::phoenix::StatusCode WriteStringArray_Impl(std::string_view name, std::span<std::string const> values,
double latencySeconds);
533#if __has_include("wpi/struct/Struct.h")
534 template <
typename T,
size_t N,
typename... I>
535 requires wpi::StructSerializable<T, I...>
536 static constexpr auto MakeStructArrayTypeName(I
const &... info) {
541 is_constexpr([&info...] { S::GetTypeName(info...); })
543 constexpr auto typeName = S::GetTypeName(info...);
544 using namespace literals;
545 if constexpr (N == std::dynamic_extent) {
547 ct_string<
char, std::char_traits<char>, typeName.size()>{typeName},
552 ct_string<
char, std::char_traits<char>, typeName.size()>{typeName},
553 "["_ct_string, NumToCtString<N>(),
"]"_ct_string
557 if constexpr (N == std::dynamic_extent) {
558 return fmt::format(
"{}[]", S::GetTypeName(info...));
560 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:421
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:407
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:336
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:434
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:240
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:506
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:391
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:479
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:285
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:493
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:323
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:350
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:378
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:464
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:449
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:364
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