mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Adds match specific calls to Java and C++ (#720)
Uses caching, matching the joystick calls.
This commit is contained in:
committed by
Peter Johnson
parent
2225c4fee2
commit
7bbd13d914
@@ -120,7 +120,7 @@ Java_edu_wpi_first_wpilibj_hal_HAL_report(
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_HAL_nativeGetControlWord(JNIEnv*, jclass) {
|
||||
NETCOMM_LOG(logDEBUG) << "Calling HAL Control Word";
|
||||
static_assert(sizeof(HAL_ControlWord) == sizeof(jint),
|
||||
static_assert(sizeof(HAL_ControlWord) == sizeof(jint),
|
||||
"Java int must match the size of control word");
|
||||
HAL_ControlWord controlWord;
|
||||
std::memset(&controlWord, 0, sizeof(HAL_ControlWord));
|
||||
@@ -285,7 +285,7 @@ Java_edu_wpi_first_wpilibj_hal_HAL_getJoystickAxisType(JNIEnv*, jclass,
|
||||
* Method: isNewControlData
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_HAL_isNewControlData(JNIEnv *, jclass) {
|
||||
return static_cast<jboolean>(HAL_IsNewControlData());
|
||||
}
|
||||
@@ -315,8 +315,8 @@ Java_edu_wpi_first_wpilibj_hal_HAL_releaseDSMutex(JNIEnv* env, jclass) {
|
||||
* Method: waitForDSDataTimeout
|
||||
* Signature: (D)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_HAL_waitForDSDataTimeout(JNIEnv *, jclass,
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_HAL_waitForDSDataTimeout(JNIEnv *, jclass,
|
||||
jdouble timeout) {
|
||||
return static_cast<jboolean>(HAL_WaitForDSDataTimeout(timeout));
|
||||
}
|
||||
@@ -358,6 +358,23 @@ Java_edu_wpi_first_wpilibj_hal_HAL_getBrownedOut(JNIEnv* env, jclass) {
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_HAL
|
||||
* Method: getMatchInfo
|
||||
* Signature: (Ledu/wpi/first/wpilibj/hal/MatchInfoData;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_HAL_getMatchInfo
|
||||
(JNIEnv * env, jclass, jobject info) {
|
||||
HAL_MatchInfo matchInfo;
|
||||
auto status = HAL_GetMatchInfo(&matchInfo);
|
||||
if (status == 0) {
|
||||
SetMatchInfoObject(env, info, matchInfo);
|
||||
}
|
||||
HAL_FreeMatchInfo(&matchInfo);
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_HAL
|
||||
* Method: HAL_SendError
|
||||
|
||||
@@ -56,6 +56,7 @@ static JException canNotInitializedExCls;
|
||||
static JException uncleanStatusExCls;
|
||||
static JClass pwmConfigDataResultCls;
|
||||
static JClass canStatusCls;
|
||||
static JClass matchInfoDataCls;
|
||||
|
||||
namespace frc {
|
||||
|
||||
@@ -208,17 +209,30 @@ jobject CreatePWMConfigDataResult(JNIEnv *env, int32_t maxPwm,
|
||||
minPwm);
|
||||
}
|
||||
|
||||
void SetCanStatusObject(JNIEnv *env, jobject canStatus,
|
||||
void SetCanStatusObject(JNIEnv *env, jobject canStatus,
|
||||
float percentBusUtilization,
|
||||
uint32_t busOffCount, uint32_t txFullCount,
|
||||
uint32_t receiveErrorCount,
|
||||
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);
|
||||
}
|
||||
static jmethodID func = env->GetMethodID(canStatusCls, "setStatus",
|
||||
"(DIIII)V");
|
||||
env->CallObjectMethod(canStatus, func, (jdouble)percentBusUtilization,
|
||||
(jint)busOffCount, (jint)txFullCount,
|
||||
(jint)receiveErrorCount, (jint)transmitErrorCount);
|
||||
}
|
||||
|
||||
void SetMatchInfoObject(JNIEnv* env, jobject matchStatus,
|
||||
const HAL_MatchInfo& matchInfo) {
|
||||
static jmethodID func = env->GetMethodID(matchInfoDataCls, "setData",
|
||||
"(Ljava/lang/String;Ljava/lang/String;III)V");
|
||||
|
||||
env->CallObjectMethod(matchStatus, func,
|
||||
MakeJString(env, matchInfo.eventName),
|
||||
MakeJString(env, matchInfo.gameSpecificMessage),
|
||||
(jint)matchInfo.matchNumber,
|
||||
(jint)matchInfo.replayNumber,
|
||||
(jint)matchInfo.matchType);
|
||||
}
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -275,6 +289,9 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
canStatusCls = JClass(env, "edu/wpi/first/wpilibj/can/CANStatus");
|
||||
if (!canStatusCls) return JNI_ERR;
|
||||
|
||||
matchInfoDataCls = JClass(env, "edu/wpi/first/wpilibj/hal/MatchInfoData");
|
||||
if (!matchInfoDataCls) return JNI_ERR;
|
||||
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
@@ -295,6 +312,7 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) {
|
||||
uncleanStatusExCls.free(env);
|
||||
pwmConfigDataResultCls.free(env);
|
||||
canStatusCls.free(env);
|
||||
matchInfoDataCls.free(env);
|
||||
jvm = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,13 @@
|
||||
|
||||
extern JavaVM *jvm;
|
||||
|
||||
struct HAL_MatchInfo;
|
||||
|
||||
namespace frc {
|
||||
|
||||
void ReportError(JNIEnv *env, int32_t status, bool doThrow = true);
|
||||
|
||||
void ThrowError(JNIEnv *env, int32_t status, int32_t minRange, int32_t maxRange,
|
||||
|
||||
void ThrowError(JNIEnv *env, int32_t status, int32_t minRange, int32_t maxRange,
|
||||
int32_t requestedValue);
|
||||
|
||||
inline bool CheckStatus(JNIEnv *env, int32_t status, bool doThrow = true) {
|
||||
@@ -26,7 +28,7 @@ inline bool CheckStatus(JNIEnv *env, int32_t status, bool doThrow = true) {
|
||||
return status == 0;
|
||||
}
|
||||
|
||||
inline bool CheckStatusRange(JNIEnv *env, int32_t status, int32_t minRange,
|
||||
inline bool CheckStatusRange(JNIEnv *env, int32_t status, int32_t minRange,
|
||||
int32_t maxRange, int32_t requestedValue) {
|
||||
if (status != 0) ThrowError(env, status, minRange, maxRange, requestedValue);
|
||||
return status == 0;
|
||||
@@ -47,17 +49,20 @@ inline bool CheckCANStatus(JNIEnv *env, int32_t status, int32_t message_id) {
|
||||
void ThrowIllegalArgumentException(JNIEnv *env, const char *msg);
|
||||
void ThrowBoundaryException(JNIEnv *env, double value, double lower,
|
||||
double upper);
|
||||
|
||||
|
||||
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,
|
||||
void SetCanStatusObject(JNIEnv *env, jobject canStatus,
|
||||
float percentBusUtilization,
|
||||
uint32_t busOffCount, uint32_t txFullCount,
|
||||
uint32_t receiveErrorCount,
|
||||
uint32_t busOffCount, uint32_t txFullCount,
|
||||
uint32_t receiveErrorCount,
|
||||
uint32_t transmitErrorCount);
|
||||
|
||||
|
||||
void SetMatchInfoObject(JNIEnv* env, jobject matchStatus,
|
||||
const HAL_MatchInfo& matchInfo);
|
||||
|
||||
} // namespace frc
|
||||
|
||||
#endif // HALUTIL_H
|
||||
|
||||
Reference in New Issue
Block a user