diff --git a/hal/src/main/java/edu/wpi/first/hal/HAL.java b/hal/src/main/java/edu/wpi/first/hal/HAL.java index 7fa3fef2b3..a14e5f910f 100644 --- a/hal/src/main/java/edu/wpi/first/hal/HAL.java +++ b/hal/src/main/java/edu/wpi/first/hal/HAL.java @@ -195,6 +195,14 @@ public final class HAL extends JNIWrapper { */ public static native boolean getRSLState(); + /** + * Gets the number of times the system has been disabled due to communication errors with the + * Driver Station. + * + * @return number of disables due to communication errors. + */ + public static native int getCommsDisableCount(); + /** * Gets if the system time is valid. * diff --git a/hal/src/main/java/edu/wpi/first/hal/PowerJNI.java b/hal/src/main/java/edu/wpi/first/hal/PowerJNI.java index 900b423f34..60c86c5d01 100644 --- a/hal/src/main/java/edu/wpi/first/hal/PowerJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/PowerJNI.java @@ -143,6 +143,9 @@ public class PowerJNI extends JNIWrapper { */ public static native int getUserCurrentFaults3V3(); + /** Resets the overcurrent fault counters for all user rails to 0. */ + public static native void resetUserCurrentFaults(); + /** * Set the voltage the roboRIO will brownout and disable all outputs. * diff --git a/hal/src/main/native/athena/HAL.cpp b/hal/src/main/native/athena/HAL.cpp index 5b351e92d6..91bb93be1f 100644 --- a/hal/src/main/native/athena/HAL.cpp +++ b/hal/src/main/native/athena/HAL.cpp @@ -452,6 +452,15 @@ HAL_Bool HAL_GetBrownedOut(int32_t* status) { return !(watchdog->readStatus_PowerAlive(status)); } +int32_t HAL_GetCommsDisableCount(int32_t* status) { + hal::init::CheckInit(); + if (!watchdog) { + *status = NiFpga_Status_ResourceNotInitialized; + return 0; + } + return watchdog->readStatus_SysDisableCount(status); +} + HAL_Bool HAL_GetRSLState(int32_t* status) { hal::init::CheckInit(); if (!global) { diff --git a/hal/src/main/native/athena/Power.cpp b/hal/src/main/native/athena/Power.cpp index 249ab98e06..19fe29f51f 100644 --- a/hal/src/main/native/athena/Power.cpp +++ b/hal/src/main/native/athena/Power.cpp @@ -118,6 +118,11 @@ void HAL_SetUserRailEnabled3V3(HAL_Bool enabled, int32_t* status) { power->writeDisable_User3V3(!enabled, status); } +void HAL_ResetUserCurrentFaults(int32_t* status) { + initializePower(status); + power->strobeResetFaultCounts(status); +} + void HAL_SetBrownoutVoltage(double voltage, int32_t* status) { initializePower(status); if (voltage < 0) { diff --git a/hal/src/main/native/cpp/jni/HAL.cpp b/hal/src/main/native/cpp/jni/HAL.cpp index 7dcdf45edb..bfde2c2824 100644 --- a/hal/src/main/native/cpp/jni/HAL.cpp +++ b/hal/src/main/native/cpp/jni/HAL.cpp @@ -154,6 +154,21 @@ Java_edu_wpi_first_hal_HAL_getBrownedOut return val; } +/* + * Class: edu_wpi_first_hal_HAL + * Method: getCommsDisableCount + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_hal_HAL_getCommsDisableCount + (JNIEnv* env, jclass) +{ + int32_t status = 0; + int32_t val = HAL_GetCommsDisableCount(&status); + CheckStatus(env, status); + return val; +} + /* * Class: edu_wpi_first_hal_HAL * Method: getRSLState diff --git a/hal/src/main/native/cpp/jni/PowerJNI.cpp b/hal/src/main/native/cpp/jni/PowerJNI.cpp index 20962053e2..f21d50f474 100644 --- a/hal/src/main/native/cpp/jni/PowerJNI.cpp +++ b/hal/src/main/native/cpp/jni/PowerJNI.cpp @@ -264,6 +264,20 @@ Java_edu_wpi_first_hal_PowerJNI_getUserCurrentFaults3V3 return val; } +/* + * Class: edu_wpi_first_hal_PowerJNI + * Method: resetUserCurrentFaults + * Signature: ()V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_hal_PowerJNI_resetUserCurrentFaults + (JNIEnv* env, jclass) +{ + int32_t status = 0; + HAL_ResetUserCurrentFaults(&status); + CheckStatus(env, status); +} + /* * Class: edu_wpi_first_hal_PowerJNI * Method: setBrownoutVoltage diff --git a/hal/src/main/native/include/hal/HALBase.h b/hal/src/main/native/include/hal/HALBase.h index 0359665985..56b6ca978b 100644 --- a/hal/src/main/native/include/hal/HALBase.h +++ b/hal/src/main/native/include/hal/HALBase.h @@ -139,6 +139,13 @@ HAL_Bool HAL_GetSystemActive(int32_t* status); */ HAL_Bool HAL_GetBrownedOut(int32_t* status); +/** + * Gets the number of times the system has been disabled due to communication + * errors with the Driver Station. + * @return number of disables due to communication errors. + */ +int32_t HAL_GetCommsDisableCount(int32_t* status); + /** * Gets a port handle for a specific channel. * diff --git a/hal/src/main/native/include/hal/Power.h b/hal/src/main/native/include/hal/Power.h index b2a01692e9..b6dd4b6952 100644 --- a/hal/src/main/native/include/hal/Power.h +++ b/hal/src/main/native/include/hal/Power.h @@ -59,7 +59,7 @@ double HAL_GetUserCurrent6V(int32_t* status); HAL_Bool HAL_GetUserActive6V(int32_t* status); /** - * Gets the fault count for the 6V rail. + * Gets the fault count for the 6V rail. Capped at 255. * * @param[out] status the error code, or 0 for success * @return the number of 6V fault counts @@ -99,7 +99,7 @@ double HAL_GetUserCurrent5V(int32_t* status); HAL_Bool HAL_GetUserActive5V(int32_t* status); /** - * Gets the fault count for the 5V rail. + * Gets the fault count for the 5V rail. Capped at 255. * * @param[out] status the error code, or 0 for success * @return the number of 5V fault counts @@ -139,7 +139,7 @@ double HAL_GetUserCurrent3V3(int32_t* status); HAL_Bool HAL_GetUserActive3V3(int32_t* status); /** - * Gets the fault count for the 3V3 rail. + * Gets the fault count for the 3V3 rail. Capped at 255. * * @param[out] status the error code, or 0 for success * @return the number of 3V3 fault counts @@ -154,6 +154,12 @@ int32_t HAL_GetUserCurrentFaults3V3(int32_t* status); */ void HAL_SetUserRailEnabled3V3(HAL_Bool enabled, int32_t* status); +/** + * Resets the overcurrent fault counters for all user rails to 0. + * @param[out] status the error code, or 0 for success + */ +void HAL_ResetUserCurrentFaults(int32_t* status); + /** * Get the current brownout voltage setting. * diff --git a/hal/src/main/native/sim/HAL.cpp b/hal/src/main/native/sim/HAL.cpp index c0fecfbd04..5960452be0 100644 --- a/hal/src/main/native/sim/HAL.cpp +++ b/hal/src/main/native/sim/HAL.cpp @@ -339,6 +339,10 @@ HAL_Bool HAL_GetBrownedOut(int32_t* status) { return false; // Figure out if we need to detect a brownout condition } +int32_t HAL_GetCommsDisableCount(int32_t* status) { + return 0; +} + HAL_Bool HAL_GetRSLState(int32_t* status) { return false; } diff --git a/hal/src/main/native/sim/Power.cpp b/hal/src/main/native/sim/Power.cpp index 1eca18f3d6..ce7a462bdd 100644 --- a/hal/src/main/native/sim/Power.cpp +++ b/hal/src/main/native/sim/Power.cpp @@ -59,6 +59,11 @@ int32_t HAL_GetUserCurrentFaults3V3(int32_t* status) { return SimRoboRioData->userFaults3V3; } void HAL_SetUserRailEnabled3V3(HAL_Bool enabled, int32_t* status) {} +void HAL_ResetUserCurrentFaults(int32_t* status) { + SimRoboRioData->userFaults3V3 = 0; + SimRoboRioData->userFaults5V = 0; + SimRoboRioData->userFaults6V = 0; +} void HAL_SetBrownoutVoltage(double voltage, int32_t* status) { SimRoboRioData->brownoutVoltage = voltage; } diff --git a/wpilibc/src/main/native/cpp/RobotController.cpp b/wpilibc/src/main/native/cpp/RobotController.cpp index 48da72372a..5c0f7fd782 100644 --- a/wpilibc/src/main/native/cpp/RobotController.cpp +++ b/wpilibc/src/main/native/cpp/RobotController.cpp @@ -84,6 +84,13 @@ bool RobotController::IsBrownedOut() { return retVal; } +int RobotController::GetCommsDisableCount() { + int32_t status = 0; + int retVal = HAL_GetCommsDisableCount(&status); + FRC_CheckErrorStatus(status, "GetCommsDisableCount"); + return retVal; +} + bool RobotController::GetRSLState() { int32_t status = 0; bool retVal = HAL_GetRSLState(&status); @@ -214,6 +221,12 @@ int RobotController::GetFaultCount6V() { return retVal; } +void RobotController::ResetRailFaultCounts() { + int32_t status = 0; + HAL_ResetUserCurrentFaults(&status); + FRC_CheckErrorStatus(status, "ResetRailFaultCounts"); +} + units::volt_t RobotController::GetBrownoutVoltage() { int32_t status = 0; double retVal = HAL_GetBrownoutVoltage(&status); diff --git a/wpilibc/src/main/native/include/frc/RobotController.h b/wpilibc/src/main/native/include/frc/RobotController.h index 5d8ddfb4de..2eca0c1b94 100644 --- a/wpilibc/src/main/native/include/frc/RobotController.h +++ b/wpilibc/src/main/native/include/frc/RobotController.h @@ -115,6 +115,14 @@ class RobotController { */ static bool IsBrownedOut(); + /** + * Gets the number of times the system has been disabled due to communication + * errors with the Driver Station. + * + * @return number of disables due to communication errors. + */ + static int GetCommsDisableCount(); + /** * Gets the current state of the Robot Signal Light (RSL) * @return The current state of the RSL- true if on, false if off @@ -174,7 +182,7 @@ class RobotController { /** * Get the count of the total current faults on the 3.3V rail since the - * controller has booted. + * code started. * * @return The number of faults */ @@ -212,7 +220,7 @@ class RobotController { /** * Get the count of the total current faults on the 5V rail since the - * controller has booted. + * code started. * * @return The number of faults */ @@ -250,12 +258,15 @@ class RobotController { /** * Get the count of the total current faults on the 6V rail since the - * controller has booted. + * code started. * * @return The number of faults. */ static int GetFaultCount6V(); + /** Reset the overcurrent fault counters for all user rails to 0. */ + static void ResetRailFaultCounts(); + /** * Get the current brownout voltage setting. * diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotController.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotController.java index e54d0d7b37..dc56bbb362 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotController.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotController.java @@ -117,6 +117,16 @@ public final class RobotController { return HAL.getBrownedOut(); } + /** + * Gets the number of times the system has been disabled due to communication errors with the + * Driver Station. + * + * @return number of disables due to communication errors. + */ + public static int getCommsDisableCount() { + return HAL.getCommsDisableCount(); + } + /** * Gets the current state of the Robot Signal Light (RSL). * @@ -191,7 +201,7 @@ public final class RobotController { } /** - * Get the count of the total current faults on the 3.3V rail since the controller has booted. + * Get the count of the total current faults on the 3.3V rail since the code started. * * @return The number of faults */ @@ -237,7 +247,7 @@ public final class RobotController { } /** - * Get the count of the total current faults on the 5V rail since the controller has booted. + * Get the count of the total current faults on the 5V rail since the code started. * * @return The number of faults */ @@ -283,7 +293,7 @@ public final class RobotController { } /** - * Get the count of the total current faults on the 6V rail since the controller has booted. + * Get the count of the total current faults on the 6V rail since the code started. * * @return The number of faults */ @@ -291,6 +301,11 @@ public final class RobotController { return PowerJNI.getUserCurrentFaults6V(); } + /** Reset the overcurrent fault counters for all user rails to 0. */ + public static void resetRailFaultCounts() { + PowerJNI.resetUserCurrentFaults(); + } + /** * Get the current brownout voltage setting. *