mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
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:
committed by
Brad Miller (WPI)
parent
927400a43c
commit
7023013c4b
@@ -6,36 +6,38 @@
|
||||
|
||||
#include "HAL/HAL.hpp"
|
||||
|
||||
extern "C" {
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_JNIWrapper
|
||||
* Method: getPortWithModule
|
||||
* Signature: (BB)Ljava/nio/ByteBuffer;
|
||||
* Signature: (BB)J
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_JNIWrapper_getPortWithModule
|
||||
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_JNIWrapper_getPortWithModule
|
||||
(JNIEnv * env, jclass, jbyte module, jbyte pin)
|
||||
{
|
||||
//FILE_LOG(logDEBUG) << "Calling JNIWrapper getPortWithModlue";
|
||||
//FILE_LOG(logDEBUG) << "Module = " << (jint)module;
|
||||
//FILE_LOG(logDEBUG) << "Pin = " << (jint)pin;
|
||||
void** portPtr = (void**)new unsigned char[4];
|
||||
*portPtr = getPortWithModule(module,pin);
|
||||
//FILE_LOG(logDEBUG) << "Port Ptr = " << *portPtr;
|
||||
return env->NewDirectByteBuffer( portPtr, 4);
|
||||
void* port = getPortWithModule(module, pin);
|
||||
//FILE_LOG(logDEBUG) << "Port Ptr = " << port;
|
||||
return (jlong)port;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_JNIWrapper
|
||||
* Method: getPort
|
||||
* Signature: (BB)Ljava/nio/ByteBuffer;
|
||||
* Signature: (BB)J
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_JNIWrapper_getPort
|
||||
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_JNIWrapper_getPort
|
||||
(JNIEnv * env, jclass, jbyte pin)
|
||||
{
|
||||
//FILE_LOG(logDEBUG) << "Calling JNIWrapper getPortWithModlue";
|
||||
//FILE_LOG(logDEBUG) << "Module = " << (jint)module;
|
||||
//FILE_LOG(logDEBUG) << "Pin = " << (jint)pin;
|
||||
void** portPtr = (void**)new unsigned char[4];
|
||||
*portPtr = getPort(pin);
|
||||
//FILE_LOG(logDEBUG) << "Port Ptr = " << *portPtr;
|
||||
return env->NewDirectByteBuffer( portPtr, 4);
|
||||
void* port = getPort(pin);
|
||||
//FILE_LOG(logDEBUG) << "Port Ptr = " << port;
|
||||
return (jlong)port;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
Reference in New Issue
Block a user