2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2016-01-02 03:02:34 -08:00
|
|
|
|
2025-11-11 22:00:42 -08:00
|
|
|
#pragma once
|
2015-11-01 09:11:52 -08:00
|
|
|
|
|
|
|
|
#include <jni.h>
|
2018-05-13 17:09:56 -07:00
|
|
|
#include <stdint.h>
|
2015-11-01 09:11:52 -08:00
|
|
|
|
2025-12-12 21:25:57 -07:00
|
|
|
#include <span>
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <string_view>
|
2018-09-24 22:17:17 -07:00
|
|
|
|
2017-11-09 19:59:29 -08:00
|
|
|
struct HAL_MatchInfo;
|
2025-12-12 21:25:57 -07:00
|
|
|
struct HAL_OpModeOption;
|
2019-09-28 11:34:46 -07:00
|
|
|
struct HAL_Value;
|
2017-11-09 19:59:29 -08:00
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
namespace wpi::hal {
|
2016-10-31 23:04:49 -07:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
void ReportError(JNIEnv* env, int32_t status, bool doThrow = true);
|
2017-11-09 19:59:29 -08:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
void ThrowError(JNIEnv* env, int32_t status, int32_t minRange, int32_t maxRange,
|
2016-09-29 20:18:40 -07:00
|
|
|
int32_t requestedValue);
|
2015-11-01 09:11:52 -08:00
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
inline bool CheckStatus(JNIEnv* env, int32_t status, bool doThrow = true) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (status != 0) {
|
|
|
|
|
ReportError(env, status, doThrow);
|
|
|
|
|
}
|
2016-07-13 20:29:28 -07:00
|
|
|
return status == 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
inline bool CheckStatusRange(JNIEnv* env, int32_t status, int32_t minRange,
|
2016-09-29 20:18:40 -07:00
|
|
|
int32_t maxRange, int32_t requestedValue) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (status != 0) {
|
|
|
|
|
ThrowError(env, status, minRange, maxRange, requestedValue);
|
|
|
|
|
}
|
2016-09-29 20:18:40 -07:00
|
|
|
return status == 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
inline bool CheckStatusForceThrow(JNIEnv* env, int32_t status) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (status != 0) {
|
|
|
|
|
ThrowError(env, status, 0, 0, 0);
|
|
|
|
|
}
|
2015-11-01 09:11:52 -08:00
|
|
|
return status == 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-29 21:57:00 -08:00
|
|
|
void ThrowNullPointerException(JNIEnv* env, std::string_view msg);
|
2023-12-29 09:10:48 -08:00
|
|
|
void ThrowCANStreamOverflowException(JNIEnv* env, jobjectArray messages,
|
|
|
|
|
jint length);
|
2021-06-06 16:13:58 -07:00
|
|
|
void ThrowIllegalArgumentException(JNIEnv* env, std::string_view msg);
|
2025-07-21 21:52:10 -07:00
|
|
|
void ThrowIndexOutOfBoundsException(JNIEnv* env, std::string_view msg);
|
2018-05-13 17:09:56 -07:00
|
|
|
void ThrowBoundaryException(JNIEnv* env, double value, double lower,
|
2015-11-01 09:11:52 -08:00
|
|
|
double upper);
|
2017-11-09 19:59:29 -08:00
|
|
|
|
2025-12-12 21:25:57 -07:00
|
|
|
jobject CreateOpModeOption(JNIEnv* env, const HAL_OpModeOption& option);
|
|
|
|
|
jobjectArray CreateOpModeOptionArray(JNIEnv* env,
|
|
|
|
|
std::span<const HAL_OpModeOption> options);
|
|
|
|
|
HAL_OpModeOption CreateOpModeOptionFromJava(JNIEnv* env, jobject option);
|
|
|
|
|
|
2021-12-19 13:41:35 -08:00
|
|
|
jobject CreateREVPHVersion(JNIEnv* env, uint32_t firmwareMajor,
|
|
|
|
|
uint32_t firmwareMinor, uint32_t firmwareFix,
|
|
|
|
|
uint32_t hardwareMinor, uint32_t hardwareMajor,
|
|
|
|
|
uint32_t uniqueId);
|
|
|
|
|
|
2018-05-13 17:09:56 -07:00
|
|
|
void SetCanStatusObject(JNIEnv* env, jobject canStatus,
|
|
|
|
|
float percentBusUtilization, uint32_t busOffCount,
|
|
|
|
|
uint32_t txFullCount, uint32_t receiveErrorCount,
|
2017-10-21 15:32:05 -07:00
|
|
|
uint32_t transmitErrorCount);
|
2017-11-09 19:59:29 -08:00
|
|
|
|
|
|
|
|
void SetMatchInfoObject(JNIEnv* env, jobject matchStatus,
|
|
|
|
|
const HAL_MatchInfo& matchInfo);
|
|
|
|
|
|
2025-02-25 19:07:01 -08:00
|
|
|
jbyteArray SetCANReceiveMessageObject(JNIEnv* env, jobject canData,
|
|
|
|
|
int32_t length, int32_t flags,
|
|
|
|
|
uint64_t timestamp);
|
2018-05-21 16:09:38 -07:00
|
|
|
|
2022-12-06 23:58:09 -06:00
|
|
|
jbyteArray SetCANStreamObject(JNIEnv* env, jobject canStreamData,
|
2025-07-14 23:46:57 -07:00
|
|
|
int32_t length, int32_t flags, uint32_t messageId,
|
2022-12-06 23:58:09 -06:00
|
|
|
uint64_t timestamp);
|
|
|
|
|
|
2019-09-28 11:34:46 -07:00
|
|
|
jobject CreateHALValue(JNIEnv* env, const HAL_Value& value);
|
|
|
|
|
|
2021-12-19 13:42:49 -08:00
|
|
|
jobject CreatePowerDistributionVersion(JNIEnv* env, uint32_t firmwareMajor,
|
|
|
|
|
uint32_t firmwareMinor,
|
|
|
|
|
uint32_t firmwareFix,
|
|
|
|
|
uint32_t hardwareMinor,
|
|
|
|
|
uint32_t hardwareMajor,
|
|
|
|
|
uint32_t uniqueId);
|
|
|
|
|
|
2023-12-28 22:50:57 -08:00
|
|
|
jobject CreateCANStreamMessage(JNIEnv* env);
|
|
|
|
|
|
2018-04-29 13:29:07 -07:00
|
|
|
JavaVM* GetJVM();
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
} // namespace wpi::hal
|