mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +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:
@@ -63,6 +63,7 @@ struct JoystickDataCache {
|
||||
HAL_AllianceStationID allianceStation;
|
||||
float matchTime;
|
||||
HAL_ControlWord controlWord;
|
||||
HAL_GameData gameData;
|
||||
};
|
||||
static_assert(std::is_standard_layout_v<JoystickDataCache>);
|
||||
// static_assert(std::is_trivial_v<JoystickDataCache>);
|
||||
@@ -77,7 +78,6 @@ struct SystemServerDriverStation {
|
||||
|
||||
wpi::nt::ProtobufSubscriber<mrc::ControlData> controlDataSubscriber;
|
||||
wpi::nt::ProtobufSubscriber<mrc::MatchInfo> matchInfoSubscriber;
|
||||
wpi::nt::StringSubscriber gameSpecificMessageSubscriber;
|
||||
|
||||
wpi::nt::ProtobufSubscriber<mrc::JoystickDescriptors>
|
||||
joystickDescriptorsTopic;
|
||||
@@ -145,8 +145,6 @@ struct SystemServerDriverStation {
|
||||
matchInfoSubscriber =
|
||||
ntInst.GetProtobufTopic<mrc::MatchInfo>(ROBOT_MATCH_INFO_PATH)
|
||||
.Subscribe({});
|
||||
gameSpecificMessageSubscriber =
|
||||
ntInst.GetStringTopic(ROBOT_GAME_SPECIFIC_MESSAGE_PATH).Subscribe({});
|
||||
|
||||
joystickDescriptorsTopic = ntInst
|
||||
.GetProtobufTopic<mrc::JoystickDescriptors>(
|
||||
@@ -239,6 +237,13 @@ void JoystickDataCache::Update(const mrc::ControlData& data) {
|
||||
allianceInt += 1;
|
||||
allianceStation = static_cast<HAL_AllianceStationID>(allianceInt);
|
||||
|
||||
auto gameData = data.GetGameData();
|
||||
if (gameData.size() > 8) {
|
||||
gameData = gameData.substr(0, 8);
|
||||
}
|
||||
std::memcpy(this->gameData.gameData, gameData.data(), gameData.size());
|
||||
this->gameData.gameData[gameData.size()] = '\0';
|
||||
|
||||
if (data.ControlWord.SupportsOpModes) {
|
||||
controlWord = HAL_MakeControlWord(
|
||||
data.CurrentOpMode.ToValue(),
|
||||
@@ -328,7 +333,6 @@ static wpi::util::mutex tcpCacheMutex;
|
||||
|
||||
void TcpCache::Update() {
|
||||
auto newMatchInfo = systemServerDs->matchInfoSubscriber.Get();
|
||||
auto gameMsg = systemServerDs->gameSpecificMessageSubscriber.Get();
|
||||
|
||||
matchInfo.matchNumber = newMatchInfo.MatchNumber;
|
||||
matchInfo.matchType = static_cast<HAL_MatchType>(newMatchInfo.Type);
|
||||
@@ -343,14 +347,6 @@ void TcpCache::Update() {
|
||||
}
|
||||
matchInfo.eventName[nameLen] = '\0';
|
||||
|
||||
auto gameDataLen =
|
||||
(std::min)(sizeof(matchInfo.gameSpecificMessage), gameMsg.size());
|
||||
|
||||
if (gameDataLen > 0) {
|
||||
std::memcpy(matchInfo.gameSpecificMessage, gameMsg.data(), gameDataLen);
|
||||
}
|
||||
matchInfo.gameSpecificMessageSize = gameDataLen;
|
||||
|
||||
const auto descriptorsMsg = systemServerDs->joystickDescriptorsTopic.Get();
|
||||
size_t descriptorCount = descriptorsMsg.GetDescriptorCount();
|
||||
|
||||
@@ -617,6 +613,12 @@ int32_t HAL_GetJoystickGamepadType(int32_t joystickNum) {
|
||||
}
|
||||
}
|
||||
|
||||
int32_t HAL_GetGameData(HAL_GameData* gameData) {
|
||||
std::scoped_lock lock{cacheMutex};
|
||||
*gameData = currentRead->gameData;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t HAL_GetJoystickSupportedOutputs(int32_t joystickNum) {
|
||||
HAL_JoystickDescriptor joystickDesc;
|
||||
if (HAL_GetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
|
||||
|
||||
@@ -101,6 +101,17 @@ void HALSIM_GetMatchInfo(HAL_MatchInfo* info) {}
|
||||
|
||||
void HALSIM_SetMatchInfo(const HAL_MatchInfo* info) {}
|
||||
|
||||
int32_t HALSIM_RegisterGameDataCallback(HAL_GameDataCallback callback,
|
||||
void* param, HAL_Bool initialNotify) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HALSIM_CancelGameDataCallback(int32_t uid) {}
|
||||
|
||||
void HALSIM_GetGameData(HAL_GameData* info) {}
|
||||
|
||||
void HALSIM_SetGameData(const HAL_GameData* info) {}
|
||||
|
||||
int32_t HALSIM_RegisterDriverStationNewDataCallback(HAL_NotifyCallback callback,
|
||||
void* param,
|
||||
HAL_Bool initialNotify) {
|
||||
@@ -149,7 +160,7 @@ void HALSIM_SetJoystickName(int32_t stick, const struct WPI_String* name) {}
|
||||
void HALSIM_SetJoystickSupportedOutputs(int32_t stick,
|
||||
int32_t supportedOutputs) {}
|
||||
|
||||
void HALSIM_SetGameSpecificMessage(const struct WPI_String* message) {}
|
||||
void HALSIM_SetGameDataString(const struct WPI_String* message) {}
|
||||
|
||||
void HALSIM_SetEventName(const struct WPI_String* name) {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user