From ae2d05eee4ffcec4c0611d907779ce8ef61d3a6e Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 19 Jul 2015 21:39:28 +0200 Subject: o Going back to a bunch of cpp files instead of launcher+bunch of header files. This ends up with an easier build file and faster builds with CMake's "OBJECT" library type. --- apps/ble-inspect-device.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 apps/ble-inspect-device.cpp (limited to 'apps/ble-inspect-device.cpp') diff --git a/apps/ble-inspect-device.cpp b/apps/ble-inspect-device.cpp new file mode 100644 index 0000000..763dd9a --- /dev/null +++ b/apps/ble-inspect-device.cpp @@ -0,0 +1,79 @@ +#include +#include +#include +#include +#include "ble/Bluetooth.h" +#include "apps.h" + +namespace trygvis { +namespace apps { + +using namespace std; +using namespace trygvis::bluetooth; +using namespace trygvis::apps; + +class ble_inspect_device : public app { +public: + ble_inspect_device() : app("ble-inspect-device") {} + + ~ble_inspect_device() = default; + + void add_options(po::options_description_easy_init &options) override { + options("device", po::value()->required(), "The MAC of the device to inspect"); + } + + void scan_callback(BluetoothDevice &device) { + cout << "Inspecting device: " << device.getMac().str() << endl; + + auto gatt = device.connectGatt(); + + gatt->discoverServices(); + + vector services = gatt->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; + } + } + } + + int main(app_execution &execution) override { + string mac_str = execution.vm["device"].as(); + + BluetoothSystem bluetoothSystem; + + try { + Mac mac = Mac::parseMac(mac_str); + + shared_ptr adapter = getAdapter(0); + + BluetoothDevice &device = adapter->getDevice(mac); + + scan_callback(device); + + return EXIT_SUCCESS; + } catch (std::runtime_error ex) { + cout << "std::runtime_error: " << ex.what() << endl; + return EXIT_FAILURE; + } catch (std::exception ex) { + cout << "std::exception: " << ex.what() << endl; + return EXIT_FAILURE; + } + } +}; +} +} + +int main(int argc, const char *argv[]) { + using namespace trygvis::apps; + + return real_main(new ble_inspect_device(), argc, argv); +} -- cgit v1.2.3