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

829 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 <wpi/StringExtras.h>
#include <wpi/jni_util.h>
#include "CallbackStore.h"
#include "edu_wpi_first_hal_simulation_DriverStationDataJNI.h"
#include "hal/simulation/DriverStationData.h"
#include "hal/simulation/MockHooks.h"
using namespace hal;
using namespace wpi::java;
extern "C" {
2018-05-13 17:09:56 -07:00
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: registerEnabledCallback
* Signature: (Ljava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: cancelEnabledCallback
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: getEnabled
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: setEnabled
* Signature: (Z)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: registerAutonomousCallback
* Signature: (Ljava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: cancelAutonomousCallback
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: getAutonomous
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: setAutonomous
* Signature: (Z)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: registerTestCallback
* Signature: (Ljava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: cancelTestCallback
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: getTest
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: setTest
* Signature: (Z)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: registerEStopCallback
* Signature: (Ljava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: cancelEStopCallback
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: getEStop
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: setEStop
* Signature: (Z)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: registerFmsAttachedCallback
* Signature: (Ljava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: cancelFmsAttachedCallback
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: getFmsAttached
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: setFmsAttached
* Signature: (Z)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: registerDsAttachedCallback
* Signature: (Ljava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: cancelDsAttachedCallback
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: getDsAttached
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_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
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: setDsAttached
* Signature: (Z)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setDsAttached
2018-05-13 17:09:56 -07:00
(JNIEnv*, jclass, jboolean value)
{
HALSIM_SetDriverStationDsAttached(value);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: registerAllianceStationIdCallback
* Signature: (Ljava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_registerAllianceStationIdCallback
(JNIEnv* env, jclass, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallbackNoIndex(
env, callback, initialNotify,
&HALSIM_RegisterDriverStationAllianceStationIdCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: cancelAllianceStationIdCallback
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_cancelAllianceStationIdCallback
(JNIEnv* env, jclass, jint handle)
{
return sim::FreeCallbackNoIndex(
env, handle, &HALSIM_CancelDriverStationAllianceStationIdCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: getAllianceStationId
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_getAllianceStationId
(JNIEnv*, jclass)
{
return HALSIM_GetDriverStationAllianceStationId();
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setAllianceStationId
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setAllianceStationId
(JNIEnv*, jclass, jint value)
{
HALSIM_SetDriverStationAllianceStationId(
static_cast<HAL_AllianceStationID>(value));
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: registerMatchTimeCallback
* Signature: (Ljava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_registerMatchTimeCallback
(JNIEnv* env, jclass, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallbackNoIndex(
env, callback, initialNotify,
&HALSIM_RegisterDriverStationMatchTimeCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: cancelMatchTimeCallback
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_cancelMatchTimeCallback
(JNIEnv* env, jclass, jint handle)
{
return sim::FreeCallbackNoIndex(env, handle,
&HALSIM_CancelDriverStationMatchTimeCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: getMatchTime
* Signature: ()D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_getMatchTime
(JNIEnv*, jclass)
{
return HALSIM_GetDriverStationMatchTime();
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setMatchTime
* Signature: (D)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setMatchTime
(JNIEnv*, jclass, jdouble value)
{
HALSIM_SetDriverStationMatchTime(value);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickAxes
* Signature: (B[F)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickAxes
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jbyte joystickNum, jfloatArray axesArray)
{
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.count = maxCount;
for (int i = 0; i < maxCount; i++) {
axes.axes[i] = arrayRef[i];
}
}
HALSIM_SetJoystickAxes(joystickNum, &axes);
return;
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickPOVs
* Signature: (B[B)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickPOVs
(JNIEnv* env, jclass, jbyte joystickNum, jbyteArray povsArray)
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.count = maxCount;
for (int i = 0; i < maxCount; i++) {
povs.povs[i] = static_cast<HAL_JoystickPOV>(arrayRef[i]);
}
}
HALSIM_SetJoystickPOVs(joystickNum, &povs);
return;
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickButtons
* Signature: (BII)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickButtons
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass, jbyte joystickNum, jint buttons, jint count)
{
if (count > 32) {
count = 32;
}
HAL_JoystickButtons joystickButtons;
joystickButtons.count = count;
joystickButtons.buttons = buttons;
HALSIM_SetJoystickButtons(joystickNum, &joystickButtons);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: getJoystickOutputs
* Signature: (I)J
*/
JNIEXPORT jlong JNICALL
Java_edu_wpi_first_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;
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: getJoystickRumble
* Signature: (II)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_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;
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setMatchInfo
* Signature: (Ljava/lang/String;Ljava/lang/String;III)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_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;
wpi::format_to_n_c_str(halMatchInfo.eventName, sizeof(halMatchInfo.eventName),
"{}", eventNameRef.str());
wpi::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);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: registerAllCallbacks
2018-05-13 17:09:56 -07:00
* Signature: (Ljava/lang/Object;Z)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_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;
});
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: notifyNewData
* Signature: ()V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_notifyNewData
2018-05-13 17:09:56 -07:00
(JNIEnv*, jclass)
{
HALSIM_NotifyDriverStationNewData();
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setSendError
* Signature: (Z)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_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; });
}
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setSendConsoleLine
* Signature: (Z)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setSendConsoleLine
(JNIEnv*, jclass, jboolean shouldSend)
{
if (shouldSend) {
HALSIM_SetSendConsoleLine(nullptr);
} else {
HALSIM_SetSendConsoleLine([](const char* line) { return 0; });
}
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickButton
* Signature: (IIZ)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickButton
(JNIEnv*, jclass, jint stick, jint button, jboolean state)
{
HALSIM_SetJoystickButton(stick, button, state);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickAxis
* Signature: (IID)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickAxis
(JNIEnv*, jclass, jint stick, jint axis, jdouble value)
{
HALSIM_SetJoystickAxis(stick, axis, value);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickPOV
* Signature: (IIB)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickPOV
(JNIEnv*, jclass, jint stick, jint pov, jbyte value)
{
HALSIM_SetJoystickPOV(stick, pov, static_cast<HAL_JoystickPOV>(value));
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickButtonsValue
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickButtonsValue
(JNIEnv*, jclass, jint stick, jint buttons)
{
HALSIM_SetJoystickButtonsValue(stick, buttons);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickAxisCount
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickAxisCount
(JNIEnv*, jclass, jint stick, jint count)
{
HALSIM_SetJoystickAxisCount(stick, count);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickPOVCount
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickPOVCount
(JNIEnv*, jclass, jint stick, jint count)
{
HALSIM_SetJoystickPOVCount(stick, count);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickButtonCount
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickButtonCount
(JNIEnv*, jclass, jint stick, jint count)
{
HALSIM_SetJoystickButtonCount(stick, count);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickIsGamepad
* Signature: (IZ)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickIsGamepad
(JNIEnv*, jclass, jint stick, jboolean isGamepad)
{
HALSIM_SetJoystickIsGamepad(stick, isGamepad);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickType
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickType
(JNIEnv*, jclass, jint stick, jint type)
{
HALSIM_SetJoystickType(stick, type);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickName
* Signature: (ILjava/lang/String;)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickName
(JNIEnv* env, jclass, jint stick, jstring name)
{
JStringRef nameJString{env, name};
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
auto str = wpi::make_string(nameJString);
HALSIM_SetJoystickName(stick, &str);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setJoystickAxisType
* Signature: (III)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickAxisType
(JNIEnv*, jclass, jint stick, jint axis, jint type)
{
HALSIM_SetJoystickAxisType(stick, axis, type);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setGameSpecificMessage
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setGameSpecificMessage
(JNIEnv* env, jclass, jstring message)
{
JStringRef messageJString{env, message};
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
auto str = wpi::make_string(messageJString);
HALSIM_SetGameSpecificMessage(&str);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setEventName
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setEventName
(JNIEnv* env, jclass, jstring name)
{
JStringRef nameJString{env, name};
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
auto str = wpi::make_string(nameJString);
HALSIM_SetEventName(&str);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setMatchType
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setMatchType
(JNIEnv*, jclass, jint type)
{
HALSIM_SetMatchType(static_cast<HAL_MatchType>(static_cast<int>(type)));
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setMatchNumber
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setMatchNumber
(JNIEnv*, jclass, jint matchNumber)
{
HALSIM_SetMatchNumber(matchNumber);
}
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
* Method: setReplayNumber
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setReplayNumber
(JNIEnv*, jclass, jint replayNumber)
{
HALSIM_SetReplayNumber(replayNumber);
}
2018-05-13 17:09:56 -07:00
/*
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
2018-05-13 17:09:56 -07:00
* Method: resetData
* Signature: ()V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_resetData
2018-05-13 17:09:56 -07:00
(JNIEnv*, jclass)
{
HALSIM_ResetDriverStationData();
}
} // extern "C"