mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[hal,wpilib] Switch to new game data (#8584)
Game data is now limited to 8 bytes, and comes through the UDP packets.
This commit is contained in:
@@ -81,12 +81,12 @@ void wpi::glass::DisplayFMS(FMSModel* model, bool editableDsAttached) {
|
||||
}
|
||||
}
|
||||
|
||||
// Game Specific Message
|
||||
if (auto data = model->GetGameSpecificMessageData()) {
|
||||
std::string gameSpecificMessage = data->GetValue();
|
||||
// Game Data
|
||||
if (auto data = model->GetGameData()) {
|
||||
std::string gameData = data->GetValue();
|
||||
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8);
|
||||
if (ImGui::InputText("Game Specific", &gameSpecificMessage)) {
|
||||
model->SetGameSpecificMessage(gameSpecificMessage);
|
||||
if (ImGui::InputText("Game Data", &gameData)) {
|
||||
model->SetGameData(gameData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,14 +145,13 @@ void wpi::glass::DisplayFMSReadOnly(FMSModel* model) {
|
||||
ImGui::TextUnformatted("?");
|
||||
}
|
||||
}
|
||||
if (auto data = model->GetGameSpecificMessageData()) {
|
||||
if (auto data = model->GetGameData()) {
|
||||
if (exists) {
|
||||
wpi::util::SmallString<64> gsmBuf;
|
||||
std::string_view gsm = data->GetValue(gsmBuf);
|
||||
ImGui::Text("Game Specific: %.*s", static_cast<int>(gsm.size()),
|
||||
gsm.data());
|
||||
ImGui::Text("Game Data: %.*s", static_cast<int>(gsm.size()), gsm.data());
|
||||
} else {
|
||||
ImGui::TextUnformatted("Game Specific: ?");
|
||||
ImGui::TextUnformatted("Game Data: ?");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class FMSModel : public Model {
|
||||
virtual BooleanSource* GetEStopData() = 0;
|
||||
virtual BooleanSource* GetEnabledData() = 0;
|
||||
virtual IntegerSource* GetRobotModeData() = 0;
|
||||
virtual StringSource* GetGameSpecificMessageData() = 0;
|
||||
virtual StringSource* GetGameData() = 0;
|
||||
|
||||
virtual void SetFmsAttached(bool val) = 0;
|
||||
virtual void SetDsAttached(bool val) = 0;
|
||||
@@ -45,7 +45,7 @@ class FMSModel : public Model {
|
||||
virtual void SetEStop(bool val) = 0;
|
||||
virtual void SetEnabled(bool val) = 0;
|
||||
virtual void SetRobotMode(RobotMode val) = 0;
|
||||
virtual void SetGameSpecificMessage(std::string_view val) = 0;
|
||||
virtual void SetGameData(std::string_view val) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,9 +30,8 @@ NTFMSModel::NTFMSModel(std::string_view path)
|
||||
NTFMSModel::NTFMSModel(wpi::nt::NetworkTableInstance inst,
|
||||
std::string_view path)
|
||||
: m_inst{inst},
|
||||
m_gameSpecificMessage{
|
||||
inst.GetStringTopic(fmt::format("{}/GameSpecificMessage", path))
|
||||
.Subscribe("")},
|
||||
m_gameDataSubscriber{
|
||||
inst.GetStringTopic(fmt::format("{}/GameData", path)).Subscribe("")},
|
||||
m_alliance{inst.GetBooleanTopic(fmt::format("{}/IsRedAlliance", path))
|
||||
.Subscribe(false)},
|
||||
m_station{inst.GetIntegerTopic(fmt::format("{}/StationNumber", path))
|
||||
@@ -45,8 +44,7 @@ NTFMSModel::NTFMSModel(wpi::nt::NetworkTableInstance inst,
|
||||
m_estop{fmt::format("NT_FMS:EStop:{}", path)},
|
||||
m_enabled{fmt::format("NT_FMS:RobotEnabled:{}", path)},
|
||||
m_robotMode{fmt::format("NT_FMS:RobotMode:{}", path)},
|
||||
m_gameSpecificMessageData{
|
||||
fmt::format("NT_FMS:GameSpecificMessage:{}", path)} {}
|
||||
m_gameData{fmt::format("NT_FMS:GameData:{}", path)} {}
|
||||
|
||||
void NTFMSModel::Update() {
|
||||
for (auto&& v : m_alliance.ReadQueue()) {
|
||||
@@ -82,8 +80,8 @@ void NTFMSModel::Update() {
|
||||
((controlWord & HAL_CONTROLWORD_DS_ATTACHED_MASK) != 0) ? 1 : 0,
|
||||
v.time);
|
||||
}
|
||||
for (auto&& v : m_gameSpecificMessage.ReadQueue()) {
|
||||
m_gameSpecificMessageData.SetValue(std::move(v.value), v.time);
|
||||
for (auto&& v : m_gameDataSubscriber.ReadQueue()) {
|
||||
m_gameData.SetValue(std::move(v.value), v.time);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,7 @@ class NTFMSModel : public FMSModel {
|
||||
BooleanSource* GetEStopData() override { return &m_estop; }
|
||||
BooleanSource* GetEnabledData() override { return &m_enabled; }
|
||||
IntegerSource* GetRobotModeData() override { return &m_robotMode; }
|
||||
StringSource* GetGameSpecificMessageData() override {
|
||||
return &m_gameSpecificMessageData;
|
||||
}
|
||||
StringSource* GetGameData() override { return &m_gameData; }
|
||||
|
||||
// NT is read-only (it's continually set by robot code)
|
||||
void SetFmsAttached(bool val) override {}
|
||||
@@ -46,7 +44,7 @@ class NTFMSModel : public FMSModel {
|
||||
void SetEStop(bool val) override {}
|
||||
void SetEnabled(bool val) override {}
|
||||
void SetRobotMode(RobotMode val) override {}
|
||||
void SetGameSpecificMessage(std::string_view val) override {}
|
||||
void SetGameData(std::string_view val) override {}
|
||||
|
||||
void Update() override;
|
||||
bool Exists() override;
|
||||
@@ -54,7 +52,7 @@ class NTFMSModel : public FMSModel {
|
||||
|
||||
private:
|
||||
wpi::nt::NetworkTableInstance m_inst;
|
||||
wpi::nt::StringSubscriber m_gameSpecificMessage;
|
||||
wpi::nt::StringSubscriber m_gameDataSubscriber;
|
||||
wpi::nt::BooleanSubscriber m_alliance;
|
||||
wpi::nt::IntegerSubscriber m_station;
|
||||
wpi::nt::RawSubscriber m_controlWord;
|
||||
@@ -65,7 +63,7 @@ class NTFMSModel : public FMSModel {
|
||||
BooleanSource m_estop;
|
||||
BooleanSource m_enabled;
|
||||
IntegerSource m_robotMode;
|
||||
StringSource m_gameSpecificMessageData;
|
||||
StringSource m_gameData;
|
||||
};
|
||||
|
||||
} // namespace wpi::glass
|
||||
|
||||
Reference in New Issue
Block a user