Simplify JNI interfaces.

These changes both simplify the Java code and improve performance across the
JNI boundary.

This also fixes the AnalogCrossConnectTest by adding delays to
setInterruptHigh() and setInterruptLow() to ensure the change in voltage has
time to propagate and extends the timeouts in AbstractInterruptTest.

Detailed changes:

Hoisted status checks to C.  This avoids the need to create direct byte
buffers (expensive) and significantly simplifies the Java code.  The C code
now directly generates the exception or reports the error to the DS.

The JVM pointer is now a global across the JNI, initialized by the OnLoad
function, avoiding the need for some of the class-specific initializers to
get this pointer for callbacks.

Opaque pointers (such as ports) are now passed as long values rather than
with a ByteBuffer wrapper.

Added extern "C" to source files.  This allows earlier detection of JNI
definition mismatches to the Java source headers.

Changed JNI signatures to more closely match HAL signatures (in particular,
boolean is now universally used instead of byte for HAL bool, which cleans
up mapping back and forth to 1/0 from true/false).

Change-Id: I4ea0032cabb0871cd74106a3a70d947258c29d2d
This commit is contained in:
Peter Johnson
2015-11-01 09:11:52 -08:00
committed by Brad Miller (WPI)
parent 927400a43c
commit 7023013c4b
69 changed files with 2232 additions and 3118 deletions

View File

@@ -1,10 +1,13 @@
#include "edu_wpi_first_wpilibj_hal_PDPJNI.h"
#include "HAL/PDP.hpp"
#include "HALUtil.h"
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_PDPJNI
* Method: getPDPTemperature
* Signature: (Ljava/nio/IntBuffer;)D
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_initializePDP
(JNIEnv *, jclass, jint module)
@@ -15,112 +18,112 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_initializePDP
/*
* Class: edu_wpi_first_wpilibj_hal_PDPJNI
* Method: getPDPTemperature
* Signature: (Ljava/nio/IntBuffer;)D
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPTemperature
(JNIEnv *env, jclass, jobject status, jint module)
(JNIEnv *env, jclass, jint module)
{
jint *status_ptr = (jint *)env->GetDirectBufferAddress(status);
*status_ptr = 0;
return getPDPTemperature(status_ptr, module);
int32_t status = 0;
double temperature = getPDPTemperature(&status, module);
CheckStatus(env, status, false);
return temperature;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PDPJNI
* Method: getPDPVoltage
* Signature: (Ljava/nio/IntBuffer;)D
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPVoltage
(JNIEnv *env, jclass, jobject status, jint module)
(JNIEnv *env, jclass, jint module)
{
jint *status_ptr = (jint *)env->GetDirectBufferAddress(status);
*status_ptr = 0;
return getPDPVoltage(status_ptr, module);
int32_t status = 0;
double voltage = getPDPVoltage(&status, module);
CheckStatus(env, status, false);
return voltage;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PDPJNI
* Method: getPDPChannelCurrent
* Signature: (BLjava/nio/IntBuffer;)D
* Signature: (BI)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPChannelCurrent
(JNIEnv *env, jclass, jbyte channel, jobject status, jint module)
(JNIEnv *env, jclass, jbyte channel, jint module)
{
jint *status_ptr = (jint *)env->GetDirectBufferAddress(status);
*status_ptr = 0;
return getPDPChannelCurrent(channel, status_ptr, module);
int32_t status = 0;
double current = getPDPChannelCurrent(channel, &status, module);
CheckStatus(env, status, false);
return current;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PDPJNI
* Method: getPDPTotalCurrent
* Signature: (BLjava/nio/IntBuffer;)D
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPTotalCurrent
(JNIEnv *env, jclass, jobject status, jint module)
(JNIEnv *env, jclass, jint module)
{
jint *status_ptr = (jint *)env->GetDirectBufferAddress(status);
*status_ptr = 0;
return getPDPTotalCurrent(status_ptr, module);
int32_t status = 0;
double current = getPDPTotalCurrent(&status, module);
CheckStatus(env, status, false);
return current;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PDPJNI
* Method: getPDPTotalPower
* Signature: (BLjava/nio/IntBuffer;)D
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPTotalPower
(JNIEnv *env, jclass, jobject status, jint module)
(JNIEnv *env, jclass, jint module)
{
jint *status_ptr = (jint *)env->GetDirectBufferAddress(status);
*status_ptr = 0;
return getPDPTotalPower(status_ptr, module);
int32_t status = 0;
double power = getPDPTotalPower(&status, module);
CheckStatus(env, status, false);
return power;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PDPJNI
* Method: resetPDPTotalEnergy
* Signature: (BLjava/nio/IntBuffer;)D
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPTotalEnergy
(JNIEnv *env, jclass, jobject status, jint module)
(JNIEnv *env, jclass, jint module)
{
jint *status_ptr = (jint *)env->GetDirectBufferAddress(status);
*status_ptr = 0;
return getPDPTotalEnergy(status_ptr, module);
int32_t status = 0;
double energy = getPDPTotalEnergy(&status, module);
CheckStatus(env, status, false);
return energy;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PDPJNI
* Method: resetPDPTotalEnergy
* Signature: (BLjava/nio/IntBuffer;)D
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_resetPDPTotalEnergy
(JNIEnv *env, jclass, jobject status, jint module)
(JNIEnv *env, jclass, jint module)
{
jint *status_ptr = (jint *)env->GetDirectBufferAddress(status);
*status_ptr = 0;
resetPDPTotalEnergy(status_ptr, module);
int32_t status = 0;
resetPDPTotalEnergy(&status, module);
CheckStatus(env, status, false);
}
/*
* Class: edu_wpi_first_wpilibj_hal_PDPJNI
* Method: clearStickyFaults
* Signature: (BLjava/nio/IntBuffer;)D
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_clearPDPStickyFaults
(JNIEnv *env, jclass, jobject status, jint module)
(JNIEnv *env, jclass, jint module)
{
jint *status_ptr = (jint *)env->GetDirectBufferAddress(status);
*status_ptr = 0;
clearPDPStickyFaults(status_ptr, module);
int32_t status = 0;
clearPDPStickyFaults(&status, module);
CheckStatus(env, status, false);
}
} // extern "C"