From 1c97f6df59c825b26ecb18975fd9f62e14fc46ce Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 10 Feb 2015 19:02:57 +0100 Subject: o wip. --- Bluetooth.h | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 5 deletions(-) (limited to 'Bluetooth.h') diff --git a/Bluetooth.h b/Bluetooth.h index 2e2f2ef..9496983 100644 --- a/Bluetooth.h +++ b/Bluetooth.h @@ -7,15 +7,24 @@ // For now #include #include +#include "ByteBuffer.h" #define D BOOST_LOG_TRIVIAL(debug) #define I BOOST_LOG_TRIVIAL(info) #define W BOOST_LOG_TRIVIAL(warning) +#define DF BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ": " +#define IF BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": " +#define WF BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << ": " + +#define UUID_PRIMARY_SERVICE 0x2800 +#define UUID_SECONDARY_SERVICE 0x2801 + namespace trygvis { using namespace std; class BluetoothAdapter; + class BluetoothDevice; class BluetoothException : public runtime_error { @@ -23,8 +32,13 @@ namespace trygvis { 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) { + + BluetoothException(const BluetoothDevice *device, string const &what) : + adapter(nullptr), device(device), runtime_error(what) { + } + + BluetoothException(string const &what) : + adapter(nullptr), device(nullptr), runtime_error(what) { } const BluetoothAdapter *adapter; @@ -44,9 +58,10 @@ namespace trygvis { string str() const; - bool operator==(Mac& other) 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: @@ -56,20 +71,63 @@ namespace trygvis { class BluetoothDevice { public: virtual Mac const &mac() = 0; + + virtual BluetoothAdapter &adapter() = 0; + virtual void connect() = 0; + virtual void disconnect() = 0; - virtual BluetoothAdapter& adapter() = 0; + + virtual void discoverServices() = 0; }; class BluetoothAdapter { public: - BluetoothAdapter() {}; + BluetoothAdapter() { + }; + virtual ~BluetoothAdapter(); virtual void stopScan() = 0; + virtual void runScan(void (callback)(BluetoothDevice &device)) = 0; }; + enum AttPduType { + ERROR = 0x00, + READ_BY_GROUP_TYPE_REQ = 0x10, + READ_BY_GROUP_TYPE_RES = 0x11 + }; + + class AttPdu { + public: + AttPdu(ByteBuffer &bytes); + + AttPdu(ByteBuffer &bytes, AttPduType type); + + AttPduType getType(); + + static AttPdu parse(ByteBuffer & bytes); + private: + ByteBuffer &bytes; + }; + + class AttributeDataList { + public: + AttributeDataList(ByteBuffer &bytes); + + private: + ByteBuffer &bytes; + }; + + class AttributeData { + public: + AttributeData(ByteBuffer &bytes); + + private: + ByteBuffer &bytes; + }; + // BluetoothAdapter &getDevice(int hciDevice); BluetoothAdapter *getDevice(int hciDevice); } -- cgit v1.2.3