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

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