mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
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
141 lines
4.0 KiB
C++
141 lines
4.0 KiB
C++
#include <jni.h>
|
|
#include "Log.hpp"
|
|
#include "HAL/HAL.hpp"
|
|
|
|
#include "edu_wpi_first_wpilibj_hal_SolenoidJNI.h"
|
|
|
|
#include "HALUtil.h"
|
|
|
|
TLogLevel solenoidJNILogLevel = logERROR;
|
|
|
|
#define SOLENOIDJNI_LOG(level) \
|
|
if (level > solenoidJNILogLevel) ; \
|
|
else Log().Get(level)
|
|
|
|
extern "C" {
|
|
|
|
/*
|
|
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
|
|
* Method: initializeSolenoidPort
|
|
* Signature: (J)J
|
|
*/
|
|
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_initializeSolenoidPort
|
|
(JNIEnv *env, jclass, jlong port_pointer)
|
|
{
|
|
SOLENOIDJNI_LOG(logDEBUG) << "Calling SolenoidJNI initializeSolenoidPort";
|
|
|
|
SOLENOIDJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)port_pointer;
|
|
char *aschars = (char *)port_pointer;
|
|
SOLENOIDJNI_LOG(logDEBUG) << '\t' << (int)aschars[0] << '\t' << (int)aschars[1] << std::endl;
|
|
|
|
int32_t status = 0;
|
|
void* solenoid_port_pointer = initializeSolenoidPort((void*)port_pointer, &status);
|
|
|
|
SOLENOIDJNI_LOG(logDEBUG) << "Status = " << status;
|
|
SOLENOIDJNI_LOG(logDEBUG) << "Solenoid Port Pointer = " << solenoid_port_pointer;
|
|
|
|
int *asints = (int *)solenoid_port_pointer;
|
|
SOLENOIDJNI_LOG(logDEBUG) << '\t' << asints[0] << '\t' << asints[1] << std::endl;
|
|
|
|
CheckStatus(env, status);
|
|
return (jlong)solenoid_port_pointer;
|
|
}
|
|
|
|
/*
|
|
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
|
|
* Method: getPortWithModule
|
|
* Signature: (BB)J
|
|
*/
|
|
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getPortWithModule
|
|
(JNIEnv *env, jclass, jbyte module, jbyte channel)
|
|
{
|
|
void* port_pointer = getPortWithModule(module, channel);
|
|
|
|
return (jlong)port_pointer;
|
|
}
|
|
|
|
/*
|
|
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
|
|
* Method: setSolenoid
|
|
* Signature: (JZ)V
|
|
*/
|
|
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_setSolenoid
|
|
(JNIEnv *env, jclass, jlong solenoid_port, jboolean value)
|
|
{
|
|
SOLENOIDJNI_LOG(logDEBUG) << "Calling SolenoidJNI SetSolenoid";
|
|
|
|
SOLENOIDJNI_LOG(logDEBUG) << "Solenoid Port Pointer = " << (void*)solenoid_port;
|
|
|
|
int32_t status = 0;
|
|
setSolenoid((void*)solenoid_port, value, &status);
|
|
CheckStatus(env, status);
|
|
}
|
|
|
|
/*
|
|
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
|
|
* Method: getSolenoid
|
|
* Signature: (J)Z
|
|
*/
|
|
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getSolenoid
|
|
(JNIEnv *env, jclass, jlong solenoid_port)
|
|
{
|
|
int32_t status = 0;
|
|
jboolean val = getSolenoid((void*)solenoid_port, &status);
|
|
CheckStatus(env, status);
|
|
return val;
|
|
}
|
|
|
|
/*
|
|
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
|
|
* Method: getPCMSolenoidBlackList
|
|
* Signature: (J)I
|
|
*/
|
|
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getPCMSolenoidBlackList
|
|
(JNIEnv *env, jclass, jlong solenoid_port)
|
|
{
|
|
int32_t status = 0;
|
|
jint val = getPCMSolenoidBlackList((void*)solenoid_port, &status);
|
|
CheckStatus(env, status);
|
|
return val;
|
|
}
|
|
/*
|
|
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
|
|
* Method: getPCMSolenoidVoltageStickyFault
|
|
* Signature: (J)Z
|
|
*/
|
|
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getPCMSolenoidVoltageStickyFault
|
|
(JNIEnv *env, jclass, jlong solenoid_port)
|
|
{
|
|
int32_t status = 0;
|
|
bool val = getPCMSolenoidVoltageStickyFault((void*)solenoid_port, &status);
|
|
CheckStatus(env, status);
|
|
return val;
|
|
}
|
|
/*
|
|
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
|
|
* Method: getPCMSolenoidVoltageFault
|
|
* Signature: (J)Z
|
|
*/
|
|
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getPCMSolenoidVoltageFault
|
|
(JNIEnv *env, jclass, jlong solenoid_port)
|
|
{
|
|
int32_t status = 0;
|
|
bool val = getPCMSolenoidVoltageFault((void*)solenoid_port, &status);
|
|
CheckStatus(env, status);
|
|
return val;
|
|
}
|
|
/*
|
|
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
|
|
* Method: clearAllPCMStickyFaults
|
|
* Signature: (J)V
|
|
*/
|
|
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_clearAllPCMStickyFaults
|
|
(JNIEnv *env, jclass, jlong solenoid_port)
|
|
{
|
|
int32_t status = 0;
|
|
clearAllPCMStickyFaults_sol((void*)solenoid_port, &status);
|
|
CheckStatus(env, status);
|
|
}
|
|
|
|
} // extern "C"
|