aboutsummaryrefslogtreecommitdiff
path: root/Bluetooth.h
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-02-08 21:29:47 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-02-08 21:29:47 +0100
commit5cb96fd96f51e949c5311db3080c58d851b7c2e1 (patch)
tree99c41d3ba8e9f5dd7eb3a5250df8c8b707c7f541 /Bluetooth.h
downloadble-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 'Bluetooth.h')
-rw-r--r--Bluetooth.h77
1 files changed, 77 insertions, 0 deletions
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 <string>
+#include <stdexcept>
+
+// For now
+#include <boost/log/core.hpp>
+#include <boost/log/trivial.hpp>
+
+#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