[wpilib] Add metadata to all dashboard ".type" entries (#6799)

This commit is contained in:
Ryan Blue
2024-07-02 16:31:50 -04:00
committed by GitHub
parent 7366a03fc9
commit 6a5448322b
12 changed files with 95 additions and 23 deletions

View File

@@ -13,19 +13,21 @@
#include <networktables/NetworkTableInstance.h>
#include <networktables/NetworkTableListener.h>
#include <networktables/StringTopic.h>
#include <wpi/json.h>
using namespace frc;
// The Preferences table name
static constexpr std::string_view kTableName{"Preferences"};
static constexpr std::string_view kSmartDashboardType = "RobotPreferences";
namespace {
struct Instance {
Instance();
std::shared_ptr<nt::NetworkTable> table{
nt::NetworkTableInstance::GetDefault().GetTable(kTableName)};
nt::StringPublisher typePublisher{table->GetStringTopic(".type").Publish()};
nt::StringPublisher typePublisher{table->GetStringTopic(".type").PublishEx(
nt::StringTopic::kTypeString, {{"SmartDashboard", kSmartDashboardType}})};
nt::MultiSubscriber tableSubscriber{nt::NetworkTableInstance::GetDefault(),
{{fmt::format("{}/", table->GetPath())}}};
nt::NetworkTableListener listener;
@@ -165,7 +167,7 @@ void Preferences::RemoveAll() {
}
Instance::Instance() {
typePublisher.Set("RobotPreferences");
typePublisher.Set(kSmartDashboardType);
listener = nt::NetworkTableListener::CreateListener(
tableSubscriber, NT_EVENT_PUBLISH | NT_EVENT_IMMEDIATE,
[typeTopic = typePublisher.GetTopic().GetHandle()](auto& event) {