FMS Hub State Reader
Disclaimer: WIP and untested on 2026 hardware; validate on your field connection. Custom code built on WPILib APIs (not official WPILib sample).
Purpose: Prefer actual FMS hub status over timer; fall back to timer when data is missing.
Code (Java/WPILib)
Assumes Alliance data and DriverStation game-specific message carry hub status (example encoding).
public class HubStateSource {
private final HubShiftTimer timer;
public HubStateSource(HubShiftTimer timer) {
this.timer = timer;
}
public HubShiftTimer.HubState getOurHub() {
Optional<HubShiftTimer.HubState> fms = readFmsHub();
return fms.orElse(timer.get().ourHub());
}
private Optional<HubShiftTimer.HubState> readFmsHub() {
String msg = DriverStation.getGameSpecificMessage();
if (msg == null || msg.isEmpty()) return Optional.empty();
// Example: first char 'A' = our hub active, 'I' = inactive
char c = msg.charAt(0);
if (c == 'A') return Optional.of(HubShiftTimer.HubState.ACTIVE);
if (c == 'I') return Optional.of(HubShiftTimer.HubState.INACTIVE);
return Optional.empty();
}
}
How to test
- Sim: set
DriverStation.simulateGameSpecificMessageand confirm state changes. - Field: compare timer vs. FMS-reported hub status; prefer FMS when present.
Pitfalls
- Encoding of hub state in FMS may differ; update parsing accordingly.