aboutsummaryrefslogtreecommitdiff
path: root/Bluetooth.h
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-02-20 22:56:22 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-02-20 22:56:22 +0100
commite44813dddbf5ba063d29ae1e40862e7a7cbb6f43 (patch)
tree67009d481b8b106af6937a5f386fe4e2e15b1fcc /Bluetooth.h
parentb6f080193d71334e8afea95ae26afbc03c27fac3 (diff)
downloadble-toys-e44813dddbf5ba063d29ae1e40862e7a7cbb6f43.tar.gz
ble-toys-e44813dddbf5ba063d29ae1e40862e7a7cbb6f43.tar.bz2
ble-toys-e44813dddbf5ba063d29ae1e40862e7a7cbb6f43.tar.xz
ble-toys-e44813dddbf5ba063d29ae1e40862e7a7cbb6f43.zip
Reorganizing the source code:
o Moving main to apps/ o Moving the library sources to ble/ o Creating cmake files for each piece.
Diffstat (limited to 'Bluetooth.h')
-rw-r--r--Bluetooth.h203
1 files changed, 0 insertions, 203 deletions
diff --git a/Bluetooth.h b/Bluetooth.h
deleted file mode 100644
index 4314d8e..0000000
--- a/Bluetooth.h
+++ /dev/null
@@ -1,203 +0,0 @@
-#ifndef BLUETOOTH_H
-#define BLUETOOTH_H
-
-#include <string>
-#include <stdexcept>
-#include <boost/uuid/uuid.hpp>
-
-#include "ByteBuffer.h"
-
-namespace trygvis {
-namespace bluetooth {
-
-using namespace std;
-
-struct SpecUuid {
-public:
- SpecUuid(uint16_t value) : value(value) {}
- uint16_t value;
-};
-
-namespace uuids {
-static const SpecUuid PRIMARY_SERVICE = SpecUuid(0x2800);
-static const SpecUuid SECONDARY_SERVICE = SpecUuid(0x2801);
-static const SpecUuid CHARACTERISTIC = SpecUuid(0x2803);
-}
-
-class BluetoothAdapter;
-
-class BluetoothDevice;
-
-class BluetoothGattService;
-
-class BluetoothGattCharacteristic;
-
-class BluetoothException : public runtime_error {
-public:
- BluetoothException(const BluetoothAdapter *adapter, string const &what) :
- runtime_error(what), adapter(adapter), device(nullptr) {
- }
-
- BluetoothException(const BluetoothDevice *device, string const &what) :
- runtime_error(what), adapter(nullptr), device(device) {
- }
-
- BluetoothException(string const &what) :
- runtime_error(what), adapter(nullptr), device(nullptr) {
- }
-
- 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;
-
- 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) throw(BluetoothException);
-
- friend bool operator<(const Mac &a, const Mac &b);
-
-private:
- uint8_t bytes[6];
-};
-
-class BluetoothGattCharacteristic {
-public:
- virtual ~BluetoothGattCharacteristic() {
- };
-
- virtual BluetoothGattService &getService() const = 0;
-
- virtual uint16_t getHandle() const = 0;
-
- virtual const boost::uuids::uuid getUuid() const = 0;
-
- virtual uint8_t getProperties() const = 0;
-
- virtual uint16_t getValueHandle() const = 0;
-};
-
-class BluetoothGattService {
-public:
- virtual ~BluetoothGattService() {
- };
-
- virtual BluetoothDevice &getDevice() const = 0;
-
- virtual boost::uuids::uuid getUuid() const = 0;
-
- virtual uint16_t getHandle() const = 0;
-
- virtual uint16_t getEndGroupHandle() const = 0;
-
- virtual const vector<BluetoothGattCharacteristic *> getCharacteristics() const = 0;
-
- virtual void addCharacteristic(BluetoothGattCharacteristic* characteristic) = 0;
-};
-
-class BluetoothDevice {
-public:
- BluetoothDevice();
-
- virtual ~BluetoothDevice();
-
- virtual Mac const &mac() = 0;
-
- virtual BluetoothAdapter &adapter() = 0;
-
- virtual void connect() = 0;
-
- virtual void disconnect() = 0;
-
- virtual void discoverServices() = 0;
-
- virtual const vector<BluetoothGattService *> getServices() const = 0;
-};
-
-class BluetoothAdapter {
-public:
- virtual void startScan() = 0;
-
- virtual void stopScan() = 0;
-
- virtual void runScan(void (callback)(BluetoothDevice &device)) = 0;
-
- virtual BluetoothDevice &getDevice(Mac &mac) = 0;
-
-protected:
- BluetoothAdapter();
-
- virtual ~BluetoothAdapter();
-};
-
-enum AttPduType {
- ERROR = 0x00,
- INVALID_HANDLE = 0x01,
- READ_BY_TYPE_REQ = 0x08,
- READ_BY_TYPE_RES = 0x09,
- READ_BY_GROUP_TYPE_REQ = 0x10,
- READ_BY_GROUP_TYPE_RES = 0x11,
-};
-
-class AttributeData;
-
-class AttPdu {
-public:
- AttPdu(ByteBuffer &bytes);
-
- AttPdu(ByteBuffer &bytes, AttPduType type);
-
- AttPduType getType();
-
- static vector<AttributeData> parseReadByGroupType(ByteBuffer &bytes);
-
- static vector<AttributeData> parseReadByType(ByteBuffer &bytes);
-
- static void makeReadByGroupType(ByteBuffer &bytes, uint16_t startHandle, uint16_t endHandle, SpecUuid uuid);
-
- static void makeReadByType(ByteBuffer &bytes, uint16_t startHandle, uint16_t endHandle, SpecUuid uuid);
-
-private:
- static void checkType(ByteBuffer &bytes, AttPduType type);
- static vector<AttributeData> parse(ByteBuffer &bytes, AttPduType type);
-
- ByteBuffer &bytes;
-};
-
-class AttributeData {
-public:
- ~AttributeData();
-
- static AttributeData fromByteBuffer(ByteBuffer &value);
-
- const uint16_t handle;
- ByteBuffer value;
-
-private:
- AttributeData(uint16_t handle, ByteBuffer value);
-};
-
-BluetoothAdapter &getAdapter(int hciDevice);
-
-void shutdown();
-
-}
-}
-
-#endif