Made CAN actually work in Java

Change-Id: I90709799de02c4cf1800f57bbecd637c76b33469
This commit is contained in:
thomasclark
2014-05-27 15:10:18 -04:00
parent db940d8c43
commit c1482cb267
2 changed files with 11 additions and 12 deletions

View File

@@ -174,18 +174,16 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
private MotorSafetyHelper m_safetyHelper;
private static final byte[] kNoData = new byte[0];
private final static int swap16(int x, byte[] buffer) {
buffer[0] = (byte) ((x >>> 8) & 0x00FF);
buffer[1] = (byte) x;
return ((((x) >>> 8) & 0x00FF) | (((x) << 8) & 0xFF00));
private final static void swap16(int x, byte[] buffer) {
buffer[0] = (byte)(x & 0xff);
buffer[1] = (byte)((x>>8) & 0xff);
}
private final static long swap32(long x, byte[] buffer) {
buffer[0] = (byte) ((x >>> 24) & 0x00FF);
buffer[1] = (byte) ((x >>> 16) & 0x00FF);
buffer[2] = (byte) ((x >>> 8) & 0x00FF);
buffer[3] = (byte) x;
return ((((x) >> 24) & 0x000000FF) | (((x) >> 8) & 0x0000FF00) | (((x) << 8) & 0x00FF0000) | (((x) << 24) & 0xFF000000));
private final static void swap32(long x, byte[] buffer) {
buffer[0] = (byte)(x & 0xff);
buffer[1] = (byte)((x>>8) & 0xff);
buffer[2] = (byte)((x>>16) & 0xff);
buffer[3] = (byte)((x>>24) & 0xff);
}
/**

View File

@@ -5,6 +5,7 @@
#include "edu_wpi_first_wpilibj_can_CANJNI.h"
#include "HAL/CAN.h"
#include "NetworkCommunication/JaguarCANDriver.h"
// set the logging level
TLogLevel canJNILogLevel = logDEBUG;
@@ -46,7 +47,7 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetworkCommunica
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
//CANJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr;
JaguarCANSendMessage((uint32_t) messageID, (const uint8_t*)dataPtr, (uint8_t)dataCapacity, statusPtr);
FRC_NetworkCommunication_JaguarCANDriver_sendMessage((uint32_t) messageID, (const uint8_t*)dataPtr, (uint8_t)dataCapacity, statusPtr);
CANJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
}
@@ -68,7 +69,7 @@ JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetworkCommun
jbyte* dataPtr = new jbyte[8];
//CANJNI_LOG(logDEBUG) << "Original MessageSize = " << (jint)dataSize;
//CANJNI_LOG(logDEBUG) << "Original MessagePtr = " << (jint*)dataPtr;
JaguarCANReceiveMessage((uint32_t*)messageIDPtr, (uint8_t*)dataPtr, &dataSize, timeout, statusPtr);
FRC_NetworkCommunication_JaguarCANDriver_receiveMessage((uint32_t*)messageIDPtr, (uint8_t*)dataPtr, &dataSize, timeout, statusPtr);
//CANJNI_LOG(logDEBUG) << "MessageID Out = " << std::hex << *messageIDPtr;
CANJNI_LOG(logDEBUG) << "MessageSize = " << (jint)dataSize;