mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-29 02:21:44 +00:00
committed by
Peter Johnson
parent
9dc1de1d09
commit
a1ea448406
@@ -29,4 +29,8 @@ public class CANJNI extends JNIWrapper {
|
||||
@SuppressWarnings("MethodName")
|
||||
public static native byte[] FRCNetCommCANSessionMuxReceiveMessage(
|
||||
IntBuffer messageID, int messageIDMask, ByteBuffer timeStamp);
|
||||
|
||||
|
||||
@SuppressWarnings("MethodName")
|
||||
public static native void GetCANStatus(CANStatus status);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
/**
|
||||
* Structure for holding the result of a CAN Status request.
|
||||
*/
|
||||
public class CANStatus {
|
||||
|
||||
/**
|
||||
* The utilization of the CAN Bus.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public double percentBusUtilization;
|
||||
|
||||
/**
|
||||
* The CAN Bus off count.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public int busOffCount;
|
||||
|
||||
/**
|
||||
* The CAN Bus TX full count.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public int txFullCount;
|
||||
|
||||
/**
|
||||
* The CAN Bus receive error count.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public int receiveErrorCount;
|
||||
|
||||
/**
|
||||
* The CAN Bus transmit error count.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public int transmitErrorCount;
|
||||
|
||||
@SuppressWarnings("JavadocMethod")
|
||||
public void setStatus(double percentBusUtilization, int busOffCount, int txFullCount,
|
||||
int receiveErrorCount, int transmitErrorCount) {
|
||||
this.percentBusUtilization = percentBusUtilization;
|
||||
this.busOffCount = busOffCount;
|
||||
this.txFullCount = txFullCount;
|
||||
this.receiveErrorCount = receiveErrorCount;
|
||||
this.transmitErrorCount = transmitErrorCount;
|
||||
}
|
||||
}
|
||||
@@ -125,4 +125,29 @@ Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetCommCANSessionMuxReceiveMessage(
|
||||
static_cast<size_t>(dataSize)});
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_can_CANJNI
|
||||
* Method: GetCANStatus
|
||||
* Signature: (Ledu/wpi/first/wpilibj/can/CANStatus;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_can_CANJNI_GetCANStatus
|
||||
(JNIEnv *env, jclass, jobject canStatus) {
|
||||
CANJNI_LOG(logDEBUG)
|
||||
<< "Calling CANJNI HAL_CAN_GetCANStatus";
|
||||
|
||||
float percentBusUtilization = 0;
|
||||
uint32_t busOffCount = 0;
|
||||
uint32_t txFullCount = 0;
|
||||
uint32_t receiveErrorCount = 0;
|
||||
uint32_t transmitErrorCount = 0;
|
||||
int32_t status = 0;
|
||||
HAL_CAN_GetCANStatus(&percentBusUtilization, &busOffCount, &txFullCount,
|
||||
&receiveErrorCount, &transmitErrorCount, &status);
|
||||
|
||||
if (!CheckStatus(env, status)) return;
|
||||
|
||||
SetCanStatusObject(env, canStatus, percentBusUtilization, busOffCount,
|
||||
txFullCount, receiveErrorCount, transmitErrorCount);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -55,6 +55,7 @@ static JException canMessageNotAllowedExCls;
|
||||
static JException canNotInitializedExCls;
|
||||
static JException uncleanStatusExCls;
|
||||
static JClass pwmConfigDataResultCls;
|
||||
static JClass canStatusCls;
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -207,6 +208,18 @@ jobject CreatePWMConfigDataResult(JNIEnv *env, int32_t maxPwm,
|
||||
minPwm);
|
||||
}
|
||||
|
||||
void SetCanStatusObject(JNIEnv *env, jobject canStatus,
|
||||
float percentBusUtilization,
|
||||
uint32_t busOffCount, uint32_t txFullCount,
|
||||
uint32_t receiveErrorCount,
|
||||
uint32_t transmitErrorCount) {
|
||||
static jmethodID func = env->GetMethodID(canStatusCls, "setStatus",
|
||||
"(DIIII)V");
|
||||
env->CallObjectMethod(canStatus, func, (jdouble)percentBusUtilization,
|
||||
(jint)busOffCount, (jint)txFullCount,
|
||||
(jint)receiveErrorCount, (jint)transmitErrorCount);
|
||||
}
|
||||
|
||||
} // namespace frc
|
||||
|
||||
using namespace frc;
|
||||
@@ -259,6 +272,9 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
pwmConfigDataResultCls = JClass(env, "edu/wpi/first/wpilibj/PWMConfigDataResult");
|
||||
if (!pwmConfigDataResultCls) return JNI_ERR;
|
||||
|
||||
canStatusCls = JClass(env, "edu/wpi/first/wpilibj/can/CANStatus");
|
||||
if (!canStatusCls) return JNI_ERR;
|
||||
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
@@ -278,6 +294,7 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) {
|
||||
canNotInitializedExCls.free(env);
|
||||
uncleanStatusExCls.free(env);
|
||||
pwmConfigDataResultCls.free(env);
|
||||
canStatusCls.free(env);
|
||||
jvm = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,12 @@ void ThrowBoundaryException(JNIEnv *env, double value, double lower,
|
||||
jobject CreatePWMConfigDataResult(JNIEnv *env, int32_t maxPwm,
|
||||
int32_t deadbandMaxPwm, int32_t centerPwm,
|
||||
int32_t deadbandMinPwm, int32_t minPwm);
|
||||
|
||||
void SetCanStatusObject(JNIEnv *env, jobject canStatus,
|
||||
float percentBusUtilization,
|
||||
uint32_t busOffCount, uint32_t txFullCount,
|
||||
uint32_t receiveErrorCount,
|
||||
uint32_t transmitErrorCount);
|
||||
|
||||
} // namespace frc
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CANStatusTest {
|
||||
@Test
|
||||
public void canStatusGetDoesntThrow() {
|
||||
CANStatus status = new CANStatus();
|
||||
CANJNI.GetCANStatus(status);
|
||||
// Nothing we can assert, so just make sure it didn't throw.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CANStatusTest {
|
||||
@Test
|
||||
public void canStatusGetDoesntThrow() {
|
||||
CANStatus status = new CANStatus();
|
||||
CANJNI.GetCANStatus(status);
|
||||
// Nothing we can assert, so just make sure it didn't throw.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user