2021-08-04 20:31:17 -07:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
|
|
|
|
|
2021-08-14 11:44:56 -07:00
|
|
|
#include <jni.h>
|
|
|
|
|
|
2026-01-04 00:41:53 -08:00
|
|
|
#include "HALUtil.hpp"
|
2025-11-07 19:55:43 -05:00
|
|
|
#include "org_wpilib_hardware_hal_PowerDistributionJNI.h"
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/hal/Ports.h"
|
|
|
|
|
#include "wpi/hal/PowerDistribution.h"
|
2025-11-07 19:57:55 -05:00
|
|
|
#include "wpi/util/jni_util.hpp"
|
2021-08-04 20:31:17 -07:00
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
using namespace wpi::hal;
|
2021-08-04 20:31:17 -07:00
|
|
|
|
2025-11-07 19:55:43 -05:00
|
|
|
static_assert(org_wpilib_hardware_hal_PowerDistributionJNI_AUTOMATIC_TYPE ==
|
2021-08-14 11:44:56 -07:00
|
|
|
HAL_PowerDistributionType::HAL_PowerDistributionType_kAutomatic);
|
2025-11-07 19:55:43 -05:00
|
|
|
static_assert(org_wpilib_hardware_hal_PowerDistributionJNI_CTRE_TYPE ==
|
2021-08-14 11:44:56 -07:00
|
|
|
HAL_PowerDistributionType::HAL_PowerDistributionType_kCTRE);
|
2025-11-07 19:55:43 -05:00
|
|
|
static_assert(org_wpilib_hardware_hal_PowerDistributionJNI_REV_TYPE ==
|
2021-08-14 11:44:56 -07:00
|
|
|
HAL_PowerDistributionType::HAL_PowerDistributionType_kRev);
|
2025-11-07 19:55:43 -05:00
|
|
|
static_assert(org_wpilib_hardware_hal_PowerDistributionJNI_DEFAULT_MODULE ==
|
2021-08-14 11:44:56 -07:00
|
|
|
HAL_DEFAULT_POWER_DISTRIBUTION_MODULE);
|
|
|
|
|
|
2021-08-04 20:31:17 -07:00
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-08-04 20:31:17 -07:00
|
|
|
* Method: initialize
|
2025-02-25 19:07:01 -08:00
|
|
|
* Signature: (III)I
|
2021-08-04 20:31:17 -07:00
|
|
|
*/
|
|
|
|
|
JNIEXPORT jint JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_initialize
|
2025-02-25 19:07:01 -08:00
|
|
|
(JNIEnv* env, jclass, jint busId, jint module, jint type)
|
2021-08-04 20:31:17 -07:00
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
2025-11-07 20:00:38 -05:00
|
|
|
auto stack = wpi::util::java::GetJavaStackTrace(env, "org.wpilib");
|
2021-08-04 20:31:17 -07:00
|
|
|
auto handle = HAL_InitializePowerDistribution(
|
2025-02-25 19:07:01 -08:00
|
|
|
busId, module, static_cast<HAL_PowerDistributionType>(type),
|
|
|
|
|
stack.c_str(), &status);
|
2021-08-04 20:31:17 -07:00
|
|
|
CheckStatusForceThrow(env, status);
|
|
|
|
|
return static_cast<jint>(handle);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-14 11:44:56 -07:00
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-08-14 11:44:56 -07:00
|
|
|
* Method: free
|
|
|
|
|
* Signature: (I)V
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT void JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_free
|
2021-08-14 11:44:56 -07:00
|
|
|
(JNIEnv*, jclass, jint handle)
|
|
|
|
|
{
|
2024-09-07 13:58:15 -04:00
|
|
|
if (handle != HAL_kInvalidHandle) {
|
|
|
|
|
HAL_CleanPowerDistribution(handle);
|
|
|
|
|
}
|
2021-08-14 11:44:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-08-14 11:44:56 -07:00
|
|
|
* Method: getModuleNumber
|
|
|
|
|
* Signature: (I)I
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jint JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_getModuleNumber
|
2021-08-14 11:44:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
auto result = HAL_GetPowerDistributionModuleNumber(handle, &status);
|
|
|
|
|
CheckStatus(env, status, false);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-04 20:31:17 -07:00
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-08-04 20:31:17 -07:00
|
|
|
* Method: checkChannel
|
|
|
|
|
* Signature: (II)Z
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_checkChannel
|
2021-08-04 20:31:17 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle, jint channel)
|
|
|
|
|
{
|
|
|
|
|
return HAL_CheckPowerDistributionChannel(handle, channel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-08-04 20:31:17 -07:00
|
|
|
* Method: checkModule
|
|
|
|
|
* Signature: (II)Z
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_checkModule
|
2021-08-04 20:31:17 -07:00
|
|
|
(JNIEnv* env, jclass, jint module, jint type)
|
|
|
|
|
{
|
|
|
|
|
return HAL_CheckPowerDistributionModule(
|
|
|
|
|
module, static_cast<HAL_PowerDistributionType>(type));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-08-04 20:31:17 -07:00
|
|
|
* Method: getType
|
|
|
|
|
* Signature: (I)I
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jint JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_getType
|
2021-08-04 20:31:17 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
auto result = HAL_GetPowerDistributionType(handle, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-14 11:44:56 -07:00
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-08-14 11:44:56 -07:00
|
|
|
* Method: getNumChannels
|
|
|
|
|
* Signature: (I)I
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jint JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_getNumChannels
|
2021-08-14 11:44:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
auto result = HAL_GetPowerDistributionNumChannels(handle, &status);
|
|
|
|
|
CheckStatus(env, status);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-04 20:31:17 -07:00
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-08-04 20:31:17 -07:00
|
|
|
* Method: getTemperature
|
|
|
|
|
* Signature: (I)D
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jdouble JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_getTemperature
|
2021-08-04 20:31:17 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
double temperature = HAL_GetPowerDistributionTemperature(handle, &status);
|
|
|
|
|
CheckStatus(env, status, false);
|
|
|
|
|
return temperature;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-08-04 20:31:17 -07:00
|
|
|
* Method: getVoltage
|
|
|
|
|
* Signature: (I)D
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jdouble JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_getVoltage
|
2021-08-04 20:31:17 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
double voltage = HAL_GetPowerDistributionVoltage(handle, &status);
|
|
|
|
|
CheckStatus(env, status, false);
|
|
|
|
|
return voltage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-08-04 20:31:17 -07:00
|
|
|
* Method: getChannelCurrent
|
2021-08-14 11:44:56 -07:00
|
|
|
* Signature: (II)D
|
2021-08-04 20:31:17 -07:00
|
|
|
*/
|
|
|
|
|
JNIEXPORT jdouble JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_getChannelCurrent
|
2021-08-14 11:44:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle, jint channel)
|
2021-08-04 20:31:17 -07:00
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
double current =
|
|
|
|
|
HAL_GetPowerDistributionChannelCurrent(handle, channel, &status);
|
|
|
|
|
CheckStatus(env, status, false);
|
|
|
|
|
return current;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-08-04 20:31:17 -07:00
|
|
|
* Method: getAllCurrents
|
|
|
|
|
* Signature: (I[D)V
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT void JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_getAllCurrents
|
2021-08-04 20:31:17 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle, jdoubleArray jarr)
|
|
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
2024-05-24 19:31:19 -04:00
|
|
|
int32_t size = HAL_GetPowerDistributionNumChannels(handle, &status);
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::util::SmallVector<double, 24> storage;
|
2024-05-24 19:31:19 -04:00
|
|
|
storage.resize_for_overwrite(size);
|
|
|
|
|
|
|
|
|
|
HAL_GetPowerDistributionAllChannelCurrents(handle, storage.data(), size,
|
|
|
|
|
&status);
|
2021-08-04 20:31:17 -07:00
|
|
|
if (!CheckStatus(env, status, false)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-24 19:31:19 -04:00
|
|
|
env->SetDoubleArrayRegion(jarr, 0, size, storage.data());
|
2021-08-04 20:31:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-08-04 20:31:17 -07:00
|
|
|
* Method: getTotalCurrent
|
|
|
|
|
* Signature: (I)D
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jdouble JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_getTotalCurrent
|
2021-08-04 20:31:17 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
double current = HAL_GetPowerDistributionTotalCurrent(handle, &status);
|
|
|
|
|
CheckStatus(env, status, false);
|
|
|
|
|
return current;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-08-04 20:31:17 -07:00
|
|
|
* Method: getTotalPower
|
|
|
|
|
* Signature: (I)D
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jdouble JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_getTotalPower
|
2021-08-04 20:31:17 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
double power = HAL_GetPowerDistributionTotalPower(handle, &status);
|
|
|
|
|
CheckStatus(env, status, false);
|
|
|
|
|
return power;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-08-04 20:31:17 -07:00
|
|
|
* Method: getTotalEnergy
|
|
|
|
|
* Signature: (I)D
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jdouble JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_getTotalEnergy
|
2021-08-04 20:31:17 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
double energy = HAL_GetPowerDistributionTotalEnergy(handle, &status);
|
|
|
|
|
CheckStatus(env, status, false);
|
|
|
|
|
return energy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-08-04 20:31:17 -07:00
|
|
|
* Method: resetTotalEnergy
|
|
|
|
|
* Signature: (I)V
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT void JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_resetTotalEnergy
|
2021-08-04 20:31:17 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_ResetPowerDistributionTotalEnergy(handle, &status);
|
|
|
|
|
CheckStatus(env, status, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-08-04 20:31:17 -07:00
|
|
|
* Method: clearStickyFaults
|
|
|
|
|
* Signature: (I)V
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT void JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_clearStickyFaults
|
2021-08-04 20:31:17 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_ClearPowerDistributionStickyFaults(handle, &status);
|
|
|
|
|
CheckStatus(env, status, false);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-14 11:44:56 -07:00
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-08-14 11:44:56 -07:00
|
|
|
* Method: setSwitchableChannel
|
|
|
|
|
* Signature: (IZ)V
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT void JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_setSwitchableChannel
|
2021-08-14 11:44:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle, jboolean enabled)
|
|
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_SetPowerDistributionSwitchableChannel(handle, enabled, &status);
|
|
|
|
|
CheckStatus(env, status, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-08-14 11:44:56 -07:00
|
|
|
* Method: getSwitchableChannel
|
|
|
|
|
* Signature: (I)Z
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_getSwitchableChannel
|
2021-08-14 11:44:56 -07:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
auto state = HAL_GetPowerDistributionSwitchableChannel(handle, &status);
|
|
|
|
|
CheckStatus(env, status, false);
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-07 13:45:28 -08:00
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-11-07 13:45:28 -08:00
|
|
|
* Method: getVoltageNoError
|
|
|
|
|
* Signature: (I)D
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jdouble JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_getVoltageNoError
|
2021-11-07 13:45:28 -08:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
double voltage = HAL_GetPowerDistributionVoltage(handle, &status);
|
|
|
|
|
return voltage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-11-07 13:45:28 -08:00
|
|
|
* Method: getChannelCurrentNoError
|
|
|
|
|
* Signature: (II)D
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jdouble JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_getChannelCurrentNoError
|
2021-11-07 13:45:28 -08:00
|
|
|
(JNIEnv* env, jclass, jint handle, jint channel)
|
|
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
double current =
|
|
|
|
|
HAL_GetPowerDistributionChannelCurrent(handle, channel, &status);
|
|
|
|
|
return current;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-11-07 13:45:28 -08:00
|
|
|
* Method: getTotalCurrentNoError
|
|
|
|
|
* Signature: (I)D
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jdouble JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_getTotalCurrentNoError
|
2021-11-07 13:45:28 -08:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
double current = HAL_GetPowerDistributionTotalCurrent(handle, &status);
|
|
|
|
|
return current;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-11-07 13:45:28 -08:00
|
|
|
* Method: setSwitchableChannelNoError
|
|
|
|
|
* Signature: (IZ)V
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT void JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_setSwitchableChannelNoError
|
2021-11-07 13:45:28 -08:00
|
|
|
(JNIEnv* env, jclass, jint handle, jboolean enabled)
|
|
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_SetPowerDistributionSwitchableChannel(handle, enabled, &status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-11-07 13:45:28 -08:00
|
|
|
* Method: getSwitchableChannelNoError
|
|
|
|
|
* Signature: (I)Z
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_getSwitchableChannelNoError
|
2021-11-07 13:45:28 -08:00
|
|
|
(JNIEnv* env, jclass, jint handle)
|
|
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
auto state = HAL_GetPowerDistributionSwitchableChannel(handle, &status);
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-19 13:42:49 -08:00
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-12-19 13:42:49 -08:00
|
|
|
* Method: getStickyFaultsNative
|
|
|
|
|
* Signature: (I)I
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jint JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_getStickyFaultsNative
|
2021-12-19 13:42:49 -08:00
|
|
|
(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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-12-19 13:42:49 -08:00
|
|
|
* Method: getFaultsNative
|
|
|
|
|
* Signature: (I)I
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jint JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_getFaultsNative
|
2021-12-19 13:42:49 -08:00
|
|
|
(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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-11-07 19:55:43 -05:00
|
|
|
* Class: org_wpilib_hardware_hal_PowerDistributionJNI
|
2021-12-19 13:42:49 -08:00
|
|
|
* Method: getVersion
|
|
|
|
|
* Signature: (I)Ljava/lang/Object;
|
|
|
|
|
*/
|
|
|
|
|
JNIEXPORT jobject JNICALL
|
2025-11-07 19:55:43 -05:00
|
|
|
Java_org_wpilib_hardware_hal_PowerDistributionJNI_getVersion
|
2021-12-19 13:42:49 -08:00
|
|
|
(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);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-04 20:31:17 -07:00
|
|
|
} // extern "C"
|