Files
allwpilib/hal/src/main/native/cpp/jni/PDPJNI.cpp

191 lines
4.3 KiB
C++
Raw Normal View History

// 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.
#include "HALUtil.h"
#include "edu_wpi_first_hal_PDPJNI.h"
#include "hal/PDP.h"
#include "hal/Ports.h"
using namespace hal;
extern "C" {
/*
* Class: edu_wpi_first_hal_PDPJNI
2018-05-13 17:09:56 -07:00
* Method: initializePDP
2018-06-07 22:31:26 -07:00
* Signature: (I)I
*/
2018-06-07 22:31:26 -07:00
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_PDPJNI_initializePDP
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint module)
{
int32_t status = 0;
2018-06-07 22:31:26 -07:00
auto handle = HAL_InitializePDP(module, &status);
CheckStatusRange(env, status, 0, HAL_GetNumPDPModules(), module);
2018-06-07 22:31:26 -07:00
return static_cast<jint>(handle);
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: checkPDPChannel
2018-05-13 17:09:56 -07:00
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_PDPJNI_checkPDPChannel
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint channel)
{
return HAL_CheckPDPChannel(channel);
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: checkPDPModule
2018-05-13 17:09:56 -07:00
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_PDPJNI_checkPDPModule
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint module)
{
return HAL_CheckPDPModule(module);
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: getPDPTemperature
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPTemperature
2018-06-07 22:31:26 -07:00
(JNIEnv* env, jclass, jint handle)
2018-05-13 17:09:56 -07:00
{
int32_t status = 0;
2018-06-07 22:31:26 -07:00
double temperature = HAL_GetPDPTemperature(handle, &status);
CheckStatus(env, status, false);
return temperature;
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: getPDPVoltage
* Signature: (I)D
*/
2018-05-13 17:09:56 -07:00
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPVoltage
2018-06-07 22:31:26 -07:00
(JNIEnv* env, jclass, jint handle)
2018-05-13 17:09:56 -07:00
{
int32_t status = 0;
2018-06-07 22:31:26 -07:00
double voltage = HAL_GetPDPVoltage(handle, &status);
CheckStatus(env, status, false);
return voltage;
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: getPDPChannelCurrent
* Signature: (BI)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPChannelCurrent
2018-06-07 22:31:26 -07:00
(JNIEnv* env, jclass, jbyte channel, jint handle)
2018-05-13 17:09:56 -07:00
{
int32_t status = 0;
2018-06-07 22:31:26 -07:00
double current = HAL_GetPDPChannelCurrent(handle, channel, &status);
CheckStatus(env, status, false);
return current;
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: getPDPAllCurrents
* Signature: (I[D)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPAllCurrents
(JNIEnv* env, jclass, jint handle, jdoubleArray jarr)
{
double storage[16];
int32_t status = 0;
HAL_GetPDPAllChannelCurrents(handle, storage, &status);
if (!CheckStatus(env, status, false)) {
return;
}
env->SetDoubleArrayRegion(jarr, 0, 16, storage);
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: getPDPTotalCurrent
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPTotalCurrent
2018-06-07 22:31:26 -07:00
(JNIEnv* env, jclass, jint handle)
2018-05-13 17:09:56 -07:00
{
int32_t status = 0;
2018-06-07 22:31:26 -07:00
double current = HAL_GetPDPTotalCurrent(handle, &status);
CheckStatus(env, status, false);
return current;
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: getPDPTotalPower
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPTotalPower
2018-06-07 22:31:26 -07:00
(JNIEnv* env, jclass, jint handle)
2018-05-13 17:09:56 -07:00
{
int32_t status = 0;
2018-06-07 22:31:26 -07:00
double power = HAL_GetPDPTotalPower(handle, &status);
CheckStatus(env, status, false);
return power;
}
/*
* Class: edu_wpi_first_hal_PDPJNI
2018-05-13 17:09:56 -07:00
* Method: getPDPTotalEnergy
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPTotalEnergy
2018-06-07 22:31:26 -07:00
(JNIEnv* env, jclass, jint handle)
2018-05-13 17:09:56 -07:00
{
int32_t status = 0;
2018-06-07 22:31:26 -07:00
double energy = HAL_GetPDPTotalEnergy(handle, &status);
CheckStatus(env, status, false);
return energy;
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: resetPDPTotalEnergy
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_PDPJNI_resetPDPTotalEnergy
2018-06-07 22:31:26 -07:00
(JNIEnv* env, jclass, jint handle)
2018-05-13 17:09:56 -07:00
{
int32_t status = 0;
2018-06-07 22:31:26 -07:00
HAL_ResetPDPTotalEnergy(handle, &status);
CheckStatus(env, status, false);
}
/*
* Class: edu_wpi_first_hal_PDPJNI
2018-05-13 17:09:56 -07:00
* Method: clearPDPStickyFaults
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_PDPJNI_clearPDPStickyFaults
2018-06-07 22:31:26 -07:00
(JNIEnv* env, jclass, jint handle)
2018-05-13 17:09:56 -07:00
{
int32_t status = 0;
2018-06-07 22:31:26 -07:00
HAL_ClearPDPStickyFaults(handle, &status);
CheckStatus(env, status, false);
}
} // extern "C"