diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-02-08 21:29:47 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-02-08 21:29:47 +0100 |
commit | 5cb96fd96f51e949c5311db3080c58d851b7c2e1 (patch) | |
tree | 99c41d3ba8e9f5dd7eb3a5250df8c8b707c7f541 /main.cpp | |
download | ble-toys-5cb96fd96f51e949c5311db3080c58d851b7c2e1.tar.gz ble-toys-5cb96fd96f51e949c5311db3080c58d851b7c2e1.tar.bz2 ble-toys-5cb96fd96f51e949c5311db3080c58d851b7c2e1.tar.xz ble-toys-5cb96fd96f51e949c5311db3080c58d851b7c2e1.zip |
o Initial import of Linux code for talking to Bluetooth devices.
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..ab1a9b0 --- /dev/null +++ b/main.cpp @@ -0,0 +1,44 @@ +#include <exception> +#include <iostream> +#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" << endl; + return; + } + + cout << "found device: " << device.mac().str() << endl; + + device.connect(); + device.disconnect(); +} + +int main(int argc, char *argv[]) { + if (argc != 2) { + cerr << "usage: " << argv[0] << " [mac]" << endl; + return EXIT_FAILURE; + } + + targetMac = Mac::parseMac(argv[1]); + + try { + BluetoothAdapter *adapter = trygvis::getDevice(0); + + adapter->runScan(scan_callback); + + delete adapter; + + return EXIT_SUCCESS; + } catch (BluetoothException ex) { + W << "Excpetion: " << ex.what(); + return EXIT_FAILURE; + } +} |