[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

@@ -28,6 +28,7 @@
#include <wpi/DataLog.h>
#include <wpi/EventVector.h>
#include <wpi/condition_variable.h>
#include <wpi/json.h>
#include <wpi/mutex.h>
#include <wpi/timestamp.h>
@@ -45,8 +46,11 @@ class MatchDataSenderEntry {
public:
MatchDataSenderEntry(const std::shared_ptr<nt::NetworkTable>& table,
std::string_view key,
typename Topic::ParamType initialVal)
: publisher{Topic{table->GetTopic(key)}.Publish()}, prevVal{initialVal} {
typename Topic::ParamType initialVal,
wpi::json topicProperties = {{}})
: publisher{Topic{table->GetTopic(key)}.PublishEx(Topic::kTypeString,
topicProperties)},
prevVal{initialVal} {
publisher.Set(initialVal);
}
@@ -62,10 +66,16 @@ class MatchDataSenderEntry {
typename Topic::ValueType prevVal;
};
static constexpr std::string_view kSmartDashboardType = "FMSInfo";
struct MatchDataSender {
std::shared_ptr<nt::NetworkTable> table =
nt::NetworkTableInstance::GetDefault().GetTable("FMSInfo");
MatchDataSenderEntry<nt::StringTopic> typeMetaData{table, ".type", "FMSInfo"};
MatchDataSenderEntry<nt::StringTopic> typeMetaData{
table,
".type",
kSmartDashboardType,
{{"SmartDashboard", kSmartDashboardType}}};
MatchDataSenderEntry<nt::StringTopic> gameSpecificMessage{
table, "GameSpecificMessage", ""};
MatchDataSenderEntry<nt::StringTopic> eventName{table, "EventName", ""};

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) {

View File

@@ -8,6 +8,7 @@
#include <networktables/NetworkTable.h>
#include <networktables/NetworkTableInstance.h>
#include <networktables/StringTopic.h>
#include <wpi/json.h>
#include <wpi/mutex.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableRegistry.h>
@@ -16,6 +17,8 @@
using namespace frc;
static constexpr std::string_view kSmartDashboardType = "LW Subsystem";
namespace {
struct Component {
bool firstTime = true;
@@ -207,8 +210,10 @@ void LiveWindow::UpdateValuesUnsafe() {
comp.namePub.Set(cbdata.name);
static_cast<SendableBuilderImpl&>(cbdata.builder).SetTable(table);
cbdata.sendable->InitSendable(cbdata.builder);
comp.typePub = nt::StringTopic{ssTable->GetTopic(".type")}.Publish();
comp.typePub.Set("LW Subsystem");
comp.typePub = nt::StringTopic{ssTable->GetTopic(".type")}.PublishEx(
nt::StringTopic::kTypeString,
{{"SmartDashboard", kSmartDashboardType}});
comp.typePub.Set(kSmartDashboardType);
comp.firstTime = false;
}

View File

@@ -4,8 +4,12 @@
#include "frc/shuffleboard/ShuffleboardLayout.h"
#include <wpi/json.h>
using namespace frc;
static constexpr std::string_view kSmartDashboardType = "ShuffleboardLayout";
ShuffleboardLayout::ShuffleboardLayout(ShuffleboardContainer& parent,
std::string_view title,
std::string_view type)
@@ -20,7 +24,9 @@ void ShuffleboardLayout::BuildInto(
std::shared_ptr<nt::NetworkTable> metaTable) {
BuildMetadata(metaTable);
auto table = parentTable->GetSubTable(GetTitle());
table->GetEntry(".type").SetString("ShuffleboardLayout");
table->GetEntry(".type").SetString(kSmartDashboardType);
table->GetEntry(".type").GetTopic().SetProperty("SmartDashboard",
kSmartDashboardType);
for (auto& component : GetComponents()) {
component->BuildInto(table, metaTable->GetSubTable(component->GetTitle()));
}

View File

@@ -4,8 +4,12 @@
#include "frc/shuffleboard/ShuffleboardTab.h"
#include <wpi/json.h>
using namespace frc;
static constexpr std::string_view kSmartDashboardType = "ShuffleboardLayout";
ShuffleboardTab::ShuffleboardTab(ShuffleboardRoot& root, std::string_view title)
: ShuffleboardValue(title), ShuffleboardContainer(title), m_root(root) {}
@@ -16,7 +20,9 @@ ShuffleboardRoot& ShuffleboardTab::GetRoot() {
void ShuffleboardTab::BuildInto(std::shared_ptr<nt::NetworkTable> parentTable,
std::shared_ptr<nt::NetworkTable> metaTable) {
auto tabTable = parentTable->GetSubTable(GetTitle());
tabTable->GetEntry(".type").SetString("ShuffleboardTab");
tabTable->GetEntry(".type").SetString(kSmartDashboardType);
tabTable->GetEntry(".type").GetTopic().SetProperty("SmartDashboard",
kSmartDashboardType);
for (auto& component : GetComponents()) {
component->BuildInto(tabTable,
metaTable->GetSubTable(component->GetTitle()));

View File

@@ -5,9 +5,12 @@
#include "frc/smartdashboard/MechanismLigament2d.h"
#include <wpi/StringExtras.h>
#include <wpi/json.h>
using namespace frc;
static constexpr std::string_view kSmartDashboardType = "line";
MechanismLigament2d::MechanismLigament2d(std::string_view name, double length,
units::degree_t angle,
double lineWeight,
@@ -21,8 +24,9 @@ MechanismLigament2d::MechanismLigament2d(std::string_view name, double length,
void MechanismLigament2d::UpdateEntries(
std::shared_ptr<nt::NetworkTable> table) {
m_typePub = table->GetStringTopic(".type").Publish();
m_typePub.Set("line");
m_typePub = table->GetStringTopic(".type").PublishEx(
nt::StringTopic::kTypeString, {{"SmartDashboard", kSmartDashboardType}});
m_typePub.Set(kSmartDashboardType);
m_colorEntry = table->GetStringTopic("color").GetEntry("");
m_colorEntry.Set(m_color);