aboutsummaryrefslogtreecommitdiff
path: root/apps/ble-inspect-device.cpp
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-02-20 22:56:22 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-02-20 22:56:22 +0100
commite44813dddbf5ba063d29ae1e40862e7a7cbb6f43 (patch)
tree67009d481b8b106af6937a5f386fe4e2e15b1fcc /apps/ble-inspect-device.cpp
parentb6f080193d71334e8afea95ae26afbc03c27fac3 (diff)
downloadble-toys-e44813dddbf5ba063d29ae1e40862e7a7cbb6f43.tar.gz
ble-toys-e44813dddbf5ba063d29ae1e40862e7a7cbb6f43.tar.bz2
ble-toys-e44813dddbf5ba063d29ae1e40862e7a7cbb6f43.tar.xz
ble-toys-e44813dddbf5ba063d29ae1e40862e7a7cbb6f43.zip
Reorganizing the source code:
o Moving main to apps/ o Moving the library sources to ble/ o Creating cmake files for each piece.
Diffstat (limited to 'apps/ble-inspect-device.cpp')
-rw-r--r--apps/ble-inspect-device.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/apps/ble-inspect-device.cpp b/apps/ble-inspect-device.cpp
new file mode 100644
index 0000000..361311c
--- /dev/null
+++ b/apps/ble-inspect-device.cpp
@@ -0,0 +1,72 @@
+#include <exception>
+#include <iostream>
+#include <vector>
+#include <boost/uuid/uuid_io.hpp>
+#include "Bluetooth.h"
+
+using namespace std;
+using namespace trygvis::bluetooth;
+
+Mac *targetMac;
+
+void scan_callback(BluetoothDevice &device) {
+ device.adapter().stopScan();
+
+ if (device.mac() != *targetMac) {
+ cout << "found device: " << device.mac().str() << ", but not the one we want " << targetMac->str() << endl;
+ return;
+ }
+
+ cout << "Connecting to device: " << device.mac().str() << endl;
+
+ device.connect();
+
+ device.discoverServices();
+
+ vector<BluetoothGattService *> services = device.getServices();
+ cout << "Device has " << services.size() << " services" << endl;
+
+ for (auto &s: services) {
+ const vector<BluetoothGattCharacteristic *> 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();
+}
+
+int main(int argc, char *argv[]) {
+ if (argc != 2) {
+ cerr << "usage: " << argv[0] << " [mac]" << endl;
+ return EXIT_FAILURE;
+ }
+
+ int e;
+// try {
+ Mac mac = Mac::parseMac(argv[1]);
+ targetMac = &mac;
+
+ BluetoothAdapter &adapter = getAdapter(0);
+
+ BluetoothDevice &device = adapter.getDevice(mac);
+
+ scan_callback(device);
+
+// adapter->runScan(scan_callback);
+
+ e = EXIT_SUCCESS;
+// } catch (std::runtime_error ex) {
+// W << "std::runtime_error: " << ex.what();
+// e = EXIT_FAILURE;
+// } catch (std::exception ex) {
+// W << "std::exception: " << ex.what();
+// e = EXIT_FAILURE;
+// }
+
+ shutdown();
+ return e;
+}