#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() override = default; string adapter_name; void add_options(po::options_description_easy_init &options) override { auto adapter_value = po::value<>(&adapter_name)->default_value("0"); options("adapter", adapter_value, "Which adapter to use."); options("device", po::value()->required(), "The MAC of the device to inspect"); } void with_device(const shared_ptr &device) { cout << "Connecting to device: " << device->getMac().str() << endl; auto gatt = device->connectGatt(); cout << "Connected, discovering services" << endl; gatt->discoverServices(); auto services = gatt->getServices(); cout << "Device has " << services.size() << " services" << endl; for (auto &s : services) { auto characteristics = s->getCharacteristics(); cout << "Service: UUID: " << s->getUuid() << ", has " << characteristics.size() << " characteristics" << endl; for (auto &c : characteristics) { cout << "Characteristic: UUID: " << c->getUuid() << ", properties: " << (uint16_t) 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); auto adapter = bluetoothSystem.getAdapter(adapter_name); auto device = adapter->getDevice(mac); with_device(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); }