diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-06-21 00:15:04 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-06-21 00:15:43 +0200 |
commit | c56840f03cf139d60c6d90b55cf16e70f6ae2bc2 (patch) | |
tree | c9f19ab065496ac704fbf855da031ef5643eefa3 /apps/ble-inspect-device.h | |
parent | d91e500592790f1ef22ebfe921f273a61ff6252f (diff) | |
download | ble-toys-c56840f03cf139d60c6d90b55cf16e70f6ae2bc2.tar.gz ble-toys-c56840f03cf139d60c6d90b55cf16e70f6ae2bc2.tar.bz2 ble-toys-c56840f03cf139d60c6d90b55cf16e70f6ae2bc2.tar.xz ble-toys-c56840f03cf139d60c6d90b55cf16e70f6ae2bc2.zip |
o Going all header file based and single-executable to launch all apps.
o Ading CMake magic to generate the launcher
Diffstat (limited to 'apps/ble-inspect-device.h')
-rw-r--r-- | apps/ble-inspect-device.h | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/apps/ble-inspect-device.h b/apps/ble-inspect-device.h new file mode 100644 index 0000000..bf79b2c --- /dev/null +++ b/apps/ble-inspect-device.h @@ -0,0 +1,79 @@ +#include <exception> +#include <iostream> +#include <vector> +#include <boost/uuid/uuid_io.hpp> +#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<string>()->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 < BluetoothGattService * > services = gatt.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; + } + } + + gatt.disconnect(); + } + + int main(app_execution &execution) override { + string mac_str = execution.vm["mac"].as<string>(); + + BluetoothSystem bluetoothSystem; + + try { + Mac mac = Mac::parseMac(mac_str); + + BluetoothAdapter &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; + } + } +}; + +} +} |