mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
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:
105
wpilibj/src/athena/cpp/lib/CANJNI.cpp
Normal file
105
wpilibj/src/athena/cpp/lib/CANJNI.cpp
Normal 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"
|
||||
Reference in New Issue
Block a user