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 8389682f83..d9eb8d599d 100644 --- a/hal/src/main/java/edu/wpi/first/hal/HAL.java +++ b/hal/src/main/java/edu/wpi/first/hal/HAL.java @@ -190,6 +190,14 @@ public final class HAL extends JNIWrapper { */ public static native boolean getRSLState(); + /** + * Gets if the system time is valid. + * + * @return True if the system time is valid, false otherwise + * @see "HAL_GetSystemTimeValid" + */ + public static native boolean getSystemTimeValid(); + /** * Gets a port handle for a specific channel and module. * diff --git a/hal/src/main/native/athena/HAL.cpp b/hal/src/main/native/athena/HAL.cpp index c59e9bbe03..d00bf9f370 100644 --- a/hal/src/main/native/athena/HAL.cpp +++ b/hal/src/main/native/athena/HAL.cpp @@ -472,6 +472,12 @@ HAL_Bool HAL_GetRSLState(int32_t* status) { return global->readLEDs_RSL(status); } +HAL_Bool HAL_GetSystemTimeValid(int32_t* status) { + uint8_t timeWasSet = 0; + *status = FRC_NetworkCommunication_getTimeWasSet(&timeWasSet); + return timeWasSet != 0; +} + static bool killExistingProgram(int timeout, int mode) { // Kill any previous robot programs std::fstream fs; diff --git a/hal/src/main/native/cpp/jni/HAL.cpp b/hal/src/main/native/cpp/jni/HAL.cpp index 63cb7fa354..6f486e5fc0 100644 --- a/hal/src/main/native/cpp/jni/HAL.cpp +++ b/hal/src/main/native/cpp/jni/HAL.cpp @@ -151,6 +151,21 @@ Java_edu_wpi_first_hal_HAL_getRSLState return val; } +/* + * Class: edu_wpi_first_hal_HAL + * Method: getSystemTimeValid + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_hal_HAL_getSystemTimeValid + (JNIEnv* env, jclass) +{ + int32_t status = 0; + bool val = HAL_GetSystemTimeValid(&status); + CheckStatus(env, status); + return val; +} + /* * Class: edu_wpi_first_hal_HAL * Method: getPortWithModule diff --git a/hal/src/main/native/include/hal/HALBase.h b/hal/src/main/native/include/hal/HALBase.h index 1264c6aa3d..fe8d1bf190 100644 --- a/hal/src/main/native/include/hal/HALBase.h +++ b/hal/src/main/native/include/hal/HALBase.h @@ -186,6 +186,14 @@ uint64_t HAL_ExpandFPGATime(uint32_t unexpandedLower, int32_t* status); */ HAL_Bool HAL_GetRSLState(int32_t* status); +/** + * Gets if the system time is valid. + * + * @param[out] status the error code, or 0 for success + * @return True if the system time is valid, false otherwise + */ +HAL_Bool HAL_GetSystemTimeValid(int32_t* status); + /** * Call this to start up HAL. This is required for robot programs. * diff --git a/hal/src/main/native/sim/HAL.cpp b/hal/src/main/native/sim/HAL.cpp index 633226e911..ce8b6dde5f 100644 --- a/hal/src/main/native/sim/HAL.cpp +++ b/hal/src/main/native/sim/HAL.cpp @@ -336,6 +336,10 @@ HAL_Bool HAL_GetRSLState(int32_t* status) { return false; } +HAL_Bool HAL_GetSystemTimeValid(int32_t* status) { + return true; +} + HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) { static std::atomic_bool initialized{false}; static wpi::mutex initializeMutex; diff --git a/shared/config.gradle b/shared/config.gradle index 1cfe8441c6..4a5467572c 100644 --- a/shared/config.gradle +++ b/shared/config.gradle @@ -15,7 +15,7 @@ nativeUtils { configureDependencies { opencvYear = "frc2023" googleTestYear = "frc2023" - niLibVersion = "2024.1.0" + niLibVersion = "2024.1.1" opencvVersion = "4.6.0-5" googleTestVersion = "1.12.1-2" } diff --git a/wpilibc/src/main/native/cpp/RobotController.cpp b/wpilibc/src/main/native/cpp/RobotController.cpp index d67f378fed..8b2b4964a8 100644 --- a/wpilibc/src/main/native/cpp/RobotController.cpp +++ b/wpilibc/src/main/native/cpp/RobotController.cpp @@ -87,6 +87,13 @@ bool RobotController::GetRSLState() { return retVal; } +bool RobotController::IsSystemTimeValid() { + int32_t status = 0; + bool retVal = HAL_GetSystemTimeValid(&status); + FRC_CheckErrorStatus(status, "IsSystemTimeValid"); + return retVal; +} + double RobotController::GetInputVoltage() { int32_t status = 0; double retVal = HAL_GetVinVoltage(&status); diff --git a/wpilibc/src/main/native/include/frc/RobotController.h b/wpilibc/src/main/native/include/frc/RobotController.h index eadd1cf10d..bf65a8cfaa 100644 --- a/wpilibc/src/main/native/include/frc/RobotController.h +++ b/wpilibc/src/main/native/include/frc/RobotController.h @@ -115,6 +115,13 @@ class RobotController { */ static bool GetRSLState(); + /** + * Gets if the system time is valid. + * + * @return True if the system time is valid, false otherwise + */ + static bool IsSystemTimeValid(); + /** * Get the input voltage to the robot controller. * 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 bd529473a8..29bcad87bd 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotController.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotController.java @@ -121,6 +121,15 @@ public final class RobotController { return HAL.getRSLState(); } + /** + * Gets if the system time is valid. + * + * @return True if the system time is valid, false otherwise + */ + public static boolean isSystemTimeValid() { + return HAL.getSystemTimeValid(); + } + /** * Get the input voltage to the robot controller. *