From 5cb96fd96f51e949c5311db3080c58d851b7c2e1 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 8 Feb 2015 21:29:47 +0100 Subject: o Initial import of Linux code for talking to Bluetooth devices. --- Bluetooth.h | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 Bluetooth.h (limited to 'Bluetooth.h') diff --git a/Bluetooth.h b/Bluetooth.h new file mode 100644 index 0000000..2e2f2ef --- /dev/null +++ b/Bluetooth.h @@ -0,0 +1,77 @@ +#ifndef BLUETOOTH_H +#define BLUETOOTH_H + +#include +#include + +// For now +#include +#include + +#define D BOOST_LOG_TRIVIAL(debug) +#define I BOOST_LOG_TRIVIAL(info) +#define W BOOST_LOG_TRIVIAL(warning) + +namespace trygvis { + using namespace std; + + class BluetoothAdapter; + class BluetoothDevice; + + class BluetoothException : public runtime_error { + public: + BluetoothException(const BluetoothAdapter *adapter, string const &what) : + adapter(adapter), device(nullptr), runtime_error(what) { + } + BluetoothException(const BluetoothAdapter *adapter, const BluetoothDevice *device, string const &what) : + adapter(adapter), device(device), runtime_error(what) { + } + + const BluetoothAdapter *adapter; + const BluetoothDevice *device; + }; + + class Mac { + public: + Mac(uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5) { + bytes[0] = _0; + bytes[1] = _1; + bytes[2] = _2; + bytes[3] = _3; + bytes[4] = _4; + bytes[5] = _5; + }; + + string str() const; + + bool operator==(Mac& other) const; + + void copy(uint8_t &_0, uint8_t &_1, uint8_t &_2, uint8_t &_3, uint8_t &_4, uint8_t &_5) const; + static Mac *parseMac(string s); + + private: + uint8_t bytes[6]; + }; + + class BluetoothDevice { + public: + virtual Mac const &mac() = 0; + virtual void connect() = 0; + virtual void disconnect() = 0; + virtual BluetoothAdapter& adapter() = 0; + }; + + class BluetoothAdapter { + public: + BluetoothAdapter() {}; + virtual ~BluetoothAdapter(); + + virtual void stopScan() = 0; + virtual void runScan(void (callback)(BluetoothDevice &device)) = 0; + }; + +// BluetoothAdapter &getDevice(int hciDevice); + BluetoothAdapter *getDevice(int hciDevice); +} + +#endif -- cgit v1.2.3