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

@@ -2,6 +2,8 @@
#include "edu_wpi_first_wpilibj_hal_AccelerometerJNI.h"
#include "HAL/Accelerometer.hpp"
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_AccelerometerJNI
* Method: setAccelerometerActive
@@ -56,3 +58,5 @@ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AccelerometerJNI_getAcc
{
return getAccelerometerZ();
}
} // extern "C"

View File

@@ -5,6 +5,7 @@
#include "edu_wpi_first_wpilibj_hal_AnalogJNI.h"
#include "HAL/Analog.hpp"
#include "HALUtil.h"
// set the logging level
TLogLevel analogJNILogLevel = logWARNING;
@@ -13,56 +14,52 @@ TLogLevel analogJNILogLevel = logWARNING;
if (level > analogJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: initializeAnalogInputPort
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Ljava/nio/ByteBuffer;
* Signature: (J)J
*/
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogInputPort
(JNIEnv * env, jclass, jobject id, jobject status)
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogInputPort
(JNIEnv * env, jclass, jlong id)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
void** analogPtr = (void**)new unsigned char[4];
*statusPtr = 0;
*analogPtr = initializeAnalogInputPort(*javaId, statusPtr);
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *analogPtr;
return env->NewDirectByteBuffer( analogPtr, 4);
ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
int32_t status = 0;
void* analog = initializeAnalogInputPort((void*)id, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << analog;
CheckStatus(env, status);
return (jlong)analog;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: initializeAnalogOutputPort
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Ljava/nio/ByteBuffer;
* Signature: (J)J
*/
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogOutputPort
(JNIEnv * env, jclass, jobject id, jobject status)
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogOutputPort
(JNIEnv * env, jclass, jlong id)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
void** analogPtr = (void**)new unsigned char[4];
*statusPtr = 0;
*analogPtr = initializeAnalogOutputPort(*javaId, statusPtr);
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *analogPtr;
return env->NewDirectByteBuffer( analogPtr, 4);
ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
int32_t status = 0;
void* analog = initializeAnalogOutputPort((void*)id, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << analog;
CheckStatus(env, status);
return (jlong)analog;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: checkAnalogModule
* Signature: (B)B
* Signature: (B)Z
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogModule
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogModule
(JNIEnv *, jclass, jbyte value)
{
//ANALOGJNI_LOG(logDEBUG) << "Module = " << (jint)value;
jbyte returnValue = checkAnalogModule( value );
jboolean returnValue = checkAnalogModule( value );
//ANALOGJNI_LOG(logDEBUG) << "checkAnalogModuleResult = " << (jint)returnValue;
return returnValue;
}
@@ -70,13 +67,13 @@ JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogModu
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: checkAnalogInputChannel
* Signature: (I)B
* Signature: (I)Z
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogInputChannel
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogInputChannel
(JNIEnv *, jclass, jint value)
{
//ANALOGJNI_LOG(logDEBUG) << "Channel = " << value;
jbyte returnValue = checkAnalogInputChannel( value );
jboolean returnValue = checkAnalogInputChannel( value );
//ANALOGJNI_LOG(logDEBUG) << "checkAnalogChannelResult = " << (jint)returnValue;
return returnValue;
}
@@ -84,13 +81,13 @@ JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogInpu
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: checkAnalogOutputChannel
* Signature: (I)B
* Signature: (I)Z
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogOutputChannel
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogOutputChannel
(JNIEnv *, jclass, jint value)
{
//ANALOGJNI_LOG(logDEBUG) << "Channel = " << value;
jbyte returnValue = checkAnalogOutputChannel( value );
jboolean returnValue = checkAnalogOutputChannel( value );
//ANALOGJNI_LOG(logDEBUG) << "checkAnalogChannelResult = " << (jint)returnValue;
return returnValue;
}
@@ -98,372 +95,349 @@ JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogOutp
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: setAnalogOutput
* Signature: (Ljava/nio/ByteBuffer;DLjava/nio/IntBuffer;)V
* Signature: (JD)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogOutput
(JNIEnv * env, jclass, jobject id, jdouble voltage, jobject status)
(JNIEnv * env, jclass, jlong id, jdouble voltage)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
setAnalogOutput(*javaId, voltage, statusPtr);
ANALOGJNI_LOG(logDEBUG) << "Calling setAnalogOutput";
ANALOGJNI_LOG(logDEBUG) << "Voltage = " << voltage;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
setAnalogOutput((void*)id, voltage, &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: getAnalogOutput
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)D
* Signature: (J)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogOutput
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
return getAnalogOutput(*javaId, statusPtr);
int32_t status = 0;
double val = getAnalogOutput((void*)id, &status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: setAnalogSampleRate
* Signature: (DLjava/nio/IntBuffer;)V
* Signature: (D)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogSampleRate
(JNIEnv * env, jclass, jdouble value, jobject status)
(JNIEnv * env, jclass, jdouble value)
{
ANALOGJNI_LOG(logDEBUG) << "SampleRate = " << value;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
setAnalogSampleRate( value, statusPtr );
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setAnalogSampleRate( value, &status );
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: getAnalogSampleRate
* Signature: (Ljava/nio/IntBuffer;)D
* Signature: ()D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogSampleRate
(JNIEnv * env, jclass, jobject status)
(JNIEnv * env, jclass)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
double returnValue = getAnalogSampleRate( statusPtr );
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
double returnValue = getAnalogSampleRate( &status );
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
ANALOGJNI_LOG(logDEBUG) << "SampleRate = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: setAnalogAverageBits
* Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogAverageBits
(JNIEnv * env, jclass, jobject id, jint value, jobject status)
(JNIEnv * env, jclass, jlong id, jint value)
{
ANALOGJNI_LOG(logDEBUG) << "AverageBits = " << value;
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
setAnalogAverageBits( *javaId, value, statusPtr );
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
setAnalogAverageBits((void*)id, value, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: getAnalogAverageBits
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogAverageBits
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
jint returnValue = getAnalogAverageBits( *javaId, statusPtr );
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
jint returnValue = getAnalogAverageBits((void*)id, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
ANALOGJNI_LOG(logDEBUG) << "AverageBits = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: setAnalogOversampleBits
* Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogOversampleBits
(JNIEnv * env, jclass, jobject id, jint value, jobject status)
(JNIEnv * env, jclass, jlong id, jint value)
{
ANALOGJNI_LOG(logDEBUG) << "OversampleBits = " << value;
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
setAnalogOversampleBits( *javaId, value, statusPtr );
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
setAnalogOversampleBits((void*)id, value, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: getAnalogOversampleBits
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogOversampleBits
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
jint returnValue = getAnalogOversampleBits( *javaId, statusPtr );
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
jint returnValue = getAnalogOversampleBits((void*)id, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
ANALOGJNI_LOG(logDEBUG) << "OversampleBits = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: getAnalogValue
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)S
* Signature: (J)S
*/
JNIEXPORT jshort JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogValue
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
//ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
jshort returnValue = getAnalogValue( *javaId, statusPtr );
//ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
//ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
jshort returnValue = getAnalogValue((void*)id, &status);
//ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
//ANALOGJNI_LOG(logDEBUG) << "Value = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: getAnalogAverageValue
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogAverageValue
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
jint returnValue = getAnalogAverageValue( *javaId, statusPtr );
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
jint returnValue = getAnalogAverageValue((void*)id, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
ANALOGJNI_LOG(logDEBUG) << "AverageValue = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: getAnalogVoltsToValue
* Signature: (Ljava/nio/ByteBuffer;DLjava/nio/IntBuffer;)I
* Signature: (JD)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogVoltsToValue
(JNIEnv * env, jclass, jobject id, jdouble voltageValue, jobject status)
(JNIEnv * env, jclass, jlong id, jdouble voltageValue)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
ANALOGJNI_LOG(logDEBUG) << "VoltageValue = " << voltageValue;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
jint returnValue = getAnalogVoltsToValue( *javaId, voltageValue, statusPtr );
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
jint returnValue = getAnalogVoltsToValue((void*)id, voltageValue, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
ANALOGJNI_LOG(logDEBUG) << "Value = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: getAnalogVoltage
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)D
* Signature: (J)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogVoltage
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
//ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
jdouble returnValue = getAnalogVoltage( *javaId, statusPtr );
//ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
//ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
jdouble returnValue = getAnalogVoltage((void*)id, &status);
//ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
//ANALOGJNI_LOG(logDEBUG) << "Voltage = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: getAnalogAverageVoltage
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)D
* Signature: (J)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogAverageVoltage
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
jdouble returnValue = getAnalogAverageVoltage( *javaId, statusPtr );
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
jdouble returnValue = getAnalogAverageVoltage((void*)id, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
ANALOGJNI_LOG(logDEBUG) << "AverageVoltage = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: getAnalogLSBWeight
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogLSBWeight
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
jint returnValue = getAnalogLSBWeight(*javaId, statusPtr);
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
jint returnValue = getAnalogLSBWeight((void*)id, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
ANALOGJNI_LOG(logDEBUG) << "AnalogLSBWeight = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: getAnalogOffset
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogOffset
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
jint returnValue = getAnalogOffset(*javaId, statusPtr);
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
jint returnValue = getAnalogOffset((void*)id, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
ANALOGJNI_LOG(logDEBUG) << "AnalogOffset = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: isAccumulatorChannel
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B
* Signature: (J)Z
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_isAccumulatorChannel
(JNIEnv * env, jclass, jobject id, jobject status)
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_isAccumulatorChannel
(JNIEnv * env, jclass, jlong id)
{
ANALOGJNI_LOG(logDEBUG) << "isAccumulatorChannel";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
// isAccumulaotrChanel returns a boolean
char vOut = isAccumulatorChannel(*javaId, statusPtr) ? 1 : 0;
//The C++ equivalent of a jbyte is a char
jbyte returnValue = vOut;
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
jboolean returnValue = isAccumulatorChannel((void*)id, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
ANALOGJNI_LOG(logDEBUG) << "AnalogOffset = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: initAccumulator
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initAccumulator
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
initAccumulator(*javaId, statusPtr);
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
initAccumulator((void*)id, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: resetAccumulator
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_resetAccumulator
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
resetAccumulator(*javaId, statusPtr);
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
resetAccumulator((void*)id, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: setAccumulatorCenter
* Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAccumulatorCenter
(JNIEnv * env, jclass, jobject id, jint center, jobject status)
(JNIEnv * env, jclass, jlong id, jint center)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
setAccumulatorCenter(*javaId, center, statusPtr);
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
setAccumulatorCenter((void*)id, center, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: setAccumulatorDeadband
* Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAccumulatorDeadband
(JNIEnv * env, jclass, jobject id, jint deadband, jobject status)
(JNIEnv * env, jclass, jlong id, jint deadband)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
setAccumulatorDeadband(*javaId, deadband, statusPtr);
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
setAccumulatorDeadband((void*)id, deadband, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: getAccumulatorValue
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)J
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorValue
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
jlong returnValue = getAccumulatorValue(*javaId, statusPtr);
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
jlong returnValue = getAccumulatorValue((void*)id, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
ANALOGJNI_LOG(logDEBUG) << "AccumulatorValue = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
@@ -471,211 +445,185 @@ JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorV
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: getAccumulatorCount
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorCount
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
jint returnValue = getAccumulatorCount(*javaId, statusPtr);
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
jint returnValue = getAccumulatorCount((void*)id, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
ANALOGJNI_LOG(logDEBUG) << "AccumulatorCount = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: getAccumulatorOutput
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/LongBuffer;Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;)V
* Signature: (JLjava/nio/LongBuffer;Ljava/nio/IntBuffer;)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorOutput
(JNIEnv * env, jclass, jobject id, jobject value, jobject count, jobject status)
(JNIEnv * env, jclass, jlong id, jobject value, jobject count)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
jlong * valuePtr = (jlong*)env->GetDirectBufferAddress(value);
uint32_t * countPtr = (uint32_t*)env->GetDirectBufferAddress(count);
getAccumulatorOutput(*javaId, valuePtr, countPtr, statusPtr);
getAccumulatorOutput((void*)id, valuePtr, countPtr, &status);
ANALOGJNI_LOG(logDEBUG) << "Value = " << *valuePtr;
ANALOGJNI_LOG(logDEBUG) << "Count = " << *countPtr;
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: initializeAnalogTrigger
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;)Ljava/nio/ByteBuffer;
* Signature: (JLjava/nio/IntBuffer;)J
*/
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogTrigger
(JNIEnv * env, jclass, jobject id, jobject index, jobject status)
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogTrigger
(JNIEnv * env, jclass, jlong id, jobject index)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId;
ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
jint * indexPtr = (jint*)env->GetDirectBufferAddress(index);
ANALOGJNI_LOG(logDEBUG) << "Index Ptr = " << indexPtr;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
void ** analogTriggerPtr = new void *;
*statusPtr = 0;
*analogTriggerPtr = initializeAnalogTrigger(*javaId, (uint32_t *)indexPtr, statusPtr);
ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ANALOGJNI_LOG(logDEBUG) << "AnalogTrigger Ptr = " << *analogTriggerPtr;
return env->NewDirectByteBuffer(analogTriggerPtr, 4);
int32_t status = 0;
void* analogTrigger = initializeAnalogTrigger((void*)id, (uint32_t *)indexPtr, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
ANALOGJNI_LOG(logDEBUG) << "AnalogTrigger Ptr = " << analogTrigger;
CheckStatus(env, status);
return (jlong)analogTrigger;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: cleanAnalogTrigger
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_cleanAnalogTrigger
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << *javaId;
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
cleanAnalogTrigger( *javaId, statusPtr );
delete javaId;
int32_t status = 0;
cleanAnalogTrigger((void*)id, &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: setAnalogTriggerLimitsRaw
* Signature: (Ljava/nio/ByteBuffer;IILjava/nio/IntBuffer;)V
* Signature: (JII)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogTriggerLimitsRaw
(JNIEnv * env, jclass, jobject id, jint lower, jint upper, jobject status)
(JNIEnv * env, jclass, jlong id, jint lower, jint upper)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << *javaId;
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setAnalogTriggerLimitsRaw( *javaId, lower, upper, statusPtr );
int32_t status = 0;
setAnalogTriggerLimitsRaw((void*)id, lower, upper, &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: setAnalogTriggerLimitsVoltage
* Signature: (Ljava/nio/ByteBuffer;DDLjava/nio/IntBuffer;)V
* Signature: (JDD)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogTriggerLimitsVoltage
(JNIEnv * env, jclass, jobject id, jdouble lower, jdouble upper, jobject status)
(JNIEnv * env, jclass, jlong id, jdouble lower, jdouble upper)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << *javaId;
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setAnalogTriggerLimitsVoltage( *javaId, lower, upper, statusPtr );
int32_t status = 0;
setAnalogTriggerLimitsVoltage((void*)id, lower, upper, &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: setAnalogTriggerAveraged
* Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)V
* Signature: (JZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogTriggerAveraged
(JNIEnv * env, jclass, jobject id, jbyte averaged, jobject status){
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << *javaId;
(JNIEnv * env, jclass, jlong id, jboolean averaged)
{
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setAnalogTriggerAveraged( *javaId, averaged, statusPtr );
int32_t status = 0;
setAnalogTriggerAveraged((void*)id, averaged, &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: setAnalogTriggerFiltered
* Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)V
* Signature: (JZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogTriggerFiltered
(JNIEnv * env, jclass, jobject id, jbyte filtered, jobject status){
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << *javaId;
(JNIEnv * env, jclass, jlong id, jboolean filtered)
{
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setAnalogTriggerFiltered( *javaId, filtered, statusPtr );
int32_t status = 0;
setAnalogTriggerFiltered((void*)id, filtered, &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: getAnalogTriggerInWindow
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B
* Signature: (J)Z
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogTriggerInWindow
(JNIEnv * env, jclass, jobject id, jobject status)
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogTriggerInWindow
(JNIEnv * env, jclass, jlong id)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << *javaId;
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
return getAnalogTriggerInWindow( *javaId, statusPtr );
int32_t status = 0;
jboolean val = getAnalogTriggerInWindow((void*)id, &status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: getAnalogTriggerTriggerState
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B
* Signature: (J)Z
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogTriggerTriggerState
(JNIEnv * env, jclass, jobject id, jobject status)
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogTriggerTriggerState
(JNIEnv * env, jclass, jlong id)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << *javaId;
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
return getAnalogTriggerTriggerState( *javaId, statusPtr );
int32_t status = 0;
jboolean val = getAnalogTriggerTriggerState((void*)id, &status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: getAnalogTriggerOutput
* Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)B
* Signature: (JI)Z
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogTriggerOutput
(JNIEnv * env, jclass, jobject id, jint type, jobject status)
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogTriggerOutput
(JNIEnv * env, jclass, jlong id, jint type)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << *javaId;
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
return getAnalogTriggerOutput( *javaId, (AnalogTriggerType)type, statusPtr )? 1 : 0;
int32_t status = 0;
jboolean val = getAnalogTriggerOutput((void*)id, (AnalogTriggerType)type, &status);
CheckStatus(env, status);
return val;
}
} // extern "C"

View File

@@ -6,6 +6,7 @@
#include "HAL/CAN.hpp"
#include "FRC_NetworkCommunication/CANSessionMux.h"
#include "HALUtil.h"
// set the logging level
//TLogLevel canJNILogLevel = logDEBUG;
@@ -15,19 +16,20 @@ TLogLevel canJNILogLevel = logERROR;
if (level > canJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_can_CANJNI
* Method: FRCNetworkCommunicationCANSessionMuxSendMessage
* Signature: (ILjava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V
* Signature: (ILjava/nio/ByteBuffer;I)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetworkCommunicationCANSessionMuxSendMessage
(JNIEnv * env, jclass, jint messageID, jobject data, jint periodMs, jobject status)
(JNIEnv * env, jclass, jint messageID, jobject data, jint periodMs)
{
CANJNI_LOG(logDEBUG) << "Calling CANJNI FRCNetworkCommunicationCANSessionMuxSendMessage";
uint8_t *dataBuffer = (uint8_t *)(data? env->GetDirectBufferAddress(data) : 0);
uint8_t dataSize = (uint8_t)(data? env->GetDirectBufferCapacity(data) : 0);
int32_t *statusPtr = (int32_t *)env->GetDirectBufferAddress(status);
CANJNI_LOG(logDEBUG) << "Message ID " << std::hex << messageID;
@@ -52,10 +54,11 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetworkCommunica
CANJNI_LOG(logDEBUG) << "Period: " << periodMs;
*statusPtr = 0;
FRC_NetworkCommunication_CANSessionMux_sendMessage(messageID, dataBuffer, dataSize, periodMs, statusPtr);
int32_t status = 0;
FRC_NetworkCommunication_CANSessionMux_sendMessage(messageID, dataBuffer, dataSize, periodMs, &status);
CANJNI_LOG(logDEBUG) << "Status: " << *statusPtr;
CANJNI_LOG(logDEBUG) << "Status: " << status;
CheckCANStatus(env, status, messageID);
}
static uint8_t buffer[8];
@@ -63,21 +66,20 @@ static uint8_t buffer[8];
/*
* Class: edu_wpi_first_wpilibj_can_CANJNI
* Method: FRCNetworkCommunicationCANSessionMuxReceiveMessage
* Signature: (Ljava/nio/IntBuffer;ILjava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Ljava/nio/ByteBuffer;
* Signature: (Ljava/nio/IntBuffer;ILjava/nio/ByteBuffer;)Ljava/nio/ByteBuffer;
*/
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetworkCommunicationCANSessionMuxReceiveMessage
(JNIEnv * env, jclass, jobject messageID, jint messageIDMask, jobject timeStamp, jobject status)
(JNIEnv * env, jclass, jobject messageID, jint messageIDMask, jobject timeStamp)
{
CANJNI_LOG(logDEBUG) << "Calling CANJNI FRCNetworkCommunicationCANSessionMuxReceiveMessage";
uint32_t *messageIDPtr = (uint32_t *)env->GetDirectBufferAddress(messageID);
uint32_t *timeStampPtr = (uint32_t *)env->GetDirectBufferAddress(timeStamp);
int32_t *statusPtr = (int32_t *)env->GetDirectBufferAddress(status);
uint8_t dataSize = 0;
*statusPtr = 0;
FRC_NetworkCommunication_CANSessionMux_receiveMessage(messageIDPtr, messageIDMask, buffer, &dataSize, timeStampPtr, statusPtr);
int32_t status = 0;
FRC_NetworkCommunication_CANSessionMux_receiveMessage(messageIDPtr, messageIDMask, buffer, &dataSize, timeStampPtr, &status);
CANJNI_LOG(logDEBUG) << "Message ID " << std::hex << *messageIDPtr;
@@ -94,7 +96,10 @@ JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetworkCommun
}
CANJNI_LOG(logDEBUG) << "Timestamp: " << *timeStampPtr;
CANJNI_LOG(logDEBUG) << "Status: " << *statusPtr;
CANJNI_LOG(logDEBUG) << "Status: " << status;
if (!CheckCANStatus(env, status, *messageIDPtr)) return nullptr;
return env->NewDirectByteBuffer(buffer, dataSize);
}
} // extern "C"

View File

@@ -1,21 +1,20 @@
#include "Log.hpp"
#include "edu_wpi_first_wpilibj_hal_CompressorJNI.h"
#include "HAL/HAL.hpp"
#include "HALUtil.h"
typedef void *VoidPointer;
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: initializeCompressor
* Signature: (B)Ljava/nio/ByteBuffer;
* Signature: (B)J
*/
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_initializeCompressor
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_initializeCompressor
(JNIEnv *env, jclass, jbyte module)
{
VoidPointer *pcm_pointer = new VoidPointer;
*pcm_pointer = initializeCompressor(module);
return env->NewDirectByteBuffer(pcm_pointer, 4);
void* pcm = initializeCompressor(module);
return (jlong)pcm;
}
/*
@@ -33,178 +32,166 @@ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_checkCom
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: getCompressor
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressor
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
(JNIEnv *env, jclass, jlong pcm_pointer)
{
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
*status_pointer = 0;
return getCompressor(*pcm_pointer, status_pointer);
int32_t status = 0;
bool val = getCompressor((void*)pcm_pointer, &status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: setClosedLoopControl
* Signature: (Ljava/nio/ByteBuffer;ZLjava/nio/IntBuffer;)V
* Signature: (JZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_setClosedLoopControl
(JNIEnv *env, jclass, jobject pcm_pointer_object, jboolean value, jobject status)
(JNIEnv *env, jclass, jlong pcm_pointer, jboolean value)
{
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
*status_pointer = 0;
setClosedLoopControl(*pcm_pointer, value, status_pointer);
int32_t status = 0;
setClosedLoopControl((void*)pcm_pointer, value, &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: getClosedLoopControl
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getClosedLoopControl
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
(JNIEnv *env, jclass, jlong pcm_pointer)
{
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
*status_pointer = 0;
return getClosedLoopControl(*pcm_pointer, status_pointer);
int32_t status = 0;
bool val = getClosedLoopControl((void*)pcm_pointer, &status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: getPressureSwitch
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getPressureSwitch
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
(JNIEnv *env, jclass, jlong pcm_pointer)
{
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
*status_pointer = 0;
return getPressureSwitch(*pcm_pointer, status_pointer);
int32_t status = 0;
bool val = getPressureSwitch((void*)pcm_pointer, &status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: getCompressorCurrent
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)F
* Signature: (J)F
*/
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrent
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
(JNIEnv *env, jclass, jlong pcm_pointer)
{
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
*status_pointer = 0;
return getCompressorCurrent(*pcm_pointer, status_pointer);
int32_t status = 0;
float val = getCompressorCurrent((void*)pcm_pointer, &status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: getCompressorCurrentTooHighFault
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrentTooHighFault
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
(JNIEnv *env, jclass, jlong pcm_pointer)
{
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
*status_pointer = 0;
return getCompressorCurrentTooHighFault(*pcm_pointer, status_pointer);
int32_t status = 0;
bool val = getCompressorCurrentTooHighFault((void*)pcm_pointer, &status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: getCompressorCurrentTooHighStickyFault
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrentTooHighStickyFault
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
(JNIEnv *env, jclass, jlong pcm_pointer)
{
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
*status_pointer = 0;
return getCompressorCurrentTooHighStickyFault(*pcm_pointer, status_pointer);
int32_t status = 0;
bool val = getCompressorCurrentTooHighStickyFault((void*)pcm_pointer, &status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: getCompressorShortedStickyFault
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorShortedStickyFault
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
(JNIEnv *env, jclass, jlong pcm_pointer)
{
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
*status_pointer = 0;
return getCompressorShortedStickyFault(*pcm_pointer, status_pointer);
int32_t status = 0;
bool val = getCompressorShortedStickyFault((void*)pcm_pointer, &status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: getCompressorShortedFault
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorShortedFault
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
(JNIEnv *env, jclass, jlong pcm_pointer)
{
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
*status_pointer = 0;
return getCompressorShortedFault(*pcm_pointer, status_pointer);
int32_t status = 0;
bool val = getCompressorShortedFault((void*)pcm_pointer, &status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: getCompressorNotConnectedStickyFault
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorNotConnectedStickyFault
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
(JNIEnv *env, jclass, jlong pcm_pointer)
{
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
*status_pointer = 0;
return getCompressorNotConnectedStickyFault(*pcm_pointer, status_pointer);
int32_t status = 0;
bool val = getCompressorNotConnectedStickyFault((void*)pcm_pointer, &status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: getCompressorNotConnectedFault
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorNotConnectedFault
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
(JNIEnv *env, jclass, jlong pcm_pointer)
{
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
*status_pointer = 0;
return getCompressorNotConnectedFault(*pcm_pointer, status_pointer);
int32_t status = 0;
bool val = getCompressorNotConnectedFault((void*)pcm_pointer, &status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: clearAllPCMStickyFaults
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_clearAllPCMStickyFaults
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
(JNIEnv *env, jclass, jlong pcm_pointer)
{
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
*status_pointer = 0;
clearAllPCMStickyFaults(*pcm_pointer, status_pointer);
int32_t status = 0;
clearAllPCMStickyFaults((void*)pcm_pointer, &status);
CheckStatus(env, status);
}
} // extern "C"

View File

@@ -5,6 +5,8 @@
#include "edu_wpi_first_wpilibj_hal_CounterJNI.h"
#include "HAL/Digital.hpp"
#include "HAL/Errors.hpp"
#include "HALUtil.h"
// set the logging level
TLogLevel counterJNILogLevel = logWARNING;
@@ -13,446 +15,412 @@ TLogLevel counterJNILogLevel = logWARNING;
if (level > counterJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: initializeCounter
* Signature: (ILjava/nio/IntBuffer;Ljava/nio/IntBuffer;)Ljava/nio/ByteBuffer;
* Signature: (ILjava/nio/IntBuffer;)J
*/
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_initializeCounter
(JNIEnv * env, jclass, jint mode, jobject index, jobject status)
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_initializeCounter
(JNIEnv * env, jclass, jint mode, jobject index)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI initializeCounter";
COUNTERJNI_LOG(logDEBUG) << "Mode = " << mode;
jint * indexPtr = (jint*)env->GetDirectBufferAddress(index);
COUNTERJNI_LOG(logDEBUG) << "Index Ptr = " << indexPtr;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
void** counterPtr = (void**)new unsigned char[4];
*statusPtr = 0;
*counterPtr = initializeCounter((Mode)mode, (uint32_t*)indexPtr, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Index Ptr = " << (uint32_t*)indexPtr;
int32_t status = 0;
void* counter = initializeCounter((Mode)mode, (uint32_t*)indexPtr, &status);
COUNTERJNI_LOG(logDEBUG) << "Index = " << *indexPtr;
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
COUNTERJNI_LOG(logDEBUG) << "COUNTER Ptr = " << *counterPtr;
return env->NewDirectByteBuffer( counterPtr, 4);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
COUNTERJNI_LOG(logDEBUG) << "COUNTER Ptr = " << counter;
CheckStatus(env, status);
return (jlong)counter;
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: freeCounter
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_freeCounter
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI freeCounter";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
freeCounter(*javaId, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
int32_t status = 0;
freeCounter((void*)id, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterAverageSize
* Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterAverageSize
(JNIEnv * env, jclass, jobject id, jint value, jobject status)
(JNIEnv * env, jclass, jlong id, jint value)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterAverageSize";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "AverageSize = " << value;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setCounterAverageSize(*javaId, value, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setCounterAverageSize((void*)id, value, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterUpSource
* Signature: (Ljava/nio/ByteBuffer;BIBLjava/nio/IntBuffer;)V
* Signature: (JIZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpSource
(JNIEnv * env, jclass, jobject id, jint pin, jbyte analogTrigger, jobject status)
(JNIEnv * env, jclass, jlong id, jint pin, jboolean analogTrigger)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterUpSource";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Pin = " << pin;
COUNTERJNI_LOG(logDEBUG) << "AnalogTrigger = " << (jint)analogTrigger;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setCounterUpSource(*javaId, pin, analogTrigger, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setCounterUpSource((void*)id, pin, analogTrigger, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterUpSourceEdge
* Signature: (Ljava/nio/ByteBuffer;BBLjava/nio/IntBuffer;)V
* Signature: (JZZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpSourceEdge
(JNIEnv * env, jclass, jobject id, jbyte valueRise, jbyte valueFall, jobject status)
(JNIEnv * env, jclass, jlong id, jboolean valueRise, jboolean valueFall)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterUpSourceEdge";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Rise = " << (jint)valueRise;
COUNTERJNI_LOG(logDEBUG) << "Fall = " << (jint)valueFall;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setCounterUpSourceEdge(*javaId, valueRise, valueFall, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setCounterUpSourceEdge((void*)id, valueRise, valueFall, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: clearCounterUpSource
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_clearCounterUpSource
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI clearCounterUpSource";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
clearCounterUpSource(*javaId, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
int32_t status = 0;
clearCounterUpSource((void*)id, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterDownSource
* Signature: (Ljava/nio/ByteBuffer;BIBLjava/nio/IntBuffer;)V
* Signature: (JIZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterDownSource
(JNIEnv * env, jclass, jobject id, jint pin, jbyte analogTrigger, jobject status)
(JNIEnv * env, jclass, jlong id, jint pin, jboolean analogTrigger)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterDownSource";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Pin = " << pin;
COUNTERJNI_LOG(logDEBUG) << "AnalogTrigger = " << (jint)analogTrigger;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setCounterDownSource(*javaId, pin, analogTrigger, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setCounterDownSource((void*)id, pin, analogTrigger, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
if (status == PARAMETER_OUT_OF_RANGE) {
ThrowIllegalArgumentException(env, "Counter only supports DownSource in TwoPulse and ExternalDirection modes.");
return;
}
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterDownSourceEdge
* Signature: (Ljava/nio/ByteBuffer;BBLjava/nio/IntBuffer;)V
* Signature: (JZZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterDownSourceEdge
(JNIEnv * env, jclass, jobject id, jbyte valueRise, jbyte valueFall, jobject status)
(JNIEnv * env, jclass, jlong id, jboolean valueRise, jboolean valueFall)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterDownSourceEdge";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Rise = " << (jint)valueRise;
COUNTERJNI_LOG(logDEBUG) << "Fall = " << (jint)valueFall;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setCounterDownSourceEdge(*javaId, valueRise, valueFall, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setCounterDownSourceEdge((void*)id, valueRise, valueFall, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: clearCounterDownSource
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_clearCounterDownSource
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI clearCounterDownSource";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
clearCounterDownSource(*javaId, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
int32_t status = 0;
clearCounterDownSource((void*)id, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterUpDownMode
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpDownMode
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterUpDownMode";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setCounterUpDownMode(*javaId, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
int32_t status = 0;
setCounterUpDownMode((void*)id, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterExternalDirectionMode
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterExternalDirectionMode
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterExternalDirectionMode";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setCounterExternalDirectionMode(*javaId, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
int32_t status = 0;
setCounterExternalDirectionMode((void*)id, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterSemiPeriodMode
* Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)V
* Signature: (JZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterSemiPeriodMode
(JNIEnv * env, jclass, jobject id, jbyte value, jobject status)
(JNIEnv * env, jclass, jlong id, jboolean value)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterSemiPeriodMode";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "SemiPeriodMode = " << (jint)value;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setCounterSemiPeriodMode(*javaId, value, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setCounterSemiPeriodMode((void*)id, value, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterPulseLengthMode
* Signature: (Ljava/nio/ByteBuffer;DLjava/nio/IntBuffer;)V
* Signature: (JD)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterPulseLengthMode
(JNIEnv * env, jclass, jobject id, jdouble value, jobject status)
(JNIEnv * env, jclass, jlong id, jdouble value)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterPulseLengthMode";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "PulseLengthMode = " << value;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setCounterPulseLengthMode(*javaId, value, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setCounterPulseLengthMode((void*)id, value, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: getCounterSamplesToAverage
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterSamplesToAverage
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI getCounterSamplesToAverage";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
jint returnValue = getCounterSamplesToAverage(*javaId, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
int32_t status = 0;
jint returnValue = getCounterSamplesToAverage((void*)id, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
COUNTERJNI_LOG(logDEBUG) << "getCounterSamplesToAverageResult = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterSamplesToAverage
* Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterSamplesToAverage
(JNIEnv * env, jclass, jobject id, jint value, jobject status)
(JNIEnv * env, jclass, jlong id, jint value)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterSamplesToAverage";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "SamplesToAverage = " << value;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setCounterSamplesToAverage(*javaId, value, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setCounterSamplesToAverage((void*)id, value, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
if (status == PARAMETER_OUT_OF_RANGE) {
ThrowBoundaryException(env, value, 1, 127);
return;
}
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: resetCounter
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_resetCounter
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI resetCounter";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
resetCounter(*javaId, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
int32_t status = 0;
resetCounter((void*)id, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: getCounter
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounter
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
//COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI getCounter";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
//COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
//COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
jint returnValue = getCounter(*javaId, statusPtr);
//COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
//COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
int32_t status = 0;
jint returnValue = getCounter((void*)id, &status);
//COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
//COUNTERJNI_LOG(logDEBUG) << "getCounterResult = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: getCounterPeriod
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)D
* Signature: (J)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterPeriod
(JNIEnv *env, jclass, jobject id, jobject status)
(JNIEnv *env, jclass, jlong id)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI getCounterPeriod";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
jdouble returnValue = getCounterPeriod(*javaId, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
int32_t status = 0;
jdouble returnValue = getCounterPeriod((void*)id, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
COUNTERJNI_LOG(logDEBUG) << "getCounterPeriodResult = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterMaxPeriod
* Signature: (Ljava/nio/ByteBuffer;DLjava/nio/IntBuffer;)V
* Signature: (JD)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterMaxPeriod
(JNIEnv * env, jclass, jobject id, jdouble value, jobject status)
(JNIEnv * env, jclass, jlong id, jdouble value)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterMaxPeriod";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "MaxPeriod = " << value;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setCounterMaxPeriod(*javaId, value, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setCounterMaxPeriod((void*)id, value, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterUpdateWhenEmpty
* Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)V
* Signature: (JZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpdateWhenEmpty
(JNIEnv * env, jclass, jobject id, jbyte value, jobject status)
(JNIEnv * env, jclass, jlong id, jboolean value)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterMaxPeriod";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "UpdateWhenEmpty = " << (jint)value;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setCounterUpdateWhenEmpty(*javaId, value, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setCounterUpdateWhenEmpty((void*)id, value, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: getCounterStopped
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B
* Signature: (J)Z
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterStopped
(JNIEnv * env, jclass, jobject id, jobject status)
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterStopped
(JNIEnv * env, jclass, jlong id)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI getCounterStopped";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
jbyte returnValue = getCounterStopped(*javaId, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
int32_t status = 0;
jboolean returnValue = getCounterStopped((void*)id, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
COUNTERJNI_LOG(logDEBUG) << "getCounterStoppedResult = " << (jint)returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: getCounterDirection
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B
* Signature: (J)Z
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterDirection
(JNIEnv * env, jclass, jobject id, jobject status)
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterDirection
(JNIEnv * env, jclass, jlong id)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI getCounterDirection";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
jbyte returnValue = getCounterDirection(*javaId, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
int32_t status = 0;
jboolean returnValue = getCounterDirection((void*)id, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
COUNTERJNI_LOG(logDEBUG) << "getCounterDirectionResult = " << (jint)returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: setCounterReverseDirection
* Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)V
* Signature: (JZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterReverseDirection
(JNIEnv * env, jclass, jobject id, jbyte value, jobject status)
(JNIEnv * env, jclass, jlong id, jboolean value)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterReverseDirection";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId;
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "ReverseDirection = " << (jint)value;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setCounterReverseDirection(*javaId, value, statusPtr);
COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setCounterReverseDirection((void*)id, value, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
} // extern "C"

View File

@@ -5,6 +5,7 @@
#include "edu_wpi_first_wpilibj_hal_DIOJNI.h"
#include "HAL/Digital.hpp"
#include "HALUtil.h"
// set the logging level
TLogLevel dioJNILogLevel = logWARNING;
@@ -13,101 +14,92 @@ TLogLevel dioJNILogLevel = logWARNING;
if (level > dioJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_DIOJNI
* Method: initializeDigitalPort
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Ljava/nio/ByteBuffer;
* Signature: (J)J;
*/
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_initializeDigitalPort
(JNIEnv * env, jclass, jobject id, jobject status)
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_initializeDigitalPort
(JNIEnv * env, jclass, jlong id)
{
DIOJNI_LOG(logDEBUG) << "Calling DIOJNI initializeDigitalPort";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
DIOJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
DIOJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
void** dioPtr = (void**)new unsigned char[4];
*statusPtr = 0;
*dioPtr = initializeDigitalPort(*javaId, statusPtr);
DIOJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
DIOJNI_LOG(logDEBUG) << "DIO Ptr = " << *dioPtr;
return env->NewDirectByteBuffer( dioPtr, 4);
DIOJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
int32_t status = 0;
void* dio = initializeDigitalPort((void*)id, &status);
DIOJNI_LOG(logDEBUG) << "Status = " << status;
DIOJNI_LOG(logDEBUG) << "DIO Ptr = " << dio;
CheckStatus(env, status);
return (jlong)dio;
}
/*
* Class: edu_wpi_first_wpilibj_hal_DIOJNI
* Method: allocateDIO
* Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)B
* Signature: (JZ)Z
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_allocateDIO
(JNIEnv * env, jclass, jobject id, jbyte value, jobject status)
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_allocateDIO
(JNIEnv * env, jclass, jlong id, jboolean value)
{
DIOJNI_LOG(logDEBUG) << "Calling DIOJNI allocateDIO";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
DIOJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
DIOJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
jbyte returnValue = allocateDIO(*javaId, value, statusPtr);
DIOJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
DIOJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
int32_t status = 0;
jboolean returnValue = allocateDIO((void*)id, value, &status);
DIOJNI_LOG(logDEBUG) << "Status = " << status;
DIOJNI_LOG(logDEBUG) << "allocateDIOResult = " << (jint)returnValue;
return returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_DIOJNI
* Method: freeDIO
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_freeDIO
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
DIOJNI_LOG(logDEBUG) << "Calling DIOJNI freeDIO";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
DIOJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
DIOJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
freeDIO(*javaId, statusPtr);
DIOJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
DIOJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
int32_t status = 0;
freeDIO((void*)id, &status);
DIOJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_DIOJNI
* Method: setDIO
* Signature: (Ljava/nio/ByteBuffer;SLjava/nio/IntBuffer;)V
* Signature: (JS)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_setDIO
(JNIEnv *env, jclass, jobject id, jshort value, jobject status)
(JNIEnv *env, jclass, jlong id, jshort value)
{
//DIOJNI_LOG(logDEBUG) << "Calling DIOJNI setDIO";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
//DIOJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId;
//DIOJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
//DIOJNI_LOG(logDEBUG) << "Value = " << value;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
//DIOJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setDIO(*javaId, value, statusPtr);
//DIOJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setDIO((void*)id, value, &status);
//DIOJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_DIOJNI
* Method: getDIO
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B
* Signature: (J)Z
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_getDIO
(JNIEnv * env, jclass, jobject id, jobject status)
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_getDIO
(JNIEnv * env, jclass, jlong id)
{
//DIOJNI_LOG(logDEBUG) << "Calling DIOJNI getDIO";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
//DIOJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
//DIOJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
jbyte returnValue = getDIO(*javaId, statusPtr);
//DIOJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
//DIOJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
int32_t status = 0;
jboolean returnValue = getDIO((void*)id, &status);
//DIOJNI_LOG(logDEBUG) << "Status = " << status;
//DIOJNI_LOG(logDEBUG) << "getDIOResult = " << (jint)returnValue;
CheckStatus(env, status);
return returnValue;
}
@@ -115,59 +107,53 @@ JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_getDIO
/*
* Class: edu_wpi_first_wpilibj_hal_DIOJNI
* Method: getDIODirection
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B
* Signature: (J)Z
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_getDIODirection
(JNIEnv *env, jclass, jobject id, jobject status)
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_getDIODirection
(JNIEnv *env, jclass, jlong id)
{
DIOJNI_LOG(logDEBUG) << "Calling DIOJNI getDIODirection (RR upd)";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
//DIOJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
//DIOJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
jbyte returnValue = getDIODirection(*javaId, statusPtr);
//DIOJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
DIOJNI_LOG(logDEBUG) << "getDIODirectionResult = " << (jbyte)returnValue;
//DIOJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
int32_t status = 0;
jboolean returnValue = getDIODirection((void*)id, &status);
//DIOJNI_LOG(logDEBUG) << "Status = " << status;
DIOJNI_LOG(logDEBUG) << "getDIODirectionResult = " << (jint)returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_DIOJNI
* Method: pulse
* Signature: (Ljava/nio/ByteBuffer;DLjava/nio/IntBuffer;)V
* Signature: (JD)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_pulse
(JNIEnv *env, jclass, jobject id, jdouble value, jobject status)
(JNIEnv *env, jclass, jlong id, jdouble value)
{
DIOJNI_LOG(logDEBUG) << "Calling DIOJNI pulse (RR upd)";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
//DIOJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId;
//DIOJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
//DIOJNI_LOG(logDEBUG) << "Value = " << value;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
//DIOJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
pulse(*javaId, value, statusPtr);
DIOJNI_LOG(logDEBUG) << "Did it work? Status = " << *statusPtr;
int32_t status = 0;
pulse((void*)id, value, &status);
DIOJNI_LOG(logDEBUG) << "Did it work? Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_DIOJNI
* Method: isPulsing
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B
* Signature: (J)Z
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_isPulsing
(JNIEnv *env, jclass, jobject id, jobject status)
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_isPulsing
(JNIEnv *env, jclass, jlong id)
{
DIOJNI_LOG(logDEBUG) << "Calling DIOJNI isPulsing (RR upd)";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
//DIOJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
//DIOJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
jbyte returnValue = isPulsing(*javaId, statusPtr);
//DIOJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
DIOJNI_LOG(logDEBUG) << "isPulsingResult = " << (jbyte)returnValue;
//DIOJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
int32_t status = 0;
jboolean returnValue = isPulsing((void*)id, &status);
//DIOJNI_LOG(logDEBUG) << "Status = " << status;
DIOJNI_LOG(logDEBUG) << "isPulsingResult = " << (jint)returnValue;
CheckStatus(env, status);
return returnValue;
@@ -176,34 +162,36 @@ JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_isPulsing
/*
* Class: edu_wpi_first_wpilibj_hal_DIOJNI
* Method: isAnyPulsing
* Signature: (Ljava/nio/IntBuffer;)B
* Signature: ()Z
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_isAnyPulsing
(JNIEnv *env, jclass, jobject status)
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_isAnyPulsing
(JNIEnv *env, jclass)
{
DIOJNI_LOG(logDEBUG) << "Calling DIOJNI isAnyPulsing (RR upd)";
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
jbyte returnValue = isAnyPulsing( statusPtr );
//DIOJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
DIOJNI_LOG(logDEBUG) << "isAnyPulsingResult = " << (jbyte)returnValue;
int32_t status = 0;
jboolean returnValue = isAnyPulsing( &status );
//DIOJNI_LOG(logDEBUG) << "Status = " << status;
DIOJNI_LOG(logDEBUG) << "isAnyPulsingResult = " << (jint)returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_DIOJNI
* Method: getLoopTiming
* Signature: (Ljava/nio/IntBuffer;)S
* Signature: ()S
*/
JNIEXPORT jshort JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_getLoopTiming
(JNIEnv * env, jclass, jobject status)
(JNIEnv * env, jclass)
{
DIOJNI_LOG(logDEBUG) << "Calling DIOJNI getLoopTimeing";
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
jshort returnValue = getLoopTiming( statusPtr );
DIOJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
jshort returnValue = getLoopTiming( &status );
DIOJNI_LOG(logDEBUG) << "Status = " << status;
DIOJNI_LOG(logDEBUG) << "LoopTiming = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
} // extern "C"

View File

@@ -5,6 +5,8 @@
#include "edu_wpi_first_wpilibj_hal_EncoderJNI.h"
#include "HAL/Digital.hpp"
#include "HAL/Errors.hpp"
#include "HALUtil.h"
// set the logging level
TLogLevel encoderJNILogLevel = logWARNING;
@@ -13,13 +15,15 @@ TLogLevel encoderJNILogLevel = logWARNING;
if (level > encoderJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_EncoderJNI
* Method: initializeEncoder
* Signature: (BIBBIBBLjava/nio/IntBuffer;Ljava/nio/IntBuffer;)Ljava/nio/ByteBuffer;
* Signature: (BIZBIZZLjava/nio/IntBuffer;)J
*/
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_initializeEncoder
(JNIEnv * env, jclass, jbyte port_a_module, jint port_a_pin, jbyte port_a_analog_trigger, jbyte port_b_module, jint port_b_pin, jbyte port_b_analog_trigger, jbyte reverseDirection, jobject index, jobject status)
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_initializeEncoder
(JNIEnv * env, jclass, jbyte port_a_module, jint port_a_pin, jboolean port_a_analog_trigger, jbyte port_b_module, jint port_b_pin, jboolean port_b_analog_trigger, jboolean reverseDirection, jobject index)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI initializeEncoder";
ENCODERJNI_LOG(logDEBUG) << "Module A = " << (jint)port_a_module;
@@ -31,228 +35,210 @@ JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_initializeEn
ENCODERJNI_LOG(logDEBUG) << "Reverse direction = " << (jint)reverseDirection;
jint * indexPtr = (jint*)env->GetDirectBufferAddress(index);
ENCODERJNI_LOG(logDEBUG) << "Index Ptr = " << indexPtr;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
void** encoderPtr = (void**)new unsigned char[4];
*statusPtr = 0;
*encoderPtr = initializeEncoder(port_a_module, port_a_pin, port_a_analog_trigger,
int32_t status = 0;
void* encoder = initializeEncoder(port_a_module, port_a_pin, port_a_analog_trigger,
port_b_module, port_b_pin, port_b_analog_trigger,
reverseDirection, indexPtr, statusPtr);
reverseDirection, indexPtr, &status);
ENCODERJNI_LOG(logDEBUG) << "Index = " << *indexPtr;
ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ENCODERJNI_LOG(logDEBUG) << "ENCODER Ptr = " << *encoderPtr;
return env->NewDirectByteBuffer( encoderPtr, 4);
ENCODERJNI_LOG(logDEBUG) << "Status = " << status;
ENCODERJNI_LOG(logDEBUG) << "ENCODER Ptr = " << encoder;
CheckStatus(env, status);
return (jlong)encoder;
}
/*
* Class: edu_wpi_first_wpilibj_hal_EncoderJNI
* Method: freeEncoder
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_freeEncoder
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI freeEncoder";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
freeEncoder(*javaId, statusPtr);
ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id;
int32_t status = 0;
freeEncoder((void*)id, &status);
ENCODERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_EncoderJNI
* Method: resetEncoder
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_resetEncoder
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI resetEncoder";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
resetEncoder(*javaId, statusPtr);
ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id;
int32_t status = 0;
resetEncoder((void*)id, &status);
ENCODERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_EncoderJNI
* Method: getEncoder
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_getEncoder
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI getEncoder";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
jint returnValue = getEncoder(*javaId, statusPtr);
ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id;
int32_t status = 0;
jint returnValue = getEncoder((void*)id, &status);
ENCODERJNI_LOG(logDEBUG) << "Status = " << status;
ENCODERJNI_LOG(logDEBUG) << "getEncoderResult = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_EncoderJNI
* Method: getEncoderPeriod
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)D
* Signature: (J)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_getEncoderPeriod
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI getEncoderPeriod";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
double returnValue = getEncoderPeriod(*javaId, statusPtr);
ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id;
int32_t status = 0;
double returnValue = getEncoderPeriod((void*)id, &status);
ENCODERJNI_LOG(logDEBUG) << "Status = " << status;
ENCODERJNI_LOG(logDEBUG) << "getEncoderPeriodResult = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_EncoderJNI
* Method: setEncoderMaxPeriod
* Signature: (Ljava/nio/ByteBuffer;DLjava/nio/IntBuffer;)V
* Signature: (JD)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_setEncoderMaxPeriod
(JNIEnv * env, jclass, jobject id, jdouble value, jobject status)
(JNIEnv * env, jclass, jlong id, jdouble value)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI setEncoderMaxPeriod";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setEncoderMaxPeriod(*javaId, value, statusPtr);
ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id;
int32_t status = 0;
setEncoderMaxPeriod((void*)id, value, &status);
ENCODERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_EncoderJNI
* Method: getEncoderStopped
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B
* Signature: (J)Z
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_getEncoderStopped
(JNIEnv * env, jclass, jobject id, jobject status)
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_getEncoderStopped
(JNIEnv * env, jclass, jlong id)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI getEncoderStopped";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
jbyte returnValue = getEncoderStopped(*javaId, statusPtr);
ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id;
int32_t status = 0;
jboolean returnValue = getEncoderStopped((void*)id, &status);
ENCODERJNI_LOG(logDEBUG) << "Status = " << status;
ENCODERJNI_LOG(logDEBUG) << "getEncoderStoppedResult = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_EncoderJNI
* Method: getEncoderDirection
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B
* Signature: (J)Z
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_getEncoderDirection
(JNIEnv * env, jclass, jobject id, jobject status)
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_getEncoderDirection
(JNIEnv * env, jclass, jlong id)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI getEncoderDirection";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
jbyte returnValue = getEncoderDirection(*javaId, statusPtr);
ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id;
int32_t status = 0;
jboolean returnValue = getEncoderDirection((void*)id, &status);
ENCODERJNI_LOG(logDEBUG) << "Status = " << status;
ENCODERJNI_LOG(logDEBUG) << "getEncoderDirectionResult = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_EncoderJNI
* Method: setEncoderReverseDirection
* Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)V
* Signature: (JZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_setEncoderReverseDirection
(JNIEnv * env, jclass, jobject id, jbyte value, jobject status)
(JNIEnv * env, jclass, jlong id, jboolean value)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI setEncoderReverseDirection";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setEncoderReverseDirection(*javaId, value, statusPtr);
ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id;
int32_t status = 0;
setEncoderReverseDirection((void*)id, value, &status);
ENCODERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_EncoderJNI
* Method: setEncoderSamplesToAverage
* Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_setEncoderSamplesToAverage
(JNIEnv * env, jclass, jobject id, jint value, jobject status)
(JNIEnv * env, jclass, jlong id, jint value)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI setEncoderSamplesToAverage";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setEncoderSamplesToAverage(*javaId, value, statusPtr);
ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id;
int32_t status = 0;
setEncoderSamplesToAverage((void*)id, value, &status);
ENCODERJNI_LOG(logDEBUG) << "Status = " << status;
if (status == PARAMETER_OUT_OF_RANGE) {
ThrowBoundaryException(env, value, 1, 127);
return;
}
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_EncoderJNI
* Method: getEncoderSamplesToAverage
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_getEncoderSamplesToAverage
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI getEncoderSamplesToAverage";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
jint returnValue = getEncoderSamplesToAverage(*javaId, statusPtr);
ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id;
int32_t status = 0;
jint returnValue = getEncoderSamplesToAverage((void*)id, &status);
ENCODERJNI_LOG(logDEBUG) << "Status = " << status;
ENCODERJNI_LOG(logDEBUG) << "getEncoderSamplesToAverageResult = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_EncoderJNI
* Method: setEncoderIndexSource
* Signature: (Ljava/nio/ByteBuffer;IZZZLjava/nio/IntBuffer;)V
* Signature: (JIZZZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_setEncoderIndexSource
(JNIEnv * env, jclass, jobject id, jint pin, jboolean analogTrigger, jboolean activeHigh, jboolean edgeSensitive, jobject status)
(JNIEnv * env, jclass, jlong id, jint pin, jboolean analogTrigger, jboolean activeHigh, jboolean edgeSensitive)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI setEncoderIndexSource";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id;
ENCODERJNI_LOG(logDEBUG) << "Pin = " << pin;
ENCODERJNI_LOG(logDEBUG) << "Analog Trigger = " << (analogTrigger?"true":"false");
ENCODERJNI_LOG(logDEBUG) << "Active High = " << (activeHigh?"true":"false");
ENCODERJNI_LOG(logDEBUG) << "Edge Sensitive = " << (edgeSensitive?"true":"false");
ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setEncoderIndexSource(*javaId, pin, analogTrigger, activeHigh, edgeSensitive, statusPtr);
ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setEncoderIndexSource((void*)id, pin, analogTrigger, activeHigh, edgeSensitive, &status);
ENCODERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
} // extern "C"

View File

@@ -6,6 +6,7 @@
#include "HAL/HAL.hpp"
//#include "NetworkCommunication/FRCComm.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "HALUtil.h"
// set the logging level
TLogLevel netCommLogLevel = logWARNING;
@@ -14,7 +15,7 @@ TLogLevel netCommLogLevel = logWARNING;
if (level > netCommLogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
@@ -394,14 +395,13 @@ JNIEXPORT jstring JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCom
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: setNewDataSem
* Signature: ([B)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_setNewDataSem
(JNIEnv * env, jclass, jobject id )
(JNIEnv * env, jclass, jlong id )
{
MULTIWAIT_ID javaId = (MULTIWAIT_ID)env->GetDirectBufferAddress(id);
NETCOMM_LOG(logDEBUG) << "Mutex Ptr = " << javaId;
HALSetNewDataSem(javaId->native_handle());
NETCOMM_LOG(logDEBUG) << "Mutex Ptr = " << (void*)id;
HALSetNewDataSem(((MULTIWAIT_ID)id)->native_handle());
}
/*
@@ -609,27 +609,29 @@ JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkComm
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: HALGetSystemActive
* Signature: (Ljava/nio/IntBuffer;)Z
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetSystemActive
(JNIEnv * env, jclass, jobject status)
(JNIEnv * env, jclass)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
return HALGetSystemActive((int32_t*)statusPtr);
int32_t status = 0;
bool val = HALGetSystemActive(&status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: HALGetBrownedOut
* Signature: (Ljava/nio/IntBuffer;)Z
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetBrownedOut
(JNIEnv * env, jclass, jobject status)
(JNIEnv * env, jclass)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
return HALGetBrownedOut((int32_t*)statusPtr);
int32_t status = 0;
bool val = HALGetBrownedOut(&status);
CheckStatus(env, status);
return val;
}
/*
@@ -650,3 +652,4 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommun
return returnValue;
}
} // extern "C"

View File

@@ -1,10 +1,13 @@
#include "HALUtil.h"
#include <jni.h>
#include <assert.h>
#include "Log.hpp"
#include "edu_wpi_first_wpilibj_hal_HALUtil.h"
#include "FRC_NetworkCommunication/CANSessionMux.h"
#include "HAL/HAL.hpp"
#include "errno.h"
#include <string.h>
#include <string>
// set the logging level
TLogLevel halUtilLogLevel = logWARNING;
@@ -13,174 +16,430 @@ TLogLevel halUtilLogLevel = logWARNING;
if (level > halUtilLogLevel) ; \
else Log().Get(level)
#define kRioStatusOffset -63000
#define kRioStatusSuccess 0
#define kRIOStatusBufferInvalidSize (kRioStatusOffset - 80)
#define kRIOStatusOperationTimedOut -52007
#define kRIOStatusFeatureNotSupported (kRioStatusOffset - 193)
#define kRIOStatusResourceNotInitialized -52010
JavaVM *jvm = nullptr;
static jclass throwableCls = nullptr;
static jclass stackTraceElementCls = nullptr;
static jclass runtimeExCls = nullptr;
static jclass illegalArgExCls = nullptr;
static jclass boundaryExCls = nullptr;
static jclass canInvalidBufferExCls = nullptr;
static jclass canMessageNotFoundExCls = nullptr;
static jclass canMessageNotAllowedExCls = nullptr;
static jclass canNotInitializedExCls = nullptr;
static jclass uncleanStatusExCls = nullptr;
static void GetStackTrace(JNIEnv *env, std::string& res) {
// create a throwable
static jmethodID constructorId = nullptr;
if (!constructorId)
constructorId = env->GetMethodID(throwableCls, "<init>", "()V");
jobject throwable = env->NewObject(throwableCls, constructorId);
// retrieve information from the exception.
// get method id
// getStackTrace returns an array of StackTraceElement
static jmethodID getStackTraceId = nullptr;
if (!getStackTraceId)
getStackTraceId = env->GetMethodID(throwableCls, "getStackTrace",
"()[Ljava/lang/StackTraceElement;");
// call getStackTrace
jobjectArray stackTrace =
(jobjectArray)env->CallObjectMethod(throwable, getStackTraceId);
if (!stackTrace) return;
// get length of the array
jsize stackTraceLength = env->GetArrayLength(stackTrace);
// get toString methodId of StackTraceElement class
static jmethodID toStringId = nullptr;
if (!toStringId)
toStringId = env->GetMethodID(stackTraceElementCls, "toString",
"()Ljava/lang/String;");
for (jsize i = 0; i < stackTraceLength; i++) {
// add the result of toString method of each element in the result
jobject curStackTraceElement = env->GetObjectArrayElement(stackTrace, i);
// call to string on the object
jstring stackElementString =
(jstring)env->CallObjectMethod(curStackTraceElement, toStringId);
if (!stackElementString) {
env->DeleteLocalRef(stackTrace);
env->DeleteLocalRef(curStackTraceElement);
return;
}
// add a line to res
//res += " at ";
const char *tmp = env->GetStringUTFChars(stackElementString, nullptr);
res += tmp;
res += '\n';
env->ReleaseStringUTFChars(stackElementString, tmp);
env->DeleteLocalRef(curStackTraceElement);
env->DeleteLocalRef(stackElementString);
}
// release java resources
env->DeleteLocalRef(stackTrace);
}
void ReportError(JNIEnv *env, int32_t status, bool do_throw) {
if (status == 0) return;
const char *message = getHALErrorMessage(status);
if (do_throw && status < 0) {
char *buf = new char[strlen(message) + 30];
sprintf(buf, " Code: %d. %s", status, message);
env->ThrowNew(runtimeExCls, buf);
delete[] buf;
} else {
std::string fullmsg = message;
fullmsg += " at ";
GetStackTrace(env, fullmsg);
fprintf(stderr, "%s\n", fullmsg.c_str());
HALControlWord controlWord;
HALGetControlWord(&controlWord);
if (controlWord.dsAttached)
HALSetErrorData(fullmsg.c_str(), fullmsg.size(), 0);
}
}
void ReportCANError(JNIEnv *env, int32_t status, int message_id) {
if (status >= 0) return;
switch (status) {
case kRioStatusSuccess:
// Everything is ok... don't throw.
break;
case ERR_CANSessionMux_InvalidBuffer:
case kRIOStatusBufferInvalidSize: {
static jmethodID invalidBufConstruct = nullptr;
if (!invalidBufConstruct)
invalidBufConstruct =
env->GetMethodID(canInvalidBufferExCls, "<init>", "()V");
jobject exception =
env->NewObject(canInvalidBufferExCls, invalidBufConstruct);
env->Throw(static_cast<jthrowable>(exception));
break;
}
case ERR_CANSessionMux_MessageNotFound:
case kRIOStatusOperationTimedOut: {
static jmethodID messageNotFoundConstruct = nullptr;
if (!messageNotFoundConstruct)
messageNotFoundConstruct =
env->GetMethodID(canMessageNotFoundExCls, "<init>", "()V");
jobject exception =
env->NewObject(canMessageNotFoundExCls, messageNotFoundConstruct);
env->Throw(static_cast<jthrowable>(exception));
break;
}
case ERR_CANSessionMux_NotAllowed:
case kRIOStatusFeatureNotSupported: {
char buf[100];
sprintf(buf, "MessageID = %d", message_id);
env->ThrowNew(canMessageNotAllowedExCls, buf);
break;
}
case ERR_CANSessionMux_NotInitialized:
case kRIOStatusResourceNotInitialized: {
static jmethodID notInitConstruct = nullptr;
if (!notInitConstruct)
notInitConstruct =
env->GetMethodID(canNotInitializedExCls, "<init>", "()V");
jobject exception =
env->NewObject(canNotInitializedExCls, notInitConstruct);
env->Throw(static_cast<jthrowable>(exception));
break;
}
default: {
char buf[100];
sprintf(buf, "Fatal status code detected: %d", status);
env->ThrowNew(uncleanStatusExCls, buf);
break;
}
}
}
void ThrowIllegalArgumentException(JNIEnv *env, const char *msg) {
env->ThrowNew(illegalArgExCls, msg);
}
void ThrowBoundaryException(JNIEnv *env, double value, double lower,
double upper) {
static jmethodID getMessage = nullptr;
if (!getMessage)
getMessage = env->GetStaticMethodID(boundaryExCls, "getMessage",
"(DDD)Ljava/lang/String;");
static jmethodID constructor = nullptr;
if (!constructor)
constructor =
env->GetMethodID(boundaryExCls, "<init>", "(Ljava/lang/String;)V");
jobject msg =
env->CallStaticObjectMethod(boundaryExCls, getMessage, (jdouble)value,
(jdouble)lower, (jdouble)upper);
jobject ex = env->NewObject(boundaryExCls, constructor, msg);
env->Throw(static_cast<jthrowable>(ex));
}
extern "C" {
//
// indicate JNI version support desired
// indicate JNI version support desired and load classes
//
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
{
jvm = vm;
// set our logging level
Log::ReportingLevel() = logDEBUG;
JNIEnv *env;
if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK)
return JNI_ERR;
// Cache references to classes
jclass local;
local = env->FindClass("java/lang/Throwable");
if (!local) return JNI_ERR;
throwableCls = static_cast<jclass>(env->NewGlobalRef(local));
if (!throwableCls) return JNI_ERR;
env->DeleteLocalRef(local);
local = env->FindClass("java/lang/StackTraceElement");
if (!local) return JNI_ERR;
stackTraceElementCls = static_cast<jclass>(env->NewGlobalRef(local));
if (!stackTraceElementCls) return JNI_ERR;
env->DeleteLocalRef(local);
local = env->FindClass("java/lang/RuntimeException");
if (!local) return JNI_ERR;
runtimeExCls = static_cast<jclass>(env->NewGlobalRef(local));
if (!runtimeExCls) return JNI_ERR;
env->DeleteLocalRef(local);
local = env->FindClass("java/lang/IllegalArgumentException");
if (!local) return JNI_ERR;
illegalArgExCls = static_cast<jclass>(env->NewGlobalRef(local));
if (!illegalArgExCls) return JNI_ERR;
env->DeleteLocalRef(local);
local = env->FindClass("edu/wpi/first/wpilibj/util/BoundaryException");
if (!local) return JNI_ERR;
boundaryExCls = static_cast<jclass>(env->NewGlobalRef(local));
if (!boundaryExCls) return JNI_ERR;
env->DeleteLocalRef(local);
local = env->FindClass("edu/wpi/first/wpilibj/can/CANInvalidBufferException");
if (!local) return JNI_ERR;
canInvalidBufferExCls = static_cast<jclass>(env->NewGlobalRef(local));
if (!canInvalidBufferExCls) return JNI_ERR;
env->DeleteLocalRef(local);
local =
env->FindClass("edu/wpi/first/wpilibj/can/CANMessageNotFoundException");
if (!local) return JNI_ERR;
canMessageNotFoundExCls = static_cast<jclass>(env->NewGlobalRef(local));
if (!canMessageNotFoundExCls) return JNI_ERR;
env->DeleteLocalRef(local);
local =
env->FindClass("edu/wpi/first/wpilibj/can/CANMessageNotAllowedException");
if (!local) return JNI_ERR;
canMessageNotAllowedExCls = static_cast<jclass>(env->NewGlobalRef(local));
if (!canMessageNotAllowedExCls) return JNI_ERR;
env->DeleteLocalRef(local);
local =
env->FindClass("edu/wpi/first/wpilibj/can/CANNotInitializedException");
if (!local) return JNI_ERR;
canNotInitializedExCls = static_cast<jclass>(env->NewGlobalRef(local));
if (!canNotInitializedExCls) return JNI_ERR;
env->DeleteLocalRef(local);
local = env->FindClass("edu/wpi/first/wpilibj/util/UncleanStatusException");
if (!local) return JNI_ERR;
uncleanStatusExCls = static_cast<jclass>(env->NewGlobalRef(local));
if (!uncleanStatusExCls) return JNI_ERR;
env->DeleteLocalRef(local);
return JNI_VERSION_1_6;
}
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
{
JNIEnv *env;
if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK)
return;
// Delete global references
if (throwableCls) env->DeleteGlobalRef(throwableCls);
if (stackTraceElementCls) env->DeleteGlobalRef(stackTraceElementCls);
if (runtimeExCls) env->DeleteGlobalRef(runtimeExCls);
if (illegalArgExCls) env->DeleteGlobalRef(illegalArgExCls);
if (boundaryExCls) env->DeleteGlobalRef(boundaryExCls);
if (canInvalidBufferExCls) env->DeleteGlobalRef(canInvalidBufferExCls);
if (canMessageNotFoundExCls) env->DeleteGlobalRef(canMessageNotFoundExCls);
if (canMessageNotAllowedExCls) env->DeleteGlobalRef(canMessageNotAllowedExCls);
if (canNotInitializedExCls) env->DeleteGlobalRef(canNotInitializedExCls);
if (uncleanStatusExCls) env->DeleteGlobalRef(uncleanStatusExCls);
jvm = nullptr;
}
/*
* Class: edu_wpi_first_wpilibj_hal_HALUtil
* Method: initializeMutex
* Signature: (I)Ljava/nio/ByteBuffer;
* Signature: (I)J
*/
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_initializeMutexNormal
(JNIEnv * env, jclass)
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_initializeMutexNormal
(JNIEnv * env, jclass)
{
HALUTIL_LOG(logDEBUG) << "Calling HALUtil initializeMutex";
MUTEX_ID mutexPtr = (MUTEX_ID)new unsigned char[sizeof(MUTEX_ID)];
mutexPtr = initializeMutexNormal();
HALUTIL_LOG(logDEBUG) << "Mutex Ptr = " << mutexPtr;
return env->NewDirectByteBuffer(mutexPtr, sizeof(MUTEX_ID));
MUTEX_ID mutex = initializeMutexNormal();
HALUTIL_LOG(logDEBUG) << "Mutex Ptr = " << mutex;
return (jlong)mutex;
}
/*
* Class: edu_wpi_first_wpilibj_hal_HALUtil
* Method: deleteMutex
* Signature: (Ljava/nio/ByteBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_deleteMutex
(JNIEnv * env, jclass, jobject id )
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_deleteMutex
(JNIEnv * env, jclass, jlong id )
{
HALUTIL_LOG(logDEBUG) << "Calling HALUtil deleteMutex";
MUTEX_ID javaId = (MUTEX_ID)env->GetDirectBufferAddress(id);
HALUTIL_LOG(logDEBUG) << "Mutex Ptr = " << javaId;
deleteMutex( javaId );
delete[] javaId;
HALUTIL_LOG(logDEBUG) << "Mutex Ptr = " << (MUTEX_ID)id;
deleteMutex((MUTEX_ID)id);
}
/*
* Class: edu_wpi_first_wpilibj_hal_HALUtil
* Method: takeMutex
* Signature: (Ljava/nio/ByteBuffer;I)B
* Signature: (JI)V
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_takeMutex
(JNIEnv * env, jclass, jobject id)
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_takeMutex
(JNIEnv * env, jclass, jlong id)
{
//HALUTIL_LOG(logDEBUG) << "Calling HALUtil takeMutex";
MUTEX_ID javaId = (MUTEX_ID)env->GetDirectBufferAddress(id);
//HALUTIL_LOG(logDEBUG) << "Mutex Ptr = " << *javaId;
takeMutex(javaId);
//HALUTIL_LOG(logDEBUG) << "Take Result = " << (void*)returnValue;
return 0;
//HALUTIL_LOG(logDEBUG) << "Mutex Ptr = " << (MUTEX_ID)id;
takeMutex((MUTEX_ID)id);
}
/*
* Class: edu_wpi_first_wpilibj_hal_HALUtil
* Method: initializeMultiWait
* Signature: ()Ljava/nio/ByteBuffer;
* Signature: ()J
*/
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_initializeMultiWait
(JNIEnv * env, jclass)
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_initializeMultiWait
(JNIEnv * env, jclass)
{
HALUTIL_LOG(logDEBUG) << "Calling HALUtil initializeMultiWait";
MULTIWAIT_ID multiWaitPtr = (MULTIWAIT_ID)new unsigned char[4];
multiWaitPtr = initializeMultiWait();
HALUTIL_LOG(logDEBUG) << "MultiWait Ptr = " << multiWaitPtr;
return env->NewDirectByteBuffer( multiWaitPtr, 4);
MULTIWAIT_ID multiWait = initializeMultiWait();
HALUTIL_LOG(logDEBUG) << "MultiWait Ptr = " << multiWait;
return (jlong)multiWait;
}
/*
* Class: edu_wpi_first_wpilibj_hal_HALUtil
* Method: deleteMultiWait
* Signature: (Ljava/nio/ByteBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_deleteMultiWait
(JNIEnv * env, jclass, jobject id)
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_deleteMultiWait
(JNIEnv * env, jclass, jlong id)
{
HALUTIL_LOG(logDEBUG) << "Calling HALUtil deleteMultiWait";
MULTIWAIT_ID javaId = (MULTIWAIT_ID)env->GetDirectBufferAddress(id);
HALUTIL_LOG(logDEBUG) << "MultiWait Ptr = " << javaId;
deleteMultiWait( javaId );
HALUTIL_LOG(logDEBUG) << "MultiWait Ptr = " << (MULTIWAIT_ID)id;
deleteMultiWait((MULTIWAIT_ID)id);
}
/*
* Class: edu_wpi_first_wpilibj_hal_HALUtil
* Method: takeMultiWait
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;I)B
* Signature: (JJ)V
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_takeMultiWait
(JNIEnv * env, jclass, jobject multiWaitId, jobject mutexId)
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_takeMultiWait
(JNIEnv * env, jclass, jlong multiWaitId, jlong mutexId)
{
MULTIWAIT_ID javaMultiWaitId = (MULTIWAIT_ID)env->GetDirectBufferAddress(multiWaitId);
MUTEX_ID javaMutexId = (MUTEX_ID)env->GetDirectBufferAddress(mutexId);
takeMultiWait(javaMultiWaitId, javaMutexId);
return 0;
takeMultiWait((MULTIWAIT_ID)multiWaitId, (MUTEX_ID)mutexId);
}
/*
* Class: edu_wpi_first_wpilibj_hal_HALUtil
* Method: getFPGAVersion
* Signature: (Ljava/nio/IntBuffer;)S
* Signature: ()S
*/
JNIEXPORT jshort JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGAVersion
(JNIEnv * env, jclass, jobject status)
JNIEXPORT jshort JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGAVersion
(JNIEnv * env, jclass)
{
HALUTIL_LOG(logDEBUG) << "Calling HALUtil getFPGAVersion";
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
jshort returnValue = getFPGAVersion( statusPtr );
HALUTIL_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
jshort returnValue = getFPGAVersion(&status);
HALUTIL_LOG(logDEBUG) << "Status = " << status;
HALUTIL_LOG(logDEBUG) << "FPGAVersion = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_HALUtil
* Method: getFPGARevision
* Signature: (Ljava/nio/IntBuffer;)I
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGARevision
(JNIEnv * env, jclass, jobject status)
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGARevision
(JNIEnv * env, jclass)
{
HALUTIL_LOG(logDEBUG) << "Calling HALUtil getFPGARevision";
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
jint returnValue = getFPGARevision( statusPtr );
HALUTIL_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
jint returnValue = getFPGARevision(&status);
HALUTIL_LOG(logDEBUG) << "Status = " << status;
HALUTIL_LOG(logDEBUG) << "FPGARevision = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_HALUtil
* Method: getFPGATime
* Signature: (Ljava/nio/IntBuffer;)I
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGATime
(JNIEnv * env, jclass, jobject status)
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGATime
(JNIEnv * env, jclass)
{
//HALUTIL_LOG(logDEBUG) << "Calling HALUtil getFPGATime";
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
jlong returnValue = getFPGATime( statusPtr );
//HALUTIL_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
jlong returnValue = getFPGATime(&status);
//HALUTIL_LOG(logDEBUG) << "Status = " << status;
//HALUTIL_LOG(logDEBUG) << "FPGATime = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_HALUtil
* Method: getFPGAButton
* Signature: (Ljava/nio/IntBuffer;)I
* Signature: ()I
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGAButton
(JNIEnv * env, jclass, jobject status)
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGAButton
(JNIEnv * env, jclass)
{
//HALUTIL_LOG(logDEBUG) << "Calling HALUtil getFPGATime";
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
jboolean returnValue = getFPGAButton( statusPtr );
//HALUTIL_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
jboolean returnValue = getFPGAButton(&status);
//HALUTIL_LOG(logDEBUG) << "Status = " << status;
//HALUTIL_LOG(logDEBUG) << "FPGATime = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
@@ -188,8 +447,8 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
* Method: getHALErrorMessage
* Signature: (I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALErrorMessage
(JNIEnv * paramEnv, jclass, jint paramId)
JNIEXPORT jstring JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALErrorMessage
(JNIEnv * paramEnv, jclass, jint paramId)
{
const char * msg = getHALErrorMessage(paramId);
HALUTIL_LOG(logDEBUG) << "Calling HALUtil getHALErrorMessage id=" << paramId << " msg=" << msg;
@@ -201,8 +460,8 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
* Method: getHALErrno
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALErrno
(JNIEnv *, jclass)
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALErrno
(JNIEnv *, jclass)
{
return errno;
}
@@ -212,15 +471,12 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
* Method: getHALstrerror
* Signature: (I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALstrerror
(JNIEnv * env, jclass, jint errorCode)
JNIEXPORT jstring JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALstrerror
(JNIEnv * env, jclass, jint errorCode)
{
const char * msg = strerror(errno);
HALUTIL_LOG(logDEBUG) << "Calling HALUtil getHALstrerror errorCode=" << errorCode << " msg=" << msg;
return env->NewStringUTF(msg);
}
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_HALUtil_pointerSize(JNIEnv*, jclass) {
return sizeof(void*);
}
} // extern "C"

View File

@@ -0,0 +1,28 @@
#ifndef HALUTIL_H
#define HALUTIL_H
#include <stdint.h>
#include <jni.h>
extern JavaVM *jvm;
void ReportError(JNIEnv *env, int32_t status, bool do_throw = true);
inline bool CheckStatus(JNIEnv *env, int32_t status, bool do_throw = true) {
if (status != 0) ReportError(env, status, do_throw);
return status == 0;
}
void ReportCANError(JNIEnv *env, int32_t status, int message_id);
inline bool CheckCANStatus(JNIEnv *env, int32_t status, int message_id) {
if (status != 0) ReportCANError(env, status, message_id);
return status == 0;
}
void ThrowIllegalArgumentException(JNIEnv *env, const char *msg);
void ThrowBoundaryException(JNIEnv *env, double value, double lower,
double upper);
#endif // HALUTIL_H

View File

@@ -5,6 +5,7 @@
#include "edu_wpi_first_wpilibj_hal_I2CJNI.h"
#include "HAL/Digital.hpp"
#include "HALUtil.h"
// set the logging level
TLogLevel i2cJNILogLevel = logWARNING;
@@ -13,44 +14,45 @@ TLogLevel i2cJNILogLevel = logWARNING;
if (level > i2cJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_I2CJNI
* Method: i2cInitialize
* Signature: (BLjava/nio/IntBuffer;)V
* Signature: (B)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CInitialize
(JNIEnv * env, jclass, jbyte value, jobject status)
(JNIEnv * env, jclass, jbyte value)
{
I2CJNI_LOG(logDEBUG) << "Calling I2CJNI i2CInititalize";
I2CJNI_LOG(logDEBUG) << "Port: " << (jint) value;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
i2CInitialize(value, statusPtr);
I2CJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
i2CInitialize(value, &status);
I2CJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_I2CJNI
* Method: i2CTransaction
* Signature: (BBLjava/nio/ByteBuffer;BLjava/nio/ByteBuffer;B)B
* Signature: (BBLjava/nio/ByteBuffer;BLjava/nio/ByteBuffer;B)I
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CTransaction
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CTransaction
(JNIEnv * env, jclass, jbyte port, jbyte address, jobject dataToSend, jbyte sendSize, jobject dataReceived, jbyte receiveSize)
{
I2CJNI_LOG(logDEBUG) << "Calling I2CJNI i2CTransaction";
I2CJNI_LOG(logDEBUG) << "Port = " << (jint)port;
I2CJNI_LOG(logDEBUG) << "Address = " << (jint)address;
jbyte * dataToSendPtr = NULL;
jbyte * dataReceivedPtr = NULL;
if(dataToSend !=0){
dataToSendPtr = (jbyte*)env->GetDirectBufferAddress(dataToSend);
uint8_t* dataToSendPtr = nullptr;
if (dataToSend != 0) {
dataToSendPtr = (uint8_t*)env->GetDirectBufferAddress(dataToSend);
}
I2CJNI_LOG(logDEBUG) << "DataToSendPtr = " << (jint*)dataToSendPtr;
I2CJNI_LOG(logDEBUG) << "SendSize = " << (jint)sendSize;
dataReceivedPtr = (jbyte*)env->GetDirectBufferAddress(dataReceived);
uint8_t* dataReceivedPtr = (uint8_t*)env->GetDirectBufferAddress(dataReceived);
I2CJNI_LOG(logDEBUG) << "DataReceivedPtr = " << (jint*)dataReceivedPtr;
I2CJNI_LOG(logDEBUG) << "ReceiveSize = " << (jint)receiveSize;
jbyte returnValue = i2CTransaction(port, address, (uint8_t*)dataToSendPtr, sendSize, (uint8_t*) dataReceivedPtr, receiveSize);
jint returnValue = i2CTransaction(port, address, dataToSendPtr, sendSize, dataReceivedPtr, receiveSize);
I2CJNI_LOG(logDEBUG) << "ReturnValue = " << returnValue;
return returnValue;
}
@@ -58,23 +60,23 @@ JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CTransaction
/*
* Class: edu_wpi_first_wpilibj_hal_I2CJNI
* Method: i2CWrite
* Signature: (BBLjava/nio/ByteBuffer;B)B
* Signature: (BBLjava/nio/ByteBuffer;B)I
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CWrite
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CWrite
(JNIEnv * env, jclass, jbyte port, jbyte address, jobject dataToSend, jbyte sendSize)
{
I2CJNI_LOG(logDEBUG) << "Calling I2CJNI i2CWrite";
I2CJNI_LOG(logDEBUG) << "Port = " << (jint)port;
I2CJNI_LOG(logDEBUG) << "Address = " << (jint)address;
jbyte * dataToSendPtr = NULL;
uint8_t* dataToSendPtr = nullptr;
if(dataToSend !=0){
dataToSendPtr = (jbyte*)env->GetDirectBufferAddress(dataToSend);
if (dataToSend != 0) {
dataToSendPtr = (uint8_t*)env->GetDirectBufferAddress(dataToSend);
}
I2CJNI_LOG(logDEBUG) << "DataToSendPtr = " << (jint*)dataToSendPtr;
I2CJNI_LOG(logDEBUG) << "DataToSendPtr = " << dataToSendPtr;
I2CJNI_LOG(logDEBUG) << "SendSize = " << (jint)dataToSend;
jbyte returnValue = i2CWrite(port, address, (uint8_t*)dataToSendPtr, sendSize);
jint returnValue = i2CWrite(port, address, dataToSendPtr, sendSize);
I2CJNI_LOG(logDEBUG) << "ReturnValue = " << (jint)returnValue;
return returnValue;
}
@@ -82,19 +84,18 @@ JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CWrite
/*
* Class: edu_wpi_first_wpilibj_hal_I2CJNI
* Method: i2CRead
* Signature: (BBLjava/nio/ByteBuffer;B)B
* Signature: (BBLjava/nio/ByteBuffer;B)I
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CRead
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CRead
(JNIEnv * env, jclass, jbyte port, jbyte address, jobject dataReceived, jbyte receiveSize)
{
I2CJNI_LOG(logDEBUG) << "Calling I2CJNI i2CRead";
I2CJNI_LOG(logDEBUG) << "Port = " << port;
I2CJNI_LOG(logDEBUG) << "Address = " << address;
jbyte * dataReceivedPtr = NULL;
dataReceivedPtr = (jbyte*)env->GetDirectBufferAddress(dataReceived);
I2CJNI_LOG(logDEBUG) << "DataReceivedPtr = " << (jint*)dataReceivedPtr;
uint8_t* dataReceivedPtr = (uint8_t*)env->GetDirectBufferAddress(dataReceived);
I2CJNI_LOG(logDEBUG) << "DataReceivedPtr = " << dataReceivedPtr;
I2CJNI_LOG(logDEBUG) << "ReceiveSize = " << receiveSize;
jbyte returnValue = i2CRead(port, address, (uint8_t*) dataReceivedPtr, receiveSize);
jint returnValue = i2CRead(port, address, dataReceivedPtr, receiveSize);
I2CJNI_LOG(logDEBUG) << "ReturnValue = " << returnValue;
return returnValue;
}
@@ -107,6 +108,8 @@ JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CRead
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CClose
(JNIEnv *, jclass, jbyte value)
{
I2CJNI_LOG(logDEBUG) << "Calling I2CJNI i2cClose";
I2CJNI_LOG(logDEBUG) << "Calling I2CJNI i2CClose";
i2CClose(value);
}
} // extern "C"

View File

@@ -4,6 +4,7 @@
#include "edu_wpi_first_wpilibj_hal_InterruptJNI.h"
#include "HAL/Interrupts.hpp"
#include "HALUtil.h"
TLogLevel interruptJNILogLevel = logERROR;
@@ -11,197 +12,165 @@ TLogLevel interruptJNILogLevel = logERROR;
if (level > interruptJNILogLevel) ; \
else Log().Get(level)
//Used for callback when an interrupt is fired.
static JavaVM *jvm;
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: initializeInterruptJVM
* Signature: (Ljava/nio/IntBuffer;)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_initializeInterruptJVM
(JNIEnv * env, jclass, jobject status)
{
//This method should be called once to setup the JVM
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI initializeInterruptJVM";
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
jint rs = env->GetJavaVM(&jvm);
assert (rs == JNI_OK);
}
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: initializeInterrupts
* Signature: (IBLjava/nio/IntBuffer;)Ljava/nio/ByteBuffer;
* Signature: (IZ)J
*/
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_initializeInterrupts
(JNIEnv * env, jclass, jint interruptIndex, jbyte watcher, jobject status)
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_initializeInterrupts
(JNIEnv * env, jclass, jint interruptIndex, jboolean watcher)
{
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI initializeInterrupts";
INTERRUPTJNI_LOG(logDEBUG) << "interruptIndex = " << interruptIndex;
INTERRUPTJNI_LOG(logDEBUG) << "watcher = " << (bool) watcher;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
void** interruptPtr = (void**)new unsigned char[4];
*statusPtr = 0;
*interruptPtr = (void**) initializeInterrupts(interruptIndex, watcher, statusPtr);
int32_t status = 0;
void* interrupt = initializeInterrupts(interruptIndex, watcher, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << *interruptPtr;
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << interrupt;
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
return env->NewDirectByteBuffer(interruptPtr, 4);
CheckStatus(env, status);
return (jlong)interrupt;
}
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: cleanInterrupts
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_cleanInterrupts
(JNIEnv * env, jclass, jobject interrupt_pointer, jobject status)
(JNIEnv * env, jclass, jlong interrupt_pointer)
{
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI cleanInterrupts";
void ** javaId = (void**)env->GetDirectBufferAddress(interrupt_pointer);
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
*statusPtr = 0;
cleanInterrupts(*javaId, statusPtr);
int32_t status = 0;
cleanInterrupts((void*)interrupt_pointer, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: waitForInterrupt
* Signature: (Ljava/nio/ByteBuffer;DLjava/nio/IntBuffer;)V
* Signature: (JD)V
*/
JNIEXPORT int JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_waitForInterrupt
(JNIEnv * env, jclass, jobject interrupt_pointer, jdouble timeout, jboolean ignorePrevious, jobject status)
(JNIEnv * env, jclass, jlong interrupt_pointer, jdouble timeout, jboolean ignorePrevious)
{
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI waitForInterrupt";
void ** javaId = (void**)env->GetDirectBufferAddress(interrupt_pointer);
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
*statusPtr = 0;
int result = waitForInterrupt(*javaId, timeout, ignorePrevious, statusPtr);
int32_t status = 0;
int result = waitForInterrupt((void*)interrupt_pointer, timeout, ignorePrevious, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
return result;
}
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: enableInterrupts
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_enableInterrupts
(JNIEnv * env, jclass, jobject interrupt_pointer, jobject status)
(JNIEnv * env, jclass, jlong interrupt_pointer)
{
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI enableInterrupts";
void ** javaId = (void**)env->GetDirectBufferAddress(interrupt_pointer);
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
*statusPtr = 0;
enableInterrupts(*javaId, statusPtr);
int32_t status = 0;
enableInterrupts((void*)interrupt_pointer, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: disableInterrupts
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_disableInterrupts
(JNIEnv * env, jclass, jobject interrupt_pointer, jobject status)
(JNIEnv * env, jclass, jlong interrupt_pointer)
{
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI disableInterrupts";
void ** javaId = (void**)env->GetDirectBufferAddress(interrupt_pointer);
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
*statusPtr = 0;
disableInterrupts(*javaId, statusPtr);
int32_t status = 0;
disableInterrupts((void*)interrupt_pointer, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: readRisingTimestamp
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)D
* Signature: (J)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_readRisingTimestamp
(JNIEnv * env, jclass, jobject interrupt_pointer, jobject status)
(JNIEnv * env, jclass, jlong interrupt_pointer)
{
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI readRisingTimestamp";
void ** javaId = (void**)env->GetDirectBufferAddress(interrupt_pointer);
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
*statusPtr = 0;
jdouble timeStamp = readRisingTimestamp(*javaId, statusPtr);
int32_t status = 0;
jdouble timeStamp = readRisingTimestamp((void*)interrupt_pointer, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
return timeStamp;
}
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: readFallingTimestamp
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)D
* Signature: (J)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_readFallingTimestamp
(JNIEnv * env, jclass, jobject interrupt_pointer, jobject status)
(JNIEnv * env, jclass, jlong interrupt_pointer)
{
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI readFallingTimestamp";
void ** javaId = (void**)env->GetDirectBufferAddress(interrupt_pointer);
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
*statusPtr = 0;
jdouble timeStamp = readFallingTimestamp(*javaId, statusPtr);
int32_t status = 0;
jdouble timeStamp = readFallingTimestamp((void*)interrupt_pointer, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
return timeStamp;
}
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: requestInterrupts
* Signature: (Ljava/nio/ByteBuffer;BIBLjava/nio/IntBuffer;)V
* Signature: (JBIZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_requestInterrupts
(JNIEnv * env, jclass, jobject interrupt_pointer, jbyte routing_module, jint routing_pin, jbyte routing_analog_trigger, jobject status)
(JNIEnv * env, jclass, jlong interrupt_pointer, jbyte routing_module, jint routing_pin, jboolean routing_analog_trigger)
{
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI requestInterrupts";
void ** javaId = (void**)env->GetDirectBufferAddress(interrupt_pointer);
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << *javaId;
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
INTERRUPTJNI_LOG(logDEBUG) << "routing module = " << (jint) routing_module;
INTERRUPTJNI_LOG(logDEBUG) << "routing pin = " << routing_pin;
INTERRUPTJNI_LOG(logDEBUG) << "routing analog trigger = " << (jint) routing_analog_trigger;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
requestInterrupts(*javaId, (uint8_t) routing_module, (uint32_t) routing_pin, routing_analog_trigger, statusPtr);
int32_t status = 0;
requestInterrupts((void*)interrupt_pointer, (uint8_t) routing_module, (uint32_t) routing_pin, routing_analog_trigger, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
@@ -260,17 +229,13 @@ void interruptHandler(uint32_t mask, void *data) {
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: attachInterruptHandler
* Signature: (Ljava/nio/ByteBuffer;Ledu/wpi/first/wpilibj/hal/InterruptJNI/InterruptHandlerFunction;Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (JLedu/wpi/first/wpilibj/hal/InterruptJNI/InterruptHandlerFunction;Ljava/nio/ByteBuffer;)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_attachInterruptHandler
(JNIEnv * env, jclass, jobject interrupt_pointer, jobject handler, jobject param, jobject status)
(JNIEnv * env, jclass, jlong interrupt_pointer, jobject handler, jobject param)
{
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI attachInterruptHandler";
void ** javaId = (void**)env->GetDirectBufferAddress(interrupt_pointer);
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
//Store the interrupt callback paramaters
InterruptHandlerParam *interruptHandlerParam = new InterruptHandlerParam();
@@ -301,31 +266,31 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_attachInterru
INTERRUPTJNI_LOG(logDEBUG) << "InterruptHandlerParam->mid = " << interruptHandlerParam->mid;
INTERRUPTJNI_LOG(logDEBUG) << "InterruptHandlerParam->param = " << interruptHandlerParam->param;
*statusPtr = 0;
attachInterruptHandler(*javaId, interruptHandler, interruptHandlerParam, statusPtr);
int32_t status = 0;
attachInterruptHandler((void*)interrupt_pointer, interruptHandler, interruptHandlerParam, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: setInterruptUpSourceEdge
* Signature: (Ljava/nio/ByteBuffer;BBLjava/nio/IntBuffer;)V
* Signature: (JZZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_setInterruptUpSourceEdge
(JNIEnv * env, jclass, jobject interrupt_pointer, jbyte risingEdge, jbyte fallingEdge, jobject status)
(JNIEnv * env, jclass, jlong interrupt_pointer, jboolean risingEdge, jboolean fallingEdge)
{
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI setInterruptUpSourceEdge";
void ** javaId = (void**)env->GetDirectBufferAddress(interrupt_pointer);
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << *javaId;
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
INTERRUPTJNI_LOG(logDEBUG) << "Rising Edge = " << (bool) risingEdge;
INTERRUPTJNI_LOG(logDEBUG) << "Falling Edge = " << (bool) fallingEdge;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
int32_t status = 0;
setInterruptUpSourceEdge((void*)interrupt_pointer, risingEdge, fallingEdge, &status);
*statusPtr = 0;
setInterruptUpSourceEdge(*javaId, risingEdge, fallingEdge, statusPtr);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
} // extern "C"

View File

@@ -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"

View File

@@ -5,6 +5,7 @@
#include "Log.hpp"
#include "edu_wpi_first_wpilibj_hal_NotifierJNI.h"
#include "HAL/Notifier.hpp"
#include "HALUtil.h"
// set the logging level
TLogLevel notifierJNILogLevel = logWARNING;
@@ -13,29 +14,6 @@ TLogLevel notifierJNILogLevel = logWARNING;
if (level > notifierJNILogLevel) ; \
else Log().Get(level)
// The jvm object is necessary in order to attach new threads (ie,
// notifierHandler), to the JVM.
static JavaVM *jvm;
static const int kPtrSize = sizeof(void*);
// Utility functions which convert back and forth between pointers and Java
// ByteBuffers.
jint* GetStatusPtr(JNIEnv *env, jobject status) {
return (jint*)env->GetDirectBufferAddress(status);
}
jobject PtrToByteBuf(JNIEnv *env, void *ptr) {
// Stores a pointer into a byte buffer of the appropriate length.
return env->NewDirectByteBuffer(ptr, kPtrSize);
}
void *ByteBufToPtr(JNIEnv *env, jobject bytebuf) {
void * ptr = (void*)env->GetDirectBufferAddress(bytebuf);
return ptr;
}
// These two are used to pass information to the notifierHandler without using
// up function parameters.
// See below for more information.
@@ -48,7 +26,7 @@ void notifierHandler(uint32_t mask, void* param) {
jobject handler_obj = func_global;
jmethodID mid = mid_global;
NOTIFIERJNI_LOG(logDEBUG) << "Calling NOTIFIERJNI interruptHandler";
NOTIFIERJNI_LOG(logDEBUG) << "Calling NOTIFIERJNI notifierHandler";
//Because this is a callback in a new thread we must attach it to the JVM.
JNIEnv *env;
@@ -73,37 +51,20 @@ void notifierHandler(uint32_t mask, void* param) {
rs = jvm->DetachCurrentThread();
assert (rs == JNI_OK);
}
NOTIFIERJNI_LOG(logDEBUG) << "Leaving NOTIFIERJNI interruptHandler";
NOTIFIERJNI_LOG(logDEBUG) << "Leaving NOTIFIERJNI notifierHandler";
}
/*
* Class: edu_wpi_first_wpilibj_hal_NotifierJNI
* Method: initializeNotifierJVM
* Signature: (Ljava/nio/IntBuffer;)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_NotifierJNI_initializeNotifierJVM
(JNIEnv *env, jclass, jobject status)
{
//This method should be called once to setup the JVM
NOTIFIERJNI_LOG(logDEBUG) << "Calling NOTIFIERJNI initializeNotifierJVM";
jint * statusPtr = GetStatusPtr(env, status);
NOTIFIERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
jint rs = env->GetJavaVM(&jvm);
assert (rs == JNI_OK);
}
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_NotifierJNI
* Method: initializeNotifier
* Signature: (Ljava/lang/Runnable;Ljava/nio/IntBuffer;)Ljava/lang/ByteBuffer;
* Signature: (Ljava/lang/Runnable;)J
*/
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_NotifierJNI_initializeNotifier
(JNIEnv *env, jclass, jobject func, jobject status)
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_NotifierJNI_initializeNotifier
(JNIEnv *env, jclass, jobject func)
{
NOTIFIERJNI_LOG(logDEBUG) << "Calling NOTIFIERJNI initializeNotifier";
jint * statusPtr = GetStatusPtr(env, status);
NOTIFIERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
jclass cls = env->GetObjectClass(func);
jmethodID mid = env->GetMethodID(cls, "run", "()V");
@@ -120,54 +81,52 @@ JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_NotifierJNI_initializeN
func_global = env->NewGlobalRef(func);
mid_global = mid;
*statusPtr = 0;
void *notifierPtr = initializeNotifier(notifierHandler, statusPtr);
int32_t status = 0;
void *notifierPtr = initializeNotifier(notifierHandler, &status);
NOTIFIERJNI_LOG(logDEBUG) << "Notifier Ptr = " << notifierPtr;
NOTIFIERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
NOTIFIERJNI_LOG(logDEBUG) << "Status = " << status;
return PtrToByteBuf(env, notifierPtr);
CheckStatus(env, status);
return (jlong)notifierPtr;
}
/*
* Class: edu_wpi_first_wpilibj_hal_NotifierJNI
* Method: cleanNotifier
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_NotifierJNI_cleanNotifier(JNIEnv *env, jclass, jobject notifierPtr, jobject status) {
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_NotifierJNI_cleanNotifier
(JNIEnv *env, jclass, jlong notifierPtr)
{
NOTIFIERJNI_LOG(logDEBUG) << "Calling NOTIFIERJNI cleanNotifier";
void *ptr = ByteBufToPtr(env, notifierPtr);
NOTIFIERJNI_LOG(logDEBUG) << "Notifier Ptr = " << ptr;
NOTIFIERJNI_LOG(logDEBUG) << "Notifier Ptr = " << (void*)notifierPtr;
jint *statusPtr = GetStatusPtr(env, status);
NOTIFIERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
cleanNotifier(ptr, statusPtr);
NOTIFIERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
cleanNotifier((void*)notifierPtr, &status);
NOTIFIERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_NotifierJNI
* Method: updateNotifierAlarm
* Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V
* Signature: (JI)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_hal_NotifierJNI_updateNotifierAlarm(
JNIEnv *env, jclass cls, jobject notifierPtr, jint triggerTime,
jobject status) {
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_NotifierJNI_updateNotifierAlarm
(JNIEnv *env, jclass cls, jlong notifierPtr, jint triggerTime)
{
NOTIFIERJNI_LOG(logDEBUG) << "Calling NOTIFIERJNI updateNotifierAlarm";
void *ptr = ByteBufToPtr(env, notifierPtr);
NOTIFIERJNI_LOG(logDEBUG) << "Notifier Ptr = " << ptr;
NOTIFIERJNI_LOG(logDEBUG) << "Notifier Ptr = " << (void*)notifierPtr;
jint *statusPtr = GetStatusPtr(env, status);
NOTIFIERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
NOTIFIERJNI_LOG(logDEBUG) << "triggerTime Ptr = " << &triggerTime;
*statusPtr = 0;
updateNotifierAlarm(ptr, (uint32_t)triggerTime, statusPtr);
NOTIFIERJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
updateNotifierAlarm((void*)notifierPtr, (uint32_t)triggerTime, &status);
NOTIFIERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
} // extern "C"

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"

View File

@@ -5,6 +5,7 @@
#include "edu_wpi_first_wpilibj_hal_PWMJNI.h"
#include "HAL/Digital.hpp"
#include "HALUtil.h"
// set the logging level
TLogLevel pwmJNILogLevel = logWARNING;
@@ -13,203 +14,187 @@ TLogLevel pwmJNILogLevel = logWARNING;
if (level > pwmJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_PWMJNI
* Method: allocatePWMChannel
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_allocatePWMChannel
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
PWMJNI_LOG(logDEBUG) << "Calling DIOJNI allocatePWMChannel";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
PWMJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
PWMJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
jbyte returnValue = allocatePWMChannel(*javaId, statusPtr);
PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
PWMJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
int32_t status = 0;
jboolean returnValue = allocatePWMChannel((void*)id, &status);
PWMJNI_LOG(logDEBUG) << "Status = " << status;
PWMJNI_LOG(logDEBUG) << "allocatePWMChannelResult = " << (jint)returnValue;
return returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PWMJNI
* Method: freePWMChannel
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_freePWMChannel
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
PWMJNI_LOG(logDEBUG) << "Calling DIOJNI freePWMChannel";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
PWMJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
PWMJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
freePWMChannel(*javaId, statusPtr);
PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
PWMJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
int32_t status = 0;
freePWMChannel((void*)id, &status);
PWMJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_PWMJNI
* Method: setPWM
* Signature: (Ljava/nio/ByteBuffer;SLjava/nio/IntBuffer;)V
* Signature: (JS)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_setPWM
(JNIEnv * env, jclass, jobject id, jshort value, jobject status)
(JNIEnv * env, jclass, jlong id, jshort value)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
PWMJNI_LOG(logDEBUG) << "DigitalPort Ptr = " << *javaId;
PWMJNI_LOG(logDEBUG) << "DigitalPort Ptr = " << (void*)id;
PWMJNI_LOG(logDEBUG) << "PWM Value = " << value;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
setPWM( *javaId, value, statusPtr );
PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setPWM((void*)id, value, &status);
PWMJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_PWMJNI
* Method: getPWM
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)S
* Signature: (J)S
*/
JNIEXPORT jshort JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_getPWM
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
jshort returnValue = getPWM( *javaId, statusPtr );
PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << (void*)id;
int32_t status = 0;
jshort returnValue = getPWM((void*)id, &status);
PWMJNI_LOG(logDEBUG) << "Status = " << status;
PWMJNI_LOG(logDEBUG) << "Value = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PWMJNI
* Method: latchPWMZero
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_latchPWMZero
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
latchPWMZero( *javaId, statusPtr );
PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << (void*)id;
int32_t status = 0;
latchPWMZero((void*)id, &status);
PWMJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_PWMJNI
* Method: setPWMPeriodScale
* Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_setPWMPeriodScale
(JNIEnv * env, jclass, jobject id, jint value, jobject status )
(JNIEnv * env, jclass, jlong id, jint value)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
PWMJNI_LOG(logDEBUG) << "DigitalPort Ptr = " << *javaId;
PWMJNI_LOG(logDEBUG) << "DigitalPort Ptr = " << (void*)id;
PWMJNI_LOG(logDEBUG) << "PeriodScale Value = " << value;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
setPWMPeriodScale( *javaId, value, statusPtr );
PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setPWMPeriodScale((void*)id, value, &status);
PWMJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_PWMJNI
* Method: allocatePWM
* Signature: (Ljava/nio/IntBuffer;)Ljava/nio/ByteBuffer;
* Signature: ()J
*/
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_allocatePWM
(JNIEnv * env, jclass, jobject status)
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_allocatePWM
(JNIEnv * env, jclass)
{
PWMJNI_LOG(logDEBUG) << "Calling PWMJNI allocatePWM";
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
PWMJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
void** pwmPtr = (void**)new unsigned char[4];
*statusPtr = 0;
*pwmPtr = allocatePWM(statusPtr);
PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << *pwmPtr;
return env->NewDirectByteBuffer( pwmPtr, 4);
int32_t status = 0;
void* pwm = allocatePWM(&status);
PWMJNI_LOG(logDEBUG) << "Status = " << status;
PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << pwm;
CheckStatus(env, status);
return (jlong)pwm;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PWMJNI
* Method: freePWM
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_freePWM
(JNIEnv * env, jclass, jobject id, jobject status)
(JNIEnv * env, jclass, jlong id)
{
PWMJNI_LOG(logDEBUG) << "Calling PWMJNI freePWM";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
PWMJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
freePWM(*javaId, statusPtr);
PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << (void*)id;
int32_t status = 0;
freePWM((void*)id, &status);
PWMJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_PWMJNI
* Method: setPWMRate
* Signature: (DLjava/nio/IntBuffer;)V
* Signature: (D)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_setPWMRate
(JNIEnv * env, jclass, jdouble value, jobject status)
(JNIEnv * env, jclass, jdouble value)
{
PWMJNI_LOG(logDEBUG) << "Calling PWMJNI setPWMRate";
PWMJNI_LOG(logDEBUG) << "Rate= " << value;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
PWMJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setPWMRate(value, statusPtr);
PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setPWMRate(value, &status);
PWMJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_PWMJNI
* Method: setPWMDutyCycle
* Signature: (Ljava/nio/ByteBuffer;DLjava/nio/IntBuffer;)V
* Signature: (JD)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_setPWMDutyCycle
(JNIEnv * env, jclass, jobject id, jdouble value, jobject status)
(JNIEnv * env, jclass, jlong id, jdouble value)
{
PWMJNI_LOG(logDEBUG) << "Calling PWMJNI setPWMDutyCycle";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << *javaId;
PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << (void*)id;
PWMJNI_LOG(logDEBUG) << "DutyCycle= " << value;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
PWMJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setPWMDutyCycle(*javaId, value, statusPtr);
PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setPWMDutyCycle((void*)id, value, &status);
PWMJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_PWMJNI
* Method: setPWMOutputChannel
* Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_setPWMOutputChannel
(JNIEnv * env, jclass, jobject id, jint value, jobject status)
(JNIEnv * env, jclass, jlong id, jint value)
{
PWMJNI_LOG(logDEBUG) << "Calling PWMJNI setPWMOutputChannel";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << *javaId;
PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << (void*)id;
PWMJNI_LOG(logDEBUG) << "Pin= " << value;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
PWMJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setPWMOutputChannel(*javaId, (uint32_t) value, statusPtr);
PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setPWMOutputChannel((void*)id, (uint32_t) value, &status);
PWMJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
} // extern "C"

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"

View File

@@ -5,6 +5,7 @@
#include "edu_wpi_first_wpilibj_hal_RelayJNI.h"
#include "HAL/Digital.hpp"
#include "HALUtil.h"
// set the logging level
TLogLevel relayJNILogLevel = logWARNING;
@@ -13,80 +14,76 @@ TLogLevel relayJNILogLevel = logWARNING;
if (level > relayJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_RelayJNI
* Method: setRelayForward
* Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)V
* Signature: (JZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_RelayJNI_setRelayForward
(JNIEnv * env, jclass, jobject id, jbyte value, jobject status)
(JNIEnv * env, jclass, jlong id, jboolean value)
{
RELAYJNI_LOG(logDEBUG) << "Calling RELAYJNI setRelayForward";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
RELAYJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId;
RELAYJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
RELAYJNI_LOG(logDEBUG) << "Flag = " << (jint)value;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
RELAYJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setRelayForward(*javaId, value, statusPtr);
RELAYJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setRelayForward((void*)id, value, &status);
RELAYJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_RelayJNI
* Method: setRelayReverse
* Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)V
* Signature: (JZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_RelayJNI_setRelayReverse
(JNIEnv * env, jclass, jobject id, jbyte value, jobject status)
(JNIEnv * env, jclass, jlong id, jboolean value)
{
RELAYJNI_LOG(logDEBUG) << "Calling RELAYJNI setRelayReverse";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
RELAYJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId;
RELAYJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
RELAYJNI_LOG(logDEBUG) << "Flag = " << (jint)value;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
RELAYJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
setRelayReverse(*javaId, value, statusPtr);
RELAYJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
setRelayReverse((void*)id, value, &status);
RELAYJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_RelayJNI
* Method: getRelayForward
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B
* Signature: (J)Z
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_RelayJNI_getRelayForward
(JNIEnv * env, jclass, jobject id, jobject status)
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_RelayJNI_getRelayForward
(JNIEnv * env, jclass, jlong id)
{
RELAYJNI_LOG(logDEBUG) << "Calling RELAYJNI getRelayForward";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
RELAYJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
RELAYJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
jbyte returnValue = getRelayForward(*javaId, statusPtr);
RELAYJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
RELAYJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
int32_t status = 0;
jboolean returnValue = getRelayForward((void*)id, &status);
RELAYJNI_LOG(logDEBUG) << "Status = " << status;
RELAYJNI_LOG(logDEBUG) << "getRelayForwardResult = " << (jint)returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_RelayJNI
* Method: getRelayReverse
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B
* Signature: (J)Z
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_RelayJNI_getRelayReverse
(JNIEnv * env, jclass, jobject id, jobject status)
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_RelayJNI_getRelayReverse
(JNIEnv * env, jclass, jlong id)
{
RELAYJNI_LOG(logDEBUG) << "Calling RELAYJNI getRelayReverse";
void ** javaId = (void**)env->GetDirectBufferAddress(id);
RELAYJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
RELAYJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
*statusPtr = 0;
jbyte returnValue = getRelayReverse(*javaId, statusPtr);
RELAYJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
RELAYJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
int32_t status = 0;
jboolean returnValue = getRelayReverse((void*)id, &status);
RELAYJNI_LOG(logDEBUG) << "Status = " << status;
RELAYJNI_LOG(logDEBUG) << "getRelayReverseResult = " << (jint)returnValue;
CheckStatus(env, status);
return returnValue;
}
} // extern "C"

View File

@@ -5,7 +5,7 @@
#include "edu_wpi_first_wpilibj_hal_SPIJNI.h"
#include "HAL/Digital.hpp"
#include "HALUtil.h"
// set the logging level
TLogLevel spiJNILogLevel = logWARNING;
@@ -14,20 +14,22 @@ TLogLevel spiJNILogLevel = logWARNING;
if (level > spiJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
* Method: spiInitialize
* Signature: (BLjava/nio/IntBuffer;)V
* Signature: (B)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiInitialize
(JNIEnv * env, jclass, jbyte port, jobject status)
(JNIEnv * env, jclass, jbyte port)
{
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiInitialize";
SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
spiInitialize(port, statusPtr);
SPIJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
spiInitialize(port, &status);
SPIJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
@@ -40,16 +42,15 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiTransaction
{
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiTransaction";
SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port;
jbyte * dataToSendPtr = NULL;
jbyte * dataReceivedPtr = NULL;
if(dataToSend != 0){
dataToSendPtr = (jbyte*)env->GetDirectBufferAddress(dataToSend);
uint8_t* dataToSendPtr = nullptr;
if (dataToSend != 0) {
dataToSendPtr = (uint8_t*)env->GetDirectBufferAddress(dataToSend);
}
dataReceivedPtr = (jbyte*)env->GetDirectBufferAddress(dataReceived);
uint8_t* dataReceivedPtr = (uint8_t*)env->GetDirectBufferAddress(dataReceived);
SPIJNI_LOG(logDEBUG) << "Size = " << (jint)size;
SPIJNI_LOG(logDEBUG) << "DataToSendPtr = " << (jint*)dataToSendPtr;
SPIJNI_LOG(logDEBUG) << "DataReceivedPtr = " << (jint*) dataReceivedPtr;
jbyte retVal = spiTransaction(port, (uint8_t*)dataToSendPtr, (uint8_t*)dataReceivedPtr, size);
SPIJNI_LOG(logDEBUG) << "DataToSendPtr = " << dataToSendPtr;
SPIJNI_LOG(logDEBUG) << "DataReceivedPtr = " << dataReceivedPtr;
jint retVal = spiTransaction(port, dataToSendPtr, dataReceivedPtr, size);
SPIJNI_LOG(logDEBUG) << "ReturnValue = " << (jint)retVal;
return retVal;
}
@@ -64,13 +65,13 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiWrite
{
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiWrite";
SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port;
jbyte * dataToSendPtr = NULL;
if(dataToSend != 0){
dataToSendPtr = (jbyte*)env->GetDirectBufferAddress(dataToSend);
uint8_t* dataToSendPtr = nullptr;
if (dataToSend != 0) {
dataToSendPtr = (uint8_t*)env->GetDirectBufferAddress(dataToSend);
}
SPIJNI_LOG(logDEBUG) << "Size = " << (jint)size;
SPIJNI_LOG(logDEBUG) << "DataToSendPtr = " << (jint*)dataToSendPtr;
jbyte retVal = spiWrite(port, (uint8_t*)dataToSendPtr, size);
SPIJNI_LOG(logDEBUG) << "DataToSendPtr = " << dataToSendPtr;
jint retVal = spiWrite(port, dataToSendPtr, size);
SPIJNI_LOG(logDEBUG) << "ReturnValue = " << (jint)retVal;
return retVal;
}
@@ -86,11 +87,10 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiRead
{
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiRead";
SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port;
jbyte * dataReceivedPtr = NULL;
dataReceivedPtr = (jbyte*)env->GetDirectBufferAddress(dataReceived);
uint8_t* dataReceivedPtr = (uint8_t*)env->GetDirectBufferAddress(dataReceived);
SPIJNI_LOG(logDEBUG) << "Size = " << (jint)size;
SPIJNI_LOG(logDEBUG) << "DataReceivedPtr = " << (jint*) dataReceivedPtr;
jbyte retVal = spiRead(port, (uint8_t*)dataReceivedPtr, size);
SPIJNI_LOG(logDEBUG) << "DataReceivedPtr = " << dataReceivedPtr;
jint retVal = spiRead(port, (uint8_t*)dataReceivedPtr, size);
SPIJNI_LOG(logDEBUG) << "ReturnValue = " << (jint)retVal;
return retVal;
}
@@ -142,32 +142,33 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiSetOpts
/*
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
* Method: spiSetChipSelectActiveHigh
* Signature: (BLjava/nio/IntBuffer;)V
* Signature: (B)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiSetChipSelectActiveHigh
(JNIEnv * env, jclass, jbyte port, jobject status)
(JNIEnv * env, jclass, jbyte port)
{
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiSetCSActiveHigh";
SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
spiSetChipSelectActiveHigh(port, statusPtr);
SPIJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
spiSetChipSelectActiveHigh(port, &status);
SPIJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
* Method: spiSetChipSelectActiveLow
* Signature: (BLjava/nio/IntBuffer;)V
* Signature: (B)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiSetChipSelectActiveLow
(JNIEnv * env, jclass, jbyte port, jobject status)
(JNIEnv * env, jclass, jbyte port)
{
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiSetCSActiveLow";
SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
spiSetChipSelectActiveLow(port, statusPtr);
SPIJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
spiSetChipSelectActiveLow(port, &status);
SPIJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
} // extern "C"

View File

@@ -5,6 +5,7 @@
#include "edu_wpi_first_wpilibj_hal_SerialPortJNI.h"
#include "HAL/SerialPort.hpp"
#include "HALUtil.h"
// set the logging level
TLogLevel serialJNILogLevel = logWARNING;
@@ -13,294 +14,298 @@ TLogLevel serialJNILogLevel = logWARNING;
if (level > serialJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialInitializePort
* Signature: (BLjava/nio/IntBuffer;)V
* Signature: (B)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialInitializePort
(JNIEnv * env, jclass, jbyte port, jobject status)
(JNIEnv * env, jclass, jbyte port)
{
SERIALJNI_LOG(logDEBUG) << "Calling Serial Initialize";
SERIALJNI_LOG(logDEBUG) << "Port = " << (jint) port;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
serialInitializePort(port, statusPtr);
SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
serialInitializePort(port, &status);
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialSetBaudRate
* Signature: (BILjava/nio/IntBuffer;)V
* Signature: (BI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetBaudRate
(JNIEnv * env, jclass, jbyte port, jint rate, jobject status)
(JNIEnv * env, jclass, jbyte port, jint rate)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Baud Rate";
SERIALJNI_LOG(logDEBUG) << "Baud: " << rate;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
serialSetBaudRate(port, rate, statusPtr);
SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
serialSetBaudRate(port, rate, &status);
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialSetDataBits
* Signature: (BBLjava/nio/IntBuffer;)V
* Signature: (BB)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetDataBits
(JNIEnv * env, jclass, jbyte port, jbyte bits, jobject status)
(JNIEnv * env, jclass, jbyte port, jbyte bits)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Data Bits";
SERIALJNI_LOG(logDEBUG) << "Data Bits: " << bits;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
serialSetDataBits(port, bits, statusPtr);
SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
serialSetDataBits(port, bits, &status);
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialSetParity
* Signature: (BBLjava/nio/IntBuffer;)V
* Signature: (BB)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetParity
(JNIEnv * env, jclass, jbyte port, jbyte parity, jobject status)
(JNIEnv * env, jclass, jbyte port, jbyte parity)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Parity";
SERIALJNI_LOG(logDEBUG) << "Parity: " << parity;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
serialSetParity(port, parity, statusPtr);
SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
serialSetParity(port, parity, &status);
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialSetStopBits
* Signature: (BBLjava/nio/IntBuffer;)V
* Signature: (BB)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetStopBits
(JNIEnv * env, jclass, jbyte port, jbyte bits, jobject status)
(JNIEnv * env, jclass, jbyte port, jbyte bits)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Stop Bits";
SERIALJNI_LOG(logDEBUG) << "Stop Bits: " << bits;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
serialSetStopBits(port, bits, statusPtr);
SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
serialSetStopBits(port, bits, &status);
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialSetWriteMode
* Signature: (BBLjava/nio/IntBuffer;)V
* Signature: (BB)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetWriteMode
(JNIEnv * env, jclass, jbyte port, jbyte mode, jobject status)
(JNIEnv * env, jclass, jbyte port, jbyte mode)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Write Mode";
SERIALJNI_LOG(logDEBUG) << "Write mode: " << mode;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
serialSetWriteMode(port, mode, statusPtr);
SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
serialSetWriteMode(port, mode, &status);
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialSetFlowControl
* Signature: (BBLjava/nio/IntBuffer;)V
* Signature: (BB)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetFlowControl
(JNIEnv * env, jclass, jbyte port, jbyte flow, jobject status)
(JNIEnv * env, jclass, jbyte port, jbyte flow)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Flow Control";
SERIALJNI_LOG(logDEBUG) << "Flow Control: " << flow;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
serialSetFlowControl(port, flow, statusPtr);
SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
serialSetFlowControl(port, flow, &status);
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialSetTimeout
* Signature: (BFLjava/nio/IntBuffer;)V
* Signature: (BF)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetTimeout
(JNIEnv * env, jclass, jbyte port, jfloat timeout, jobject status)
(JNIEnv * env, jclass, jbyte port, jfloat timeout)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Timeout";
SERIALJNI_LOG(logDEBUG) << "Timeout: " << timeout;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
serialSetTimeout(port, timeout, statusPtr);
SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
serialSetTimeout(port, timeout, &status);
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialEnableTermination
* Signature: (BCLjava/nio/IntBuffer;)V
* Signature: (BC)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialEnableTermination
(JNIEnv * env, jclass, jbyte port, jchar terminator, jobject status)
(JNIEnv * env, jclass, jbyte port, jchar terminator)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Enable Termination";
SERIALJNI_LOG(logDEBUG) << "Terminator: " << terminator;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
serialEnableTermination(port, terminator, statusPtr);
SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
serialEnableTermination(port, terminator, &status);
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialDisableTermination
* Signature: (BLjava/nio/IntBuffer;)V
* Signature: (B)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialDisableTermination
(JNIEnv * env, jclass, jbyte port, jobject status)
(JNIEnv * env, jclass, jbyte port)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Disable termination";
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
serialDisableTermination(port, statusPtr);
SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
serialDisableTermination(port, &status);
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialSetReadBufferSize
* Signature: (BILjava/nio/IntBuffer;)V
* Signature: (BI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetReadBufferSize
(JNIEnv * env, jclass, jbyte port, jint size, jobject status)
(JNIEnv * env, jclass, jbyte port, jint size)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Read Buffer Size";
SERIALJNI_LOG(logDEBUG) << "Size: " << size;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
serialSetReadBufferSize(port, size, statusPtr);
SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
serialSetReadBufferSize(port, size, &status);
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialSetWriteBufferSize
* Signature: (BILjava/nio/IntBuffer;)V
* Signature: (BI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetWriteBufferSize
(JNIEnv * env, jclass, jbyte port, jint size, jobject status)
(JNIEnv * env, jclass, jbyte port, jint size)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Write Buffer Size";
SERIALJNI_LOG(logDEBUG) << "Size: " << size;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
serialSetWriteBufferSize(port, size, statusPtr);
SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
serialSetWriteBufferSize(port, size, &status);
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialGetBytesRecieved
* Signature: (BLjava/nio/IntBuffer;)I
* Signature: (B)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialGetBytesRecieved
(JNIEnv * env, jclass, jbyte port, jobject status)
(JNIEnv * env, jclass, jbyte port)
{
SERIALJNI_LOG(logDEBUG) << "Serial Get Bytes Received";
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
jint retVal = serialGetBytesReceived(port, statusPtr);
SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
jint retVal = serialGetBytesReceived(port, &status);
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
return retVal;
}
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialRead
* Signature: (BLjava/nio/ByteBuffer;ILjava/nio/IntBuffer;)I
* Signature: (BLjava/nio/ByteBuffer;I)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialRead
(JNIEnv * env, jclass, jbyte port, jobject dataReceived, jint size, jobject status)
(JNIEnv * env, jclass, jbyte port, jobject dataReceived, jint size)
{
SERIALJNI_LOG(logDEBUG) << "Serial Read";
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
jbyte * dataReceivedPtr = NULL;
dataReceivedPtr = (jbyte*)env->GetDirectBufferAddress(dataReceived);
*statusPtr = 0;
jint retVal = serialRead(port, (char*)dataReceivedPtr, size, statusPtr);
int32_t status = 0;
jint retVal = serialRead(port, (char*)dataReceivedPtr, size, &status);
SERIALJNI_LOG(logDEBUG) << "ReturnValue = " << retVal;
SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
return retVal;
}
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialWrite
* Signature: (BLjava/nio/ByteBuffer;ILjava/nio/IntBuffer;)I
* Signature: (BLjava/nio/ByteBuffer;I)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialWrite
(JNIEnv * env, jclass, jbyte port, jobject dataToSend, jint size, jobject status)
(JNIEnv * env, jclass, jbyte port, jobject dataToSend, jint size)
{
SERIALJNI_LOG(logDEBUG) << "Serial Write";
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
jbyte * dataToSendPtr = NULL;
if(dataToSend != 0){
dataToSendPtr = (jbyte*)env->GetDirectBufferAddress(dataToSend);
}
*statusPtr = 0;
jint retVal = serialWrite(port, (const char*)dataToSendPtr, size, statusPtr);
int32_t status = 0;
jint retVal = serialWrite(port, (const char*)dataToSendPtr, size, &status);
SERIALJNI_LOG(logDEBUG) << "ReturnValue = " << retVal;
SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
return retVal;
}
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialFlush
* Signature: (BLjava/nio/IntBuffer;)V
* Signature: (B)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialFlush
(JNIEnv * env, jclass, jbyte port, jobject status)
(JNIEnv * env, jclass, jbyte port)
{
SERIALJNI_LOG(logDEBUG) << "Serial Flush";
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
serialFlush(port, statusPtr);
SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
serialFlush(port, &status);
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialClear
* Signature: (BLjava/nio/IntBuffer;)V
* Signature: (B)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialClear
(JNIEnv * env, jclass, jbyte port, jobject status)
(JNIEnv * env, jclass, jbyte port)
{
SERIALJNI_LOG(logDEBUG) << "Serial Clear";
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
serialClear(port, statusPtr);
SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
serialClear(port, &status);
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialClose
* Signature: (BLjava/nio/IntBuffer;)V
* Signature: (B)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialClose
(JNIEnv * env, jclass, jbyte port, jobject status)
(JNIEnv * env, jclass, jbyte port)
{
SERIALJNI_LOG(logDEBUG) << "Serial Close";
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
serialClose(port, statusPtr);
SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
int32_t status = 0;
serialClose(port, &status);
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
} // extern "C"

View File

@@ -4,149 +4,137 @@
#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)
typedef void *VoidPointer;
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
* Method: initializeSolenoidPort
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)J
*/
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_initializeSolenoidPort
(JNIEnv *env, jclass, jobject port_pointer, jobject status)
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_initializeSolenoidPort
(JNIEnv *env, jclass, jlong port_pointer)
{
SOLENOIDJNI_LOG(logDEBUG) << "Calling SolenoidJNI initializeSolenoidPort";
VoidPointer *port_pointer_pointer = (VoidPointer *)env->GetDirectBufferAddress(port_pointer);
SOLENOIDJNI_LOG(logDEBUG) << "Port Ptr = " << *port_pointer_pointer;
char *aschars = (char *)(*port_pointer_pointer);
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;
jint *status_pointer = (jint*)env->GetDirectBufferAddress(status);
SOLENOIDJNI_LOG(logDEBUG) << "Status Ptr = " << status_pointer;
int32_t status = 0;
void* solenoid_port_pointer = initializeSolenoidPort((void*)port_pointer, &status);
VoidPointer *solenoid_port_pointer = new VoidPointer;
*status_pointer = 0;
*solenoid_port_pointer = initializeSolenoidPort(*port_pointer_pointer, status_pointer);
SOLENOIDJNI_LOG(logDEBUG) << "Status = " << status;
SOLENOIDJNI_LOG(logDEBUG) << "Solenoid Port Pointer = " << solenoid_port_pointer;
SOLENOIDJNI_LOG(logDEBUG) << "Status = " << *status_pointer;
SOLENOIDJNI_LOG(logDEBUG) << "Solenoid Port Pointer = " << *solenoid_port_pointer;
int *asints = (int *)(*solenoid_port_pointer);
int *asints = (int *)solenoid_port_pointer;
SOLENOIDJNI_LOG(logDEBUG) << '\t' << asints[0] << '\t' << asints[1] << std::endl;
return env->NewDirectByteBuffer(solenoid_port_pointer, 4);
CheckStatus(env, status);
return (jlong)solenoid_port_pointer;
}
/*
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
* Method: getPortWithModule
* Signature: (BB)Ljava/nio/ByteBuffer;
* Signature: (BB)J
*/
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getPortWithModule
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getPortWithModule
(JNIEnv *env, jclass, jbyte module, jbyte channel)
{
VoidPointer *port_pointer = new VoidPointer;
*port_pointer = getPortWithModule(module, channel);
void* port_pointer = getPortWithModule(module, channel);
return env->NewDirectByteBuffer(port_pointer, 4);
return (jlong)port_pointer;
}
/*
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
* Method: setSolenoid
* Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)V
* Signature: (JZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_setSolenoid
(JNIEnv *env, jclass, jobject solenoid_port, jbyte value, jobject status)
(JNIEnv *env, jclass, jlong solenoid_port, jboolean value)
{
SOLENOIDJNI_LOG(logDEBUG) << "Calling SolenoidJNI SetSolenoid";
VoidPointer *solenoid_port_pointer = (VoidPointer *)env->GetDirectBufferAddress(solenoid_port);
SOLENOIDJNI_LOG(logDEBUG) << "Solenoid Port Pointer = " << *solenoid_port_pointer;
SOLENOIDJNI_LOG(logDEBUG) << "Solenoid Port Pointer = " << (void*)solenoid_port;
jint *status_pointer = (jint*)env->GetDirectBufferAddress(status);
SOLENOIDJNI_LOG(logDEBUG) << "Status Ptr = " << status_pointer;
*status_pointer = 0;
setSolenoid(*solenoid_port_pointer, value, status_pointer);
int32_t status = 0;
setSolenoid((void*)solenoid_port, value, &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
* Method: getSolenoid
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B
* Signature: (J)Z
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getSolenoid
(JNIEnv *env, jclass, jobject solenoid_port, jobject status)
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getSolenoid
(JNIEnv *env, jclass, jlong solenoid_port)
{
VoidPointer *solenoid_port_pointer = (VoidPointer *)env->GetDirectBufferAddress(solenoid_port);
jint *status_pointer = (jint*)env->GetDirectBufferAddress(status);
*status_pointer = 0;
return getSolenoid(*solenoid_port_pointer, status_pointer);
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: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B
* Signature: (J)I
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getPCMSolenoidBlackList
(JNIEnv *env, jclass, jobject solenoid_port, jobject status)
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getPCMSolenoidBlackList
(JNIEnv *env, jclass, jlong solenoid_port)
{
VoidPointer *solenoid_port_pointer = (VoidPointer *)env->GetDirectBufferAddress(solenoid_port);
jint *status_pointer = (jint*)env->GetDirectBufferAddress(status);
*status_pointer = 0;
return getPCMSolenoidBlackList(*solenoid_port_pointer, status_pointer);
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: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getPCMSolenoidVoltageStickyFault
(JNIEnv *env, jclass, jobject solenoid_port, jobject status)
(JNIEnv *env, jclass, jlong solenoid_port)
{
VoidPointer *solenoid_port_pointer = (VoidPointer *)env->GetDirectBufferAddress(solenoid_port);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
*status_pointer = 0;
return getPCMSolenoidVoltageStickyFault(*solenoid_port_pointer, status_pointer);
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: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getPCMSolenoidVoltageFault
(JNIEnv *env, jclass, jobject solenoid_port, jobject status)
(JNIEnv *env, jclass, jlong solenoid_port)
{
VoidPointer *solenoid_port_pointer = (VoidPointer *)env->GetDirectBufferAddress(solenoid_port);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
*status_pointer = 0;
return getPCMSolenoidVoltageFault(*solenoid_port_pointer, status_pointer);
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: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_clearAllPCMStickyFaults
(JNIEnv *env, jclass, jobject solenoid_port, jobject status)
(JNIEnv *env, jclass, jlong solenoid_port)
{
VoidPointer *solenoid_port_pointer = (VoidPointer *)env->GetDirectBufferAddress(solenoid_port);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
*status_pointer = 0;
clearAllPCMStickyFaults_sol(*solenoid_port_pointer, status_pointer);
int32_t status = 0;
clearAllPCMStickyFaults_sol((void*)solenoid_port, &status);
CheckStatus(env, status);
}
} // extern "C"