Merge "Add methods for checking Watchdog status, ds status, and brownout status"

This commit is contained in:
Fred Silberberg (WPI)
2014-11-19 10:34:33 -08:00
committed by Gerrit Code Review
7 changed files with 89 additions and 0 deletions

View File

@@ -216,6 +216,9 @@ extern "C"
int HALGetJoystickButtons(uint8_t joystickNum, HALJoystickButtons *buttons, uint8_t *count);
void HALSetNewDataSem(pthread_cond_t *);
bool HALGetSystemActive(int32_t *status);
bool HALGetBrownedOut(int32_t *status);
int HALInitialize(int mode = 0);
void HALNetworkCommunicationObserveUserProgramStarting();

View File

@@ -19,6 +19,7 @@ const uint32_t interrupt_kNumSystems = tInterrupt::kNumSystems;
const uint32_t kSystemClockTicksPerMicrosecond = 40;
static tGlobal *global;
static tSysWatchdog *watchdog;
void* getPort(uint8_t pin)
{
@@ -210,6 +211,16 @@ void HALSetNewDataSem(pthread_cond_t * param)
setNewDataSem(param);
}
bool HALGetSystemActive(int32_t *status)
{
return watchdog->readStatus_SystemActive(status);
}
bool HALGetBrownedOut(int32_t *status)
{
return !(watchdog->readStatus_PowerAlive(status));
}
/**
* Call this to start up HAL. This is required for robot programs.
*/
@@ -227,6 +238,7 @@ int HALInitialize(int mode)
int32_t status;
global = tGlobal::create(&status);
watchdog = tSysWatchdog::create(&status);
// Kill any previous robot programs
std::fstream fs;

View File

@@ -41,8 +41,11 @@ public:
bool IsAutonomous();
bool IsOperatorControl();
bool IsTest();
bool IsDSAttached();
bool IsNewControlData();
bool IsFMSAttached();
bool IsSysActive();
bool IsSysBrownedOut();
Alliance GetAlliance();
uint32_t GetLocation();

View File

@@ -286,6 +286,29 @@ bool DriverStation::IsTest()
return m_controlWord.test;
}
bool DriverStation::IsDSAttached()
{
HALControlWord controlWord;
HALGetControlWord(&controlWord);
return controlWord.dsAttached;
}
bool DriverStation::IsSysActive()
{
int32_t status = 0;
bool retVal = HALGetSystemActive(&status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
return retVal;
}
bool DriverStation::IsSysBrownedOut()
{
int32_t status = 0;
bool retVal = HALGetBrownedOut(&status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
return retVal;
}
/**
* Has a new control packet from the driver station arrived since the last time this function was called?
* Warning: If you call this function from more than one place at the same time,

View File

@@ -8,6 +8,7 @@ package edu.wpi.first.wpilibj;
import java.nio.IntBuffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary;
import edu.wpi.first.wpilibj.communication.HALControlWord;
@@ -329,6 +330,22 @@ public class DriverStation implements RobotState.Interface {
public boolean isOperatorControl() {
return !(isAutonomous() || isTest());
}
public boolean isSysActive() {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
boolean retVal = FRCNetworkCommunicationsLibrary.HALGetSystemActive(status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return retVal;
}
public boolean isBrownedOut() {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
boolean retVal = FRCNetworkCommunicationsLibrary.HALGetBrownedOut(status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return retVal;
}
/**
* Has a new control packet from the driver station arrived since the last time this function was called?
@@ -393,6 +410,11 @@ public class DriverStation implements RobotState.Interface {
public boolean isFMSAttached() {
return m_controlWord.getFMSAttached();
}
public boolean isDSAttached() {
HALControlWord controlWord = FRCNetworkCommunicationsLibrary.HALGetControlWord();
return controlWord.getDSAttached();
}
/**
* Return the approximate match time

View File

@@ -468,6 +468,8 @@ public class FRCNetworkCommunicationsLibrary extends JNIWrapper {
return HALAllianceStationID.Blue2;
case 5:
return HALAllianceStationID.Blue3;
default:
return null;
}
}

View File

@@ -535,6 +535,30 @@ JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCom
return env->NewDirectByteBuffer(returnByteArray, 4);
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: HALGetSystemActive
* Signature: (Ljava/nio/IntBuffer;)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetSystemActive
(JNIEnv * env, jclass, jobject status)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
return HALGetSystemActive((int32_t*)statusPtr);
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: HALGetBrownedOut
* Signature: (Ljava/nio/IntBuffer;)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetBrownedOut
(JNIEnv * env, jclass, jobject status)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
return HALGetBrownedOut((int32_t*)statusPtr);
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: HALSetErrorData