mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[hal, wpilib] Remove SPI support (#7678)
This commit is contained in:
@@ -61,20 +61,6 @@ HAL_PortHandle createPortHandle(uint8_t channel, uint8_t module) {
|
||||
handle += channel;
|
||||
return handle;
|
||||
}
|
||||
HAL_PortHandle createPortHandleForSPI(uint8_t channel) {
|
||||
// set last 8 bits, then shift to first 8 bits
|
||||
HAL_PortHandle handle = static_cast<HAL_PortHandle>(HAL_HandleEnum::Port);
|
||||
handle = handle << 16;
|
||||
// set second set up bits to 1
|
||||
int32_t temp = 1;
|
||||
temp = (temp << 8) & 0xff00;
|
||||
handle += temp;
|
||||
// shift to last set of bits
|
||||
handle = handle << 8;
|
||||
// add channel to last 8 bits
|
||||
handle += channel;
|
||||
return handle;
|
||||
}
|
||||
HAL_Handle createHandle(int16_t index, HAL_HandleEnum handleType,
|
||||
int16_t version) {
|
||||
if (index < 0) {
|
||||
|
||||
@@ -1,466 +0,0 @@
|
||||
// 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 <cassert>
|
||||
|
||||
#include <wpi/jni_util.h>
|
||||
|
||||
#include "HALUtil.h"
|
||||
#include "edu_wpi_first_hal_SPIJNI.h"
|
||||
#include "hal/SPI.h"
|
||||
|
||||
using namespace hal;
|
||||
using namespace wpi::java;
|
||||
|
||||
static_assert(HAL_SPIPort::HAL_SPI_kInvalid ==
|
||||
edu_wpi_first_hal_SPIJNI_INVALID_PORT);
|
||||
static_assert(HAL_SPIPort::HAL_SPI_kOnboardCS0 ==
|
||||
edu_wpi_first_hal_SPIJNI_ONBOARD_CS0_PORT);
|
||||
static_assert(HAL_SPIPort::HAL_SPI_kOnboardCS1 ==
|
||||
edu_wpi_first_hal_SPIJNI_ONBOARD_CS1_PORT);
|
||||
static_assert(HAL_SPIPort::HAL_SPI_kOnboardCS2 ==
|
||||
edu_wpi_first_hal_SPIJNI_ONBOARD_CS2_PORT);
|
||||
static_assert(HAL_SPIPort::HAL_SPI_kOnboardCS3 ==
|
||||
edu_wpi_first_hal_SPIJNI_ONBOARD_CS3_PORT);
|
||||
static_assert(HAL_SPIPort::HAL_SPI_kMXP == edu_wpi_first_hal_SPIJNI_MXP_PORT);
|
||||
|
||||
static_assert(HAL_SPIMode::HAL_SPI_kMode0 ==
|
||||
edu_wpi_first_hal_SPIJNI_SPI_MODE0);
|
||||
static_assert(HAL_SPIMode::HAL_SPI_kMode1 ==
|
||||
edu_wpi_first_hal_SPIJNI_SPI_MODE1);
|
||||
static_assert(HAL_SPIMode::HAL_SPI_kMode2 ==
|
||||
edu_wpi_first_hal_SPIJNI_SPI_MODE2);
|
||||
static_assert(HAL_SPIMode::HAL_SPI_kMode3 ==
|
||||
edu_wpi_first_hal_SPIJNI_SPI_MODE3);
|
||||
|
||||
extern "C" {
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiInitialize
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiInitialize
|
||||
(JNIEnv* env, jclass, jint port)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_InitializeSPI(static_cast<HAL_SPIPort>(port), &status);
|
||||
CheckStatusForceThrow(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiTransaction
|
||||
* Signature: (ILjava/lang/Object;Ljava/lang/Object;B)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiTransaction
|
||||
(JNIEnv* env, jclass, jint port, jobject dataToSend, jobject dataReceived,
|
||||
jbyte size)
|
||||
{
|
||||
uint8_t* dataToSendPtr = nullptr;
|
||||
if (dataToSend != nullptr) {
|
||||
dataToSendPtr =
|
||||
reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(dataToSend));
|
||||
}
|
||||
uint8_t* dataReceivedPtr =
|
||||
reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(dataReceived));
|
||||
jint retVal = HAL_TransactionSPI(static_cast<HAL_SPIPort>(port),
|
||||
dataToSendPtr, dataReceivedPtr, size);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiTransactionB
|
||||
* Signature: (I[B[BB)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiTransactionB
|
||||
(JNIEnv* env, jclass, jint port, jbyteArray dataToSend,
|
||||
jbyteArray dataReceived, jbyte size)
|
||||
{
|
||||
if (size < 0) {
|
||||
ThrowIllegalArgumentException(env, "SPIJNI.spiTransactionB() size < 0");
|
||||
return 0;
|
||||
}
|
||||
|
||||
wpi::SmallVector<uint8_t, 128> recvBuf;
|
||||
recvBuf.resize(size);
|
||||
jint retVal =
|
||||
HAL_TransactionSPI(static_cast<HAL_SPIPort>(port),
|
||||
reinterpret_cast<const uint8_t*>(
|
||||
JSpan<const jbyte>(env, dataToSend).data()),
|
||||
recvBuf.data(), size);
|
||||
env->SetByteArrayRegion(dataReceived, 0, size,
|
||||
reinterpret_cast<const jbyte*>(recvBuf.data()));
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiWrite
|
||||
* Signature: (ILjava/lang/Object;B)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiWrite
|
||||
(JNIEnv* env, jclass, jint port, jobject dataToSend, jbyte size)
|
||||
{
|
||||
uint8_t* dataToSendPtr = nullptr;
|
||||
if (dataToSend != nullptr) {
|
||||
dataToSendPtr =
|
||||
reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(dataToSend));
|
||||
}
|
||||
jint retVal =
|
||||
HAL_WriteSPI(static_cast<HAL_SPIPort>(port), dataToSendPtr, size);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiWriteB
|
||||
* Signature: (I[BB)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiWriteB
|
||||
(JNIEnv* env, jclass, jint port, jbyteArray dataToSend, jbyte size)
|
||||
{
|
||||
jint retVal = HAL_WriteSPI(static_cast<HAL_SPIPort>(port),
|
||||
reinterpret_cast<const uint8_t*>(
|
||||
JSpan<const jbyte>(env, dataToSend).data()),
|
||||
size);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiRead
|
||||
* Signature: (IZLjava/lang/Object;B)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiRead
|
||||
(JNIEnv* env, jclass, jint port, jboolean initiate, jobject dataReceived,
|
||||
jbyte size)
|
||||
{
|
||||
if (size < 0) {
|
||||
ThrowIllegalArgumentException(env, "SPIJNI.spiRead() size < 0");
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t* dataReceivedPtr =
|
||||
reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(dataReceived));
|
||||
jint retVal;
|
||||
if (initiate) {
|
||||
wpi::SmallVector<uint8_t, 128> sendBuf;
|
||||
sendBuf.resize(size);
|
||||
retVal = HAL_TransactionSPI(static_cast<HAL_SPIPort>(port), sendBuf.data(),
|
||||
dataReceivedPtr, size);
|
||||
} else {
|
||||
retVal = HAL_ReadSPI(static_cast<HAL_SPIPort>(port),
|
||||
reinterpret_cast<uint8_t*>(dataReceivedPtr), size);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiReadB
|
||||
* Signature: (IZ[BB)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiReadB
|
||||
(JNIEnv* env, jclass, jint port, jboolean initiate, jbyteArray dataReceived,
|
||||
jbyte size)
|
||||
{
|
||||
if (size < 0) {
|
||||
ThrowIllegalArgumentException(env, "SPIJNI.spiReadB() size < 0");
|
||||
return 0;
|
||||
}
|
||||
|
||||
jint retVal;
|
||||
wpi::SmallVector<uint8_t, 128> recvBuf;
|
||||
recvBuf.resize(size);
|
||||
if (initiate) {
|
||||
wpi::SmallVector<uint8_t, 128> sendBuf;
|
||||
sendBuf.resize(size);
|
||||
retVal = HAL_TransactionSPI(static_cast<HAL_SPIPort>(port), sendBuf.data(),
|
||||
recvBuf.data(), size);
|
||||
} else {
|
||||
retVal = HAL_ReadSPI(static_cast<HAL_SPIPort>(port), recvBuf.data(), size);
|
||||
}
|
||||
env->SetByteArrayRegion(dataReceived, 0, size,
|
||||
reinterpret_cast<const jbyte*>(recvBuf.data()));
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiClose
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiClose
|
||||
(JNIEnv*, jclass, jint port)
|
||||
{
|
||||
HAL_CloseSPI(static_cast<HAL_SPIPort>(port));
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiSetSpeed
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiSetSpeed
|
||||
(JNIEnv*, jclass, jint port, jint speed)
|
||||
{
|
||||
HAL_SetSPISpeed(static_cast<HAL_SPIPort>(port), speed);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiSetMode
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiSetMode
|
||||
(JNIEnv*, jclass, jint port, jint mode)
|
||||
{
|
||||
HAL_SetSPIMode(static_cast<HAL_SPIPort>(port),
|
||||
static_cast<HAL_SPIMode>(mode));
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiGetMode
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiGetMode
|
||||
(JNIEnv*, jclass, jint port)
|
||||
{
|
||||
return static_cast<jint>(HAL_GetSPIMode(static_cast<HAL_SPIPort>(port)));
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiSetChipSelectActiveHigh
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiSetChipSelectActiveHigh
|
||||
(JNIEnv* env, jclass, jint port)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_SetSPIChipSelectActiveHigh(static_cast<HAL_SPIPort>(port), &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiSetChipSelectActiveLow
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiSetChipSelectActiveLow
|
||||
(JNIEnv* env, jclass, jint port)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_SetSPIChipSelectActiveLow(static_cast<HAL_SPIPort>(port), &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiInitAuto
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiInitAuto
|
||||
(JNIEnv* env, jclass, jint port, jint bufferSize)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_InitSPIAuto(static_cast<HAL_SPIPort>(port), bufferSize, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiFreeAuto
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiFreeAuto
|
||||
(JNIEnv* env, jclass, jint port)
|
||||
{
|
||||
int32_t status = 0;
|
||||
if (port != HAL_kInvalidHandle) {
|
||||
HAL_FreeSPIAuto(static_cast<HAL_SPIPort>(port), &status);
|
||||
}
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiStartAutoRate
|
||||
* Signature: (ID)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiStartAutoRate
|
||||
(JNIEnv* env, jclass, jint port, jdouble period)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_StartSPIAutoRate(static_cast<HAL_SPIPort>(port), period, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiStartAutoTrigger
|
||||
* Signature: (IIIZZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiStartAutoTrigger
|
||||
(JNIEnv* env, jclass, jint port, jint digitalSourceHandle,
|
||||
jint analogTriggerType, jboolean triggerRising, jboolean triggerFalling)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_StartSPIAutoTrigger(static_cast<HAL_SPIPort>(port), digitalSourceHandle,
|
||||
static_cast<HAL_AnalogTriggerType>(analogTriggerType),
|
||||
triggerRising, triggerFalling, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiStopAuto
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiStopAuto
|
||||
(JNIEnv* env, jclass, jint port)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_StopSPIAuto(static_cast<HAL_SPIPort>(port), &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiSetAutoTransmitData
|
||||
* Signature: (I[BI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiSetAutoTransmitData
|
||||
(JNIEnv* env, jclass, jint port, jbyteArray dataToSend, jint zeroSize)
|
||||
{
|
||||
JSpan<const jbyte> jarr(env, dataToSend);
|
||||
int32_t status = 0;
|
||||
HAL_SetSPIAutoTransmitData(static_cast<HAL_SPIPort>(port),
|
||||
reinterpret_cast<const uint8_t*>(jarr.data()),
|
||||
jarr.size(), zeroSize, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiForceAutoRead
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiForceAutoRead
|
||||
(JNIEnv* env, jclass, jint port)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_ForceSPIAutoRead(static_cast<HAL_SPIPort>(port), &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiReadAutoReceivedData
|
||||
* Signature: (ILjava/lang/Object;ID)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiReadAutoReceivedData__ILjava_nio_ByteBuffer_2ID
|
||||
(JNIEnv* env, jclass, jint port, jobject buffer, jint numToRead,
|
||||
jdouble timeout)
|
||||
{
|
||||
uint32_t* recvBuf =
|
||||
reinterpret_cast<uint32_t*>(env->GetDirectBufferAddress(buffer));
|
||||
int32_t status = 0;
|
||||
jint retval = HAL_ReadSPIAutoReceivedData(
|
||||
static_cast<HAL_SPIPort>(port), recvBuf, numToRead, timeout, &status);
|
||||
CheckStatus(env, status);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiReadAutoReceivedData
|
||||
* Signature: (I[IID)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiReadAutoReceivedData__I_3IID
|
||||
(JNIEnv* env, jclass, jint port, jintArray buffer, jint numToRead,
|
||||
jdouble timeout)
|
||||
{
|
||||
if (numToRead < 0) {
|
||||
ThrowIllegalArgumentException(
|
||||
env, "SPIJNI.spiReadAutoReceivedData() numToRead < 0");
|
||||
return 0;
|
||||
}
|
||||
|
||||
wpi::SmallVector<uint32_t, 128> recvBuf;
|
||||
recvBuf.resize(numToRead);
|
||||
int32_t status = 0;
|
||||
jint retval =
|
||||
HAL_ReadSPIAutoReceivedData(static_cast<HAL_SPIPort>(port),
|
||||
recvBuf.data(), numToRead, timeout, &status);
|
||||
if (!CheckStatus(env, status)) {
|
||||
return retval;
|
||||
}
|
||||
if (numToRead > 0) {
|
||||
env->SetIntArrayRegion(buffer, 0, numToRead,
|
||||
reinterpret_cast<const jint*>(recvBuf.data()));
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiGetAutoDroppedCount
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiGetAutoDroppedCount
|
||||
(JNIEnv* env, jclass, jint port)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto retval =
|
||||
HAL_GetSPIAutoDroppedCount(static_cast<HAL_SPIPort>(port), &status);
|
||||
CheckStatus(env, status);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiConfigureAutoStall
|
||||
* Signature: (IIII)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiConfigureAutoStall
|
||||
(JNIEnv* env, jclass, jint port, jint csToSclkTicks, jint stallTicks,
|
||||
jint pow2BytesPerRead)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_ConfigureSPIAutoStall(static_cast<HAL_SPIPort>(port), csToSclkTicks,
|
||||
stallTicks, pow2BytesPerRead, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
@@ -1,277 +0,0 @@
|
||||
// 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"
|
||||
#include "edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI.h"
|
||||
#include "hal/simulation/SPIAccelerometerData.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
extern "C" {
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: registerActiveCallback
|
||||
* Signature: (ILjava/lang/Object;Z)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_registerActiveCallback
|
||||
(JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
|
||||
{
|
||||
return sim::AllocateCallback(env, index, callback, initialNotify,
|
||||
&HALSIM_RegisterSPIAccelerometerActiveCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: cancelActiveCallback
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_cancelActiveCallback
|
||||
(JNIEnv* env, jclass, jint index, jint handle)
|
||||
{
|
||||
return sim::FreeCallback(env, handle, index,
|
||||
&HALSIM_CancelSPIAccelerometerActiveCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: getActive
|
||||
* Signature: (I)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_getActive
|
||||
(JNIEnv*, jclass, jint index)
|
||||
{
|
||||
return HALSIM_GetSPIAccelerometerActive(index);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: setActive
|
||||
* Signature: (IZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_setActive
|
||||
(JNIEnv*, jclass, jint index, jboolean value)
|
||||
{
|
||||
HALSIM_SetSPIAccelerometerActive(index, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: registerRangeCallback
|
||||
* Signature: (ILjava/lang/Object;Z)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_registerRangeCallback
|
||||
(JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
|
||||
{
|
||||
return sim::AllocateCallback(env, index, callback, initialNotify,
|
||||
&HALSIM_RegisterSPIAccelerometerRangeCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: cancelRangeCallback
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_cancelRangeCallback
|
||||
(JNIEnv* env, jclass, jint index, jint handle)
|
||||
{
|
||||
return sim::FreeCallback(env, handle, index,
|
||||
&HALSIM_CancelSPIAccelerometerRangeCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: getRange
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_getRange
|
||||
(JNIEnv*, jclass, jint index)
|
||||
{
|
||||
return HALSIM_GetSPIAccelerometerRange(index);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: setRange
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_setRange
|
||||
(JNIEnv*, jclass, jint index, jint value)
|
||||
{
|
||||
HALSIM_SetSPIAccelerometerRange(index, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: registerXCallback
|
||||
* Signature: (ILjava/lang/Object;Z)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_registerXCallback
|
||||
(JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
|
||||
{
|
||||
return sim::AllocateCallback(env, index, callback, initialNotify,
|
||||
&HALSIM_RegisterSPIAccelerometerXCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: cancelXCallback
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_cancelXCallback
|
||||
(JNIEnv* env, jclass, jint index, jint handle)
|
||||
{
|
||||
return sim::FreeCallback(env, handle, index,
|
||||
&HALSIM_CancelSPIAccelerometerXCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: getX
|
||||
* Signature: (I)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_getX
|
||||
(JNIEnv*, jclass, jint index)
|
||||
{
|
||||
return HALSIM_GetSPIAccelerometerX(index);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: setX
|
||||
* Signature: (ID)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_setX
|
||||
(JNIEnv*, jclass, jint index, jdouble value)
|
||||
{
|
||||
HALSIM_SetSPIAccelerometerX(index, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: registerYCallback
|
||||
* Signature: (ILjava/lang/Object;Z)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_registerYCallback
|
||||
(JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
|
||||
{
|
||||
return sim::AllocateCallback(env, index, callback, initialNotify,
|
||||
&HALSIM_RegisterSPIAccelerometerYCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: cancelYCallback
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_cancelYCallback
|
||||
(JNIEnv* env, jclass, jint index, jint handle)
|
||||
{
|
||||
return sim::FreeCallback(env, handle, index,
|
||||
&HALSIM_CancelSPIAccelerometerYCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: getY
|
||||
* Signature: (I)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_getY
|
||||
(JNIEnv*, jclass, jint index)
|
||||
{
|
||||
return HALSIM_GetSPIAccelerometerY(index);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: setY
|
||||
* Signature: (ID)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_setY
|
||||
(JNIEnv*, jclass, jint index, jdouble value)
|
||||
{
|
||||
HALSIM_SetSPIAccelerometerY(index, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: registerZCallback
|
||||
* Signature: (ILjava/lang/Object;Z)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_registerZCallback
|
||||
(JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
|
||||
{
|
||||
return sim::AllocateCallback(env, index, callback, initialNotify,
|
||||
&HALSIM_RegisterSPIAccelerometerZCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: cancelZCallback
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_cancelZCallback
|
||||
(JNIEnv* env, jclass, jint index, jint handle)
|
||||
{
|
||||
return sim::FreeCallback(env, handle, index,
|
||||
&HALSIM_CancelSPIAccelerometerZCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: getZ
|
||||
* Signature: (I)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_getZ
|
||||
(JNIEnv*, jclass, jint index)
|
||||
{
|
||||
return HALSIM_GetSPIAccelerometerZ(index);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: setZ
|
||||
* Signature: (ID)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_setZ
|
||||
(JNIEnv*, jclass, jint index, jdouble value)
|
||||
{
|
||||
HALSIM_SetSPIAccelerometerZ(index, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI
|
||||
* Method: resetData
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIAccelerometerDataJNI_resetData
|
||||
(JNIEnv*, jclass, jint index)
|
||||
{
|
||||
HALSIM_ResetSPIAccelerometerData(index);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
@@ -1,157 +0,0 @@
|
||||
// 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 "BufferCallbackStore.h"
|
||||
#include "CallbackStore.h"
|
||||
#include "ConstBufferCallbackStore.h"
|
||||
#include "SpiReadAutoReceiveBufferCallbackStore.h"
|
||||
#include "edu_wpi_first_hal_simulation_SPIDataJNI.h"
|
||||
#include "hal/simulation/SPIData.h"
|
||||
|
||||
using namespace hal;
|
||||
|
||||
extern "C" {
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
|
||||
* Method: registerInitializedCallback
|
||||
* Signature: (ILjava/lang/Object;Z)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIDataJNI_registerInitializedCallback
|
||||
(JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
|
||||
{
|
||||
return sim::AllocateCallback(env, index, callback, initialNotify,
|
||||
&HALSIM_RegisterSPIInitializedCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
|
||||
* Method: cancelInitializedCallback
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIDataJNI_cancelInitializedCallback
|
||||
(JNIEnv* env, jclass, jint index, jint handle)
|
||||
{
|
||||
return sim::FreeCallback(env, handle, index,
|
||||
&HALSIM_CancelSPIInitializedCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
|
||||
* Method: getInitialized
|
||||
* Signature: (I)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIDataJNI_getInitialized
|
||||
(JNIEnv*, jclass, jint index)
|
||||
{
|
||||
return HALSIM_GetSPIInitialized(index);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
|
||||
* Method: setInitialized
|
||||
* Signature: (IZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIDataJNI_setInitialized
|
||||
(JNIEnv*, jclass, jint index, jboolean value)
|
||||
{
|
||||
HALSIM_SetSPIInitialized(index, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
|
||||
* Method: registerReadCallback
|
||||
* Signature: (ILjava/lang/Object;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIDataJNI_registerReadCallback
|
||||
(JNIEnv* env, jclass, jint index, jobject callback)
|
||||
{
|
||||
return sim::AllocateBufferCallback(env, index, callback,
|
||||
&HALSIM_RegisterSPIReadCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
|
||||
* Method: cancelReadCallback
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIDataJNI_cancelReadCallback
|
||||
(JNIEnv* env, jclass, jint index, jint handle)
|
||||
{
|
||||
sim::FreeBufferCallback(env, handle, index, &HALSIM_CancelSPIReadCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
|
||||
* Method: registerWriteCallback
|
||||
* Signature: (ILjava/lang/Object;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIDataJNI_registerWriteCallback
|
||||
(JNIEnv* env, jclass, jint index, jobject callback)
|
||||
{
|
||||
return sim::AllocateConstBufferCallback(env, index, callback,
|
||||
&HALSIM_RegisterSPIWriteCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
|
||||
* Method: cancelWriteCallback
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIDataJNI_cancelWriteCallback
|
||||
(JNIEnv* env, jclass, jint index, jint handle)
|
||||
{
|
||||
sim::FreeConstBufferCallback(env, handle, index,
|
||||
&HALSIM_CancelSPIWriteCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
|
||||
* Method: registerReadAutoReceiveBufferCallback
|
||||
* Signature: (ILjava/lang/Object;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIDataJNI_registerReadAutoReceiveBufferCallback
|
||||
(JNIEnv* env, jclass, jint index, jobject callback)
|
||||
{
|
||||
return sim::AllocateSpiBufferCallback(
|
||||
env, index, callback, &HALSIM_RegisterSPIReadAutoReceivedDataCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
|
||||
* Method: cancelReadAutoReceiveBufferCallback
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIDataJNI_cancelReadAutoReceiveBufferCallback
|
||||
(JNIEnv* env, jclass, jint index, jint handle)
|
||||
{
|
||||
sim::FreeSpiBufferCallback(env, handle, index,
|
||||
&HALSIM_CancelSPIReadAutoReceivedDataCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_SPIDataJNI
|
||||
* Method: resetData
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_SPIDataJNI_resetData
|
||||
(JNIEnv*, jclass, jint index)
|
||||
{
|
||||
HALSIM_ResetSPIData(index);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "CallbackStore.h"
|
||||
#include "ConstBufferCallbackStore.h"
|
||||
#include "SimDeviceDataJNI.h"
|
||||
#include "SpiReadAutoReceiveBufferCallbackStore.h"
|
||||
#include "edu_wpi_first_hal_simulation_SimulatorJNI.h"
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
@@ -22,11 +21,9 @@ static JavaVM* jvm = nullptr;
|
||||
static JClass notifyCallbackCls;
|
||||
static JClass bufferCallbackCls;
|
||||
static JClass constBufferCallbackCls;
|
||||
static JClass spiReadAutoReceiveBufferCallbackCls;
|
||||
static jmethodID notifyCallbackCallback;
|
||||
static jmethodID bufferCallbackCallback;
|
||||
static jmethodID constBufferCallbackCallback;
|
||||
static jmethodID spiReadAutoReceiveBufferCallbackCallback;
|
||||
|
||||
namespace hal::sim {
|
||||
jint SimOnLoad(JavaVM* vm, void* reserved) {
|
||||
@@ -73,23 +70,9 @@ jint SimOnLoad(JavaVM* vm, void* reserved) {
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
spiReadAutoReceiveBufferCallbackCls = JClass(
|
||||
env, "edu/wpi/first/hal/simulation/SpiReadAutoReceiveBufferCallback");
|
||||
if (!spiReadAutoReceiveBufferCallbackCls) {
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
spiReadAutoReceiveBufferCallbackCallback =
|
||||
env->GetMethodID(spiReadAutoReceiveBufferCallbackCls, "callback",
|
||||
"(Ljava/lang/String;[II)I");
|
||||
if (!spiReadAutoReceiveBufferCallbackCallback) {
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
InitializeStore();
|
||||
InitializeBufferStore();
|
||||
InitializeConstBufferStore();
|
||||
InitializeSpiBufferStore();
|
||||
if (!InitializeSimDeviceDataJNI(env)) {
|
||||
return JNI_ERR;
|
||||
}
|
||||
@@ -106,7 +89,6 @@ void SimOnUnload(JavaVM* vm, void* reserved) {
|
||||
notifyCallbackCls.free(env);
|
||||
bufferCallbackCls.free(env);
|
||||
constBufferCallbackCls.free(env);
|
||||
spiReadAutoReceiveBufferCallbackCls.free(env);
|
||||
FreeSimDeviceDataJNI(env);
|
||||
jvm = nullptr;
|
||||
}
|
||||
@@ -127,9 +109,6 @@ jmethodID GetConstBufferCallback() {
|
||||
return constBufferCallbackCallback;
|
||||
}
|
||||
|
||||
jmethodID GetSpiReadAutoReceiveBufferCallback() {
|
||||
return spiReadAutoReceiveBufferCallbackCallback;
|
||||
}
|
||||
} // namespace hal::sim
|
||||
|
||||
extern "C" {
|
||||
|
||||
@@ -15,5 +15,4 @@ JavaVM* GetJVM();
|
||||
jmethodID GetNotifyCallback();
|
||||
jmethodID GetBufferCallback();
|
||||
jmethodID GetConstBufferCallback();
|
||||
jmethodID GetSpiReadAutoReceiveBufferCallback();
|
||||
} // namespace hal::sim
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
// 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 "SpiReadAutoReceiveBufferCallbackStore.h"
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/jni_util.h>
|
||||
|
||||
#include "SimulatorJNI.h"
|
||||
#include "hal/Types.h"
|
||||
#include "hal/handles/UnlimitedHandleResource.h"
|
||||
|
||||
using namespace hal;
|
||||
using namespace hal::sim;
|
||||
using namespace wpi::java;
|
||||
|
||||
static hal::UnlimitedHandleResource<
|
||||
SIM_JniHandle, SpiReadAutoReceiveBufferCallbackStore,
|
||||
hal::HAL_HandleEnum::SimulationJni>* callbackHandles;
|
||||
|
||||
namespace hal::sim {
|
||||
void InitializeSpiBufferStore() {
|
||||
static hal::UnlimitedHandleResource<SIM_JniHandle,
|
||||
SpiReadAutoReceiveBufferCallbackStore,
|
||||
hal::HAL_HandleEnum::SimulationJni>
|
||||
cb;
|
||||
callbackHandles = &cb;
|
||||
}
|
||||
} // namespace hal::sim
|
||||
|
||||
void SpiReadAutoReceiveBufferCallbackStore::create(JNIEnv* env, jobject obj) {
|
||||
m_call = JGlobal<jobject>(env, obj);
|
||||
}
|
||||
|
||||
int32_t SpiReadAutoReceiveBufferCallbackStore::performCallback(
|
||||
const char* name, uint32_t* buffer, int32_t numToRead) {
|
||||
JNIEnv* env;
|
||||
JavaVM* vm = sim::GetJVM();
|
||||
bool didAttachThread = false;
|
||||
int tryGetEnv = vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
|
||||
if (tryGetEnv == JNI_EDETACHED) {
|
||||
// Thread not attached
|
||||
didAttachThread = true;
|
||||
if (vm->AttachCurrentThread(reinterpret_cast<void**>(&env), nullptr) != 0) {
|
||||
// Failed to attach, log and return
|
||||
std::puts("Failed to attach");
|
||||
std::fflush(stdout);
|
||||
return -1;
|
||||
}
|
||||
} else if (tryGetEnv == JNI_EVERSION) {
|
||||
std::puts("Invalid JVM Version requested");
|
||||
std::fflush(stdout);
|
||||
}
|
||||
|
||||
auto toCallbackArr = MakeJIntArray(
|
||||
env, std::span<const uint32_t>{buffer, static_cast<size_t>(numToRead)});
|
||||
|
||||
jint ret = env->CallIntMethod(m_call, sim::GetBufferCallback(),
|
||||
MakeJString(env, name), toCallbackArr,
|
||||
static_cast<jint>(numToRead));
|
||||
|
||||
jint* fromCallbackArr = reinterpret_cast<jint*>(
|
||||
env->GetPrimitiveArrayCritical(toCallbackArr, nullptr));
|
||||
|
||||
for (int i = 0; i < ret; i++) {
|
||||
buffer[i] = fromCallbackArr[i];
|
||||
}
|
||||
|
||||
env->ReleasePrimitiveArrayCritical(toCallbackArr, fromCallbackArr, JNI_ABORT);
|
||||
|
||||
if (env->ExceptionCheck()) {
|
||||
env->ExceptionDescribe();
|
||||
}
|
||||
|
||||
if (didAttachThread) {
|
||||
vm->DetachCurrentThread();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SpiReadAutoReceiveBufferCallbackStore::free(JNIEnv* env) {
|
||||
m_call.free(env);
|
||||
}
|
||||
|
||||
SIM_JniHandle sim::AllocateSpiBufferCallback(
|
||||
JNIEnv* env, jint index, jobject callback,
|
||||
RegisterSpiBufferCallbackFunc createCallback) {
|
||||
auto callbackStore =
|
||||
std::make_shared<SpiReadAutoReceiveBufferCallbackStore>();
|
||||
|
||||
auto handle = callbackHandles->Allocate(callbackStore);
|
||||
|
||||
if (handle == HAL_kInvalidHandle) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
uintptr_t handleAsPtr = static_cast<uintptr_t>(handle);
|
||||
void* handleAsVoidPtr = reinterpret_cast<void*>(handleAsPtr);
|
||||
|
||||
callbackStore->create(env, callback);
|
||||
|
||||
auto callbackFunc = [](const char* name, void* param, uint32_t* buffer,
|
||||
int32_t numToRead, int32_t* outputCount) {
|
||||
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
|
||||
SIM_JniHandle handle = static_cast<SIM_JniHandle>(handleTmp);
|
||||
auto data = callbackHandles->Get(handle);
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
*outputCount = data->performCallback(name, buffer, numToRead);
|
||||
};
|
||||
|
||||
auto id = createCallback(index, callbackFunc, handleAsVoidPtr);
|
||||
|
||||
callbackStore->setCallbackId(id);
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void sim::FreeSpiBufferCallback(JNIEnv* env, SIM_JniHandle handle, jint index,
|
||||
FreeSpiBufferCallbackFunc freeCallback) {
|
||||
auto callback = callbackHandles->Free(handle);
|
||||
if (callback == nullptr) {
|
||||
return;
|
||||
}
|
||||
freeCallback(index, callback->getCallbackId());
|
||||
callback->free(env);
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <wpi/jni_util.h>
|
||||
|
||||
#include "SimulatorJNI.h"
|
||||
#include "hal/Types.h"
|
||||
#include "hal/Value.h"
|
||||
#include "hal/handles/UnlimitedHandleResource.h"
|
||||
#include "hal/simulation/NotifyListener.h"
|
||||
#include "hal/simulation/SPIData.h"
|
||||
|
||||
namespace hal::sim {
|
||||
class SpiReadAutoReceiveBufferCallbackStore {
|
||||
public:
|
||||
void create(JNIEnv* env, jobject obj);
|
||||
int32_t performCallback(const char* name, uint32_t* buffer,
|
||||
int32_t numToRead);
|
||||
void free(JNIEnv* env);
|
||||
void setCallbackId(int32_t id) { callbackId = id; }
|
||||
int32_t getCallbackId() { return callbackId; }
|
||||
|
||||
private:
|
||||
wpi::java::JGlobal<jobject> m_call;
|
||||
int32_t callbackId;
|
||||
};
|
||||
|
||||
void InitializeSpiBufferStore();
|
||||
|
||||
using RegisterSpiBufferCallbackFunc = int32_t (*)(
|
||||
int32_t index, HAL_SpiReadAutoReceiveBufferCallback callback, void* param);
|
||||
using FreeSpiBufferCallbackFunc = void (*)(int32_t index, int32_t uid);
|
||||
|
||||
SIM_JniHandle AllocateSpiBufferCallback(
|
||||
JNIEnv* env, jint index, jobject callback,
|
||||
RegisterSpiBufferCallbackFunc createCallback);
|
||||
void FreeSpiBufferCallback(JNIEnv* env, SIM_JniHandle handle, jint index,
|
||||
FreeSpiBufferCallbackFunc freeCallback);
|
||||
} // namespace hal::sim
|
||||
Reference in New Issue
Block a user