From 6d8629a8b38feb5c682fc2235418184cb3eba7cf Mon Sep 17 00:00:00 2001 From: Jonathan Leitschuh Date: Tue, 20 May 2014 15:38:41 -0400 Subject: [PATCH] Adds the Accumulator code to the AnalogJNI.cpp Disables the debug printlines from the AnalogJNI.cpp file Change-Id: Iac962721fb3eeca8f208feb162c96d5ae9f342a2 --- hal/lib/Athena/Analog.cpp | 9 +- wpilibj/wpilibJavaJNI/lib/AnalogJNI.cpp | 119 +++++++++++++++++++----- 2 files changed, 98 insertions(+), 30 deletions(-) diff --git a/hal/lib/Athena/Analog.cpp b/hal/lib/Athena/Analog.cpp index b23c2b1a3d..f2630c8c7a 100644 --- a/hal/lib/Athena/Analog.cpp +++ b/hal/lib/Athena/Analog.cpp @@ -10,8 +10,6 @@ #include "NetworkCommunication/AICalibration.h" #include "NetworkCommunication/LoadOut.h" -#include // TODO: remove printf for debugging - static const long kTimebase = 40000000; ///< 40 MHz clock static const long kDefaultOversampleBits = 0; static const long kDefaultAverageBits = 7; @@ -540,7 +538,6 @@ uint32_t getAccumulatorCount(void* analog_port_pointer, int32_t *status) { * @param count Pointer to the number of accumulation cycles. */ void getAccumulatorOutput(void* analog_port_pointer, int64_t *value, uint32_t *count, int32_t *status) { - printf("[HAL] getAccumulatorOutput()\n"); AnalogPort* port = (AnalogPort*) analog_port_pointer; if (port->accumulator == NULL) { *status = NULL_PARAMETER; @@ -551,12 +548,8 @@ void getAccumulatorOutput(void* analog_port_pointer, int64_t *value, uint32_t *c return; } - printf("[HAL]\t Getting output...\n"); tAccumulator::tOutput output = port->accumulator->readOutput(status); - - printf("[HAL]\t Status: %d, Value: %lld, Count: %d.\n", *status, output.Value, output.Count); - printf("[HAL]\t value: %d, value2: %d, value3: %d.\n", output.value, output.value2, output.value3); - printf("[HAL]\t Value: %lld, Count: %d.\n", port->accumulator->readOutput_Value(status), port->accumulator->readOutput_Count(status)); + *value = output.Value; *count = output.Count; } diff --git a/wpilibj/wpilibJavaJNI/lib/AnalogJNI.cpp b/wpilibj/wpilibJavaJNI/lib/AnalogJNI.cpp index 74152be115..d8eded535d 100644 --- a/wpilibj/wpilibJavaJNI/lib/AnalogJNI.cpp +++ b/wpilibj/wpilibJavaJNI/lib/AnalogJNI.cpp @@ -7,7 +7,7 @@ #include "HAL/Analog.h" // set the logging level -TLogLevel analogJNILogLevel = logDEBUG; +TLogLevel analogJNILogLevel = logWARNING; #define ANALOGJNI_LOG(level) \ if (level > analogJNILogLevel) ; \ @@ -278,9 +278,16 @@ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogAver * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogLSBWeight - (JNIEnv *, jclass, jobject, jobject) + (JNIEnv * env, jclass, jobject id, jobject status) { - assert(false); + void ** javaId = (void**)env->GetDirectBufferAddress(id); + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; + jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); + + jint returnValue = getAnalogLSBWeight(*javaId, statusPtr); + ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ANALOGJNI_LOG(logDEBUG) << "AnalogLSBWeight = " << returnValue; + return returnValue; } /* @@ -289,9 +296,16 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogLSBWeig * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogOffset - (JNIEnv *, jclass, jobject, jobject) + (JNIEnv * env, jclass, jobject id, jobject status) { - assert(false); + void ** javaId = (void**)env->GetDirectBufferAddress(id); + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; + jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); + + jint returnValue = getAnalogOffset(*javaId, statusPtr); + ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ANALOGJNI_LOG(logDEBUG) << "AnalogOffset = " << returnValue; + return returnValue; } /* @@ -300,9 +314,20 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogOffset * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B */ JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_isAccumulatorChannel - (JNIEnv *, jclass, jobject, jobject) + (JNIEnv * env, jclass, jobject id, jobject status) { - assert(false); + ANALOGJNI_LOG(logDEBUG) << "isAccumulatorChannel"; + void ** javaId = (void**)env->GetDirectBufferAddress(id); + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; + jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); + + // isAccumulaotrChanel returns a boolean + char vOut = isAccumulatorChannel(*javaId, statusPtr) ? 1 : 0; + //The C++ equivalent of a jbyte is a char + jbyte returnValue = vOut; + ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ANALOGJNI_LOG(logDEBUG) << "AnalogOffset = " << returnValue; + return returnValue; } /* @@ -311,9 +336,17 @@ JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_isAccumulatorCh * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initAccumulator - (JNIEnv *, jclass, jobject, jobject) + (JNIEnv * env, jclass, jobject id, jobject status) { - assert(false); + void ** javaId = (void**)env->GetDirectBufferAddress(id); + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; + + jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); + + initAccumulator(*javaId, statusPtr); + + ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + } /* @@ -322,9 +355,14 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initAccumulator * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_resetAccumulator - (JNIEnv *, jclass, jobject, jobject) + (JNIEnv * env, jclass, jobject id, jobject status) { - assert(false); + void ** javaId = (void**)env->GetDirectBufferAddress(id); + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; + jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); + + resetAccumulator(*javaId, statusPtr); + ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; } /* @@ -333,9 +371,15 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_resetAccumulator * Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAccumulatorCenter - (JNIEnv *, jclass, jobject, jint, jobject) + (JNIEnv *env, jclass, jobject id, jint center, jobject status) { - assert(false); + void ** javaId = (void**)env->GetDirectBufferAddress(id); + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; + jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); + + setAccumulatorCenter(*javaId, center, statusPtr); + ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + } /* @@ -344,9 +388,14 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAccumulatorCe * Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAccumulatorDeadband - (JNIEnv *, jclass, jobject, jint, jobject) + (JNIEnv *env, jclass, jobject id, jint deadband, jobject status) { - assert(false); + void ** javaId = (void**)env->GetDirectBufferAddress(id); + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; + jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); + + setAccumulatorDeadband(*javaId, deadband, statusPtr); + ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; } /* @@ -355,9 +404,17 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAccumulatorDe * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)J */ JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorValue - (JNIEnv *, jclass, jobject, jobject) + (JNIEnv *env, jclass, jobject id, jobject status) { - assert(false); + void ** javaId = (void**)env->GetDirectBufferAddress(id); + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; + jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); + + jlong returnValue = getAccumulatorValue(*javaId, statusPtr); + ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ANALOGJNI_LOG(logDEBUG) << "AccumulatorValue = " << returnValue; + + return returnValue; } /* @@ -366,9 +423,16 @@ JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorV * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorCount - (JNIEnv *, jclass, jobject, jobject) + (JNIEnv *env, jclass, jobject id, jobject status) { - assert(false); + void ** javaId = (void**)env->GetDirectBufferAddress(id); + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; + jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); + + jint returnValue = getAccumulatorCount(*javaId, statusPtr); + ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ANALOGJNI_LOG(logDEBUG) << "AccumulatorCount = " << returnValue; + return returnValue; } /* @@ -377,9 +441,20 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorCo * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/LongBuffer;Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorOutput - (JNIEnv *, jclass, jobject, jobject, jobject, jobject) + (JNIEnv * env, jclass, jobject id, jobject value, jobject count, jobject status) { - assert(false); + void ** javaId = (void**)env->GetDirectBufferAddress(id); + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; + jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); + + jlong * valuePtr = (jlong*)env->GetDirectBufferAddress(value); + uint32_t * countPtr = (uint32_t*)env->GetDirectBufferAddress(count); + + getAccumulatorOutput(*javaId, valuePtr, countPtr, statusPtr); + + ANALOGJNI_LOG(logDEBUG) << "Value = " << *valuePtr; + ANALOGJNI_LOG(logDEBUG) << "Count = " << *countPtr; + ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; } /* @@ -388,7 +463,7 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorOu * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;)Ljava/nio/ByteBuffer; */ JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogTrigger - (JNIEnv *, jclass, jobject, jobject, jobject) + (JNIEnv *, jclass, jobject, jobject , jobject) { assert(false); }