diff --git a/hal/src/main/java/edu/wpi/first/hal/REVPHJNI.java b/hal/src/main/java/edu/wpi/first/hal/REVPHJNI.java index a345416453..8ad9351d85 100644 --- a/hal/src/main/java/edu/wpi/first/hal/REVPHJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/REVPHJNI.java @@ -279,6 +279,15 @@ public class REVPHJNI extends JNIWrapper { return new REVPHFaults(getFaultsNative(handle)); } + /** + * Get a bitmask of disabled solenoids. + * + * @param handle the PH handle + * @return Bitmask indicating disabled solenoids. The LSB represents solenoid 0. + * @see "HAL_GetREVPHSolenoidDisabledList" + */ + public static native int getSolenoidDisabledList(int handle); + /** * Returns the hardware and firmware versions of the PH. * diff --git a/hal/src/main/native/athena/REVPH.cpp b/hal/src/main/native/athena/REVPH.cpp index ae3f460cc8..fd74c012b5 100644 --- a/hal/src/main/native/athena/REVPH.cpp +++ b/hal/src/main/native/athena/REVPH.cpp @@ -751,3 +751,35 @@ void HAL_ClearREVPHStickyFaults(HAL_REVPHHandle handle, int32_t* status) { HAL_WriteCANPacket(ph->hcan, packedData, PH_CLEAR_FAULTS_LENGTH, PH_CLEAR_FAULTS_FRAME_API, status); } + +int32_t HAL_GetREVPHSolenoidDisabledList(HAL_REVPHHandle handle, + int32_t* status) { + auto ph = REVPHHandles->Get(handle); + if (ph == nullptr) { + *status = HAL_HANDLE_ERROR; + return false; + } + + PH_status_0_t status0 = HAL_ReadREVPHStatus0(ph->hcan, status); + if (*status != 0) { + return 0; + } + + uint32_t solenoidFaults = status0.channel_0_fault; + solenoidFaults |= status0.channel_1_fault << 1; + solenoidFaults |= status0.channel_2_fault << 2; + solenoidFaults |= status0.channel_3_fault << 3; + solenoidFaults |= status0.channel_4_fault << 4; + solenoidFaults |= status0.channel_5_fault << 5; + solenoidFaults |= status0.channel_6_fault << 6; + solenoidFaults |= status0.channel_7_fault << 7; + solenoidFaults |= status0.channel_8_fault << 8; + solenoidFaults |= status0.channel_9_fault << 9; + solenoidFaults |= status0.channel_10_fault << 10; + solenoidFaults |= status0.channel_11_fault << 11; + solenoidFaults |= status0.channel_12_fault << 12; + solenoidFaults |= status0.channel_13_fault << 13; + solenoidFaults |= status0.channel_14_fault << 14; + solenoidFaults |= status0.channel_15_fault << 15; + return solenoidFaults; +} diff --git a/hal/src/main/native/cpp/jni/REVPHJNI.cpp b/hal/src/main/native/cpp/jni/REVPHJNI.cpp index c6309746d6..cc687aeeed 100644 --- a/hal/src/main/native/cpp/jni/REVPHJNI.cpp +++ b/hal/src/main/native/cpp/jni/REVPHJNI.cpp @@ -381,6 +381,21 @@ Java_edu_wpi_first_hal_REVPHJNI_getFaultsNative return faults; } +/* + * Class: edu_wpi_first_hal_REVPHJNI + * Method: getSolenoidDisabledList + * Signature: (I)I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_hal_REVPHJNI_getSolenoidDisabledList + (JNIEnv* env, jclass, jint handle) +{ + int32_t status = 0; + auto result = HAL_GetREVPHSolenoidDisabledList(handle, &status); + CheckStatus(env, status, false); + return result; +} + /* * Class: edu_wpi_first_hal_REVPHJNI * Method: getVersion diff --git a/hal/src/main/native/include/hal/REVPH.h b/hal/src/main/native/include/hal/REVPH.h index 545adc5789..c90ea52037 100644 --- a/hal/src/main/native/include/hal/REVPH.h +++ b/hal/src/main/native/include/hal/REVPH.h @@ -369,6 +369,16 @@ void HAL_GetREVPHStickyFaults(HAL_REVPHHandle handle, */ void HAL_ClearREVPHStickyFaults(HAL_REVPHHandle handle, int32_t* status); +/** + * Get a bitmask of disabled solenoids. + * + * @param[in] handle the PH handle + * @param[out] status Error status variable. 0 on success. + * @return Bitmask indicating disabled solenoids. The LSB represents solenoid 0. + */ +int32_t HAL_GetREVPHSolenoidDisabledList(HAL_REVPHHandle handle, + int32_t* status); + #ifdef __cplusplus } // extern "C" #endif diff --git a/hal/src/main/native/sim/REVPH.cpp b/hal/src/main/native/sim/REVPH.cpp index a9e96f1e86..957aed73f8 100644 --- a/hal/src/main/native/sim/REVPH.cpp +++ b/hal/src/main/native/sim/REVPH.cpp @@ -254,4 +254,9 @@ void HAL_GetREVPHStickyFaults(HAL_REVPHHandle handle, HAL_REVPHStickyFaults* stickyFaults, int32_t* status) {} +int32_t HAL_GetREVPHSolenoidDisabledList(HAL_REVPHHandle handle, + int32_t* status) { + return 0; +} + void HAL_ClearREVPHStickyFaults(HAL_REVPHHandle handle, int32_t* status) {} diff --git a/wpilibc/src/main/native/cpp/PneumaticHub.cpp b/wpilibc/src/main/native/cpp/PneumaticHub.cpp index 91014735a6..ab402ed37a 100644 --- a/wpilibc/src/main/native/cpp/PneumaticHub.cpp +++ b/wpilibc/src/main/native/cpp/PneumaticHub.cpp @@ -243,14 +243,9 @@ int PneumaticHub::GetModuleNumber() const { int PneumaticHub::GetSolenoidDisabledList() const { int32_t status = 0; - HAL_REVPHStickyFaults faults; - std::memset(&faults, 0, sizeof(faults)); - HAL_GetREVPHStickyFaults(m_handle, &faults, &status); + auto result = HAL_GetREVPHSolenoidDisabledList(m_handle, &status); FRC_ReportError(status, "Module {}", m_module); - uint32_t intFaults = 0; - static_assert(sizeof(faults) == sizeof(intFaults)); - std::memcpy(&intFaults, &faults, sizeof(faults)); - return intFaults & 0xFFFF; + return result; } void PneumaticHub::FireOneShot(int index) { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PneumaticHub.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PneumaticHub.java index cdfb0cbc2d..dedd790b45 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PneumaticHub.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PneumaticHub.java @@ -249,8 +249,7 @@ public class PneumaticHub implements PneumaticsBase { @Override public int getSolenoidDisabledList() { - int raw = REVPHJNI.getStickyFaultsNative(m_handle); - return raw & 0xFFFF; + return REVPHJNI.getSolenoidDisabledList(m_handle); } /**