diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-07-26 18:33:15 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-07-26 18:41:40 +0200 |
commit | d720fa36ad4768ed1b948a92ba5287c30093fbec (patch) | |
tree | 3d566e0d4ab47981af85a783f81ebbd363d57f15 /include/ble/ByteBuffer.h | |
parent | 33c537c84fea53c899fb5275256518598f66101e (diff) | |
download | ble-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/ByteBuffer.h')
-rw-r--r-- | include/ble/ByteBuffer.h | 34 |
1 files changed, 34 insertions, 0 deletions
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; /** |