mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-04 03:11:43 +00:00
Made CAN actually work in Java
Change-Id: I90709799de02c4cf1800f57bbecd637c76b33469
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user