aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/CMakeLists.txt18
-rw-r--r--examples/direct_bt_scanner/dbt_scanner.cpp24
-rw-r--r--examples/java/AsyncTinyB.java11
-rw-r--r--examples/java/HelloTinyB.java16
-rw-r--r--examples/java/Notification.java12
-rw-r--r--examples/java/ScannerTinyB00.java9
-rw-r--r--examples/java/ScannerTinyB01.java9
7 files changed, 65 insertions, 34 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 26edd814..356658c0 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,9 +1,13 @@
-include_directories(
- ${tinyb_LIB_INCLUDE_DIRS}
- ${GLIB2_INCLUDE_DIRS}
- ${GIO_INCLUDE_DIRS}
- ${GIO-UNIX_INCLUDE_DIRS}
-)
+include_directories(${PROJECT_SOURCE_DIR}/api)
+
+#include_directories(
+# ${PROJECT_SOURCE_DIR}/api
+# ${direct_bt_LIB_INCLUDE_DIRS}
+# ${tinyb_LIB_INCLUDE_DIRS}
+# ${GLIB2_INCLUDE_DIRS}
+# ${GIO_INCLUDE_DIRS}
+# ${GIO-UNIX_INCLUDE_DIRS}
+#)
add_executable (hellotinyb tinyb/hellotinyb.cpp)
set_target_properties(hellotinyb
@@ -45,8 +49,6 @@ set_target_properties(list_mfg
PROPERTIES
CXX_STANDARD 11)
-include_directories(${PROJECT_SOURCE_DIR}/api)
-
target_link_libraries (hellotinyb tinyb)
target_link_libraries (checkinit tinyb)
target_link_libraries (asynctinyb tinyb)
diff --git a/examples/direct_bt_scanner/dbt_scanner.cpp b/examples/direct_bt_scanner/dbt_scanner.cpp
index 055aa7e1..fcce3a22 100644
--- a/examples/direct_bt_scanner/dbt_scanner.cpp
+++ b/examples/direct_bt_scanner/dbt_scanner.cpp
@@ -24,10 +24,10 @@
*/
#include <direct_bt/BTAddress.hpp>
-#include <direct_bt/HCITypes.hpp>
#include <direct_bt/ATTPDUTypes.hpp>
#include <direct_bt/GATTHandler.hpp>
#include <direct_bt/GATTNumbers.hpp>
+#include <direct_bt/DBTTypes.hpp>
#include <cinttypes>
extern "C" {
@@ -36,18 +36,18 @@ extern "C" {
using namespace direct_bt;
-class DeviceDiscoveryListener : public direct_bt::HCIDeviceDiscoveryListener {
- void deviceAdded(direct_bt::HCIAdapter const &a, std::shared_ptr<direct_bt::HCIDevice> device) override {
+class DeviceDiscoveryListener : public direct_bt::DBTDeviceDiscoveryListener {
+ void deviceAdded(direct_bt::DBTAdapter const &a, std::shared_ptr<direct_bt::DBTDevice> device) override {
fprintf(stderr, "****** ADDED__: %s\n", device->toString().c_str());
fprintf(stderr, "Status HCIAdapter:\n");
fprintf(stderr, "%s\n", a.toString().c_str());
}
- void deviceUpdated(direct_bt::HCIAdapter const &a, std::shared_ptr<direct_bt::HCIDevice> device) override {
+ void deviceUpdated(direct_bt::DBTAdapter const &a, std::shared_ptr<direct_bt::DBTDevice> device) override {
fprintf(stderr, "****** UPDATED: %s\n", device->toString().c_str());
fprintf(stderr, "Status HCIAdapter:\n");
fprintf(stderr, "%s\n", a.toString().c_str());
}
- void deviceRemoved(direct_bt::HCIAdapter const &a, std::shared_ptr<direct_bt::HCIDevice> device) override {
+ void deviceRemoved(direct_bt::DBTAdapter const &a, std::shared_ptr<direct_bt::DBTDevice> device) override {
fprintf(stderr, "****** REMOVED: %s\n", device->toString().c_str());
fprintf(stderr, "Status HCIAdapter:\n");
fprintf(stderr, "%s\n", a.toString().c_str());
@@ -57,7 +57,7 @@ class DeviceDiscoveryListener : public direct_bt::HCIDeviceDiscoveryListener {
static const uuid16_t _TEMPERATURE_MEASUREMENT(GattCharacteristicType::TEMPERATURE_MEASUREMENT);
class MyGATTNotificationListener : public direct_bt::GATTNotificationListener {
- void notificationReceived(std::shared_ptr<HCIDevice> dev,
+ void notificationReceived(std::shared_ptr<DBTDevice> dev,
GATTCharacterisicsDeclRef charDecl, std::shared_ptr<const AttHandleValueRcv> charValue) override {
const int64_t tR = direct_bt::getCurrentMilliseconds();
fprintf(stderr, "****** GATT Notify (td %" PRIu64 " ms, dev-discovered %" PRIu64 " ms): From %s\n",
@@ -69,7 +69,7 @@ class MyGATTNotificationListener : public direct_bt::GATTNotificationListener {
}
};
class MyGATTIndicationListener : public direct_bt::GATTIndicationListener {
- void indicationReceived(std::shared_ptr<HCIDevice> dev,
+ void indicationReceived(std::shared_ptr<DBTDevice> dev,
GATTCharacterisicsDeclRef charDecl, std::shared_ptr<const AttHandleValueRcv> charValue,
const bool confirmationSent) override
{
@@ -126,7 +126,7 @@ int main(int argc, char *argv[])
getchar();
}
- direct_bt::HCIAdapter adapter; // default
+ direct_bt::DBTAdapter adapter; // default
if( !adapter.hasDevId() ) {
fprintf(stderr, "Default adapter not available.\n");
exit(1);
@@ -138,11 +138,11 @@ int main(int argc, char *argv[])
fprintf(stderr, "Adapter: device %s, address %s\n",
adapter.getName().c_str(), adapter.getAddressString().c_str());
- adapter.setDeviceDiscoveryListener(std::shared_ptr<direct_bt::HCIDeviceDiscoveryListener>(new DeviceDiscoveryListener()));
+ adapter.setDeviceDiscoveryListener(std::shared_ptr<direct_bt::DBTDeviceDiscoveryListener>(new DeviceDiscoveryListener()));
const int64_t t0 = direct_bt::getCurrentMilliseconds();
- std::shared_ptr<direct_bt::HCISession> session = adapter.open();
+ std::shared_ptr<direct_bt::DBTSession> session = adapter.open();
while( ok && !done && nullptr != session ) {
ok = adapter.startDiscovery(*session);
@@ -160,11 +160,11 @@ int main(int argc, char *argv[])
if( ok && 0 < deviceCount ) {
const uint64_t t1 = direct_bt::getCurrentMilliseconds();
- std::vector<std::shared_ptr<direct_bt::HCIDevice>> discoveredDevices = adapter.getDiscoveredDevices();
+ std::vector<std::shared_ptr<direct_bt::DBTDevice>> discoveredDevices = adapter.getDiscoveredDevices();
int i=0, j=0, k=0;
for(auto it = discoveredDevices.begin(); it != discoveredDevices.end(); it++) {
i++;
- std::shared_ptr<direct_bt::HCIDevice> device = *it;
+ std::shared_ptr<direct_bt::DBTDevice> device = *it;
const uint64_t lup = device->getLastUpdateAge(t1);
if( 2000 > lup ) {
// less than 2s old ..
diff --git a/examples/java/AsyncTinyB.java b/examples/java/AsyncTinyB.java
index 28c492b5..f70b890a 100644
--- a/examples/java/AsyncTinyB.java
+++ b/examples/java/AsyncTinyB.java
@@ -7,6 +7,7 @@ import org.tinyb.BluetoothGattCharacteristic;
import org.tinyb.BluetoothGattService;
import org.tinyb.BluetoothManager;
+import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.TimeUnit;
public class AsyncTinyB {
@@ -45,7 +46,15 @@ public class AsyncTinyB {
* library is through the BluetoothManager. There can be only one BluetoothManager at one time, and the
* reference to it is obtained through the getBluetoothManager method.
*/
- final BluetoothManager manager = BluetoothFactory.getDBusBluetoothManager();
+ final BluetoothManager manager;
+ try {
+ manager = BluetoothFactory.getDBusBluetoothManager();
+ } catch (BluetoothException | NoSuchMethodException | SecurityException
+ | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException | ClassNotFoundException e) {
+ System.err.println("Failed to initialized "+BluetoothFactory.DBusImplementationID);
+ throw new RuntimeException(e);
+ }
/*
* The manager will try to initialize a BluetoothAdapter if any adapter is present in the system. To initialize
diff --git a/examples/java/HelloTinyB.java b/examples/java/HelloTinyB.java
index 4e8a2d0d..77435de6 100644
--- a/examples/java/HelloTinyB.java
+++ b/examples/java/HelloTinyB.java
@@ -1,3 +1,4 @@
+import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
@@ -30,8 +31,7 @@ public class HelloTinyB {
* getDevices method. We can the look through the list of devices to find the device with the MAC which we provided
* as a parameter. We continue looking until we find it, or we try 15 times (1 minutes).
*/
- static BluetoothDevice getDevice(final String address) throws InterruptedException {
- final BluetoothManager manager = BluetoothFactory.getDBusBluetoothManager();
+ static BluetoothDevice getDevice(final BluetoothManager manager, final String address) throws InterruptedException {
BluetoothDevice sensor = null;
for (int i = 0; (i < 15) && running; ++i) {
final List<BluetoothDevice> list = manager.getDevices();
@@ -113,7 +113,15 @@ public class HelloTinyB {
* library is through the BluetoothManager. There can be only one BluetoothManager at one time, and the
* reference to it is obtained through the getBluetoothManager method.
*/
- final BluetoothManager manager = BluetoothFactory.getDBusBluetoothManager();
+ final BluetoothManager manager;
+ try {
+ manager = BluetoothFactory.getDBusBluetoothManager();
+ } catch (BluetoothException | NoSuchMethodException | SecurityException
+ | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException | ClassNotFoundException e) {
+ System.err.println("Failed to initialized "+BluetoothFactory.DBusImplementationID);
+ throw new RuntimeException(e);
+ }
/*
* The manager will try to initialize a BluetoothAdapter if any adapter is present in the system. To initialize
@@ -122,7 +130,7 @@ public class HelloTinyB {
final boolean discoveryStarted = manager.startDiscovery();
System.out.println("The discovery started: " + (discoveryStarted ? "true" : "false"));
- final BluetoothDevice sensor = getDevice(args[0]);
+ final BluetoothDevice sensor = getDevice(manager, args[0]);
/*
* After we find the device we can stop looking for other devices.
diff --git a/examples/java/Notification.java b/examples/java/Notification.java
index 069e013d..c39a0a9e 100644
--- a/examples/java/Notification.java
+++ b/examples/java/Notification.java
@@ -22,11 +22,13 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.tinyb.BluetoothDevice;
+import org.tinyb.BluetoothException;
import org.tinyb.BluetoothFactory;
import org.tinyb.BluetoothGattCharacteristic;
import org.tinyb.BluetoothGattService;
@@ -105,7 +107,15 @@ public class Notification {
* library is through the BluetoothManager. There can be only one BluetoothManager at one time, and the
* reference to it is obtained through the getBluetoothManager method.
*/
- final BluetoothManager manager = BluetoothFactory.getDBusBluetoothManager();
+ final BluetoothManager manager;
+ try {
+ manager = BluetoothFactory.getDBusBluetoothManager();
+ } catch (BluetoothException | NoSuchMethodException | SecurityException
+ | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException | ClassNotFoundException e) {
+ System.err.println("Failed to initialized "+BluetoothFactory.DBusImplementationID);
+ throw new RuntimeException(e);
+ }
/*
* The manager will try to initialize a BluetoothAdapter if any adapter is present in the system. To initialize
diff --git a/examples/java/ScannerTinyB00.java b/examples/java/ScannerTinyB00.java
index db9c2b38..c5ec4790 100644
--- a/examples/java/ScannerTinyB00.java
+++ b/examples/java/ScannerTinyB00.java
@@ -45,7 +45,7 @@ public class ScannerTinyB00 {
static long TO_DISCOVER = 60000;
public static void main(final String[] args) throws InterruptedException {
- String factoryImplClassName = BluetoothFactory.DBusFactoryImplClassName;
+ int factory = 0;
String mac = null;
int mode = 0;
boolean forever = false;
@@ -58,7 +58,7 @@ public class ScannerTinyB00 {
} else if( arg.equals("-mode") ) {
mode = Integer.valueOf(args[++i]).intValue();
} else if( arg.equals("-factory") ) {
- factoryImplClassName = args[++i];
+ factory = Integer.valueOf(args[++i]).intValue();
} else if( arg.equals("-forever") ) {
forever = true;
}
@@ -69,6 +69,7 @@ public class ScannerTinyB00 {
System.exit(-1);
}
+ final BluetoothFactory.ImplementationIdentifier implID = 0 == factory ? BluetoothFactory.DirectBTImplementationID : BluetoothFactory.DBusImplementationID;
final boolean useAdapter = mode/10 > 0;
mode = mode %10;
@@ -76,11 +77,11 @@ public class ScannerTinyB00 {
{
BluetoothManager _manager = null;
try {
- _manager = BluetoothFactory.getBluetoothManager(factoryImplClassName);
+ _manager = BluetoothFactory.getBluetoothManager( implID );
} catch (BluetoothException | NoSuchMethodException | SecurityException
| IllegalAccessException | IllegalArgumentException
| InvocationTargetException | ClassNotFoundException e) {
- System.err.println("Unable to instantiate BluetoothManager via factory "+factoryImplClassName);
+ System.err.println("Unable to instantiate BluetoothManager via "+implID);
e.printStackTrace();
System.exit(-1);
}
diff --git a/examples/java/ScannerTinyB01.java b/examples/java/ScannerTinyB01.java
index 449ab765..f6cd5a87 100644
--- a/examples/java/ScannerTinyB01.java
+++ b/examples/java/ScannerTinyB01.java
@@ -47,7 +47,7 @@ public class ScannerTinyB01 {
static long TO_DISCOVER = 60000;
public static void main(final String[] args) throws InterruptedException {
- String factoryImplClassName = BluetoothFactory.DirectBTFactoryImplClassName;
+ int factory = 0;
int mode = 0;
boolean forever = false;
final String mac;
@@ -61,7 +61,7 @@ public class ScannerTinyB01 {
} else if( arg.equals("-mode") ) {
mode = Integer.valueOf(args[++i]).intValue();
} else if( arg.equals("-factory") ) {
- factoryImplClassName = args[++i];
+ factory = Integer.valueOf(args[++i]).intValue();
} else if( arg.equals("-forever") ) {
forever = true;
}
@@ -74,15 +74,16 @@ public class ScannerTinyB01 {
mac = _mac;
}
+ final BluetoothFactory.ImplementationIdentifier implID = 0 == factory ? BluetoothFactory.DirectBTImplementationID : BluetoothFactory.DBusImplementationID;
final BluetoothManager manager;
{
BluetoothManager _manager = null;
try {
- _manager = BluetoothFactory.getBluetoothManager(factoryImplClassName);
+ _manager = BluetoothFactory.getBluetoothManager( implID );
} catch (BluetoothException | NoSuchMethodException | SecurityException
| IllegalAccessException | IllegalArgumentException
| InvocationTargetException | ClassNotFoundException e) {
- System.err.println("Unable to instantiate BluetoothManager via factory "+factoryImplClassName);
+ System.err.println("Unable to instantiate BluetoothManager via "+implID);
e.printStackTrace();
System.exit(-1);
}