mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[hal] Report previous allocation location for indexed resource duplicates (#3322)
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <wpi/jni_util.h>
|
||||
|
||||
#include "HALUtil.h"
|
||||
#include "edu_wpi_first_hal_AnalogGyroJNI.h"
|
||||
#include "hal/AnalogGyro.h"
|
||||
@@ -24,8 +26,9 @@ Java_edu_wpi_first_hal_AnalogGyroJNI_initializeAnalogGyro
|
||||
(JNIEnv* env, jclass, jint id)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_GyroHandle handle =
|
||||
HAL_InitializeAnalogGyro((HAL_AnalogInputHandle)id, &status);
|
||||
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
|
||||
HAL_GyroHandle handle = HAL_InitializeAnalogGyro((HAL_AnalogInputHandle)id,
|
||||
stack.c_str(), &status);
|
||||
// Analog input does range checking, so we don't need to do so.
|
||||
CheckStatusForceThrow(env, status);
|
||||
return (jint)handle;
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <wpi/jni_util.h>
|
||||
|
||||
#include "HALUtil.h"
|
||||
#include "edu_wpi_first_hal_AnalogJNI.h"
|
||||
#include "hal/AnalogAccumulator.h"
|
||||
@@ -29,9 +31,10 @@ Java_edu_wpi_first_hal_AnalogJNI_initializeAnalogInputPort
|
||||
(JNIEnv* env, jclass, jint id)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto analog = HAL_InitializeAnalogInputPort((HAL_PortHandle)id, &status);
|
||||
CheckStatusRange(env, status, 0, HAL_GetNumAnalogInputs(),
|
||||
hal::getPortHandleChannel((HAL_PortHandle)id));
|
||||
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
|
||||
auto analog =
|
||||
HAL_InitializeAnalogInputPort((HAL_PortHandle)id, stack.c_str(), &status);
|
||||
CheckStatusForceThrow(env, status);
|
||||
return (jint)analog;
|
||||
}
|
||||
|
||||
@@ -57,10 +60,10 @@ Java_edu_wpi_first_hal_AnalogJNI_initializeAnalogOutputPort
|
||||
(JNIEnv* env, jclass, jint id)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_AnalogOutputHandle analog =
|
||||
HAL_InitializeAnalogOutputPort((HAL_PortHandle)id, &status);
|
||||
CheckStatusRange(env, status, 0, HAL_GetNumAnalogOutputs(),
|
||||
hal::getPortHandleChannel((HAL_PortHandle)id));
|
||||
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
|
||||
HAL_AnalogOutputHandle analog = HAL_InitializeAnalogOutputPort(
|
||||
(HAL_PortHandle)id, stack.c_str(), &status);
|
||||
CheckStatusForceThrow(env, status);
|
||||
return (jlong)analog;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <wpi/jni_util.h>
|
||||
|
||||
#include "HALUtil.h"
|
||||
#include "edu_wpi_first_hal_DIOJNI.h"
|
||||
#include "hal/DIO.h"
|
||||
@@ -27,10 +29,10 @@ Java_edu_wpi_first_hal_DIOJNI_initializeDIOPort
|
||||
(JNIEnv* env, jclass, jint id, jboolean input)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto dio = HAL_InitializeDIOPort((HAL_PortHandle)id,
|
||||
static_cast<uint8_t>(input), &status);
|
||||
CheckStatusRange(env, status, 0, HAL_GetNumDigitalChannels(),
|
||||
hal::getPortHandleChannel((HAL_PortHandle)id));
|
||||
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
|
||||
auto dio = HAL_InitializeDIOPort(
|
||||
(HAL_PortHandle)id, static_cast<uint8_t>(input), stack.c_str(), &status);
|
||||
CheckStatusForceThrow(env, status);
|
||||
return (jint)dio;
|
||||
}
|
||||
|
||||
|
||||
@@ -83,15 +83,13 @@ void ThrowUncleanStatusException(JNIEnv* env, wpi::StringRef msg,
|
||||
env->Throw(static_cast<jthrowable>(exception));
|
||||
}
|
||||
|
||||
void ThrowAllocationException(JNIEnv* env, int32_t minRange, int32_t maxRange,
|
||||
int32_t requestedValue, int32_t status) {
|
||||
const char* message = HAL_GetLastError(&status);
|
||||
void ThrowAllocationException(JNIEnv* env, const char* lastError,
|
||||
int32_t status) {
|
||||
wpi::SmallString<1024> buf;
|
||||
wpi::raw_svector_ostream oss(buf);
|
||||
oss << " Code: " << status << ". " << message
|
||||
<< ", Minimum Value: " << minRange << ", Maximum Value: " << maxRange
|
||||
<< ", Requested Value: " << requestedValue;
|
||||
env->ThrowNew(allocationExCls, buf.c_str());
|
||||
|
||||
oss << "Code: " << status << '\n' << lastError;
|
||||
|
||||
allocationExCls.Throw(env, buf.c_str());
|
||||
}
|
||||
|
||||
@@ -107,10 +105,11 @@ void ReportError(JNIEnv* env, int32_t status, bool doThrow) {
|
||||
if (status == 0) {
|
||||
return;
|
||||
}
|
||||
const char* message = HAL_GetLastError(&status);
|
||||
if (status == HAL_HANDLE_ERROR) {
|
||||
ThrowHalHandleException(env, status);
|
||||
return;
|
||||
}
|
||||
const char* message = HAL_GetLastError(&status);
|
||||
if (doThrow && status < 0) {
|
||||
wpi::SmallString<1024> buf;
|
||||
wpi::raw_svector_ostream oss(buf);
|
||||
@@ -132,17 +131,19 @@ void ThrowError(JNIEnv* env, int32_t status, int32_t minRange, int32_t maxRange,
|
||||
if (status == 0) {
|
||||
return;
|
||||
}
|
||||
const char* lastError = HAL_GetLastError(&status);
|
||||
if (status == NO_AVAILABLE_RESOURCES || status == RESOURCE_IS_ALLOCATED ||
|
||||
status == RESOURCE_OUT_OF_RANGE) {
|
||||
ThrowAllocationException(env, minRange, maxRange, requestedValue, status);
|
||||
ThrowAllocationException(env, lastError, status);
|
||||
return;
|
||||
}
|
||||
if (status == HAL_HANDLE_ERROR) {
|
||||
ThrowHalHandleException(env, status);
|
||||
return;
|
||||
}
|
||||
const char* message = HAL_GetErrorMessage(status);
|
||||
wpi::SmallString<1024> buf;
|
||||
wpi::raw_svector_ostream oss(buf);
|
||||
oss << " Code: " << status << ". " << message;
|
||||
oss << " Code: " << status << ". " << lastError;
|
||||
ThrowUncleanStatusException(env, buf.c_str(), status);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <wpi/jni_util.h>
|
||||
|
||||
#include "HALUtil.h"
|
||||
#include "edu_wpi_first_hal_PWMJNI.h"
|
||||
#include "hal/DIO.h"
|
||||
@@ -27,9 +29,9 @@ Java_edu_wpi_first_hal_PWMJNI_initializePWMPort
|
||||
(JNIEnv* env, jclass, jint id)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto pwm = HAL_InitializePWMPort((HAL_PortHandle)id, &status);
|
||||
CheckStatusRange(env, status, 0, HAL_GetNumPWMChannels(),
|
||||
hal::getPortHandleChannel((HAL_PortHandle)id));
|
||||
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
|
||||
auto pwm = HAL_InitializePWMPort((HAL_PortHandle)id, stack.c_str(), &status);
|
||||
CheckStatusForceThrow(env, status);
|
||||
return (jint)pwm;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <wpi/jni_util.h>
|
||||
|
||||
#include "HALUtil.h"
|
||||
#include "edu_wpi_first_hal_RelayJNI.h"
|
||||
#include "hal/Ports.h"
|
||||
@@ -26,10 +28,10 @@ Java_edu_wpi_first_hal_RelayJNI_initializeRelayPort
|
||||
(JNIEnv* env, jclass, jint id, jboolean fwd)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first");
|
||||
HAL_RelayHandle handle = HAL_InitializeRelayPort(
|
||||
(HAL_PortHandle)id, static_cast<uint8_t>(fwd), &status);
|
||||
CheckStatusRange(env, status, 0, HAL_GetNumRelayChannels(),
|
||||
hal::getPortHandleChannel((HAL_PortHandle)id));
|
||||
(HAL_PortHandle)id, static_cast<uint8_t>(fwd), stack.c_str(), &status);
|
||||
CheckStatusForceThrow(env, status);
|
||||
return (jint)handle;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user