aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVlad Kolotov <[email protected]>2017-10-14 11:02:31 +1300
committerpetreeftime <[email protected]>2017-10-14 17:18:12 +0300
commitbbe7933403df85309ccac68d4293678f5a3c1add (patch)
treea288e06b248101132dda197bf60a43730b53d9cd
parentfd4fdb0854d328f44bbf0f3ce2493c30e8587849 (diff)
Implementing a generic method to set discover filters (UUIDs, rssi, pathloss, type)
Signed-off-by: Vlad Kolotov <[email protected]>
-rw-r--r--api/tinyb/BluetoothAdapter.hpp6
-rw-r--r--api/tinyb/BluetoothObject.hpp5
-rw-r--r--java/BluetoothAdapter.java29
-rw-r--r--java/TransportType.java19
-rw-r--r--java/jni/BluetoothAdapter.cxx8
-rw-r--r--java/jni/helper.cxx25
-rw-r--r--java/jni/helper.hpp1
7 files changed, 83 insertions, 10 deletions
diff --git a/api/tinyb/BluetoothAdapter.hpp b/api/tinyb/BluetoothAdapter.hpp
index b38cd636..43000e45 100644
--- a/api/tinyb/BluetoothAdapter.hpp
+++ b/api/tinyb/BluetoothAdapter.hpp
@@ -34,12 +34,6 @@ typedef struct _Object Object;
struct _Adapter1;
typedef struct _Adapter1 Adapter1;
-enum class TransportType {
- AUTO,
- BREDR,
- LE
-};
-
/**
* Provides access to Bluetooth adapters. Follows the BlueZ adapter API
* available at: http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt
diff --git a/api/tinyb/BluetoothObject.hpp b/api/tinyb/BluetoothObject.hpp
index cac8da26..549229fd 100644
--- a/api/tinyb/BluetoothObject.hpp
+++ b/api/tinyb/BluetoothObject.hpp
@@ -38,6 +38,11 @@ enum class BluetoothType {
GATT_CHARACTERISTIC,
GATT_DESCRIPTOR
};
+ enum class TransportType {
+ AUTO,
+ BREDR,
+ LE
+ };
class BluetoothEvent;
class BluetoothEventManager;
diff --git a/java/BluetoothAdapter.java b/java/BluetoothAdapter.java
index 0bbaecde..94fd1f76 100644
--- a/java/BluetoothAdapter.java
+++ b/java/BluetoothAdapter.java
@@ -239,11 +239,36 @@ public class BluetoothAdapter extends BluetoothObject
*/
public native String getModalias();
+ /** This method sets the device discovery filter for the caller. When this method is called
+ * with no filter parameter, filter is removed.
+ * <p>
+ * When a remote device is found that advertises any UUID from UUIDs, it will be reported if:
+ * <ul><li>Pathloss and RSSI are both empty.</li>
+ * <li>only Pathloss param is set, device advertise TX pwer, and computed pathloss is less than Pathloss param.</li>
+ * <li>only RSSI param is set, and received RSSI is higher than RSSI param.</li>
+ * </ul>
+ * <p>
+ * If one or more discovery filters have been set, the RSSI delta-threshold,
+ * that is imposed by StartDiscovery by default, will not be applied.
+ * <p>
+ * If "auto" transport is requested, scan will use LE, BREDR, or both, depending on what's
+ * currently enabled on the controller.
+ *
+ * @param uuids a list of device UUIDs
+ * @param rssi a rssi value
+ * @param pathloss a pathloss value
+ */
+ public void setDiscoveryFilter(List<Integer> uuids, int rssi, int pathloss, TransportType transportType) {
+ setDiscoveryFilter(uuids, rssi, pathloss, transportType.ordinal());
+ }
+
/** This method sets RSSI device discovery filter for the caller. When this method is called
* with 0, filter is removed.
* @param rssi a rssi value
*/
- public native void setRssiDiscoveryFilter(int rssi);
+ public void setRssiDiscoveryFilter(int rssi) {
+ setDiscoveryFilter(Collections.EMPTY_LIST, rssi, 0, TransportType.AUTO);
+ }
/** Returns the interface name of the adapter.
* @return The interface name of the adapter.
@@ -255,6 +280,8 @@ public class BluetoothAdapter extends BluetoothObject
private native void delete();
+ private native void setDiscoveryFilter(List<Integer> uuids, int rssi, int pathloss, int transportType);
+
private BluetoothAdapter(long instance)
{
super(instance);
diff --git a/java/TransportType.java b/java/TransportType.java
new file mode 100644
index 00000000..ab71a1cb
--- /dev/null
+++ b/java/TransportType.java
@@ -0,0 +1,19 @@
+package tinyb;
+
+/**
+ * TransportType determines type of bluetooth scan.
+ */
+public enum TransportType {
+ /**
+ * interleaved scan
+ */
+ AUTO,
+ /**
+ * BR/EDR inquiry
+ */
+ BREDR,
+ /**
+ * LE scan only
+ */
+ LE
+}
diff --git a/java/jni/BluetoothAdapter.cxx b/java/jni/BluetoothAdapter.cxx
index 0a15a4e1..c17d1fb5 100644
--- a/java/jni/BluetoothAdapter.cxx
+++ b/java/jni/BluetoothAdapter.cxx
@@ -787,7 +787,7 @@ void Java_tinyb_BluetoothAdapter_delete(JNIEnv *env, jobject obj)
}
}
-void Java_tinyb_BluetoothAdapter_setRssiDiscoveryFilter(JNIEnv *env, jobject obj, jint rssi)
+void Java_tinyb_BluetoothAdapter_setDiscoveryFilter(JNIEnv *env, jobject obj, jobject uuids, jint rssi, jint pathloss, jint transportType)
{
try {
BluetoothAdapter *obj_adapter = getInstance<BluetoothAdapter>(env, obj);
@@ -795,8 +795,10 @@ void Java_tinyb_BluetoothAdapter_setRssiDiscoveryFilter(JNIEnv *env, jobject obj
std::vector<BluetoothUUID> native_uuids;
native_uuids.reserve(0);
- obj_adapter->set_discovery_filter(native_uuids, (int16_t) rssi, 0, TransportType::AUTO);
- } catch (std::bad_alloc &e) {
+ TransportType t_type = from_int_to_transport_type((int) transportType);
+
+ obj_adapter->set_discovery_filter(native_uuids, (int16_t) rssi, (uint16_t) pathloss, t_type);
+ } catch (std::bad_alloc &e) {
raise_java_oom_exception(env, e);
} catch (BluetoothException &e) {
raise_java_bluetooth_exception(env, e);
diff --git a/java/jni/helper.cxx b/java/jni/helper.cxx
index 3ae6acea..9987ae3e 100644
--- a/java/jni/helper.cxx
+++ b/java/jni/helper.cxx
@@ -183,6 +183,31 @@ tinyb::BluetoothType from_int_to_btype(int type)
return result;
}
+tinyb::TransportType from_int_to_transport_type(int type)
+{
+ tinyb::TransportType result = tinyb::TransportType::AUTO;
+
+ switch (type)
+ {
+ case 0:
+ result = tinyb::TransportType::AUTO;
+ break;
+
+ case 1:
+ result = tinyb::TransportType::BREDR;
+ break;
+
+ case 2:
+ result = tinyb::TransportType::LE;
+ break;
+
+ default:
+ result = tinyb::TransportType::AUTO;
+ break;
+ }
+
+ return result;
+}
jobject get_bluetooth_type(JNIEnv *env, const char *field_name)
{
diff --git a/java/jni/helper.hpp b/java/jni/helper.hpp
index 4a4fb795..2f297734 100644
--- a/java/jni/helper.hpp
+++ b/java/jni/helper.hpp
@@ -42,6 +42,7 @@ std::string from_jstring_to_string(JNIEnv *env, jstring str);
tinyb::BluetoothType from_int_to_btype(int type);
jobject get_bluetooth_type(JNIEnv *env, const char *field_name);
jobject get_new_arraylist(JNIEnv *env, unsigned int size, jmethodID *add);
+tinyb::TransportType from_int_to_transport_type(int type);
template <typename T>
T *getInstance(JNIEnv *env, jobject obj)