90 explicit Loggable(std::shared_ptr<nt::NetworkTable> table);
129 void LogChild(std::string_view name, wpi::Sendable* child);
131 inline bool WriteLog(std::string_view field,
bool data) {
133 frc::SmartDashboard::PutBoolean(smartDashboardPrefix + std::string{field}, data);
137 inline double WriteLog(std::string_view field,
double data) {
139 frc::SmartDashboard::PutNumber(smartDashboardPrefix + std::string{field}, data);
143 inline void WriteLog(std::string_view field,
const std::vector<double>& data) {
145 frc::SmartDashboard::PutNumberArray(smartDashboardPrefix + std::string{field}, data);
148 template <
typename U>
149 requires units::traits::is_unit_t_v<U>
150 inline U WriteLog(std::string_view field, U data) {
151 WriteLog(field, data.value());
155 inline void WriteLog(std::string_view field, std::string_view data) {
157 frc::SmartDashboard::PutString(smartDashboardPrefix + std::string{field}, data);
160 template <
typename E>
161 requires std::is_enum_v<E>
162 inline void WriteLog(std::string_view field, E data) {
163 WriteLog(field, magic_enum::enum_name(data));
166 template <
typename T>
167 requires wpi::StructSerializable<T> && (!std::is_arithmetic_v<T>)
168 inline void WriteLog(std::string_view field,
const T& data) {
171 auto pub = publishers.find(field);
172 if (pub == publishers.end())
174 .try_emplace(std::string{field}, std::make_unique<nt::StructPublisher<T>>(table->GetStructTopic<T>(field).Publish()))
176 static_cast<nt::StructPublisher<T>*
>(pub->second.get())->Set(data);
179 template <
typename T>
180 requires wpi::StructSerializable<T> && (!std::is_arithmetic_v<T>)
181 inline void WriteLog(std::string_view field,
const std::vector<T>& data) {
184 auto pub = publishers.find(field);
185 if (pub == publishers.end())
187 .try_emplace(std::string{field},
188 std::make_unique<nt::StructArrayPublisher<T>>(table->GetStructArrayTopic<T>(field).Publish()))
190 static_cast<nt::StructArrayPublisher<T>*
>(pub->second.get())->Set(data);
193 inline bool ReadLog(std::string_view field,
bool defaultValue) {
195 return frc::SmartDashboard::GetBoolean(smartDashboardPrefix + std::string{field}, defaultValue);
199 inline double ReadLog(std::string_view field,
double defaultValue) {
201 return frc::SmartDashboard::GetNumber(smartDashboardPrefix + std::string{field}, defaultValue);
205 template <
typename U>
206 requires units::traits::is_unit_t_v<U>
207 inline U ReadLog(std::string_view field, U defaultValue) {
208 return U{ReadLog(field, defaultValue.value())};
211 static constexpr Loggable& GetRoot() {
return rootLoggable; }
232 std::string GetSmartDashboardPrefix()
const;
234 std::shared_ptr<nt::NetworkTable> table;
235 std::string smartDashboardPrefix;
236 std::unordered_map<std::string, Loggable*> loggableChildren;
237 std::unordered_map<std::string, wpi::Sendable*> sendableChildren;