From 2ecb939b35f779e642fdcc89fcc8e3e22464c165 Mon Sep 17 00:00:00 2001 From: Thad House Date: Tue, 13 Sep 2016 21:21:57 -0700 Subject: [PATCH] Add a method to detect the HAL runtime version (#228) --- hal/include/HAL/HAL.h | 6 ++++++ hal/lib/athena/HAL.cpp | 7 +++++++ wpilibj/src/athena/cpp/lib/HALUtil.cpp | 13 +++++++++++++ .../java/edu/wpi/first/wpilibj/hal/HALUtil.java | 2 ++ 4 files changed, 28 insertions(+) diff --git a/hal/include/HAL/HAL.h b/hal/include/HAL/HAL.h index 66cf7331b4..3ff7699a25 100644 --- a/hal/include/HAL/HAL.h +++ b/hal/include/HAL/HAL.h @@ -38,6 +38,11 @@ namespace HALUsageReporting = nUsageReporting; +enum HAL_RuntimeType : int32_t { + HAL_Athena, + HAL_Mock +}; + #ifdef __cplusplus extern "C" { #endif @@ -49,6 +54,7 @@ int32_t HAL_GetFPGAVersion(int32_t* status); int64_t HAL_GetFPGARevision(int32_t* status); uint64_t HAL_GetFPGATime(int32_t* status); +HAL_RuntimeType HAL_GetRuntimeType(); HAL_Bool HAL_GetFPGAButton(int32_t* status); HAL_Bool HAL_GetSystemActive(int32_t* status); diff --git a/hal/lib/athena/HAL.cpp b/hal/lib/athena/HAL.cpp index fc05a9184f..b78ca225a7 100644 --- a/hal/lib/athena/HAL.cpp +++ b/hal/lib/athena/HAL.cpp @@ -164,6 +164,13 @@ const char* HAL_GetErrorMessage(int32_t code) { } } +/** + * Returns the runtime type of this HAL + */ +HAL_RuntimeType HAL_GetRuntimeType() { + return HAL_Athena; +} + /** * Return the FPGA Version number. * For now, expect this to be competition year. diff --git a/wpilibj/src/athena/cpp/lib/HALUtil.cpp b/wpilibj/src/athena/cpp/lib/HALUtil.cpp index 877659572b..24368ffe32 100644 --- a/wpilibj/src/athena/cpp/lib/HALUtil.cpp +++ b/wpilibj/src/athena/cpp/lib/HALUtil.cpp @@ -429,6 +429,19 @@ Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGATime(JNIEnv *env, jclass) { return returnValue; } +/* + * Class: edu_wpi_first_wpilibj_hal_HALUtil + * Method: getHALRuntimeType + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALRuntimeType(JNIEnv *env, jclass) { + // HALUTIL_LOG(logDEBUG) << "Calling HALUtil getHALRuntimeType"; + jint returnValue = HAL_GetRuntimeType(); + // HALUTIL_LOG(logDEBUG) << "RuntimeType = " << returnValue; + return returnValue; +} + /* * Class: edu_wpi_first_wpilibj_hal_HALUtil * Method: getFPGAButton diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/HALUtil.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/HALUtil.java index 96e60e4e4e..7a82ba9a95 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/HALUtil.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/HALUtil.java @@ -23,6 +23,8 @@ public class HALUtil extends JNIWrapper { public static native int getFPGARevision(); public static native long getFPGATime(); + + public static native int getHALRuntimeType(); public static native boolean getFPGAButton();