Handle cases where no DS is attached (initial m_controlWord, reportError, getAlliance and getLocation) fixes artf3778

Change-Id: I6befa8e31e6762a101cd0a19641e558c955865b9
This commit is contained in:
Kevin O'Connor
2014-11-18 16:54:06 -05:00
parent e73b3ed7b5
commit cd29e1c32f

View File

@@ -54,7 +54,7 @@ public class DriverStation implements RobotState.Interface {
private static DriverStation instance = new DriverStation(); private static DriverStation instance = new DriverStation();
private HALControlWord m_controlWord; private HALControlWord m_controlWord = FRCNetworkCommunicationsLibrary.HALGetControlWord();
private HALAllianceStationID m_allianceStationID; private HALAllianceStationID m_allianceStationID;
private short[][] m_joystickAxes = new short[kJoystickPorts][FRCNetworkCommunicationsLibrary.kMaxJoystickAxes]; private short[][] m_joystickAxes = new short[kJoystickPorts][FRCNetworkCommunicationsLibrary.kMaxJoystickAxes];
private short[][] m_joystickPOVs = new short[kJoystickPorts][FRCNetworkCommunicationsLibrary.kMaxJoystickPOVs]; private short[][] m_joystickPOVs = new short[kJoystickPorts][FRCNetworkCommunicationsLibrary.kMaxJoystickPOVs];
@@ -289,7 +289,7 @@ public class DriverStation implements RobotState.Interface {
* @return True if the robot is enabled, false otherwise. * @return True if the robot is enabled, false otherwise.
*/ */
public boolean isEnabled() { public boolean isEnabled() {
return m_controlWord.getEnabled(); return m_controlWord.getEnabled() && isDSAttached();
} }
/** /**
@@ -362,6 +362,9 @@ public class DriverStation implements RobotState.Interface {
* @return the current alliance * @return the current alliance
*/ */
public Alliance getAlliance() { public Alliance getAlliance() {
if(m_allianceStationID == null) {
return Alliance.Invalid;
}
switch (m_allianceStationID) { switch (m_allianceStationID) {
case Red1: case Red1:
case Red2: case Red2:
@@ -384,6 +387,9 @@ public class DriverStation implements RobotState.Interface {
* @return the location of the team's driver station controls: 1, 2, or 3 * @return the location of the team's driver station controls: 1, 2, or 3
*/ */
public int getLocation() { public int getLocation() {
if(m_allianceStationID == null) {
return 0;
}
switch (m_allianceStationID) { switch (m_allianceStationID) {
case Red1: case Red1:
case Blue1: case Blue1:
@@ -450,7 +456,10 @@ public class DriverStation implements RobotState.Interface {
} }
} }
System.err.println(errorString); System.err.println(errorString);
FRCNetworkCommunicationsLibrary.HALSetErrorData(errorString); HALControlWord controlWord = FRCNetworkCommunicationsLibrary.HALGetControlWord();
if(controlWord.getDSAttached()) {
FRCNetworkCommunicationsLibrary.HALSetErrorData(errorString);
}
} }
/** Only to be used to tell the Driver Station what code you claim to be executing /** Only to be used to tell the Driver Station what code you claim to be executing