[hal] Add no throw/error version of CAN Write methods (#2063)

This commit is contained in:
Thad House
2020-08-29 23:07:22 -07:00
committed by GitHub
parent 7c99224bb7
commit ed18693345
5 changed files with 147 additions and 2 deletions

View File

@@ -107,6 +107,59 @@ Java_edu_wpi_first_hal_CANAPIJNI_writeCANRTRFrame
CheckStatus(env, status);
}
/*
* Class: edu_wpi_first_hal_CANAPIJNI
* Method: writeCANPacketNoThrow
* Signature: (I[BI)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_CANAPIJNI_writeCANPacketNoThrow
(JNIEnv* env, jclass, jint handle, jbyteArray data, jint apiId)
{
auto halHandle = static_cast<HAL_CANHandle>(handle);
JByteArrayRef arr{env, data};
auto arrRef = arr.array();
int32_t status = 0;
HAL_WriteCANPacket(halHandle, reinterpret_cast<const uint8_t*>(arrRef.data()),
arrRef.size(), apiId, &status);
return status;
}
/*
* Class: edu_wpi_first_hal_CANAPIJNI
* Method: writeCANPacketRepeatingNoThrow
* Signature: (I[BII)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_CANAPIJNI_writeCANPacketRepeatingNoThrow
(JNIEnv* env, jclass, jint handle, jbyteArray data, jint apiId,
jint timeoutMs)
{
auto halHandle = static_cast<HAL_CANHandle>(handle);
JByteArrayRef arr{env, data};
auto arrRef = arr.array();
int32_t status = 0;
HAL_WriteCANPacketRepeating(halHandle,
reinterpret_cast<const uint8_t*>(arrRef.data()),
arrRef.size(), apiId, timeoutMs, &status);
return status;
}
/*
* Class: edu_wpi_first_hal_CANAPIJNI
* Method: writeCANRTRFrameNoThrow
* Signature: (III)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_CANAPIJNI_writeCANRTRFrameNoThrow
(JNIEnv* env, jclass, jint handle, jint length, jint apiId)
{
auto halHandle = static_cast<HAL_CANHandle>(handle);
int32_t status = 0;
HAL_WriteCANRTRFrame(halHandle, static_cast<int32_t>(length), apiId, &status);
return status;
}
/*
* Class: edu_wpi_first_hal_CANAPIJNI
* Method: stopCANPacketRepeating