Add newer DriverStation methods to ahal
Change-Id: I30c5bf4ccbf72cb135dedc08ef7ee23e101c90fc
Signed-off-by: Lee Mracek <lee@valkyrierobotics.com>
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/frc971/wpilib/ahal/DriverStation.cc b/frc971/wpilib/ahal/DriverStation.cc
index 2ed0a97..8b31af7 100644
--- a/frc971/wpilib/ahal/DriverStation.cc
+++ b/frc971/wpilib/ahal/DriverStation.cc
@@ -272,6 +272,54 @@
}
/**
+ * Returns the game specific message provided by the FMS.
+ *
+ * @return A string containing the game specific message.
+ */
+std::string_view DriverStation::GetGameSpecificMessage() const {
+ return std::string_view(
+ reinterpret_cast<const char *>(info_.gameSpecificMessage),
+ info_.gameSpecificMessageSize);
+}
+
+/**
+ * Returns the name of the competition event provided by the FMS.
+ *
+ * @return A string containing the event name
+ */
+std::string_view DriverStation::GetEventName() const {
+ return info_.eventName;
+}
+
+/**
+ * Returns the match number provided by the FMS.
+ *
+ * @return The number of the match
+ */
+DriverStation::MatchType DriverStation::GetMatchType() const {
+ return static_cast<DriverStation::MatchType>(info_.matchType);
+}
+
+/**
+ * Returns the match number provided by the FMS.
+ *
+ * @return The number of the match
+ */
+int DriverStation::GetMatchNumber() const {
+ return info_.matchNumber;
+}
+
+/**
+ * Returns the number of times the current match has been replayed from the
+ * FMS.
+ *
+ * @return The number of replays
+ */
+int DriverStation::GetReplayNumber() const {
+ return info_.replayNumber;
+}
+
+/**
* Return the alliance that the driver station says it is on.
*
* This could return kRed or kBlue.
@@ -374,10 +422,14 @@
HAL_ControlWord control_word;
HAL_GetControlWord(&control_word);
- is_enabled_ = control_word.enabled;
+ is_enabled_ = control_word.enabled && control_word.dsAttached;
is_autonomous_ = control_word.autonomous;
is_test_mode_ = control_word.test;
is_fms_attached_ = control_word.fmsAttached;
+ is_ds_attached_ = control_word.dsAttached;
+ is_teleop_ = !(control_word.autonomous || control_word.test);
+
+ HAL_GetMatchInfo(&info_);
}
/**
diff --git a/frc971/wpilib/ahal/DriverStation.h b/frc971/wpilib/ahal/DriverStation.h
index 5150360..8bcdcf1 100644
--- a/frc971/wpilib/ahal/DriverStation.h
+++ b/frc971/wpilib/ahal/DriverStation.h
@@ -27,6 +27,7 @@
class DriverStation {
public:
enum Alliance { kRed, kBlue, kInvalid };
+ enum MatchType { kNone, kPractice, kQualification, kElimination };
virtual ~DriverStation();
static DriverStation &GetInstance();
@@ -55,10 +56,18 @@
bool IsTestMode() const { return is_test_mode_; }
bool IsFmsAttached() const { return is_fms_attached_; }
bool IsAutonomous() const { return is_autonomous_; }
+ bool IsTeleop() const { return is_teleop_; }
+ bool IsDSAttached() const { return is_ds_attached_; }
bool IsSysActive() const;
bool IsBrownedOut() const;
+ std::string_view GetGameSpecificMessage() const;
+
+ std::string_view GetEventName() const;
+ MatchType GetMatchType() const;
+ int GetMatchNumber() const;
+ int GetReplayNumber() const;
Alliance GetAlliance() const;
int GetLocation() const;
double GetMatchTime() const;
@@ -88,6 +97,11 @@
bool is_test_mode_ = false;
bool is_autonomous_ = false;
bool is_fms_attached_ = false;
+ bool is_teleop_ = false;
+ bool is_ds_attached_ = false;
+
+ // statically allocated match info so we can return string_views into it.
+ HAL_MatchInfo info_;
};
} // namespace frc