mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpilib, hal] Add support for getting faults and versions from power distribution (#3794)
This commit is contained in:
@@ -46,6 +46,7 @@ static JException canMessageNotFoundExCls;
|
||||
static JException canMessageNotAllowedExCls;
|
||||
static JException canNotInitializedExCls;
|
||||
static JException uncleanStatusExCls;
|
||||
static JClass powerDistributionVersionCls;
|
||||
static JClass pwmConfigDataResultCls;
|
||||
static JClass canStatusCls;
|
||||
static JClass matchInfoDataCls;
|
||||
@@ -56,6 +57,8 @@ static JClass baseStoreCls;
|
||||
static JClass revPHVersionCls;
|
||||
|
||||
static const JClassInit classes[] = {
|
||||
{"edu/wpi/first/hal/PowerDistributionVersion",
|
||||
&powerDistributionVersionCls},
|
||||
{"edu/wpi/first/hal/PWMConfigDataResult", &pwmConfigDataResultCls},
|
||||
{"edu/wpi/first/hal/can/CANStatus", &canStatusCls},
|
||||
{"edu/wpi/first/hal/MatchInfoData", &matchInfoDataCls},
|
||||
@@ -333,6 +336,21 @@ jobject CreateDMABaseStore(JNIEnv* env, jint valueType, jint index) {
|
||||
return env->NewObject(baseStoreCls, ctor, valueType, index);
|
||||
}
|
||||
|
||||
jobject CreatePowerDistributionVersion(JNIEnv* env, uint32_t firmwareMajor,
|
||||
uint32_t firmwareMinor,
|
||||
uint32_t firmwareFix,
|
||||
uint32_t hardwareMinor,
|
||||
uint32_t hardwareMajor,
|
||||
uint32_t uniqueId) {
|
||||
static jmethodID constructor =
|
||||
env->GetMethodID(powerDistributionVersionCls, "<init>", "(IIIIII)V");
|
||||
return env->NewObject(
|
||||
powerDistributionVersionCls, constructor,
|
||||
static_cast<jint>(firmwareMajor), static_cast<jint>(firmwareMinor),
|
||||
static_cast<jint>(firmwareFix), static_cast<jint>(hardwareMinor),
|
||||
static_cast<jint>(hardwareMajor), static_cast<jint>(uniqueId));
|
||||
}
|
||||
|
||||
JavaVM* GetJVM() {
|
||||
return jvm;
|
||||
}
|
||||
|
||||
@@ -82,6 +82,13 @@ jobject CreateHALValue(JNIEnv* env, const HAL_Value& value);
|
||||
|
||||
jobject CreateDMABaseStore(JNIEnv* env, jint valueType, jint index);
|
||||
|
||||
jobject CreatePowerDistributionVersion(JNIEnv* env, uint32_t firmwareMajor,
|
||||
uint32_t firmwareMinor,
|
||||
uint32_t firmwareFix,
|
||||
uint32_t hardwareMinor,
|
||||
uint32_t hardwareMajor,
|
||||
uint32_t uniqueId);
|
||||
|
||||
JavaVM* GetJVM();
|
||||
|
||||
} // namespace hal
|
||||
|
||||
@@ -362,4 +362,63 @@ Java_edu_wpi_first_hal_PowerDistributionJNI_getSwitchableChannelNoError
|
||||
return state;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_PowerDistributionJNI
|
||||
* Method: getStickyFaultsNative
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_PowerDistributionJNI_getStickyFaultsNative
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_PowerDistributionStickyFaults halFaults;
|
||||
std::memset(&halFaults, 0, sizeof(halFaults));
|
||||
HAL_GetPowerDistributionStickyFaults(handle, &halFaults, &status);
|
||||
CheckStatus(env, status, false);
|
||||
jint faults;
|
||||
static_assert(sizeof(faults) == sizeof(halFaults));
|
||||
std::memcpy(&faults, &halFaults, sizeof(faults));
|
||||
return faults;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_PowerDistributionJNI
|
||||
* Method: getFaultsNative
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_PowerDistributionJNI_getFaultsNative
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_PowerDistributionFaults halFaults;
|
||||
std::memset(&halFaults, 0, sizeof(halFaults));
|
||||
HAL_GetPowerDistributionFaults(handle, &halFaults, &status);
|
||||
CheckStatus(env, status, false);
|
||||
jint faults;
|
||||
static_assert(sizeof(faults) == sizeof(halFaults));
|
||||
std::memcpy(&faults, &halFaults, sizeof(faults));
|
||||
return faults;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_PowerDistributionJNI
|
||||
* Method: getVersion
|
||||
* Signature: (I)Ljava/lang/Object;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_edu_wpi_first_hal_PowerDistributionJNI_getVersion
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_PowerDistributionVersion version;
|
||||
std::memset(&version, 0, sizeof(version));
|
||||
HAL_GetPowerDistributionVersion(handle, &version, &status);
|
||||
CheckStatus(env, status, false);
|
||||
return CreatePowerDistributionVersion(
|
||||
env, version.firmwareMajor, version.firmwareMinor, version.firmwareFix,
|
||||
version.hardwareMinor, version.hardwareMajor, version.uniqueId);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
Reference in New Issue
Block a user