Skip to content

Commit

Permalink
[wpilib] Make GameSpecificMessage optional
Browse files Browse the repository at this point in the history
Resolves #7444

Signed-off-by: Jade Turner <[email protected]>
  • Loading branch information
spacey-sooty committed Nov 29, 2024
1 parent b6de7ac commit 2dfa985
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions wpilibc/src/main/native/cpp/DriverStation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,15 @@ bool DriverStation::IsFMSAttached() {
return controlWord.fmsAttached;
}

std::string DriverStation::GetGameSpecificMessage() {
std::optional<std::string> DriverStation::GetGameSpecificMessage() {
HAL_MatchInfo info;
HAL_GetMatchInfo(&info);
return std::string(reinterpret_cast<char*>(info.gameSpecificMessage),
info.gameSpecificMessageSize);
if (info.gameSpecificMessageSize != 0) {
return std::string(reinterpret_cast<char*>(info.gameSpecificMessage),
info.gameSpecificMessageSize);
} else {
return std::nullopt;
}
}

std::string DriverStation::GetEventName() {
Expand Down
2 changes: 1 addition & 1 deletion wpilibc/src/main/native/include/frc/DriverStation.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class DriverStation final {
*
* @return A string containing the game specific message.
*/
static std::string GetGameSpecificMessage();
static std::optional<std::string> GetGameSpecificMessage();

/**
* Returns the name of the competition event provided by the FMS.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1009,10 +1009,14 @@ public static boolean isFMSAttached() {
*
* @return the game specific message
*/
public static String getGameSpecificMessage() {
public static Optional<String> getGameSpecificMessage() {
m_cacheDataMutex.lock();
try {
return m_matchInfo.gameSpecificMessage;
if (m_matchInfo.gameSpecificMessage != null) {
return m_matchInfo.gameSpecificMessage;
} else {
return Optional.empty();
}
} finally {
m_cacheDataMutex.unlock();
}
Expand Down

0 comments on commit 2dfa985

Please sign in to comment.