aboutsummaryrefslogtreecommitdiff
path: root/include/ble
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-07-26 18:33:15 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2015-07-26 18:41:40 +0200
commitd720fa36ad4768ed1b948a92ba5287c30093fbec (patch)
tree3d566e0d4ab47981af85a783f81ebbd363d57f15 /include/ble
parent33c537c84fea53c899fb5275256518598f66101e (diff)
downloadble-toys-d720fa36ad4768ed1b948a92ba5287c30093fbec.tar.gz
ble-toys-d720fa36ad4768ed1b948a92ba5287c30093fbec.tar.bz2
ble-toys-d720fa36ad4768ed1b948a92ba5287c30093fbec.tar.xz
ble-toys-d720fa36ad4768ed1b948a92ba5287c30093fbec.zip
o Overhaul of the bluetooth code.
- Adding support for reading FLOAT (specified in IEEE 11073-20601) values from a bluetooth device. - More shared pointers to help keep track of the object's lifecycle. Makes sure that the connections are released back to Linux, Linux is way to sensitive with crashing applications. o Adding support for reading the temperature sensors from the SoilMoisture device.
Diffstat (limited to 'include/ble')
-rw-r--r--include/ble/Bluetooth.h18
-rw-r--r--include/ble/ByteBuffer.h34
2 files changed, 44 insertions, 8 deletions
diff --git a/include/ble/Bluetooth.h b/include/ble/Bluetooth.h
index d238377..8da602f 100644
--- a/include/ble/Bluetooth.h
+++ b/include/ble/Bluetooth.h
@@ -7,6 +7,7 @@
#include <stdexcept>
#include <vector>
#include <cstdint>
+#include <map>
#include "ByteBuffer.h"
@@ -115,7 +116,7 @@ public:
virtual void addCharacteristic(BluetoothGattCharacteristic *characteristic) = 0;
- virtual const boost::optional<BluetoothGattCharacteristic &> findCharacteristic(boost::uuids::uuid uuid) const = 0;
+ virtual const boost::optional<const BluetoothGattCharacteristic &> findCharacteristic(boost::uuids::uuid uuid) const = 0;
};
class BluetoothGatt {
@@ -165,9 +166,9 @@ public:
virtual void stopScan() = 0;
- virtual void runScan(std::function<void(BluetoothDevice &device)>) = 0;
+ virtual void runScan(std::function<void(const shared_ptr<BluetoothDevice> &device)>) = 0;
- virtual BluetoothDevice &getDevice(Mac &mac) = 0;
+ virtual shared_ptr <BluetoothDevice> getDevice(Mac &mac) = 0;
protected:
BluetoothAdapter();
@@ -185,6 +186,11 @@ public:
BluetoothSystem();
~BluetoothSystem();
+
+ shared_ptr<BluetoothAdapter> getAdapter(string name);
+
+private:
+ map<string, shared_ptr<BluetoothAdapter>> adapters;
};
enum AttPduType {
@@ -227,7 +233,7 @@ public:
static void makeWrite(ByteBuffer &req, uint16_t handle, const ByteBuffer &bytes);
private:
- static void checkType(ByteBuffer &bytes, AttPduType type);
+// static void checkType(ByteBuffer &bytes, AttPduType type);
static vector<AttributeData> parse(ByteBuffer &bytes, AttPduType type);
@@ -247,10 +253,6 @@ private:
AttributeData(uint16_t handle, ByteBuffer value);
};
-shared_ptr<BluetoothAdapter> getAdapter(int hciDevice);
-
-void shutdown();
-
boost::uuids::uuid makeUuid(const boost::uuids::uuid base, uint8_t a, uint8_t b);
}
diff --git a/include/ble/ByteBuffer.h b/include/ble/ByteBuffer.h
index d977c67..1032187 100644
--- a/include/ble/ByteBuffer.h
+++ b/include/ble/ByteBuffer.h
@@ -7,6 +7,29 @@
#include <iosfwd>
#include <memory>
#include <stdexcept>
+#include <math.h>
+
+namespace FLOAT {
+static const uint32_t positive_infinity = 0x007FFFFE;
+static const uint32_t negative_infinity = 0x00800002;
+static const uint32_t NaN = 0x007FFFFF;
+static const uint32_t NRes = 0x00800000;
+static const uint32_t FLAOT_reserved_value = 0x00800001;
+
+// (2^23 - 3) * 10^127
+static const double max = 8.388604999999999e+133;
+static const double min = -max;
+
+static const double mantissa_max = 0x007FFFFD;
+static const double exponent_max = 127;
+static const double exponent_min = -128;
+
+// 10^-128
+static const double epsilon = 1e-128;
+
+// 10^upper(23 * log(2) / log(10))
+static const double precision = 10000000;
+}
class ByteBufferException : public std::runtime_error {
public:
@@ -53,6 +76,8 @@ public:
ByteBuffer &write16le(uint16_t value);
+ ByteBuffer &write32le(uint32_t value);
+
/**
* Appends the entire buffer. Make a view if you want to write a part of it.
*/
@@ -60,12 +85,21 @@ public:
ByteBuffer &write(const uint8_t *bytes, size_t len);
+ ByteBuffer &writeFLOAT(double d);
+
uint8_t get8(size_t index) const;
uint8_t read8();
uint16_t read16le();
+ uint32_t read32le();
+
+ /**
+ * IEEE-11073 32-bit FLOAT
+ */
+ double readFLOAT();
+
void copy(uint8_t *bytes, size_t length) const;
/**