11#include <wpi/units/time.hpp>
16#if __has_include(<wpi/util/struct/Struct.hpp>)
17#include <wpi/util/struct/Struct.hpp>
18#include <wpi/util/SmallVector.hpp>
20#if __has_include(<wpi/util/protobuf/Protobuf.hpp>)
21#include <wpi/util/protobuf/Protobuf.hpp>
22#include <wpi/util/SmallVector.hpp>
143 return AddSchema(name, type, {(uint8_t
const *)schema.data(), schema.size()});
175 return WriteSchemaValue_Impl(name, schema, type, data, latencySeconds.value());
178#if __has_include(<wpi/util/struct/Struct.hpp>) || defined(_CTRE_DOCS_)
189 template <
typename T,
typename... I>
190 requires wpi::util::StructSerializable<T, I...>
193 using S = wpi::util::Struct<T, I...>;
195 auto const typeName = S::GetTypeName(info...);
198 if constexpr (wpi::util::HasNestedStruct<T, I...>) {
199 S::ForEachNested([](std::string_view typeName,
auto schema) {
200 if (typeName.starts_with(
"struct:")) {
201 typeName.remove_prefix(7);
211 if constexpr (
sizeof...(I) == 0) {
212 if constexpr (wpi::util::is_constexpr([] { S::GetSize(); })) {
213 std::array<uint8_t, S::GetSize()> data;
214 S::Pack(data, value);
219 wpi::util::SmallVector<uint8_t, 128> buf;
220 buf.resize_for_overwrite(S::GetSize(info...));
221 S::Pack(buf, value, info...);
235 template <
typename T,
typename... I>
236 requires wpi::util::StructSerializable<T, I...>
239 using S = wpi::util::Struct<T, I...>;
241 auto const typeName = MakeStructArrayTypeName<T, std::dynamic_extent>(info...);
244 wpi::util::ForEachStructSchema<T>([](std::string_view typeName,
auto schema) {
245 if (typeName.starts_with(
"struct:")) {
246 typeName.remove_prefix(7);
255 auto const size = S::GetSize(info...);
256 wpi::util::SmallVector<uint8_t, 256> buf;
257 buf.resize_for_overwrite(size * values.size());
259 uint8_t *out = buf.data();
260 for (
auto &&val : values) {
262 std::span<uint8_t>{out, size},
263 std::forward<decltype(val)>(val), info...
271#if __has_include(<wpi/util/protobuf/Protobuf.hpp>) || defined(_CTRE_DOCS_)
281 template <wpi::util::ProtobufSerializable T>
284 std::string_view
const typeName = wpi::util::Protobuf<std::remove_cvref_t<T>>::MessageStruct::msg_descriptor()->proto_name;
286 wpi::util::ProtobufMessage<T> proto;
288 proto.ForEachProtobufDescriptor(
289 [](std::string_view typeName) {
290 if (typeName.starts_with(
"proto:")) {
291 typeName.remove_prefix(6);
295 [](std::string_view typeName,
auto schema) {
296 if (typeName.starts_with(
"proto:")) {
297 typeName.remove_prefix(6);
305 wpi::util::SmallVector<uint8_t, 128> buf;
306 proto.Pack(buf, value);
322 return WriteRaw_Impl(name, data, latencySeconds.value());
335 return WriteBoolean_Impl(name, value, latencySeconds.value());
349 return WriteInteger_Impl(name, value, units, latencySeconds.value());
363 return WriteFloat_Impl(name, value, units, latencySeconds.value());
377 return WriteDouble_Impl(name, value, units, latencySeconds.value());
390 return WriteString_Impl(name, value, latencySeconds.value());
402 template <
typename U>
403 requires wpi::units::traits::is_unit_t_v<U>
406 return WriteDouble(name, value.value(), wpi::units::abbreviation(value), latencySeconds);
420 return WriteBooleanArray_Impl(name, values, latencySeconds.value());
433 return WriteBooleanArray_Impl(name, values, latencySeconds.value());
448 return WriteIntegerArray_Impl(name, values, units, latencySeconds.value());
463 return WriteFloatArray_Impl(name, values, units, latencySeconds.value());
478 return WriteDoubleArray_Impl(name, values, units, latencySeconds.value());
492 return WriteStringArray_Impl(name, values, latencySeconds.value());
505 return WriteStringArray_Impl(name, values, latencySeconds.value());
509 static ctre::phoenix::StatusCode WriteRaw_Impl(std::string_view name, std::span<uint8_t const> data,
double latencySeconds);
511 static ctre::phoenix::StatusCode WriteInteger_Impl(std::string_view name, int64_t value, std::string_view units,
double latencySeconds);
512 static ctre::phoenix::StatusCode WriteFloat_Impl(std::string_view name,
float value, std::string_view units,
double latencySeconds);
513 static ctre::phoenix::StatusCode WriteDouble_Impl(std::string_view name,
double value, std::string_view units,
double latencySeconds);
516 static ctre::phoenix::StatusCode WriteBooleanArray_Impl(std::string_view name, std::span<bool const> values,
double latencySeconds)
518 static_assert(
sizeof(bool) ==
sizeof(uint8_t),
"bool is not uint8_t");
519 return WriteBooleanArray_Impl(name, std::span{(uint8_t
const *)values.data(), values.size()}, latencySeconds);
521 static ctre::phoenix::StatusCode WriteBooleanArray_Impl(std::string_view name, std::span<uint8_t const> values,
double latencySeconds);
522 static ctre::phoenix::StatusCode WriteIntegerArray_Impl(std::string_view name, std::span<int64_t const> values, std::string_view units,
double latencySeconds);
523 static ctre::phoenix::StatusCode WriteFloatArray_Impl(std::string_view name, std::span<float const> values, std::string_view units,
double latencySeconds);
524 static ctre::phoenix::StatusCode WriteDoubleArray_Impl(std::string_view name, std::span<double const> values, std::string_view units,
double latencySeconds);
525 static ctre::phoenix::StatusCode WriteStringArray_Impl(std::string_view name, std::span<std::string_view const> values,
double latencySeconds);
526 static ctre::phoenix::StatusCode WriteStringArray_Impl(std::string_view name, std::span<std::string const> values,
double latencySeconds);
530#if __has_include(<wpi/util/struct/Struct.hpp>)
531 template <
typename T,
size_t N,
typename... I>
532 requires wpi::util::StructSerializable<T, I...>
533 static constexpr auto MakeStructArrayTypeName(I
const &... info) {
534 using namespace wpi::util;
538 is_constexpr([&info...] { S::GetTypeName(info...); })
540 constexpr auto typeName = S::GetTypeName(info...);
541 using namespace literals;
542 if constexpr (N == std::dynamic_extent) {
544 ct_string<
char, std::char_traits<char>, typeName.size()>{typeName},
549 ct_string<
char, std::char_traits<char>, typeName.size()>{typeName},
550 "["_ct_string, NumToCtString<N>(),
"]"_ct_string
554 if constexpr (N == std::dynamic_extent) {
555 return fmt::format(
"{}[]", S::GetTypeName(info...));
557 return fmt::format(
"{}[{}]", S::GetTypeName(info...), N);
Static class for controlling the Phoenix 6 signal logger.
Definition SignalLogger.hpp:44
static ctre::phoenix::StatusCode WriteValue(std::string_view name, U value, wpi::units::second_t latencySeconds=0_s)
Writes the unit value to the log file.
Definition SignalLogger.hpp:404
static ctre::phoenix::StatusCode WriteBoolean(std::string_view name, bool value, wpi::units::second_t latencySeconds=0_s)
Writes the boolean to the log file.
Definition SignalLogger.hpp:333
static ctre::phoenix::StatusCode WriteStructArray(std::string_view name, std::span< T const > values, I const &... info, wpi::units::second_t latencySeconds=0_s)
Writes the array of WPILib Structs to the log file.
Definition SignalLogger.hpp:237
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, wpi::units::second_t latencySeconds=0_s)
Writes the array of strings to the log file.
Definition SignalLogger.hpp:503
static ctre::phoenix::StatusCode WriteProtobuf(std::string_view name, T const &value, wpi::units::second_t latencySeconds=0_s)
Writes the protobuf to the log file.
Definition SignalLogger.hpp:282
static ctre::phoenix::StatusCode WriteInteger(std::string_view name, int64_t value, std::string_view units="", wpi::units::second_t latencySeconds=0_s)
Writes the integer to the log file.
Definition SignalLogger.hpp:347
static ctre::phoenix::StatusCode WriteRaw(std::string_view name, std::span< uint8_t const > data, wpi::units::second_t latencySeconds=0_s)
Writes the raw data bytes to the log file.
Definition SignalLogger.hpp:320
static ctre::phoenix::StatusCode WriteBooleanArray(std::string_view name, std::span< bool const > values, wpi::units::second_t latencySeconds=0_s)
Writes the array of booleans to the log file.
Definition SignalLogger.hpp:418
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:141
static ctre::phoenix::StatusCode WriteSchemaValue(std::string_view name, std::string_view schema, HootSchemaType type, std::span< uint8_t const > data, wpi::units::second_t latencySeconds=0_s)
Writes the schema-serialized bytes to the log file.
Definition SignalLogger.hpp:173
static ctre::phoenix::StatusCode WriteIntegerArray(std::string_view name, std::span< int64_t const > values, std::string_view units="", wpi::units::second_t latencySeconds=0_s)
Writes the array of integers to the log file.
Definition SignalLogger.hpp:446
static ctre::phoenix::StatusCode WriteBooleanArray(std::string_view name, std::span< uint8_t const > values, wpi::units::second_t latencySeconds=0_s)
Writes the array of booleans to the log file.
Definition SignalLogger.hpp:431
static ctre::phoenix::StatusCode WriteDouble(std::string_view name, double value, std::string_view units="", wpi::units::second_t latencySeconds=0_s)
Writes the double to the log file.
Definition SignalLogger.hpp:375
static ctre::phoenix::StatusCode Stop()
Stops logging status signals.
static ctre::phoenix::StatusCode WriteString(std::string_view name, std::string_view value, wpi::units::second_t latencySeconds=0_s)
Writes the string to the log file.
Definition SignalLogger.hpp:388
static ctre::phoenix::StatusCode WriteStruct(std::string_view name, T const &value, I const &... info, wpi::units::second_t latencySeconds=0_s)
Writes the WPILib Struct to the log file.
Definition SignalLogger.hpp:191
static ctre::phoenix::StatusCode WriteDoubleArray(std::string_view name, std::span< double const > values, std::string_view units="", wpi::units::second_t latencySeconds=0_s)
Writes the array of doubles to the log file.
Definition SignalLogger.hpp:476
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 WriteFloatArray(std::string_view name, std::span< float const > values, std::string_view units="", wpi::units::second_t latencySeconds=0_s)
Writes the array of floats to the log file.
Definition SignalLogger.hpp:461
static ctre::phoenix::StatusCode WriteStringArray(std::string_view name, std::span< std::string_view const > values, wpi::units::second_t latencySeconds=0_s)
Writes the array of strings to the log file.
Definition SignalLogger.hpp:490
static ctre::phoenix::StatusCode WriteFloat(std::string_view name, float value, std::string_view units="", wpi::units::second_t latencySeconds=0_s)
Writes the float to the log file.
Definition SignalLogger.hpp:361
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
Definition ExternalFeedbackConfigs.hpp:16
HootSchemaType
Supported schema types for a hoot user signal.
Definition HootSchemaType.hpp:15
@ Struct
Serialize using the WPILib Struct format.
Definition HootSchemaType.hpp:19
@ Protobuf
Serialize using the Protobuf format.
Definition HootSchemaType.hpp:23
Definition motor_constants.h:14