From b6f080193d71334e8afea95ae26afbc03c27fac3 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 20 Feb 2015 20:45:43 +0100 Subject: o Decoding GATT characteristics. --- main.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 7ae4c1b..361311c 100644 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include "Bluetooth.h" using namespace std; @@ -15,12 +17,25 @@ void scan_callback(BluetoothDevice &device) { return; } - cout << "found device: " << device.mac().str() << endl; + cout << "Connecting to device: " << device.mac().str() << endl; device.connect(); device.discoverServices(); + vector services = device.getServices(); + cout << "Device has " << services.size() << " services" << endl; + + for (auto &s: services) { + const vector characteristics = s->getCharacteristics(); + + cout << "Service: UUID: " << s->getUuid() << ", has " << characteristics.size() << " characteristics" << endl; + + for (auto &c: characteristics) { + cout << "Characteristic: UUID: " << c->getUuid() << ", properties: " << (int) c->getProperties() << endl; + } + } + device.disconnect(); } @@ -32,18 +47,18 @@ int main(int argc, char *argv[]) { int e; // try { - Mac mac = Mac::parseMac(argv[1]); - targetMac = &mac; + Mac mac = Mac::parseMac(argv[1]); + targetMac = &mac; - BluetoothAdapter &adapter = getAdapter(0); + BluetoothAdapter &adapter = getAdapter(0); - BluetoothDevice &device = adapter.getDevice(mac); + BluetoothDevice &device = adapter.getDevice(mac); - scan_callback(device); + scan_callback(device); // adapter->runScan(scan_callback); - e = EXIT_SUCCESS; + e = EXIT_SUCCESS; // } catch (std::runtime_error ex) { // W << "std::runtime_error: " << ex.what(); // e = EXIT_FAILURE; -- cgit v1.2.3