aboutsummaryrefslogtreecommitdiffstats
path: root/java/jni
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2021-09-24 13:30:43 +0200
committerSven Gothel <[email protected]>2021-09-24 13:30:43 +0200
commit8b475db0e662e00a1577b7a6090c3a99857560c8 (patch)
tree87bb68c109b892a6ab118614004268da005246b3 /java/jni
parent61bfb0757a1c337eaf86f9df8b0524bec1b7bc0f (diff)
Java: BTAdapter/BTDevice: Add [get|set]ConnectedLE_PHY(..), setDefaultLE_PHY(); Add LE_Features and LE_PHYs class
Supporting added LE_PHYs features of commit 61bfb0757a1c337eaf86f9df8b0524bec1b7bc0f in Java
Diffstat (limited to 'java/jni')
-rw-r--r--java/jni/direct_bt/DBTAdapter.cxx28
-rw-r--r--java/jni/direct_bt/DBTDevice.cxx84
2 files changed, 112 insertions, 0 deletions
diff --git a/java/jni/direct_bt/DBTAdapter.cxx b/java/jni/direct_bt/DBTAdapter.cxx
index 6a8303bd..a7ee582e 100644
--- a/java/jni/direct_bt/DBTAdapter.cxx
+++ b/java/jni/direct_bt/DBTAdapter.cxx
@@ -765,6 +765,17 @@ jboolean Java_jau_direct_1bt_DBTAdapter_isValidImpl(JNIEnv *env, jobject obj)
return JNI_FALSE;
}
+jlong Java_jau_direct_1bt_DBTAdapter_getLEFeaturesImpl(JNIEnv *env, jobject obj)
+{
+ try {
+ BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj);
+ return (jlong) number( adapter->getLEFeatures() );
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+ return JNI_FALSE;
+}
+
jbyte Java_jau_direct_1bt_DBTAdapter_startDiscoveryImpl(JNIEnv *env, jobject obj, jboolean keepAlive, jboolean le_scan_active,
jshort le_scan_interval, jshort le_scan_window,
jbyte filter_policy)
@@ -913,6 +924,23 @@ jbyte Java_jau_direct_1bt_DBTAdapter_resetImpl(JNIEnv *env, jobject obj) {
return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
}
+jbyte Java_jau_direct_1bt_DBTAdapter_setDefaultLE_1PHYImpl(JNIEnv *env, jobject obj,
+ jboolean tryTx, jboolean tryRx,
+ jbyte jTx, jbyte jRx) {
+ try {
+ BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj);
+ jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+
+ const LE_PHYs Tx = static_cast<LE_PHYs>(jTx);
+ const LE_PHYs Rx = static_cast<LE_PHYs>(jRx);
+
+ return number ( adapter->setDefaultLE_PHY(tryTx, tryRx, Tx, Rx) );
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+ return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
+}
+
jstring Java_jau_direct_1bt_DBTAdapter_getNameImpl(JNIEnv *env, jobject obj) {
try {
BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj);
diff --git a/java/jni/direct_bt/DBTDevice.cxx b/java/jni/direct_bt/DBTDevice.cxx
index 13ef92c1..d37f76df 100644
--- a/java/jni/direct_bt/DBTDevice.cxx
+++ b/java/jni/direct_bt/DBTDevice.cxx
@@ -324,6 +324,90 @@ jbyte Java_jau_direct_1bt_DBTDevice_getRoleImpl(JNIEnv *env, jobject obj)
return (jbyte) number( BTRole::None );
}
+jbyte Java_jau_direct_1bt_DBTDevice_getConnectedLE_1PHYImpl(JNIEnv *env, jobject obj,
+ jbyteArray jresTx, jbyteArray jresRx) {
+ try {
+ BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
+ JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
+
+ if( nullptr == jresTx ) {
+ throw IllegalArgumentException("resTx byte array null", E_FILE_LINE);
+ }
+ if( nullptr == jresRx ) {
+ throw IllegalArgumentException("resRx byte array null", E_FILE_LINE);
+ }
+
+ const size_t resTx_size = env->GetArrayLength(jresTx);
+ if( 1 > resTx_size ) {
+ throw IllegalArgumentException("resTx byte array "+std::to_string(resTx_size)+" < 1", E_FILE_LINE);
+ }
+ const size_t resRx_size = env->GetArrayLength(jresRx);
+ if( 1 > resRx_size ) {
+ throw IllegalArgumentException("resRx byte array "+std::to_string(resRx_size)+" < 1", E_FILE_LINE);
+ }
+
+ JNICriticalArray<uint8_t, jbyteArray> criticalArrayTx(env); // RAII - release
+ uint8_t * resTx_ptr = criticalArrayTx.get(jresTx, criticalArrayTx.Mode::UPDATE_AND_RELEASE);
+ if( NULL == resTx_ptr ) {
+ throw InternalError("GetPrimitiveArrayCritical(resTx byte array) is null", E_FILE_LINE);
+ }
+ JNICriticalArray<uint8_t, jbyteArray> criticalArrayRx(env); // RAII - release
+ uint8_t * resRx_ptr = criticalArrayRx.get(jresRx, criticalArrayTx.Mode::UPDATE_AND_RELEASE);
+ if( NULL == resRx_ptr ) {
+ throw InternalError("GetPrimitiveArrayCritical(resRx byte array) is null", E_FILE_LINE);
+ }
+
+ LE_PHYs& resTx = *reinterpret_cast<LE_PHYs *>(resTx_ptr);
+ LE_PHYs& resRx = *reinterpret_cast<LE_PHYs *>(resRx_ptr);
+
+ return number( device->getConnectedLE_PHY(resTx, resRx) );
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+ return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
+}
+
+jbyte Java_jau_direct_1bt_DBTDevice_setConnectedLE_1PHYImpl(JNIEnv *env, jobject obj,
+ jboolean tryTx, jboolean tryRx,
+ jbyte jTx, jbyte jRx) {
+ try {
+ BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
+ JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
+
+ const LE_PHYs Tx = static_cast<LE_PHYs>(jTx);
+ const LE_PHYs Rx = static_cast<LE_PHYs>(jRx);
+
+ return number ( device->setConnectedLE_PHY(tryTx, tryRx, Tx, Rx) );
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+ return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
+}
+
+jbyte Java_jau_direct_1bt_DBTDevice_getTxPhysImpl(JNIEnv *env, jobject obj) {
+ try {
+ BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
+ JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
+
+ return number( device->getTxPhys() );
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+ return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
+}
+
+jbyte Java_jau_direct_1bt_DBTDevice_getRxPhysImpl(JNIEnv *env, jobject obj) {
+ try {
+ BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
+ JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
+
+ return number( device->getRxPhys() );
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+ return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
+}
+
jbyte Java_jau_direct_1bt_DBTDevice_disconnectImpl(JNIEnv *env, jobject obj)
{
try {