#include #include #include "Bluetooth.h" using namespace std; using namespace trygvis; static 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 << "found device: " << device.mac().str() << endl; device.connect(); device.discoverServices(); device.disconnect(); } int main(int argc, char *argv[]) { if (argc != 2) { cerr << "usage: " << argv[0] << " [mac]" << endl; return EXIT_FAILURE; } BluetoothAdapter *adapter = nullptr; int e; try { targetMac = Mac::parseMac(argv[1]); adapter = trygvis::getAdapter(0); BluetoothDevice &device = adapter->getDevice(*targetMac); scan_callback(device); // adapter->runScan(scan_callback); e = EXIT_SUCCESS; } catch (BluetoothException ex) { W << "BluetoothException: " << ex.what(); e = EXIT_FAILURE; } catch (std::exception ex) { W << "std::exception: " << ex.what(); e = EXIT_FAILURE; } if (adapter != nullptr) { delete adapter; } return e; }