WPILib Reorganization

This is a major restructuring of the WPILib repository to simply build
procedures and remove the remnants of Maven from everything except the
eclipse plugins. Gradle files have been largely simplified or rewritten,
taking advantage of splitting up parts of the build into separate build
files for ease of reading.

The eclipse plugins are now in a separate project, as is ntcore. All
dependencies are resolved via Maven dependencies, with the
Jenkins-maintained WPILib repo. Project structures have also been
simplified: we no longer have separate subprojects inside wpilibc and
wpilibj. Where possible, these changes hav been done with git renames,
to make sure we still have full history for all repositories. Other
unrelated subprojects have also been broken out: OutlineViewer is now a
separate project.

Change-Id: Ib4e2a6e1a2f66427a14f16612b0e0d69ed661878
This commit is contained in:
Fredric Silberberg
2015-09-24 20:26:49 -04:00
parent c20d34c2b6
commit 6d854afb0e
1769 changed files with 2278 additions and 333177 deletions

View File

@@ -0,0 +1,62 @@
#include <jni.h>
#include "edu_wpi_first_wpilibj_hal_AccelerometerJNI.h"
#include "HAL/Accelerometer.hpp"
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_AccelerometerJNI
* Method: setAccelerometerActive
* Signature: (Z)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AccelerometerJNI_setAccelerometerActive
(JNIEnv *, jclass, jboolean active)
{
setAccelerometerActive(active);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AccelerometerJNI
* Method: setAccelerometerRange
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AccelerometerJNI_setAccelerometerRange
(JNIEnv *, jclass, jint range)
{
setAccelerometerRange((AccelerometerRange)range);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AccelerometerJNI
* Method: getAccelerometerX
* Signature: ()D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AccelerometerJNI_getAccelerometerX
(JNIEnv *, jclass)
{
return getAccelerometerX();
}
/*
* Class: edu_wpi_first_wpilibj_hal_AccelerometerJNI
* Method: getAccelerometerY
* Signature: ()D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AccelerometerJNI_getAccelerometerY
(JNIEnv *, jclass)
{
return getAccelerometerY();
}
/*
* Class: edu_wpi_first_wpilibj_hal_AccelerometerJNI
* Method: getAccelerometerZ
* Signature: ()D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AccelerometerJNI_getAccelerometerZ
(JNIEnv *, jclass)
{
return getAccelerometerZ();
}
} // extern "C"

View File

@@ -0,0 +1,629 @@
#include <jni.h>
#include <assert.h>
#include "Log.hpp"
#include "edu_wpi_first_wpilibj_hal_AnalogJNI.h"
#include "HAL/Analog.hpp"
#include "HALUtil.h"
// set the logging level
TLogLevel analogJNILogLevel = logWARNING;
#define ANALOGJNI_LOG(level) \
if (level > analogJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: initializeAnalogInputPort
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogInputPort
(JNIEnv * env, jclass, jlong id)
{
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: (J)J
*/
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogOutputPort
(JNIEnv * env, jclass, jlong id)
{
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)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogModule
(JNIEnv *, jclass, jbyte value)
{
//ANALOGJNI_LOG(logDEBUG) << "Module = " << (jint)value;
jboolean returnValue = checkAnalogModule( value );
//ANALOGJNI_LOG(logDEBUG) << "checkAnalogModuleResult = " << (jint)returnValue;
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: checkAnalogInputChannel
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogInputChannel
(JNIEnv *, jclass, jint value)
{
//ANALOGJNI_LOG(logDEBUG) << "Channel = " << value;
jboolean returnValue = checkAnalogInputChannel( value );
//ANALOGJNI_LOG(logDEBUG) << "checkAnalogChannelResult = " << (jint)returnValue;
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: checkAnalogOutputChannel
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogOutputChannel
(JNIEnv *, jclass, jint value)
{
//ANALOGJNI_LOG(logDEBUG) << "Channel = " << value;
jboolean returnValue = checkAnalogOutputChannel( value );
//ANALOGJNI_LOG(logDEBUG) << "checkAnalogChannelResult = " << (jint)returnValue;
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: setAnalogOutput
* Signature: (JD)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogOutput
(JNIEnv * env, jclass, jlong id, jdouble voltage)
{
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: (J)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogOutput
(JNIEnv * env, jclass, jlong id)
{
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: (D)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogSampleRate
(JNIEnv * env, jclass, jdouble value)
{
ANALOGJNI_LOG(logDEBUG) << "SampleRate = " << value;
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: ()D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogSampleRate
(JNIEnv * env, jclass)
{
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: (JI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogAverageBits
(JNIEnv * env, jclass, jlong id, jint value)
{
ANALOGJNI_LOG(logDEBUG) << "AverageBits = " << value;
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: (J)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogAverageBits
(JNIEnv * env, jclass, jlong id)
{
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: (JI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogOversampleBits
(JNIEnv * env, jclass, jlong id, jint value)
{
ANALOGJNI_LOG(logDEBUG) << "OversampleBits = " << value;
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: (J)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogOversampleBits
(JNIEnv * env, jclass, jlong id)
{
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: (J)S
*/
JNIEXPORT jshort JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogValue
(JNIEnv * env, jclass, jlong id)
{
//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: (J)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogAverageValue
(JNIEnv * env, jclass, jlong id)
{
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: (JD)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogVoltsToValue
(JNIEnv * env, jclass, jlong id, jdouble voltageValue)
{
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
ANALOGJNI_LOG(logDEBUG) << "VoltageValue = " << voltageValue;
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: (J)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogVoltage
(JNIEnv * env, jclass, jlong id)
{
//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: (J)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogAverageVoltage
(JNIEnv * env, jclass, jlong id)
{
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: (J)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogLSBWeight
(JNIEnv * env, jclass, jlong id)
{
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
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: (J)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogOffset
(JNIEnv * env, jclass, jlong id)
{
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
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: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_isAccumulatorChannel
(JNIEnv * env, jclass, jlong id)
{
ANALOGJNI_LOG(logDEBUG) << "isAccumulatorChannel";
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
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: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initAccumulator
(JNIEnv * env, jclass, jlong id)
{
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: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_resetAccumulator
(JNIEnv * env, jclass, jlong id)
{
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
resetAccumulator((void*)id, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: setAccumulatorCenter
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAccumulatorCenter
(JNIEnv * env, jclass, jlong id, jint center)
{
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: (JI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAccumulatorDeadband
(JNIEnv * env, jclass, jlong id, jint deadband)
{
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
setAccumulatorDeadband((void*)id, deadband, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: getAccumulatorValue
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorValue
(JNIEnv * env, jclass, jlong id)
{
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
jlong returnValue = getAccumulatorValue((void*)id, &status);
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
ANALOGJNI_LOG(logDEBUG) << "AccumulatorValue = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: getAccumulatorCount
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorCount
(JNIEnv * env, jclass, jlong id)
{
ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id;
int32_t status = 0;
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: (JLjava/nio/LongBuffer;Ljava/nio/IntBuffer;)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorOutput
(JNIEnv * env, jclass, jlong id, jobject value, jobject count)
{
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((void*)id, valuePtr, countPtr, &status);
ANALOGJNI_LOG(logDEBUG) << "Value = " << *valuePtr;
ANALOGJNI_LOG(logDEBUG) << "Count = " << *countPtr;
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: initializeAnalogTrigger
* Signature: (JLjava/nio/IntBuffer;)J
*/
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogTrigger
(JNIEnv * env, jclass, jlong id, jobject index)
{
ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
jint * indexPtr = (jint*)env->GetDirectBufferAddress(index);
ANALOGJNI_LOG(logDEBUG) << "Index Ptr = " << indexPtr;
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: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_cleanAnalogTrigger
(JNIEnv * env, jclass, jlong id)
{
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id;
int32_t status = 0;
cleanAnalogTrigger((void*)id, &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: setAnalogTriggerLimitsRaw
* Signature: (JII)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogTriggerLimitsRaw
(JNIEnv * env, jclass, jlong id, jint lower, jint upper)
{
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id;
int32_t status = 0;
setAnalogTriggerLimitsRaw((void*)id, lower, upper, &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: setAnalogTriggerLimitsVoltage
* Signature: (JDD)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogTriggerLimitsVoltage
(JNIEnv * env, jclass, jlong id, jdouble lower, jdouble upper)
{
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id;
int32_t status = 0;
setAnalogTriggerLimitsVoltage((void*)id, lower, upper, &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: setAnalogTriggerAveraged
* Signature: (JZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogTriggerAveraged
(JNIEnv * env, jclass, jlong id, jboolean averaged)
{
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id;
int32_t status = 0;
setAnalogTriggerAveraged((void*)id, averaged, &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: setAnalogTriggerFiltered
* Signature: (JZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogTriggerFiltered
(JNIEnv * env, jclass, jlong id, jboolean filtered)
{
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id;
int32_t status = 0;
setAnalogTriggerFiltered((void*)id, filtered, &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
* Method: getAnalogTriggerInWindow
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogTriggerInWindow
(JNIEnv * env, jclass, jlong id)
{
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id;
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: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogTriggerTriggerState
(JNIEnv * env, jclass, jlong id)
{
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id;
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: (JI)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogTriggerOutput
(JNIEnv * env, jclass, jlong id, jint type)
{
ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id;
int32_t status = 0;
jboolean val = getAnalogTriggerOutput((void*)id, (AnalogTriggerType)type, &status);
CheckStatus(env, status);
return val;
}
} // extern "C"

View File

@@ -0,0 +1,105 @@
#include <jni.h>
#include <assert.h>
#include "Log.hpp"
#include "edu_wpi_first_wpilibj_can_CANJNI.h"
#include "HAL/CAN.hpp"
#include "FRC_NetworkCommunication/CANSessionMux.h"
#include "HALUtil.h"
// set the logging level
//TLogLevel canJNILogLevel = logDEBUG;
TLogLevel canJNILogLevel = logERROR;
#define CANJNI_LOG(level) \
if (level > canJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_can_CANJNI
* Method: FRCNetworkCommunicationCANSessionMuxSendMessage
* 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)
{
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);
CANJNI_LOG(logDEBUG) << "Message ID " << std::hex << messageID;
if(logDEBUG <= canJNILogLevel)
{
if(dataBuffer)
{
std::ostringstream str;
str << std::setfill('0') << std::hex;
for(int i = 0; i < dataSize; i++)
{
str << std::setw(2) << (int)dataBuffer[i] << ' ';
}
Log().Get(logDEBUG) << "Data: " << str.str();
}
else
{
CANJNI_LOG(logDEBUG) << "Data: null";
}
}
CANJNI_LOG(logDEBUG) << "Period: " << periodMs;
int32_t status = 0;
FRC_NetworkCommunication_CANSessionMux_sendMessage(messageID, dataBuffer, dataSize, periodMs, &status);
CANJNI_LOG(logDEBUG) << "Status: " << status;
CheckCANStatus(env, status, messageID);
}
static uint8_t buffer[8];
/*
* Class: edu_wpi_first_wpilibj_can_CANJNI
* Method: FRCNetworkCommunicationCANSessionMuxReceiveMessage
* 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)
{
CANJNI_LOG(logDEBUG) << "Calling CANJNI FRCNetworkCommunicationCANSessionMuxReceiveMessage";
uint32_t *messageIDPtr = (uint32_t *)env->GetDirectBufferAddress(messageID);
uint32_t *timeStampPtr = (uint32_t *)env->GetDirectBufferAddress(timeStamp);
uint8_t dataSize = 0;
int32_t status = 0;
FRC_NetworkCommunication_CANSessionMux_receiveMessage(messageIDPtr, messageIDMask, buffer, &dataSize, timeStampPtr, &status);
CANJNI_LOG(logDEBUG) << "Message ID " << std::hex << *messageIDPtr;
if(logDEBUG <= canJNILogLevel)
{
std::ostringstream str;
str << std::setfill('0') << std::hex;
for(int i = 0; i < dataSize; i++)
{
str << std::setw(2) << (int)buffer[i] << ' ';
}
Log().Get(logDEBUG) << "Data: " << str.str();
}
CANJNI_LOG(logDEBUG) << "Timestamp: " << *timeStampPtr;
CANJNI_LOG(logDEBUG) << "Status: " << status;
if (!CheckCANStatus(env, status, *messageIDPtr)) return nullptr;
return env->NewDirectByteBuffer(buffer, dataSize);
}
} // extern "C"

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,197 @@
#include "Log.hpp"
#include "edu_wpi_first_wpilibj_hal_CompressorJNI.h"
#include "HAL/HAL.hpp"
#include "HALUtil.h"
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: initializeCompressor
* Signature: (B)J
*/
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_initializeCompressor
(JNIEnv *env, jclass, jbyte module)
{
void* pcm = initializeCompressor(module);
return (jlong)pcm;
}
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: checkCompressorModule
* Signature: (B)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_checkCompressorModule
(JNIEnv *env, jclass, jbyte module)
{
return checkCompressorModule(module);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: getCompressor
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressor
(JNIEnv *env, jclass, jlong pcm_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: (JZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_setClosedLoopControl
(JNIEnv *env, jclass, jlong pcm_pointer, jboolean value)
{
int32_t status = 0;
setClosedLoopControl((void*)pcm_pointer, value, &status);
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: getClosedLoopControl
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getClosedLoopControl
(JNIEnv *env, jclass, jlong pcm_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: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getPressureSwitch
(JNIEnv *env, jclass, jlong pcm_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: (J)F
*/
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrent
(JNIEnv *env, jclass, jlong pcm_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: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrentTooHighFault
(JNIEnv *env, jclass, jlong pcm_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: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrentTooHighStickyFault
(JNIEnv *env, jclass, jlong pcm_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: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorShortedStickyFault
(JNIEnv *env, jclass, jlong pcm_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: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorShortedFault
(JNIEnv *env, jclass, jlong pcm_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: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorNotConnectedStickyFault
(JNIEnv *env, jclass, jlong pcm_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: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorNotConnectedFault
(JNIEnv *env, jclass, jlong pcm_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: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_clearAllPCMStickyFaults
(JNIEnv *env, jclass, jlong pcm_pointer)
{
int32_t status = 0;
clearAllPCMStickyFaults((void*)pcm_pointer, &status);
CheckStatus(env, status);
}
} // extern "C"

View File

@@ -0,0 +1,426 @@
#include <jni.h>
#include <assert.h>
#include "Log.hpp"
#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;
#define COUNTERJNI_LOG(level) \
if (level > counterJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: initializeCounter
* Signature: (ILjava/nio/IntBuffer;)J
*/
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 = " << (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 = " << status;
COUNTERJNI_LOG(logDEBUG) << "COUNTER Ptr = " << counter;
CheckStatus(env, status);
return (jlong)counter;
}
/*
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
* Method: freeCounter
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_freeCounter
(JNIEnv * env, jclass, jlong id)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI freeCounter";
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: (JI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterAverageSize
(JNIEnv * env, jclass, jlong id, jint value)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterAverageSize";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "AverageSize = " << value;
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: (JIZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpSource
(JNIEnv * env, jclass, jlong id, jint pin, jboolean analogTrigger)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterUpSource";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Pin = " << pin;
COUNTERJNI_LOG(logDEBUG) << "AnalogTrigger = " << (jint)analogTrigger;
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: (JZZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpSourceEdge
(JNIEnv * env, jclass, jlong id, jboolean valueRise, jboolean valueFall)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterUpSourceEdge";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Rise = " << (jint)valueRise;
COUNTERJNI_LOG(logDEBUG) << "Fall = " << (jint)valueFall;
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: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_clearCounterUpSource
(JNIEnv * env, jclass, jlong id)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI clearCounterUpSource";
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: (JIZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterDownSource
(JNIEnv * env, jclass, jlong id, jint pin, jboolean analogTrigger)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterDownSource";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Pin = " << pin;
COUNTERJNI_LOG(logDEBUG) << "AnalogTrigger = " << (jint)analogTrigger;
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: (JZZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterDownSourceEdge
(JNIEnv * env, jclass, jlong id, jboolean valueRise, jboolean valueFall)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterDownSourceEdge";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "Rise = " << (jint)valueRise;
COUNTERJNI_LOG(logDEBUG) << "Fall = " << (jint)valueFall;
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: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_clearCounterDownSource
(JNIEnv * env, jclass, jlong id)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI clearCounterDownSource";
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: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpDownMode
(JNIEnv * env, jclass, jlong id)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterUpDownMode";
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: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterExternalDirectionMode
(JNIEnv * env, jclass, jlong id)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterExternalDirectionMode";
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: (JZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterSemiPeriodMode
(JNIEnv * env, jclass, jlong id, jboolean value)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterSemiPeriodMode";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "SemiPeriodMode = " << (jint)value;
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: (JD)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterPulseLengthMode
(JNIEnv * env, jclass, jlong id, jdouble value)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterPulseLengthMode";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "PulseLengthMode = " << value;
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: (J)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterSamplesToAverage
(JNIEnv * env, jclass, jlong id)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI getCounterSamplesToAverage";
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: (JI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterSamplesToAverage
(JNIEnv * env, jclass, jlong id, jint value)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterSamplesToAverage";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "SamplesToAverage = " << value;
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: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_resetCounter
(JNIEnv * env, jclass, jlong id)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI resetCounter";
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: (J)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounter
(JNIEnv * env, jclass, jlong id)
{
//COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI getCounter";
//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: (J)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterPeriod
(JNIEnv *env, jclass, jlong id)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI getCounterPeriod";
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: (JD)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterMaxPeriod
(JNIEnv * env, jclass, jlong id, jdouble value)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterMaxPeriod";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "MaxPeriod = " << value;
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: (JZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpdateWhenEmpty
(JNIEnv * env, jclass, jlong id, jboolean value)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterMaxPeriod";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "UpdateWhenEmpty = " << (jint)value;
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: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterStopped
(JNIEnv * env, jclass, jlong id)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI getCounterStopped";
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: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterDirection
(JNIEnv * env, jclass, jlong id)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI getCounterDirection";
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: (JZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterReverseDirection
(JNIEnv * env, jclass, jlong id, jboolean value)
{
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterReverseDirection";
COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id;
COUNTERJNI_LOG(logDEBUG) << "ReverseDirection = " << (jint)value;
int32_t status = 0;
setCounterReverseDirection((void*)id, value, &status);
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
} // extern "C"

View File

@@ -0,0 +1,197 @@
#include <jni.h>
#include <assert.h>
#include "Log.hpp"
#include "edu_wpi_first_wpilibj_hal_DIOJNI.h"
#include "HAL/Digital.hpp"
#include "HALUtil.h"
// set the logging level
TLogLevel dioJNILogLevel = logWARNING;
#define DIOJNI_LOG(level) \
if (level > dioJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_DIOJNI
* Method: initializeDigitalPort
* Signature: (J)J;
*/
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_initializeDigitalPort
(JNIEnv * env, jclass, jlong id)
{
DIOJNI_LOG(logDEBUG) << "Calling DIOJNI initializeDigitalPort";
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: (JZ)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_allocateDIO
(JNIEnv * env, jclass, jlong id, jboolean value)
{
DIOJNI_LOG(logDEBUG) << "Calling DIOJNI allocateDIO";
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;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_DIOJNI
* Method: freeDIO
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_freeDIO
(JNIEnv * env, jclass, jlong id)
{
DIOJNI_LOG(logDEBUG) << "Calling DIOJNI freeDIO";
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: (JS)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_setDIO
(JNIEnv *env, jclass, jlong id, jshort value)
{
//DIOJNI_LOG(logDEBUG) << "Calling DIOJNI setDIO";
//DIOJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
//DIOJNI_LOG(logDEBUG) << "Value = " << value;
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: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_getDIO
(JNIEnv * env, jclass, jlong id)
{
//DIOJNI_LOG(logDEBUG) << "Calling DIOJNI getDIO";
//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;
}
/*
* Class: edu_wpi_first_wpilibj_hal_DIOJNI
* Method: getDIODirection
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_getDIODirection
(JNIEnv *env, jclass, jlong id)
{
DIOJNI_LOG(logDEBUG) << "Calling DIOJNI getDIODirection (RR upd)";
//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: (JD)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_pulse
(JNIEnv *env, jclass, jlong id, jdouble value)
{
DIOJNI_LOG(logDEBUG) << "Calling DIOJNI pulse (RR upd)";
//DIOJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
//DIOJNI_LOG(logDEBUG) << "Value = " << value;
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: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_isPulsing
(JNIEnv *env, jclass, jlong id)
{
DIOJNI_LOG(logDEBUG) << "Calling DIOJNI isPulsing (RR upd)";
//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;
}
/*
* Class: edu_wpi_first_wpilibj_hal_DIOJNI
* Method: isAnyPulsing
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_isAnyPulsing
(JNIEnv *env, jclass)
{
DIOJNI_LOG(logDEBUG) << "Calling DIOJNI isAnyPulsing (RR upd)";
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: ()S
*/
JNIEXPORT jshort JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_getLoopTiming
(JNIEnv * env, jclass)
{
DIOJNI_LOG(logDEBUG) << "Calling DIOJNI getLoopTimeing";
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

@@ -0,0 +1,244 @@
#include <jni.h>
#include <assert.h>
#include "Log.hpp"
#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;
#define ENCODERJNI_LOG(level) \
if (level > encoderJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_EncoderJNI
* Method: initializeEncoder
* Signature: (BIZBIZZLjava/nio/IntBuffer;)J
*/
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;
ENCODERJNI_LOG(logDEBUG) << "Pin A = " << port_a_pin;
ENCODERJNI_LOG(logDEBUG) << "Analog Trigger A = " << (jint)port_a_analog_trigger;
ENCODERJNI_LOG(logDEBUG) << "Module B = " << (jint)port_b_module;
ENCODERJNI_LOG(logDEBUG) << "Pin B = " << port_b_pin;
ENCODERJNI_LOG(logDEBUG) << "Analog Trigger B = " << (jint)port_b_analog_trigger;
ENCODERJNI_LOG(logDEBUG) << "Reverse direction = " << (jint)reverseDirection;
jint * indexPtr = (jint*)env->GetDirectBufferAddress(index);
ENCODERJNI_LOG(logDEBUG) << "Index Ptr = " << indexPtr;
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, &status);
ENCODERJNI_LOG(logDEBUG) << "Index = " << *indexPtr;
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: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_freeEncoder
(JNIEnv * env, jclass, jlong id)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI freeEncoder";
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: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_resetEncoder
(JNIEnv * env, jclass, jlong id)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI resetEncoder";
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: (J)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_getEncoder
(JNIEnv * env, jclass, jlong id)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI getEncoder";
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: (J)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_getEncoderPeriod
(JNIEnv * env, jclass, jlong id)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI getEncoderPeriod";
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: (JD)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_setEncoderMaxPeriod
(JNIEnv * env, jclass, jlong id, jdouble value)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI setEncoderMaxPeriod";
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: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_getEncoderStopped
(JNIEnv * env, jclass, jlong id)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI getEncoderStopped";
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: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_getEncoderDirection
(JNIEnv * env, jclass, jlong id)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI getEncoderDirection";
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: (JZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_setEncoderReverseDirection
(JNIEnv * env, jclass, jlong id, jboolean value)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI setEncoderReverseDirection";
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: (JI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_setEncoderSamplesToAverage
(JNIEnv * env, jclass, jlong id, jint value)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI setEncoderSamplesToAverage";
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: (J)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_getEncoderSamplesToAverage
(JNIEnv * env, jclass, jlong id)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI getEncoderSamplesToAverage";
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: (JIZZZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_setEncoderIndexSource
(JNIEnv * env, jclass, jlong id, jint pin, jboolean analogTrigger, jboolean activeHigh, jboolean edgeSensitive)
{
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI setEncoderIndexSource";
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");
int32_t status = 0;
setEncoderIndexSource((void*)id, pin, analogTrigger, activeHigh, edgeSensitive, &status);
ENCODERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
} // extern "C"

View File

@@ -0,0 +1,656 @@
#include <jni.h>
#include <assert.h>
#include "Log.hpp"
#include "edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary.h"
#include "HAL/HAL.hpp"
//#include "NetworkCommunication/FRCComm.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "HALUtil.h"
// set the logging level
TLogLevel netCommLogLevel = logWARNING;
#define NETCOMM_LOG(level) \
if (level > netCommLogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: FRC_NetworkCommunication_nAICalibration_getLSBWeight
* Signature: (IILjava/lang/Integer;)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_FRCNetworkCommunicationAICalibrationGetLSBWeight
(JNIEnv *, jclass, jint, jint, jobject)
{
assert(false);
return 0;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: FRC_NetworkCommunication_nAICalibration_getOffset
* Signature: (IILjava/lang/Integer;)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_FRCNetworkCommunicationAICalibrationGetOffset
(JNIEnv *, jclass, jint, jint, jobject)
{
assert(false);
return 0;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: getTargetClass
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_getTargetClass
(JNIEnv *, jclass)
{
assert(false);
return 0;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: FRC_NetworkCommunication_nLoadOut_getModulePresence
* Signature: (IB)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_FRCNetworkCommunicationLoadOutGetModulePresence
(JNIEnv *, jclass, jint, jbyte)
{
assert(false);
return 0;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: FRC_NetworkCommunication_nLoadOut_getTargetClass
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_FRCNetworkCommunicationLoadOutGetTargetClass
(JNIEnv *, jclass)
{
assert(false);
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: report
* Signature: (IBBLjava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_report
(JNIEnv *, jclass, jint, jbyte, jbyte, jstring)
{
assert(false);
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: FRC_NetworkCommunication_nUsageReporting_report
* Signature: (BBBLjava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_FRCNetworkCommunicationUsageReportingReport
(JNIEnv * paramEnv, jclass, jbyte paramResource, jbyte paramInstanceNumber, jbyte paramContext, jstring paramFeature)
{
const char * featureStr = paramEnv->GetStringUTFChars(paramFeature, NULL);
NETCOMM_LOG(logDEBUG) << "Calling FRCNetworkCommunicationsLibrary report " << "res:"<< (unsigned int)paramResource << " instance:" << (unsigned int)paramInstanceNumber << " context:" << (unsigned int)paramContext << " feature:" << featureStr;
jint returnValue = HALReport(paramResource, paramInstanceNumber, paramContext, featureStr);
paramEnv->ReleaseStringUTFChars(paramFeature,featureStr);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: getFPGAHardwareVersion
* Signature: (Ljava/nio/ShortBuffer;Ljava/nio/IntBuffer;)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_getFPGAHardwareVersion
(JNIEnv *, jclass, jobject, jobject)
{
assert(false);
}
//
// field ids
//
bool initializeComplete = false;
jclass dataClass;
jfieldID packetIndexFieldID;
jfieldID controlFieldID;
jfieldID dsDigitalInFieldID;
jfieldID teamIDFieldID;
jfieldID dsID_AllianceFieldID;
jfieldID dsID_PositionFieldID;
jfieldID stick0AxesFieldID;
jfieldID stick0ButtonsFieldID;
jfieldID stick1AxesFieldID;
jfieldID stick1ButtonsFieldID;
jfieldID stick2AxesFieldID;
jfieldID stick2ButtonsFieldID;
jfieldID stick3AxesFieldID;
jfieldID stick3ButtonsFieldID;
jfieldID analog1FieldID;
jfieldID analog2FieldID;
jfieldID analog3FieldID;
jfieldID analog4FieldID;
jfieldID cRIOChecksumFieldID;
jfieldID FPGAChecksum0FieldID;
jfieldID FPGAChecksum1FieldID;
jfieldID FPGAChecksum2FieldID;
jfieldID FPGAChecksum3FieldID;
jfieldID versionDataFieldID;
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: setErrorData
* Signature: (Ljava/lang/String;II)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_setErrorData
(JNIEnv *, jclass, jstring, jint, jint)
{
assert(false);
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: overrideIOConfig
* Signature: (Ljava/lang/String;I)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_overrideIOConfig
(JNIEnv *, jclass, jstring, jint)
{
assert(false);
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: signalResyncActionDone
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_signalResyncActionDone
(JNIEnv *, jclass)
{
assert(false);
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: setNewDataOccurRef
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_setNewDataOccurRef
(JNIEnv *, jclass, jint)
{
assert(false);
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: setResyncOccurRef
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_setResyncOccurRef
(JNIEnv *, jclass, jint)
{
assert(false);
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: FRC_NetworkCommunication_getVersionString
* Signature: (Ljava/nio/ByteBuffer;)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_FRCNetworkCommunicationGetVersionString
(JNIEnv *, jclass, jobject)
{
assert(false);
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: FRC_NetworkCommunication_observeUserProgramStarting
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_FRCNetworkCommunicationObserveUserProgramStarting
(JNIEnv *, jclass)
{
HALNetworkCommunicationObserveUserProgramStarting();
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: FRC_NetworkCommunication_observeUserProgramDisabled
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_FRCNetworkCommunicationObserveUserProgramDisabled
(JNIEnv *, jclass)
{
HALNetworkCommunicationObserveUserProgramDisabled();
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: FRC_NetworkCommunication_observeUserProgramAutonomous
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_FRCNetworkCommunicationObserveUserProgramAutonomous
(JNIEnv *, jclass)
{
HALNetworkCommunicationObserveUserProgramAutonomous();
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: FRC_NetworkCommunication_observeUserProgramTeleop
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_FRCNetworkCommunicationObserveUserProgramTeleop
(JNIEnv *, jclass)
{
HALNetworkCommunicationObserveUserProgramTeleop();
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: FRC_NetworkCommunication_observeUserProgramTest
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_FRCNetworkCommunicationObserveUserProgramTest
(JNIEnv *, jclass)
{
HALNetworkCommunicationObserveUserProgramTest();
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: FRCNetworkCommunicationReserve
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_FRCNetworkCommunicationReserve
(JNIEnv *, jclass)
{
int rv = HALInitialize(0);
assert(1 == rv);
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: NativeHALGetControlWord
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_NativeHALGetControlWord
(JNIEnv *, jclass)
{
NETCOMM_LOG(logDEBUG) << "Calling HAL Control Word";
jint controlWord;
HALGetControlWord((HALControlWord*)&controlWord);
return controlWord;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: NativeHALGetAllianceStation
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_NativeHALGetAllianceStation
(JNIEnv *, jclass)
{
NETCOMM_LOG(logDEBUG) << "Calling HAL Alliance Station";
jint allianceStation;
HALGetAllianceStation((HALAllianceStationID*)&allianceStation);
return allianceStation;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: HALGetJoystickAxes
* Signature: (B)[S
*/
JNIEXPORT jshortArray JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetJoystickAxes
(JNIEnv * env, jclass, jbyte joystickNum)
{
NETCOMM_LOG(logDEBUG) << "Calling HALJoystickAxes";
HALJoystickAxes axes;
HALGetJoystickAxes(joystickNum, &axes);
jshortArray axesArray = env->NewShortArray(axes.count);
env->SetShortArrayRegion(axesArray, 0, axes.count, axes.axes);
return axesArray;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: HALGetJoystickPOVs
* Signature: (B)[S
*/
JNIEXPORT jshortArray JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetJoystickPOVs
(JNIEnv * env, jclass, jbyte joystickNum)
{
NETCOMM_LOG(logDEBUG) << "Calling HALJoystickPOVs";
HALJoystickPOVs povs;
HALGetJoystickPOVs(joystickNum, &povs);
jshortArray povsArray = env->NewShortArray(povs.count);
env->SetShortArrayRegion(povsArray, 0, povs.count, povs.povs);
return povsArray;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: HALGetJoystickButtons
* Signature: (B)S
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetJoystickButtons
(JNIEnv * env, jclass, jbyte joystickNum, jobject count)
{
NETCOMM_LOG(logDEBUG) << "Calling HALJoystickButtons";
HALJoystickButtons joystickButtons;
HALGetJoystickButtons(joystickNum, &joystickButtons);
jbyte *countPtr = (jbyte*)env->GetDirectBufferAddress(count);
NETCOMM_LOG(logDEBUG) << "Buttons = " << joystickButtons.buttons;
NETCOMM_LOG(logDEBUG) << "Count = " << (jint)joystickButtons.count;
*countPtr = joystickButtons.count;
NETCOMM_LOG(logDEBUG) << "CountBuffer = " << (jint)*countPtr;
return joystickButtons.buttons;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: HALSetJoystickOutputs
* Signature: (BISS)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALSetJoystickOutputs
(JNIEnv *, jclass, jbyte port, jint outputs, jshort leftRumble, jshort rightRumble)
{
NETCOMM_LOG(logDEBUG) << "Calling HALSetJoystickOutputs on port " << port;
NETCOMM_LOG(logDEBUG) << "Outputs: " << outputs;
NETCOMM_LOG(logDEBUG) << "Left Rumble: " << leftRumble << " Right Rumble: " << rightRumble;
return HALSetJoystickOutputs(port, outputs, leftRumble, rightRumble);
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: HALGetJoystickIsXbox
* Signature: (B)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetJoystickIsXbox
(JNIEnv *, jclass, jbyte port)
{
NETCOMM_LOG(logDEBUG) << "Calling HALGetJoystickIsXbox";
return HALGetJoystickIsXbox(port);
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: HALGetJoystickType
* Signature: (B)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetJoystickType
(JNIEnv *, jclass, jbyte port)
{
NETCOMM_LOG(logDEBUG) << "Calling HALGetJoystickType";
return HALGetJoystickType(port);
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: HALGetJoystickName
* Signature: (B)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetJoystickName
(JNIEnv * env, jclass, jbyte port)
{
NETCOMM_LOG(logDEBUG) << "Calling HALGetJoystickName";
return env->NewStringUTF(HALGetJoystickName(port));
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: setNewDataSem
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_setNewDataSem
(JNIEnv * env, jclass, jlong id )
{
NETCOMM_LOG(logDEBUG) << "Mutex Ptr = " << (void*)id;
HALSetNewDataSem(((MULTIWAIT_ID)id)->native_handle());
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: JNIValueParameterTest
* Signature: (ZBCSIJFD)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_JNIValueParameterTest
(JNIEnv *, jclass, jboolean booleanParam, jbyte byteParam, jchar charParam, jshort shortParam, jint intParam, jlong longParam, jfloat floatParam, jdouble doubleParam)
{
NETCOMM_LOG(logDEBUG) << "Boolean: " << booleanParam;
NETCOMM_LOG(logDEBUG) << "Byte : " << byteParam;
NETCOMM_LOG(logDEBUG) << "Char : " << charParam;
NETCOMM_LOG(logDEBUG) << "Short : " << shortParam;
NETCOMM_LOG(logDEBUG) << "Int : " << intParam;
NETCOMM_LOG(logDEBUG) << "Long : " << longParam;
NETCOMM_LOG(logDEBUG) << "Float : " << floatParam;
NETCOMM_LOG(logDEBUG) << "Double : " << doubleParam;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: JNIValueReturnBooleanTest
* Signature: (Z)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_JNIValueReturnBooleanTest
(JNIEnv *, jclass, jboolean booleanParam )
{
NETCOMM_LOG(logDEBUG) << "Boolean: " << booleanParam;
return !booleanParam;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: JNIValueReturnByteTest
* Signature: (B)B
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_JNIValueReturnByteTest
(JNIEnv *, jclass, jbyte byteParam)
{
NETCOMM_LOG(logDEBUG) << "Byte: " << byteParam;
return byteParam+1;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: JNIValueReturnCharTest
* Signature: (C)C
*/
JNIEXPORT jchar JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_JNIValueReturnCharTest
(JNIEnv *, jclass, jchar charParam)
{
NETCOMM_LOG(logDEBUG) << "Char: " << charParam;
return charParam+1;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: JNIValueReturnShortTest
* Signature: (S)S
*/
JNIEXPORT jshort JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_JNIValueReturnShortTest
(JNIEnv *, jclass, jshort shortParam)
{
NETCOMM_LOG(logDEBUG) << "Short: " << shortParam;
return shortParam+1;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: JNIValueReturnIntTest
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_JNIValueReturnIntTest
(JNIEnv *, jclass, jint intParam)
{
NETCOMM_LOG(logDEBUG) << "Int: " << intParam;
return intParam+1;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: JNIValueReturnLongTest
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_JNIValueReturnLongTest
(JNIEnv *, jclass, jlong longParam)
{
NETCOMM_LOG(logDEBUG) << "Long: " << longParam;
return longParam+1;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: JNIValueReturnFloatTest
* Signature: (F)F
*/
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_JNIValueReturnFloatTest
(JNIEnv *, jclass, jfloat floatParam)
{
NETCOMM_LOG(logDEBUG) << "Float: " << floatParam;
return floatParam/100.0f;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: JNIValueReturnDoubleTest
* Signature: (D)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_JNIValueReturnDoubleTest
(JNIEnv *, jclass, jdouble doubleParam)
{
NETCOMM_LOG(logDEBUG) << "Double: " << doubleParam;
return doubleParam * 100.0;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: JNIObjectReturnString
* Signature: (Ljava/lang/String;)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_JNIObjectReturnStringTest
(JNIEnv * env, jclass, jstring stringParam)
{
const char * stringParamLocal = env->GetStringUTFChars(stringParam, NULL);
NETCOMM_LOG(logDEBUG) << "String: " << stringParamLocal;
env->ReleaseStringUTFChars(stringParam,stringParamLocal);
char returnStringLocal[] = "this is the return string";
return env->NewStringUTF(returnStringLocal);
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: JNIObjectReturnByteBufferTest
* Signature: (Ljava/nio/ByteBuffer;)Ljava/nio/ByteBuffer;
*/
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_JNIObjectReturnByteBufferTest
(JNIEnv * env, jclass, jobject byteArrayIn )
{
jbyte * byteArray = (jbyte*)env->GetDirectBufferAddress(byteArrayIn);
NETCOMM_LOG(logDEBUG) << "Ptr: " << (long)byteArray;
jlong byteArrayLength = env->GetDirectBufferCapacity(byteArrayIn);
NETCOMM_LOG(logDEBUG) << "Capacity: " << byteArrayLength;
NETCOMM_LOG(logDEBUG) << "Byte0: " << (short)byteArray[0];
NETCOMM_LOG(logDEBUG) << "Byte1: " << (short)byteArray[1];
NETCOMM_LOG(logDEBUG) << "Byte2: " << (short)byteArray[2];
NETCOMM_LOG(logDEBUG) << "Byte3: " << (short)byteArray[3];
jbyte * returnByteArray = new jbyte[4];
returnByteArray[0] = byteArray[0];
returnByteArray[1] = byteArray[1];
returnByteArray[2] = byteArray[2];
returnByteArray[3] = byteArray[3];
return env->NewDirectByteBuffer(returnByteArray, 4);
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: JNIObjectAndParamReturnIntBufferTest
* Signature: (Ljava/nio/IntBuffer;)Ljava/nio/ByteBuffer;
*/
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_JNIObjectAndParamReturnIntBufferTest
(JNIEnv * env, jclass, jobject intArrayIn)
{
jint * intArray = (jint*)env->GetDirectBufferAddress(intArrayIn);
jbyte * byteArray = (jbyte*)env->GetDirectBufferAddress(intArrayIn);
NETCOMM_LOG(logDEBUG) << "Ptr: " << (long)intArray;
jlong byteArrayLength = env->GetDirectBufferCapacity(intArrayIn);
NETCOMM_LOG(logDEBUG) << "Capacity: " << byteArrayLength;
NETCOMM_LOG(logDEBUG) << "Int0: " << intArray[0];
NETCOMM_LOG(logDEBUG) << "Byte0: " << (short)byteArray[0];
NETCOMM_LOG(logDEBUG) << "Byte1: " << (short)byteArray[1];
NETCOMM_LOG(logDEBUG) << "Byte2: " << (short)byteArray[2];
NETCOMM_LOG(logDEBUG) << "Byte3: " << (short)byteArray[3];
// increment the param
intArray[0]++;
jbyte * returnByteArray = new jbyte[4];
returnByteArray[0] = byteArray[0];
returnByteArray[1] = byteArray[1];
returnByteArray[2] = byteArray[2];
returnByteArray[3] = byteArray[3];
return env->NewDirectByteBuffer(returnByteArray, 4);
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: HALGetMatchTime
* Signature: ()F
*/
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetMatchTime
(JNIEnv * env, jclass)
{
jfloat matchTime;
HALGetMatchTime((float*)&matchTime);
return matchTime;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: HALGetSystemActive
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetSystemActive
(JNIEnv * env, jclass)
{
int32_t status = 0;
bool val = HALGetSystemActive(&status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: HALGetBrownedOut
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetBrownedOut
(JNIEnv * env, jclass)
{
int32_t status = 0;
bool val = HALGetBrownedOut(&status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: HALSetErrorData
* Signature: (Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALSetErrorData
(JNIEnv * env, jclass, jstring error)
{
const char * errorStr = env->GetStringUTFChars(error, NULL);
jsize length = env->GetStringUTFLength(error);
NETCOMM_LOG(logDEBUG) << "Set Error: " << errorStr;
NETCOMM_LOG(logDEBUG) << "Length: " << length;
jint returnValue = HALSetErrorData(errorStr, (jint) length, 0);
env->ReleaseStringUTFChars(error,errorStr);
return returnValue;
}
} // extern "C"

View File

@@ -0,0 +1,482 @@
#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;
#define HALUTIL_LOG(level) \
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 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)J
*/
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_initializeMutexNormal
(JNIEnv * env, jclass)
{
HALUTIL_LOG(logDEBUG) << "Calling HALUtil initializeMutex";
MUTEX_ID mutex = initializeMutexNormal();
HALUTIL_LOG(logDEBUG) << "Mutex Ptr = " << mutex;
return (jlong)mutex;
}
/*
* Class: edu_wpi_first_wpilibj_hal_HALUtil
* Method: deleteMutex
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_deleteMutex
(JNIEnv * env, jclass, jlong id )
{
HALUTIL_LOG(logDEBUG) << "Calling HALUtil deleteMutex";
HALUTIL_LOG(logDEBUG) << "Mutex Ptr = " << (MUTEX_ID)id;
deleteMutex((MUTEX_ID)id);
}
/*
* Class: edu_wpi_first_wpilibj_hal_HALUtil
* Method: takeMutex
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_takeMutex
(JNIEnv * env, jclass, jlong id)
{
//HALUTIL_LOG(logDEBUG) << "Calling HALUtil takeMutex";
//HALUTIL_LOG(logDEBUG) << "Mutex Ptr = " << (MUTEX_ID)id;
takeMutex((MUTEX_ID)id);
}
/*
* Class: edu_wpi_first_wpilibj_hal_HALUtil
* Method: initializeMultiWait
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_initializeMultiWait
(JNIEnv * env, jclass)
{
HALUTIL_LOG(logDEBUG) << "Calling HALUtil initializeMultiWait";
MULTIWAIT_ID multiWait = initializeMultiWait();
HALUTIL_LOG(logDEBUG) << "MultiWait Ptr = " << multiWait;
return (jlong)multiWait;
}
/*
* Class: edu_wpi_first_wpilibj_hal_HALUtil
* Method: deleteMultiWait
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_deleteMultiWait
(JNIEnv * env, jclass, jlong id)
{
HALUTIL_LOG(logDEBUG) << "Calling HALUtil deleteMultiWait";
HALUTIL_LOG(logDEBUG) << "MultiWait Ptr = " << (MULTIWAIT_ID)id;
deleteMultiWait((MULTIWAIT_ID)id);
}
/*
* Class: edu_wpi_first_wpilibj_hal_HALUtil
* Method: takeMultiWait
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_takeMultiWait
(JNIEnv * env, jclass, jlong multiWaitId, jlong mutexId)
{
takeMultiWait((MULTIWAIT_ID)multiWaitId, (MUTEX_ID)mutexId);
}
/*
* Class: edu_wpi_first_wpilibj_hal_HALUtil
* Method: getFPGAVersion
* Signature: ()S
*/
JNIEXPORT jshort JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGAVersion
(JNIEnv * env, jclass)
{
HALUTIL_LOG(logDEBUG) << "Calling HALUtil getFPGAVersion";
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: ()I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGARevision
(JNIEnv * env, jclass)
{
HALUTIL_LOG(logDEBUG) << "Calling HALUtil getFPGARevision";
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: ()J
*/
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGATime
(JNIEnv * env, jclass)
{
//HALUTIL_LOG(logDEBUG) << "Calling HALUtil getFPGATime";
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: ()I
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGAButton
(JNIEnv * env, jclass)
{
//HALUTIL_LOG(logDEBUG) << "Calling HALUtil getFPGATime";
int32_t status = 0;
jboolean returnValue = getFPGAButton(&status);
//HALUTIL_LOG(logDEBUG) << "Status = " << status;
//HALUTIL_LOG(logDEBUG) << "FPGATime = " << returnValue;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_HALUtil
* Method: getHALErrorMessage
* Signature: (I)Ljava/lang/String;
*/
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;
return paramEnv->NewStringUTF(msg);
}
/*
* Class: edu_wpi_first_wpilibj_hal_HALUtil
* Method: getHALErrno
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALErrno
(JNIEnv *, jclass)
{
return errno;
}
/*
* Class: edu_wpi_first_wpilibj_hal_HALUtil
* Method: getHALstrerror
* Signature: (I)Ljava/lang/String;
*/
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);
}
} // 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

@@ -0,0 +1,115 @@
#include <jni.h>
#include <assert.h>
#include "Log.hpp"
#include "edu_wpi_first_wpilibj_hal_I2CJNI.h"
#include "HAL/Digital.hpp"
#include "HALUtil.h"
// set the logging level
TLogLevel i2cJNILogLevel = logWARNING;
#define I2CJNI_LOG(level) \
if (level > i2cJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_I2CJNI
* Method: i2cInitialize
* Signature: (B)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CInitialize
(JNIEnv * env, jclass, jbyte value)
{
I2CJNI_LOG(logDEBUG) << "Calling I2CJNI i2CInititalize";
I2CJNI_LOG(logDEBUG) << "Port: " << (jint) value;
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)I
*/
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;
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;
uint8_t* dataReceivedPtr = (uint8_t*)env->GetDirectBufferAddress(dataReceived);
I2CJNI_LOG(logDEBUG) << "DataReceivedPtr = " << (jint*)dataReceivedPtr;
I2CJNI_LOG(logDEBUG) << "ReceiveSize = " << (jint)receiveSize;
jint returnValue = i2CTransaction(port, address, dataToSendPtr, sendSize, dataReceivedPtr, receiveSize);
I2CJNI_LOG(logDEBUG) << "ReturnValue = " << returnValue;
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_I2CJNI
* Method: i2CWrite
* Signature: (BBLjava/nio/ByteBuffer;B)I
*/
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;
uint8_t* dataToSendPtr = nullptr;
if (dataToSend != 0) {
dataToSendPtr = (uint8_t*)env->GetDirectBufferAddress(dataToSend);
}
I2CJNI_LOG(logDEBUG) << "DataToSendPtr = " << dataToSendPtr;
I2CJNI_LOG(logDEBUG) << "SendSize = " << (jint)dataToSend;
jint returnValue = i2CWrite(port, address, dataToSendPtr, sendSize);
I2CJNI_LOG(logDEBUG) << "ReturnValue = " << (jint)returnValue;
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_I2CJNI
* Method: i2CRead
* Signature: (BBLjava/nio/ByteBuffer;B)I
*/
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;
uint8_t* dataReceivedPtr = (uint8_t*)env->GetDirectBufferAddress(dataReceived);
I2CJNI_LOG(logDEBUG) << "DataReceivedPtr = " << dataReceivedPtr;
I2CJNI_LOG(logDEBUG) << "ReceiveSize = " << receiveSize;
jint returnValue = i2CRead(port, address, dataReceivedPtr, receiveSize);
I2CJNI_LOG(logDEBUG) << "ReturnValue = " << returnValue;
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_I2CJNI
* Method: i2CClose
* Signature: (B)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CClose
(JNIEnv *, jclass, jbyte value)
{
I2CJNI_LOG(logDEBUG) << "Calling I2CJNI i2CClose";
i2CClose(value);
}
} // extern "C"

View File

@@ -0,0 +1,296 @@
#include <jni.h>
#include <assert.h>
#include "Log.hpp"
#include "edu_wpi_first_wpilibj_hal_InterruptJNI.h"
#include "HAL/Interrupts.hpp"
#include "HALUtil.h"
TLogLevel interruptJNILogLevel = logERROR;
#define INTERRUPTJNI_LOG(level) \
if (level > interruptJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: initializeInterrupts
* Signature: (IZ)J
*/
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;
int32_t status = 0;
void* interrupt = initializeInterrupts(interruptIndex, watcher, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << interrupt;
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
return (jlong)interrupt;
}
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: cleanInterrupts
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_cleanInterrupts
(JNIEnv * env, jclass, jlong interrupt_pointer)
{
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI cleanInterrupts";
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
int32_t status = 0;
cleanInterrupts((void*)interrupt_pointer, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: waitForInterrupt
* Signature: (JD)V
*/
JNIEXPORT int JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_waitForInterrupt
(JNIEnv * env, jclass, jlong interrupt_pointer, jdouble timeout, jboolean ignorePrevious)
{
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI waitForInterrupt";
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
int32_t status = 0;
int result = waitForInterrupt((void*)interrupt_pointer, timeout, ignorePrevious, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
return result;
}
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: enableInterrupts
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_enableInterrupts
(JNIEnv * env, jclass, jlong interrupt_pointer)
{
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI enableInterrupts";
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
int32_t status = 0;
enableInterrupts((void*)interrupt_pointer, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: disableInterrupts
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_disableInterrupts
(JNIEnv * env, jclass, jlong interrupt_pointer)
{
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI disableInterrupts";
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
int32_t status = 0;
disableInterrupts((void*)interrupt_pointer, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: readRisingTimestamp
* Signature: (J)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_readRisingTimestamp
(JNIEnv * env, jclass, jlong interrupt_pointer)
{
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI readRisingTimestamp";
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
int32_t status = 0;
jdouble timeStamp = readRisingTimestamp((void*)interrupt_pointer, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
return timeStamp;
}
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: readFallingTimestamp
* Signature: (J)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_readFallingTimestamp
(JNIEnv * env, jclass, jlong interrupt_pointer)
{
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI readFallingTimestamp";
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
int32_t status = 0;
jdouble timeStamp = readFallingTimestamp((void*)interrupt_pointer, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
return timeStamp;
}
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: requestInterrupts
* Signature: (JBIZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_requestInterrupts
(JNIEnv * env, jclass, jlong interrupt_pointer, jbyte routing_module, jint routing_pin, jboolean routing_analog_trigger)
{
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI requestInterrupts";
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;
int32_t status = 0;
requestInterrupts((void*)interrupt_pointer, (uint8_t) routing_module, (uint32_t) routing_pin, routing_analog_trigger, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
struct InterruptHandlerParam {
/*
* The object edu/wpi/first/wpilibj/hal/InterruptJNI/InterruptHandlerFunction
* that contains the callback method [code]mid[/code].
*/
jobject handler_obj;
//The method id for the callback method
jmethodID mid;
//The params passed to the function
jobject param;
~InterruptHandlerParam(){
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI InterruptHandlerParam Destructor";
JNIEnv *env;
jint rs = jvm->AttachCurrentThread((void**)&env, NULL);
assert (rs == JNI_OK);
env->DeleteGlobalRef(handler_obj);
env->DeleteGlobalRef(param);
rs = jvm->DetachCurrentThread();
assert (rs == JNI_OK);
INTERRUPTJNI_LOG(logDEBUG) << "Leaving INTERRUPTJNI InterruptHandlerParam Destructor";
}
};
void interruptHandler(uint32_t mask, void *data) {
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI interruptHandler";
InterruptHandlerParam *param = static_cast<InterruptHandlerParam *>(data);
INTERRUPTJNI_LOG(logDEBUG) << "InterruptHandlerParam Ptr = " << param;
INTERRUPTJNI_LOG(logDEBUG) << "InterruptHandlerParam->obj = " << param->handler_obj;
INTERRUPTJNI_LOG(logDEBUG) << "InterruptHandlerParam->param = " << param->param;
//Because this is a callback in a new thread we must attach it to the JVM
JNIEnv *env;
jint rs = jvm->AttachCurrentThread((void**)&env, NULL);
assert (rs == JNI_OK);
INTERRUPTJNI_LOG(logDEBUG) << "Attached to thread";
env->CallVoidMethod(param->handler_obj, param->mid, mask, param->param);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
}
rs = jvm->DetachCurrentThread();
assert (rs == JNI_OK);
INTERRUPTJNI_LOG(logDEBUG) << "Leaving INTERRUPTJNI interruptHandler";
}
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: attachInterruptHandler
* 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, jlong interrupt_pointer, jobject handler, jobject param)
{
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI attachInterruptHandler";
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
//Store the interrupt callback paramaters
InterruptHandlerParam *interruptHandlerParam = new InterruptHandlerParam();
//Stores the object that contains the callback
interruptHandlerParam->handler_obj = env->NewGlobalRef(handler);
//The parameter that will be passed back to the JVM when the method is called
interruptHandlerParam->param = env->NewGlobalRef(param);
jclass cls = env->GetObjectClass(handler);
INTERRUPTJNI_LOG(logDEBUG) << "class = " << cls;
if (cls == 0) {
INTERRUPTJNI_LOG(logERROR) << "Error getting java class";
assert (false);
return;
}
jmethodID mid = env->GetMethodID(cls, "apply", "(ILjava/lang/Object;)V");
INTERRUPTJNI_LOG(logDEBUG) << "method = " << mid;
if (mid == 0) {
INTERRUPTJNI_LOG(logERROR) << "Error getting java method ID";
assert (false);
return;
}
interruptHandlerParam->mid = mid;
INTERRUPTJNI_LOG(logDEBUG) << "InterruptHandlerParam Ptr = " << interruptHandlerParam;
INTERRUPTJNI_LOG(logDEBUG) << "InterruptHandlerParam->obj (handler) = " << interruptHandlerParam->handler_obj;
INTERRUPTJNI_LOG(logDEBUG) << "InterruptHandlerParam->mid = " << interruptHandlerParam->mid;
INTERRUPTJNI_LOG(logDEBUG) << "InterruptHandlerParam->param = " << interruptHandlerParam->param;
int32_t status = 0;
attachInterruptHandler((void*)interrupt_pointer, interruptHandler, interruptHandlerParam, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
* Method: setInterruptUpSourceEdge
* Signature: (JZZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_setInterruptUpSourceEdge
(JNIEnv * env, jclass, jlong interrupt_pointer, jboolean risingEdge, jboolean fallingEdge)
{
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI setInterruptUpSourceEdge";
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer;
INTERRUPTJNI_LOG(logDEBUG) << "Rising Edge = " << (bool) risingEdge;
INTERRUPTJNI_LOG(logDEBUG) << "Falling Edge = " << (bool) fallingEdge;
int32_t status = 0;
setInterruptUpSourceEdge((void*)interrupt_pointer, risingEdge, fallingEdge, &status);
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
} // extern "C"

View File

@@ -0,0 +1,43 @@
#include <jni.h>
#include <assert.h>
#include "Log.hpp"
#include "edu_wpi_first_wpilibj_hal_JNIWrapper.h"
#include "HAL/HAL.hpp"
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_JNIWrapper
* Method: getPortWithModule
* Signature: (BB)J
*/
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* port = getPortWithModule(module, pin);
//FILE_LOG(logDEBUG) << "Port Ptr = " << port;
return (jlong)port;
}
/*
* Class: edu_wpi_first_wpilibj_hal_JNIWrapper
* Method: getPort
* Signature: (BB)J
*/
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* port = getPort(pin);
//FILE_LOG(logDEBUG) << "Port Ptr = " << port;
return (jlong)port;
}
} // extern "C"

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,132 @@
#include <jni.h>
#include <assert.h>
#include <functional>
#include <stdio.h>
#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;
#define NOTIFIERJNI_LOG(level) \
if (level > notifierJNILogLevel) ; \
else Log().Get(level)
// These two are used to pass information to the notifierHandler without using
// up function parameters.
// See below for more information.
static jobject func_global;
static jmethodID mid_global;
// The arguments are unused by the HAL Notifier; they just satisfy a particular
// function signature.
void notifierHandler(uint32_t mask, void* param) {
jobject handler_obj = func_global;
jmethodID mid = mid_global;
NOTIFIERJNI_LOG(logDEBUG) << "Calling NOTIFIERJNI notifierHandler";
//Because this is a callback in a new thread we must attach it to the JVM.
JNIEnv *env;
jint rs;
// Check to see if we are already part of a JVM thread or if we need to attach
// ourselves.
int getEnvStat = jvm->GetEnv((void **)&env, JNI_VERSION_1_8);
if (getEnvStat == JNI_EDETACHED) {
rs = jvm->AttachCurrentThread((void**)&env, NULL);
assert (rs == JNI_OK);
}
NOTIFIERJNI_LOG(logDEBUG) << "Attached to thread. Object is: " << handler_obj;
// Actuall call the user function.
env->CallVoidMethod(handler_obj, mid);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
}
// Only detach if we needed to attach oursleves in the first place.
if (getEnvStat == JNI_EDETACHED) {
rs = jvm->DetachCurrentThread();
assert (rs == JNI_OK);
}
NOTIFIERJNI_LOG(logDEBUG) << "Leaving NOTIFIERJNI notifierHandler";
}
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_NotifierJNI
* Method: initializeNotifier
* Signature: (Ljava/lang/Runnable;)J
*/
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_NotifierJNI_initializeNotifier
(JNIEnv *env, jclass, jobject func)
{
NOTIFIERJNI_LOG(logDEBUG) << "Calling NOTIFIERJNI initializeNotifier";
jclass cls = env->GetObjectClass(func);
jmethodID mid = env->GetMethodID(cls, "run", "()V");
// In order to pass the user's Runnable to the notifierHandler, we have to use
// something other than the function arguments (because the function arguments
// are dictated by the callback format). As such, we instead use a couple of
// global variables to pass around the object reference.
// This is not ideal, but the only other option that came to mind was to use
// lambda function captures, but, unfortunately, it turns out that using
// captures in a lambda changes the function signature such that it can no
// long be used as a standared C-style function pointer.
// Need to set as global ref to avoid seg faults when referring to it later.
func_global = env->NewGlobalRef(func);
mid_global = mid;
int32_t status = 0;
void *notifierPtr = initializeNotifier(notifierHandler, &status);
NOTIFIERJNI_LOG(logDEBUG) << "Notifier Ptr = " << notifierPtr;
NOTIFIERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
return (jlong)notifierPtr;
}
/*
* Class: edu_wpi_first_wpilibj_hal_NotifierJNI
* Method: cleanNotifier
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_NotifierJNI_cleanNotifier
(JNIEnv *env, jclass, jlong notifierPtr)
{
NOTIFIERJNI_LOG(logDEBUG) << "Calling NOTIFIERJNI cleanNotifier";
NOTIFIERJNI_LOG(logDEBUG) << "Notifier Ptr = " << (void*)notifierPtr;
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: (JI)V
*/
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";
NOTIFIERJNI_LOG(logDEBUG) << "Notifier Ptr = " << (void*)notifierPtr;
NOTIFIERJNI_LOG(logDEBUG) << "triggerTime Ptr = " << &triggerTime;
int32_t status = 0;
updateNotifierAlarm((void*)notifierPtr, (uint32_t)triggerTime, &status);
NOTIFIERJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
} // extern "C"

View File

@@ -0,0 +1,129 @@
#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: (I)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_initializePDP
(JNIEnv *, jclass, jint module)
{
initializePDP(module);
}
/*
* Class: edu_wpi_first_wpilibj_hal_PDPJNI
* Method: getPDPTemperature
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPTemperature
(JNIEnv *env, jclass, jint 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: (I)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPVoltage
(JNIEnv *env, jclass, jint 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: (BI)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPChannelCurrent
(JNIEnv *env, jclass, jbyte channel, jint 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: (I)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPTotalCurrent
(JNIEnv *env, jclass, jint 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: (I)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPTotalPower
(JNIEnv *env, jclass, jint 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: (I)D
*/
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPTotalEnergy
(JNIEnv *env, jclass, jint 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: (I)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_resetPDPTotalEnergy
(JNIEnv *env, jclass, jint module)
{
int32_t status = 0;
resetPDPTotalEnergy(&status, module);
CheckStatus(env, status, false);
}
/*
* Class: edu_wpi_first_wpilibj_hal_PDPJNI
* Method: clearStickyFaults
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_clearPDPStickyFaults
(JNIEnv *env, jclass, jint module)
{
int32_t status = 0;
clearPDPStickyFaults(&status, module);
CheckStatus(env, status, false);
}
} // extern "C"

View File

@@ -0,0 +1,200 @@
#include <jni.h>
#include <assert.h>
#include "Log.hpp"
#include "edu_wpi_first_wpilibj_hal_PWMJNI.h"
#include "HAL/Digital.hpp"
#include "HALUtil.h"
// set the logging level
TLogLevel pwmJNILogLevel = logWARNING;
#define PWMJNI_LOG(level) \
if (level > pwmJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_PWMJNI
* Method: allocatePWMChannel
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_allocatePWMChannel
(JNIEnv * env, jclass, jlong id)
{
PWMJNI_LOG(logDEBUG) << "Calling DIOJNI allocatePWMChannel";
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;
CheckStatus(env, status);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PWMJNI
* Method: freePWMChannel
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_freePWMChannel
(JNIEnv * env, jclass, jlong id)
{
PWMJNI_LOG(logDEBUG) << "Calling DIOJNI freePWMChannel";
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: (JS)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_setPWM
(JNIEnv * env, jclass, jlong id, jshort value)
{
PWMJNI_LOG(logDEBUG) << "DigitalPort Ptr = " << (void*)id;
PWMJNI_LOG(logDEBUG) << "PWM Value = " << value;
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: (J)S
*/
JNIEXPORT jshort JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_getPWM
(JNIEnv * env, jclass, jlong id)
{
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: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_latchPWMZero
(JNIEnv * env, jclass, jlong id)
{
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: (JI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_setPWMPeriodScale
(JNIEnv * env, jclass, jlong id, jint value)
{
PWMJNI_LOG(logDEBUG) << "DigitalPort Ptr = " << (void*)id;
PWMJNI_LOG(logDEBUG) << "PeriodScale Value = " << value;
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: ()J
*/
JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_allocatePWM
(JNIEnv * env, jclass)
{
PWMJNI_LOG(logDEBUG) << "Calling PWMJNI allocatePWM";
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: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_freePWM
(JNIEnv * env, jclass, jlong id)
{
PWMJNI_LOG(logDEBUG) << "Calling PWMJNI freePWM";
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: (D)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_setPWMRate
(JNIEnv * env, jclass, jdouble value)
{
PWMJNI_LOG(logDEBUG) << "Calling PWMJNI setPWMRate";
PWMJNI_LOG(logDEBUG) << "Rate= " << value;
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: (JD)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_setPWMDutyCycle
(JNIEnv * env, jclass, jlong id, jdouble value)
{
PWMJNI_LOG(logDEBUG) << "Calling PWMJNI setPWMDutyCycle";
PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << (void*)id;
PWMJNI_LOG(logDEBUG) << "DutyCycle= " << value;
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: (JI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_setPWMOutputChannel
(JNIEnv * env, jclass, jlong id, jint value)
{
PWMJNI_LOG(logDEBUG) << "Calling PWMJNI setPWMOutputChannel";
PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << (void*)id;
PWMJNI_LOG(logDEBUG) << "Pin= " << value;
int32_t status = 0;
setPWMOutputChannel((void*)id, (uint32_t) value, &status);
PWMJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
} // extern "C"

View File

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

View File

@@ -0,0 +1,89 @@
#include <jni.h>
#include <assert.h>
#include "Log.hpp"
#include "edu_wpi_first_wpilibj_hal_RelayJNI.h"
#include "HAL/Digital.hpp"
#include "HALUtil.h"
// set the logging level
TLogLevel relayJNILogLevel = logWARNING;
#define RELAYJNI_LOG(level) \
if (level > relayJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_RelayJNI
* Method: setRelayForward
* Signature: (JZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_RelayJNI_setRelayForward
(JNIEnv * env, jclass, jlong id, jboolean value)
{
RELAYJNI_LOG(logDEBUG) << "Calling RELAYJNI setRelayForward";
RELAYJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
RELAYJNI_LOG(logDEBUG) << "Flag = " << (jint)value;
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: (JZ)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_RelayJNI_setRelayReverse
(JNIEnv * env, jclass, jlong id, jboolean value)
{
RELAYJNI_LOG(logDEBUG) << "Calling RELAYJNI setRelayReverse";
RELAYJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id;
RELAYJNI_LOG(logDEBUG) << "Flag = " << (jint)value;
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: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_RelayJNI_getRelayForward
(JNIEnv * env, jclass, jlong id)
{
RELAYJNI_LOG(logDEBUG) << "Calling RELAYJNI getRelayForward";
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: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_RelayJNI_getRelayReverse
(JNIEnv * env, jclass, jlong id)
{
RELAYJNI_LOG(logDEBUG) << "Calling RELAYJNI getRelayReverse";
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

@@ -0,0 +1,174 @@
#include <jni.h>
#include <assert.h>
#include "Log.hpp"
#include "edu_wpi_first_wpilibj_hal_SPIJNI.h"
#include "HAL/Digital.hpp"
#include "HALUtil.h"
// set the logging level
TLogLevel spiJNILogLevel = logWARNING;
#define SPIJNI_LOG(level) \
if (level > spiJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
* Method: spiInitialize
* Signature: (B)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiInitialize
(JNIEnv * env, jclass, jbyte port)
{
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiInitialize";
SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port;
int32_t status = 0;
spiInitialize(port, &status);
SPIJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
* Method: spiTransaction
* Signature: (BLjava/nio/ByteBuffer;Ljava/nio/ByteBuffer;B)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiTransaction
(JNIEnv * env, jclass, jbyte port, jobject dataToSend, jobject dataReceived, jbyte size)
{
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiTransaction";
SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port;
uint8_t* dataToSendPtr = nullptr;
if (dataToSend != 0) {
dataToSendPtr = (uint8_t*)env->GetDirectBufferAddress(dataToSend);
}
uint8_t* dataReceivedPtr = (uint8_t*)env->GetDirectBufferAddress(dataReceived);
SPIJNI_LOG(logDEBUG) << "Size = " << (jint)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;
}
/*
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
* Method: spiWrite
* Signature: (BLjava/nio/ByteBuffer;B)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiWrite
(JNIEnv * env, jclass, jbyte port, jobject dataToSend, jbyte size)
{
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiWrite";
SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port;
uint8_t* dataToSendPtr = nullptr;
if (dataToSend != 0) {
dataToSendPtr = (uint8_t*)env->GetDirectBufferAddress(dataToSend);
}
SPIJNI_LOG(logDEBUG) << "Size = " << (jint)size;
SPIJNI_LOG(logDEBUG) << "DataToSendPtr = " << dataToSendPtr;
jint retVal = spiWrite(port, dataToSendPtr, size);
SPIJNI_LOG(logDEBUG) << "ReturnValue = " << (jint)retVal;
return retVal;
}
/*
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
* Method: spiRead
* Signature: (BLjava/nio/ByteBuffer;B)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiRead
(JNIEnv * env, jclass, jbyte port, jobject dataReceived, jbyte size)
{
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiRead";
SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port;
uint8_t* dataReceivedPtr = (uint8_t*)env->GetDirectBufferAddress(dataReceived);
SPIJNI_LOG(logDEBUG) << "Size = " << (jint)size;
SPIJNI_LOG(logDEBUG) << "DataReceivedPtr = " << dataReceivedPtr;
jint retVal = spiRead(port, (uint8_t*)dataReceivedPtr, size);
SPIJNI_LOG(logDEBUG) << "ReturnValue = " << (jint)retVal;
return retVal;
}
/*
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
* Method: spiClose
* Signature: (B)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiClose
(JNIEnv *, jclass, jbyte port)
{
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiClose";
SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port;
spiClose(port);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
* Method: spiSetSpeed
* Signature: (BI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiSetSpeed
(JNIEnv *, jclass, jbyte port, jint speed)
{
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiSetSpeed";
SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port;
SPIJNI_LOG(logDEBUG) << "Speed = " << (jint) speed;
spiSetSpeed(port, speed);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
* Method: spiSetOpts
* Signature: (BIII)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiSetOpts
(JNIEnv *, jclass, jbyte port, jint msb_first, jint sample_on_trailing, jint clk_idle_high)
{
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiSetOpts";
SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port;
SPIJNI_LOG(logDEBUG) << "msb_first = " << msb_first;
SPIJNI_LOG(logDEBUG) << "sample_on_trailing = " << sample_on_trailing;
SPIJNI_LOG(logDEBUG) << "clk_idle_high = " << clk_idle_high;
spiSetOpts(port, msb_first, sample_on_trailing, clk_idle_high);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
* Method: spiSetChipSelectActiveHigh
* Signature: (B)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiSetChipSelectActiveHigh
(JNIEnv * env, jclass, jbyte port)
{
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiSetCSActiveHigh";
SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port;
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: (B)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiSetChipSelectActiveLow
(JNIEnv * env, jclass, jbyte port)
{
SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiSetCSActiveLow";
SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port;
int32_t status = 0;
spiSetChipSelectActiveLow(port, &status);
SPIJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
} // extern "C"

View File

@@ -0,0 +1,311 @@
#include <jni.h>
#include <assert.h>
#include "Log.hpp"
#include "edu_wpi_first_wpilibj_hal_SerialPortJNI.h"
#include "HAL/SerialPort.hpp"
#include "HALUtil.h"
// set the logging level
TLogLevel serialJNILogLevel = logWARNING;
#define SERIALJNI_LOG(level) \
if (level > serialJNILogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialInitializePort
* Signature: (B)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialInitializePort
(JNIEnv * env, jclass, jbyte port)
{
SERIALJNI_LOG(logDEBUG) << "Calling Serial Initialize";
SERIALJNI_LOG(logDEBUG) << "Port = " << (jint) port;
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: (BI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetBaudRate
(JNIEnv * env, jclass, jbyte port, jint rate)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Baud Rate";
SERIALJNI_LOG(logDEBUG) << "Baud: " << rate;
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: (BB)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetDataBits
(JNIEnv * env, jclass, jbyte port, jbyte bits)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Data Bits";
SERIALJNI_LOG(logDEBUG) << "Data Bits: " << bits;
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: (BB)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetParity
(JNIEnv * env, jclass, jbyte port, jbyte parity)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Parity";
SERIALJNI_LOG(logDEBUG) << "Parity: " << parity;
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: (BB)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetStopBits
(JNIEnv * env, jclass, jbyte port, jbyte bits)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Stop Bits";
SERIALJNI_LOG(logDEBUG) << "Stop Bits: " << bits;
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: (BB)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetWriteMode
(JNIEnv * env, jclass, jbyte port, jbyte mode)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Write Mode";
SERIALJNI_LOG(logDEBUG) << "Write mode: " << mode;
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: (BB)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetFlowControl
(JNIEnv * env, jclass, jbyte port, jbyte flow)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Flow Control";
SERIALJNI_LOG(logDEBUG) << "Flow Control: " << flow;
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: (BF)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetTimeout
(JNIEnv * env, jclass, jbyte port, jfloat timeout)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Timeout";
SERIALJNI_LOG(logDEBUG) << "Timeout: " << timeout;
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: (BC)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialEnableTermination
(JNIEnv * env, jclass, jbyte port, jchar terminator)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Enable Termination";
SERIALJNI_LOG(logDEBUG) << "Terminator: " << terminator;
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: (B)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialDisableTermination
(JNIEnv * env, jclass, jbyte port)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Disable termination";
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: (BI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetReadBufferSize
(JNIEnv * env, jclass, jbyte port, jint size)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Read Buffer Size";
SERIALJNI_LOG(logDEBUG) << "Size: " << size;
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: (BI)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetWriteBufferSize
(JNIEnv * env, jclass, jbyte port, jint size)
{
SERIALJNI_LOG(logDEBUG) << "Setting Serial Write Buffer Size";
SERIALJNI_LOG(logDEBUG) << "Size: " << size;
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: (B)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialGetBytesRecieved
(JNIEnv * env, jclass, jbyte port)
{
SERIALJNI_LOG(logDEBUG) << "Serial Get Bytes Received";
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;I)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialRead
(JNIEnv * env, jclass, jbyte port, jobject dataReceived, jint size)
{
SERIALJNI_LOG(logDEBUG) << "Serial Read";
jbyte * dataReceivedPtr = NULL;
dataReceivedPtr = (jbyte*)env->GetDirectBufferAddress(dataReceived);
int32_t status = 0;
jint retVal = serialRead(port, (char*)dataReceivedPtr, size, &status);
SERIALJNI_LOG(logDEBUG) << "ReturnValue = " << retVal;
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
return retVal;
}
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialWrite
* 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)
{
SERIALJNI_LOG(logDEBUG) << "Serial Write";
jbyte * dataToSendPtr = NULL;
if(dataToSend != 0){
dataToSendPtr = (jbyte*)env->GetDirectBufferAddress(dataToSend);
}
int32_t status = 0;
jint retVal = serialWrite(port, (const char*)dataToSendPtr, size, &status);
SERIALJNI_LOG(logDEBUG) << "ReturnValue = " << retVal;
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
return retVal;
}
/*
* Class: edu_wpi_first_wpilibj_hal_SerialPortJNI
* Method: serialFlush
* Signature: (B)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialFlush
(JNIEnv * env, jclass, jbyte port)
{
SERIALJNI_LOG(logDEBUG) << "Serial Flush";
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: (B)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialClear
(JNIEnv * env, jclass, jbyte port)
{
SERIALJNI_LOG(logDEBUG) << "Serial Clear";
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: (B)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialClose
(JNIEnv * env, jclass, jbyte port)
{
SERIALJNI_LOG(logDEBUG) << "Serial Close";
int32_t status = 0;
serialClose(port, &status);
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
CheckStatus(env, status);
}
} // extern "C"

View File

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