SPI: Provide byte[] JNI interfaces.

This avoids a direct byte buffer allocation on every read/write/transaction
for the byte[] variants.

Also change spiGetAccumulatorOutput() to directly set the AccumulatorResult
object, avoiding a ByteBuffer allocation.

Changes HAL SPI interfaces to use const for dataToSend.

Fixes #733.
This commit is contained in:
Peter Johnson
2017-11-14 00:00:45 -08:00
parent df7c1389de
commit 6307d41002
11 changed files with 168 additions and 73 deletions

View File

@@ -57,6 +57,7 @@ static JException uncleanStatusExCls;
static JClass pwmConfigDataResultCls;
static JClass canStatusCls;
static JClass matchInfoDataCls;
static JClass accumulatorResultCls;
namespace frc {
@@ -234,6 +235,14 @@ void SetMatchInfoObject(JNIEnv* env, jobject matchStatus,
(jint)matchInfo.matchType);
}
void SetAccumulatorResultObject(JNIEnv* env, jobject accumulatorResult,
int64_t value, int64_t count) {
static jmethodID func = env->GetMethodID(accumulatorResultCls, "set",
"(JJ)V");
env->CallObjectMethod(accumulatorResult, func, (jlong)value, (jlong)count);
}
} // namespace frc
using namespace frc;
@@ -292,6 +301,9 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
matchInfoDataCls = JClass(env, "edu/wpi/first/wpilibj/hal/MatchInfoData");
if (!matchInfoDataCls) return JNI_ERR;
accumulatorResultCls = JClass(env, "edu/wpi/first/wpilibj/AccumulatorResult");
if (!accumulatorResultCls) return JNI_ERR;
return JNI_VERSION_1_6;
}