Support for the CAN pneumatics module in C++ and Java

Change-Id: I2ccb1d13d1c5da00a99329c761b75a6c2b3ea56d
This commit is contained in:
thomasclark
2014-05-29 14:25:09 -04:00
parent 9b831ed34c
commit 980d52becc
19 changed files with 2286 additions and 91 deletions

View File

@@ -0,0 +1,115 @@
#include "Log.h"
#include "edu_wpi_first_wpilibj_hal_CompressorJNI.h"
#include "HAL/HAL.h"
typedef void *VoidPointer;
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: initializeCompressor
* Signature: (B)Ljava/nio/ByteBuffer;
*/
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_initializeCompressor
(JNIEnv *env, jclass, jbyte module)
{
VoidPointer *pcm_pointer = new VoidPointer;
*pcm_pointer = initializeCompressor(module);
return env->NewDirectByteBuffer(pcm_pointer, 4);
}
/*
* 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: setCompressor
* Signature: (Ljava/nio/ByteBuffer;ZLjava/nio/IntBuffer;)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_setCompressor
(JNIEnv *env, jclass, jobject pcm_pointer_object, jboolean value, jobject status)
{
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
setCompressor(*pcm_pointer, value, status_pointer);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: getCompressor
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressor
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
{
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
return getCompressor(*pcm_pointer, status_pointer);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: setClosedLoopControl
* Signature: (Ljava/nio/ByteBuffer;ZLjava/nio/IntBuffer;)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_setClosedLoopControl
(JNIEnv *env, jclass, jobject pcm_pointer_object, jboolean value, jobject status)
{
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
setClosedLoopControl(*pcm_pointer, value, status_pointer);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: getClosedLoopControl
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getClosedLoopControl
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
{
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
return getClosedLoopControl(*pcm_pointer, status_pointer);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: getPressureSwitch
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getPressureSwitch
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
{
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
return getPressureSwitch(*pcm_pointer, status_pointer);
}
/*
* Class: edu_wpi_first_wpilibj_hal_CompressorJNI
* Method: getCompressorCurrent
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)F
*/
JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrent
(JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status)
{
VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object);
jint *status_pointer = (jint *)env->GetDirectBufferAddress(status);
return getCompressorCurrent(*pcm_pointer, status_pointer);
}

View File

@@ -0,0 +1,91 @@
#include <jni.h>
#include "Log.h"
#include "HAL/HAL.h"
#include "edu_wpi_first_wpilibj_hal_SolenoidJNI.h"
TLogLevel solenoidJNILogLevel = logERROR;
#define SOLENOIDJNI_LOG(level) \
if (level > solenoidJNILogLevel) ; \
else Log().Get(level)
typedef void *VoidPointer;
/*
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
* Method: initializeSolenoidPort
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
*/
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_initializeSolenoidPort
(JNIEnv *env, jclass, jobject port_pointer, jobject status)
{
SOLENOIDJNI_LOG(logDEBUG) << "Calling SolenoidJNI initializeSolenoidPort";
VoidPointer *port_pointer_pointer = (VoidPointer *)env->GetDirectBufferAddress(port_pointer);
SOLENOIDJNI_LOG(logDEBUG) << "Port Ptr = " << *port_pointer_pointer;
char *aschars = (char *)(*port_pointer_pointer);
SOLENOIDJNI_LOG(logDEBUG) << '\t' << (int)aschars[0] << '\t' << (int)aschars[1] << std::endl;
jint *status_pointer = (jint*)env->GetDirectBufferAddress(status);
SOLENOIDJNI_LOG(logDEBUG) << "Status Ptr = " << status_pointer;
VoidPointer *solenoid_port_pointer = new VoidPointer;
*solenoid_port_pointer = initializeSolenoidPort(*port_pointer_pointer, status_pointer);
SOLENOIDJNI_LOG(logDEBUG) << "Status = " << *status_pointer;
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;
return env->NewDirectByteBuffer(solenoid_port_pointer, 4);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
* Method: getPortWithModule
* Signature: (BB)Ljava/nio/ByteBuffer;
*/
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getPortWithModule
(JNIEnv *env, jclass, jbyte module, jbyte channel)
{
VoidPointer *port_pointer = new VoidPointer;
*port_pointer = getPortWithModule(module + 1, channel);
return env->NewDirectByteBuffer(port_pointer, 4);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
* Method: setSolenoid
* Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_setSolenoid
(JNIEnv *env, jclass, jobject solenoid_port, jbyte value, jobject status)
{
SOLENOIDJNI_LOG(logDEBUG) << "Calling SolenoidJNI SetSolenoid";
VoidPointer *solenoid_port_pointer = (VoidPointer *)env->GetDirectBufferAddress(solenoid_port);
SOLENOIDJNI_LOG(logDEBUG) << "Solenoid Port Pointer = " << *solenoid_port_pointer;
jint *status_pointer = (jint*)env->GetDirectBufferAddress(status);
SOLENOIDJNI_LOG(logDEBUG) << "Status Ptr = " << status_pointer;
setSolenoid(*solenoid_port_pointer, value, status_pointer);
}
/*
* Class: edu_wpi_first_wpilibj_hal_SolenoidJNI
* Method: getSolenoid
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B
*/
JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getSolenoid
(JNIEnv *env, jclass, jobject solenoid_port, jobject status)
{
VoidPointer *solenoid_port_pointer = (VoidPointer *)env->GetDirectBufferAddress(solenoid_port);
jint *status_pointer = (jint*)env->GetDirectBufferAddress(status);
return getSolenoid(*solenoid_port_pointer, status_pointer);
}

View File

@@ -122,6 +122,8 @@ this default location, specify a value for the 'embeddedJDKHome' property at the
<javahClassName>edu.wpi.first.wpilibj.hal.PWMJNI</javahClassName>
<javahClassName>edu.wpi.first.wpilibj.hal.RelayJNI</javahClassName>
<javahClassName>edu.wpi.first.wpilibj.hal.SPIJNI</javahClassName>
<javahClassName>edu.wpi.first.wpilibj.hal.SolenoidJNI</javahClassName>
<javahClassName>edu.wpi.first.wpilibj.hal.CompressorJNI</javahClassName>
</javahClassNames>
<!-- enable additional javah interface in dependencies list -->
<!-- javahSearchJNIFromDependencies>true</javahSearchJNIFromDependencies -->