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,186 +1,204 @@
#include <jni.h>
#include "edu_wpi_first_wpilibj_hal_PowerJNI.h"
#include "HAL/Power.hpp"
#include "HALUtil.h"
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
* Method: getVinVoltage
* Signature: (Ljava/nio/IntBuffer;)F
* Signature: ()F
*/
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getVinVoltage
(JNIEnv * env, jclass, jobject status)
(JNIEnv * env, jclass)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
return getVinVoltage(statusPtr);
int32_t status = 0;
float val = getVinVoltage(&status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
* Method: getVinCurrent
* Signature: (Ljava/nio/IntBuffer;)F
* Signature: ()F
*/
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getVinCurrent
(JNIEnv * env, jclass, jobject status)
(JNIEnv * env, jclass)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
return getVinCurrent(statusPtr);
int32_t status = 0;
float val = getVinCurrent(&status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
* Method: getUserVoltage6V
* Signature: (Ljava/nio/IntBuffer;)F
* Signature: ()F
*/
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserVoltage6V
(JNIEnv * env, jclass, jobject status)
(JNIEnv * env, jclass)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
return getUserVoltage6V(statusPtr);
int32_t status = 0;
float val = getUserVoltage6V(&status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
* Method: getUserCurrent6V
* Signature: (Ljava/nio/IntBuffer;)F
* Signature: ()F
*/
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserCurrent6V
(JNIEnv * env, jclass, jobject status)
(JNIEnv * env, jclass)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
return getUserCurrent6V(statusPtr);
int32_t status = 0;
float val = getUserCurrent6V(&status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
* Method: getUserActive6V
* Signature: (Ljava/nio/IntBuffer;)Z
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserActive6V
(JNIEnv * env, jclass, jobject status)
(JNIEnv * env, jclass)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
return getUserActive6V(statusPtr);
int32_t status = 0;
bool val = getUserActive6V(&status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
* Method: getUserCurrentFaults6V
* Signature: (Ljava/nio/IntBuffer;)I
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserCurrentFaults6V
(JNIEnv * env, jclass, jobject status)
(JNIEnv * env, jclass)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
return getUserCurrentFaults6V(statusPtr);
int32_t status = 0;
int val = getUserCurrentFaults6V(&status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
* Method: getUserVoltage5V
* Signature: (Ljava/nio/IntBuffer;)F
* Signature: ()F
*/
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserVoltage5V
(JNIEnv * env, jclass, jobject status)
(JNIEnv * env, jclass)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
return getUserVoltage5V(statusPtr);
int32_t status = 0;
float val = getUserVoltage5V(&status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
* Method: getUserCurrent5V
* Signature: (Ljava/nio/IntBuffer;)F
* Signature: ()F
*/
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserCurrent5V
(JNIEnv * env, jclass, jobject status)
(JNIEnv * env, jclass)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
return getUserCurrent5V(statusPtr);
int32_t status = 0;
float val = getUserCurrent5V(&status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
* Method: getUserActive5V
* Signature: (Ljava/nio/IntBuffer;)Z
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserActive5V
(JNIEnv * env, jclass, jobject status)
(JNIEnv * env, jclass)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
return getUserActive5V(statusPtr);
int32_t status = 0;
bool val = getUserActive5V(&status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
* Method: getUserCurrentFaults5V
* Signature: (Ljava/nio/IntBuffer;)I
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserCurrentFaults5V
(JNIEnv * env, jclass, jobject status)
(JNIEnv * env, jclass)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
return getUserCurrentFaults5V(statusPtr);
int32_t status = 0;
int val = getUserCurrentFaults5V(&status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
* Method: getUserVoltage3V3
* Signature: (Ljava/nio/IntBuffer;)F
* Signature: ()F
*/
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserVoltage3V3
(JNIEnv * env, jclass, jobject status)
(JNIEnv * env, jclass)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
return getUserVoltage3V3(statusPtr);
int32_t status = 0;
float val = getUserVoltage3V3(&status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
* Method: getUserCurrent3V3
* Signature: (Ljava/nio/IntBuffer;)F
* Signature: ()F
*/
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserCurrent3V3
(JNIEnv * env, jclass, jobject status)
(JNIEnv * env, jclass)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
return getUserCurrent3V3(statusPtr);
int32_t status = 0;
float val = getUserCurrent3V3(&status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
* Method: getUserActive3V3
* Signature: (Ljava/nio/IntBuffer;)Z
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserActive3V3
(JNIEnv * env, jclass, jobject status)
(JNIEnv * env, jclass)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
return getUserActive3V3(statusPtr);
int32_t status = 0;
bool val = getUserActive3V3(&status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PowerJNI
* Method: getUserCurrentFaults3V3
* Signature: (Ljava/nio/IntBuffer;)I
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserCurrentFaults3V3
(JNIEnv * env, jclass, jobject status)
(JNIEnv * env, jclass)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
return getUserCurrentFaults3V3(statusPtr);
int32_t status = 0;
int val = getUserCurrentFaults3V3(&status);
CheckStatus(env, status);
return val;
}
} // extern "C"