Files
allwpilib/hal/src/main/native/cpp/jni/simulation/DriverStationDataJNI.cpp

816 lines
23 KiB
C++
Raw Normal View History

// 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.
#include <jni.h>
#include "CallbackStore.h"
2025-11-07 19:55:43 -05:00
#include "org_wpilib_hardware_hal_simulation_DriverStationDataJNI.h"
2025-11-07 19:56:21 -05:00
#include "wpi/hal/simulation/DriverStationData.h"
#include "wpi/hal/simulation/MockHooks.h"
2025-11-07 19:57:55 -05:00
#include "wpi/util/StringExtras.hpp"
#include "wpi/util/jni_util.hpp"
2025-11-07 20:00:05 -05:00
using namespace wpi::hal;
using namespace wpi::util::java;
extern "C" {
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: registerEnabledCallback
* Signature: (Ljava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_registerEnabledCallback
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallbackNoIndex(
env, callback, initialNotify,
&HALSIM_RegisterDriverStationEnabledCallback);
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: cancelEnabledCallback
* Signature: (I)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_cancelEnabledCallback
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint handle)
{
return sim::FreeCallbackNoIndex(env, handle,
&HALSIM_CancelDriverStationEnabledCallback);
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: getEnabled
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_getEnabled
2018-05-13 17:09:56 -07:00
(JNIEnv*, jclass)
{
return HALSIM_GetDriverStationEnabled();
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: setEnabled
* Signature: (Z)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setEnabled
2018-05-13 17:09:56 -07:00
(JNIEnv*, jclass, jboolean value)
{
HALSIM_SetDriverStationEnabled(value);
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: registerAutonomousCallback
* Signature: (Ljava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_registerAutonomousCallback
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallbackNoIndex(
env, callback, initialNotify,
&HALSIM_RegisterDriverStationAutonomousCallback);
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: cancelAutonomousCallback
* Signature: (I)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_cancelAutonomousCallback
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint handle)
{
return sim::FreeCallbackNoIndex(
env, handle, &HALSIM_CancelDriverStationAutonomousCallback);
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: getAutonomous
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_getAutonomous
2018-05-13 17:09:56 -07:00
(JNIEnv*, jclass)
{
return HALSIM_GetDriverStationAutonomous();
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: setAutonomous
* Signature: (Z)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setAutonomous
2018-05-13 17:09:56 -07:00
(JNIEnv*, jclass, jboolean value)
{
HALSIM_SetDriverStationAutonomous(value);
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: registerTestCallback
* Signature: (Ljava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_registerTestCallback
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallbackNoIndex(
env, callback, initialNotify, &HALSIM_RegisterDriverStationTestCallback);
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: cancelTestCallback
* Signature: (I)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_cancelTestCallback
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint handle)
{
return sim::FreeCallbackNoIndex(env, handle,
&HALSIM_CancelDriverStationTestCallback);
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: getTest
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_getTest
2018-05-13 17:09:56 -07:00
(JNIEnv*, jclass)
{
return HALSIM_GetDriverStationTest();
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: setTest
* Signature: (Z)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setTest
2018-05-13 17:09:56 -07:00
(JNIEnv*, jclass, jboolean value)
{
HALSIM_SetDriverStationTest(value);
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: registerEStopCallback
* Signature: (Ljava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_registerEStopCallback
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallbackNoIndex(
env, callback, initialNotify, &HALSIM_RegisterDriverStationEStopCallback);
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: cancelEStopCallback
* Signature: (I)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_cancelEStopCallback
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint handle)
{
return sim::FreeCallbackNoIndex(env, handle,
&HALSIM_CancelDriverStationEStopCallback);
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: getEStop
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_getEStop
2018-05-13 17:09:56 -07:00
(JNIEnv*, jclass)
{
return HALSIM_GetDriverStationEStop();
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: setEStop
* Signature: (Z)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setEStop
2018-05-13 17:09:56 -07:00
(JNIEnv*, jclass, jboolean value)
{
HALSIM_SetDriverStationEStop(value);
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: registerFmsAttachedCallback
* Signature: (Ljava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_registerFmsAttachedCallback
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallbackNoIndex(
env, callback, initialNotify,
&HALSIM_RegisterDriverStationFmsAttachedCallback);
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: cancelFmsAttachedCallback
* Signature: (I)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_cancelFmsAttachedCallback
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint handle)
{
return sim::FreeCallbackNoIndex(
env, handle, &HALSIM_CancelDriverStationFmsAttachedCallback);
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: getFmsAttached
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_getFmsAttached
2018-05-13 17:09:56 -07:00
(JNIEnv*, jclass)
{
return HALSIM_GetDriverStationFmsAttached();
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: setFmsAttached
* Signature: (Z)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setFmsAttached
2018-05-13 17:09:56 -07:00
(JNIEnv*, jclass, jboolean value)
{
HALSIM_SetDriverStationFmsAttached(value);
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: registerDsAttachedCallback
* Signature: (Ljava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_registerDsAttachedCallback
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallbackNoIndex(
env, callback, initialNotify,
&HALSIM_RegisterDriverStationDsAttachedCallback);
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: cancelDsAttachedCallback
* Signature: (I)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_cancelDsAttachedCallback
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jint handle)
{
return sim::FreeCallbackNoIndex(
env, handle, &HALSIM_CancelDriverStationDsAttachedCallback);
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: getDsAttached
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_getDsAttached
2018-05-13 17:09:56 -07:00
(JNIEnv*, jclass)
{
return HALSIM_GetDriverStationDsAttached();
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: setDsAttached
* Signature: (Z)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setDsAttached
2018-05-13 17:09:56 -07:00
(JNIEnv*, jclass, jboolean value)
{
HALSIM_SetDriverStationDsAttached(value);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: registerAllianceStationIdCallback
* Signature: (Ljava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_registerAllianceStationIdCallback
(JNIEnv* env, jclass, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallbackNoIndex(
env, callback, initialNotify,
&HALSIM_RegisterDriverStationAllianceStationIdCallback);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: cancelAllianceStationIdCallback
* Signature: (I)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_cancelAllianceStationIdCallback
(JNIEnv* env, jclass, jint handle)
{
return sim::FreeCallbackNoIndex(
env, handle, &HALSIM_CancelDriverStationAllianceStationIdCallback);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: getAllianceStationId
* Signature: ()I
*/
JNIEXPORT jint JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_getAllianceStationId
(JNIEnv*, jclass)
{
return HALSIM_GetDriverStationAllianceStationId();
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setAllianceStationId
* Signature: (I)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setAllianceStationId
(JNIEnv*, jclass, jint value)
{
HALSIM_SetDriverStationAllianceStationId(
static_cast<HAL_AllianceStationID>(value));
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: registerMatchTimeCallback
* Signature: (Ljava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_registerMatchTimeCallback
(JNIEnv* env, jclass, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallbackNoIndex(
env, callback, initialNotify,
&HALSIM_RegisterDriverStationMatchTimeCallback);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: cancelMatchTimeCallback
* Signature: (I)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_cancelMatchTimeCallback
(JNIEnv* env, jclass, jint handle)
{
return sim::FreeCallbackNoIndex(env, handle,
&HALSIM_CancelDriverStationMatchTimeCallback);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: getMatchTime
* Signature: ()D
*/
JNIEXPORT jdouble JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_getMatchTime
(JNIEnv*, jclass)
{
return HALSIM_GetDriverStationMatchTime();
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setMatchTime
* Signature: (D)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setMatchTime
(JNIEnv*, jclass, jdouble value)
{
HALSIM_SetDriverStationMatchTime(value);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setJoystickAxes
* Signature: (B[FS)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setJoystickAxes
(JNIEnv* env, jclass, jbyte joystickNum, jfloatArray axesArray,
jshort availableAxes)
2018-05-13 17:09:56 -07:00
{
HAL_JoystickAxes axes;
{
JSpan<const jfloat> jArrayRef(env, axesArray);
auto arrayRef = jArrayRef.array();
auto arraySize = arrayRef.size();
int maxCount =
arraySize < HAL_kMaxJoystickAxes ? arraySize : HAL_kMaxJoystickAxes;
axes.available = availableAxes;
for (int i = 0; i < maxCount; i++) {
axes.axes[i] = arrayRef[i];
}
}
HALSIM_SetJoystickAxes(joystickNum, &axes);
return;
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setJoystickPOVs
* Signature: (B[BS)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setJoystickPOVs
(JNIEnv* env, jclass, jbyte joystickNum, jbyteArray povsArray,
jshort availablePovs)
2018-05-13 17:09:56 -07:00
{
HAL_JoystickPOVs povs;
{
JSpan<const jbyte> jArrayRef(env, povsArray);
auto arrayRef = jArrayRef.array();
auto arraySize = arrayRef.size();
int maxCount =
arraySize < HAL_kMaxJoystickPOVs ? arraySize : HAL_kMaxJoystickPOVs;
povs.available = availablePovs;
for (int i = 0; i < maxCount; i++) {
povs.povs[i] = static_cast<HAL_JoystickPOV>(arrayRef[i]);
}
}
HALSIM_SetJoystickPOVs(joystickNum, &povs);
return;
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setJoystickButtons
* Signature: (BJJ)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setJoystickButtons
(JNIEnv* env, jclass, jbyte joystickNum, jlong buttons,
jlong availableButtons)
2018-05-13 17:09:56 -07:00
{
HAL_JoystickButtons joystickButtons;
joystickButtons.available = availableButtons;
joystickButtons.buttons = buttons;
HALSIM_SetJoystickButtons(joystickNum, &joystickButtons);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: getJoystickOutputs
* Signature: (I)J
*/
JNIEXPORT jlong JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_getJoystickOutputs
(JNIEnv* env, jclass, jint stick)
{
int64_t outputs = 0;
int32_t leftRumble;
int32_t rightRumble;
HALSIM_GetJoystickOutputs(stick, &outputs, &leftRumble, &rightRumble);
return outputs;
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: getJoystickRumble
* Signature: (II)I
*/
JNIEXPORT jint JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_getJoystickRumble
(JNIEnv* env, jclass, jint stick, jint rumbleNum)
{
int64_t outputs;
int32_t leftRumble = 0;
int32_t rightRumble = 0;
HALSIM_GetJoystickOutputs(stick, &outputs, &leftRumble, &rightRumble);
return rumbleNum == 0 ? leftRumble : rightRumble;
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setMatchInfo
* Signature: (Ljava/lang/String;Ljava/lang/String;III)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setMatchInfo
(JNIEnv* env, jclass, jstring eventName, jstring gameSpecificMessage,
jint matchNumber, jint replayNumber, jint matchType)
{
JStringRef eventNameRef{env, eventName};
JStringRef gameSpecificMessageRef{env, gameSpecificMessage};
HAL_MatchInfo halMatchInfo;
2025-11-07 20:00:05 -05:00
wpi::util::format_to_n_c_str(halMatchInfo.eventName, sizeof(halMatchInfo.eventName),
"{}", eventNameRef.str());
2025-11-07 20:00:05 -05:00
wpi::util::format_to_n_c_str(
reinterpret_cast<char*>(halMatchInfo.gameSpecificMessage),
sizeof(halMatchInfo.gameSpecificMessage), "{}",
gameSpecificMessageRef.str());
halMatchInfo.gameSpecificMessageSize = gameSpecificMessageRef.size();
halMatchInfo.matchType = (HAL_MatchType)matchType;
halMatchInfo.matchNumber = matchNumber;
halMatchInfo.replayNumber = replayNumber;
HALSIM_SetMatchInfo(&halMatchInfo);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: registerAllCallbacks
2018-05-13 17:09:56 -07:00
* Signature: (Ljava/lang/Object;Z)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_registerAllCallbacks
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jobject callback, jboolean initialNotify)
{
sim::AllocateCallbackNoIndex(
env, callback, initialNotify,
[](HAL_NotifyCallback cb, void* param, HAL_Bool in) {
HALSIM_RegisterDriverStationAllCallbacks(cb, param, in);
return 0;
});
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: notifyNewData
* Signature: ()V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_notifyNewData
2018-05-13 17:09:56 -07:00
(JNIEnv*, jclass)
{
HALSIM_NotifyDriverStationNewData();
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setSendError
* Signature: (Z)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setSendError
(JNIEnv*, jclass, jboolean shouldSend)
{
if (shouldSend) {
HALSIM_SetSendError(nullptr);
} else {
HALSIM_SetSendError([](HAL_Bool isError, int32_t errorCode,
HAL_Bool isLVCode, const char* details,
const char* location, const char* callStack,
HAL_Bool printMsg) { return 0; });
}
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setSendConsoleLine
* Signature: (Z)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setSendConsoleLine
(JNIEnv*, jclass, jboolean shouldSend)
{
if (shouldSend) {
HALSIM_SetSendConsoleLine(nullptr);
} else {
HALSIM_SetSendConsoleLine([](const char* line) { return 0; });
}
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setJoystickButton
* Signature: (IIZ)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setJoystickButton
(JNIEnv*, jclass, jint stick, jint button, jboolean state)
{
HALSIM_SetJoystickButton(stick, button, state);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setJoystickAxis
* Signature: (IID)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setJoystickAxis
(JNIEnv*, jclass, jint stick, jint axis, jdouble value)
{
HALSIM_SetJoystickAxis(stick, axis, value);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setJoystickPOV
* Signature: (IIB)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setJoystickPOV
(JNIEnv*, jclass, jint stick, jint pov, jbyte value)
{
HALSIM_SetJoystickPOV(stick, pov, static_cast<HAL_JoystickPOV>(value));
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setJoystickButtonsValue
* Signature: (IJ)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setJoystickButtonsValue
(JNIEnv*, jclass, jint stick, jlong buttons)
{
HALSIM_SetJoystickButtonsValue(stick, buttons);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setJoystickAxesAvailable
* Signature: (II)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setJoystickAxesAvailable
(JNIEnv*, jclass, jint stick, jint available)
{
HALSIM_SetJoystickAxesAvailable(stick, available);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setJoystickPOVsAvailable
* Signature: (II)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setJoystickPOVsAvailable
(JNIEnv*, jclass, jint stick, jint available)
{
HALSIM_SetJoystickPOVsAvailable(stick, available);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setJoystickButtonsAvailable
* Signature: (IJ)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setJoystickButtonsAvailable
(JNIEnv*, jclass, jint stick, jlong available)
{
HALSIM_SetJoystickButtonsAvailable(stick, available);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setJoystickIsGamepad
* Signature: (IZ)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setJoystickIsGamepad
(JNIEnv*, jclass, jint stick, jboolean isGamepad)
{
HALSIM_SetJoystickIsGamepad(stick, isGamepad);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setJoystickType
* Signature: (II)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setJoystickType
(JNIEnv*, jclass, jint stick, jint type)
{
HALSIM_SetJoystickType(stick, type);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setJoystickName
* Signature: (ILjava/lang/String;)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setJoystickName
(JNIEnv* env, jclass, jint stick, jstring name)
{
JStringRef nameJString{env, name};
2025-11-07 20:00:05 -05:00
auto str = wpi::util::make_string(nameJString);
Change C APIs to a unified string implementation (#6299) Currently in the entire C API of WPILib we have ~8 different ways of handling strings. The C API actually isn't built for pure C callers (We don't actually have any of those). Instead, they're built for interop between languages like LabVIEW and C# which can talk to C API's directly. For output parameters, the choice was fairly obvious. An output struct containing a const string pointer and a length makes the most sense. Its easy to use these from most other languages, and doesn't require special null termination handling. Freeing these is also easy, as if you ever receive one of these string structures, theres just a single function call to free it. Input parameters are a bit more complex. To be used from pure C, and from LabVIEW, a null terminated string is the best in most cases. However, null terminated strings in general have a lot of downsides. Additionally, from LabVIEW there are other considerations around encoding that having a wrapper struct helps make a bit easier. From a language like C#, a wrapper struct is by far the easiest, as custom marshalling can make it trivial to marshal both UTF8 and UTF16 strings down. The final consideration is its nice to have an identical concept for both input and output. It makes the rules fairly easy to understand. WPILib will not have any APIs that manipulate a string allocated externally. This means WPI_String can be const, as across the boundary it is always const. If a WPILib API takes a const WPI_String*, WPILib will not manipulate or attempt to free that string, and that string is treated as an input. It is up to the caller to handle that memory, WPILib will never hold onto that memory longer than the call. If a WPILib API takes a WPI_String*, that string is an output. WPILib will allocate that API with WPI_AllocateString(), fill in the string, and return to the caller. When the caller is done with the string, they must free it with WPI_FreeString(). If an output struct contains a WPI_String member, that member is considered read only, and should not be explicitly freed. The caller should call the free function for that struct. If an array of WPI_Strings are returned, each individual string is considered read only, and should not be explicitly freed. The free function for that array should be called by the caller. If an input struct containing a WPI_String, or an input array of WPI_Strings is passed to WPILib, the individual strings will not be manipulated or freed by WPILib, and the caller owns and should free that memory. Callbacks also follow these rules. The most common is a callback either getting passed a const WPI_String* or a struct containing a WPI_String. In both of these cases, the callback target should consider these strings read only, and not attempt to free them or manipulate them.
2024-05-13 05:35:14 -07:00
HALSIM_SetJoystickName(stick, &str);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setGameSpecificMessage
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setGameSpecificMessage
(JNIEnv* env, jclass, jstring message)
{
JStringRef messageJString{env, message};
2025-11-07 20:00:05 -05:00
auto str = wpi::util::make_string(messageJString);
Change C APIs to a unified string implementation (#6299) Currently in the entire C API of WPILib we have ~8 different ways of handling strings. The C API actually isn't built for pure C callers (We don't actually have any of those). Instead, they're built for interop between languages like LabVIEW and C# which can talk to C API's directly. For output parameters, the choice was fairly obvious. An output struct containing a const string pointer and a length makes the most sense. Its easy to use these from most other languages, and doesn't require special null termination handling. Freeing these is also easy, as if you ever receive one of these string structures, theres just a single function call to free it. Input parameters are a bit more complex. To be used from pure C, and from LabVIEW, a null terminated string is the best in most cases. However, null terminated strings in general have a lot of downsides. Additionally, from LabVIEW there are other considerations around encoding that having a wrapper struct helps make a bit easier. From a language like C#, a wrapper struct is by far the easiest, as custom marshalling can make it trivial to marshal both UTF8 and UTF16 strings down. The final consideration is its nice to have an identical concept for both input and output. It makes the rules fairly easy to understand. WPILib will not have any APIs that manipulate a string allocated externally. This means WPI_String can be const, as across the boundary it is always const. If a WPILib API takes a const WPI_String*, WPILib will not manipulate or attempt to free that string, and that string is treated as an input. It is up to the caller to handle that memory, WPILib will never hold onto that memory longer than the call. If a WPILib API takes a WPI_String*, that string is an output. WPILib will allocate that API with WPI_AllocateString(), fill in the string, and return to the caller. When the caller is done with the string, they must free it with WPI_FreeString(). If an output struct contains a WPI_String member, that member is considered read only, and should not be explicitly freed. The caller should call the free function for that struct. If an array of WPI_Strings are returned, each individual string is considered read only, and should not be explicitly freed. The free function for that array should be called by the caller. If an input struct containing a WPI_String, or an input array of WPI_Strings is passed to WPILib, the individual strings will not be manipulated or freed by WPILib, and the caller owns and should free that memory. Callbacks also follow these rules. The most common is a callback either getting passed a const WPI_String* or a struct containing a WPI_String. In both of these cases, the callback target should consider these strings read only, and not attempt to free them or manipulate them.
2024-05-13 05:35:14 -07:00
HALSIM_SetGameSpecificMessage(&str);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setEventName
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setEventName
(JNIEnv* env, jclass, jstring name)
{
JStringRef nameJString{env, name};
2025-11-07 20:00:05 -05:00
auto str = wpi::util::make_string(nameJString);
Change C APIs to a unified string implementation (#6299) Currently in the entire C API of WPILib we have ~8 different ways of handling strings. The C API actually isn't built for pure C callers (We don't actually have any of those). Instead, they're built for interop between languages like LabVIEW and C# which can talk to C API's directly. For output parameters, the choice was fairly obvious. An output struct containing a const string pointer and a length makes the most sense. Its easy to use these from most other languages, and doesn't require special null termination handling. Freeing these is also easy, as if you ever receive one of these string structures, theres just a single function call to free it. Input parameters are a bit more complex. To be used from pure C, and from LabVIEW, a null terminated string is the best in most cases. However, null terminated strings in general have a lot of downsides. Additionally, from LabVIEW there are other considerations around encoding that having a wrapper struct helps make a bit easier. From a language like C#, a wrapper struct is by far the easiest, as custom marshalling can make it trivial to marshal both UTF8 and UTF16 strings down. The final consideration is its nice to have an identical concept for both input and output. It makes the rules fairly easy to understand. WPILib will not have any APIs that manipulate a string allocated externally. This means WPI_String can be const, as across the boundary it is always const. If a WPILib API takes a const WPI_String*, WPILib will not manipulate or attempt to free that string, and that string is treated as an input. It is up to the caller to handle that memory, WPILib will never hold onto that memory longer than the call. If a WPILib API takes a WPI_String*, that string is an output. WPILib will allocate that API with WPI_AllocateString(), fill in the string, and return to the caller. When the caller is done with the string, they must free it with WPI_FreeString(). If an output struct contains a WPI_String member, that member is considered read only, and should not be explicitly freed. The caller should call the free function for that struct. If an array of WPI_Strings are returned, each individual string is considered read only, and should not be explicitly freed. The free function for that array should be called by the caller. If an input struct containing a WPI_String, or an input array of WPI_Strings is passed to WPILib, the individual strings will not be manipulated or freed by WPILib, and the caller owns and should free that memory. Callbacks also follow these rules. The most common is a callback either getting passed a const WPI_String* or a struct containing a WPI_String. In both of these cases, the callback target should consider these strings read only, and not attempt to free them or manipulate them.
2024-05-13 05:35:14 -07:00
HALSIM_SetEventName(&str);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setMatchType
* Signature: (I)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setMatchType
(JNIEnv*, jclass, jint type)
{
HALSIM_SetMatchType(static_cast<HAL_MatchType>(static_cast<int>(type)));
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setMatchNumber
* Signature: (I)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setMatchNumber
(JNIEnv*, jclass, jint matchNumber)
{
HALSIM_SetMatchNumber(matchNumber);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
* Method: setReplayNumber
* Signature: (I)V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setReplayNumber
(JNIEnv*, jclass, jint replayNumber)
{
HALSIM_SetReplayNumber(replayNumber);
}
2018-05-13 17:09:56 -07:00
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: resetData
* Signature: ()V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_resetData
2018-05-13 17:09:56 -07:00
(JNIEnv*, jclass)
{
HALSIM_ResetDriverStationData();
}
} // extern "C"