diff options
Diffstat (limited to 'include/ble/misc.h')
-rw-r--r-- | include/ble/misc.h | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/include/ble/misc.h b/include/ble/misc.h index 2508d8e..70a19f5 100644 --- a/include/ble/misc.h +++ b/include/ble/misc.h @@ -1,7 +1,8 @@ #pragma once -#include <optional> +#include "ByteBuffer.h" +#include <optional> #include <cstring> #include <cctype> #include <stdexcept> @@ -34,6 +35,10 @@ struct Uuid { std::memcpy(this->value, value, 16); } + explicit Uuid(ByteBuffer& buffer) noexcept : value() { + std::memcpy(value, buffer.cbegin(), 16); + } + Uuid(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6, uint8_t b7, uint8_t b8, uint8_t b9, uint8_t b10, uint8_t b11, uint8_t b12, uint8_t b13, uint8_t b14, uint8_t b15) noexcept : value{ b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15} {} @@ -62,6 +67,8 @@ private: public: explicit ShortUuid(uint16_t value) noexcept : value(value) {} + explicit ShortUuid(ByteBuffer& buffer) noexcept : value(buffer.read16le()) {} + Uuid toLong() const noexcept { auto b2 = static_cast<uint8_t>(value >> 8); @@ -91,5 +98,42 @@ const ShortUuid CLIENT_CHARACTERISTIC_CONFIG{0x2902}; const ShortUuid TemperatureMeasurement{0x2A1C}; } +class CharacteristicProperties { +public: + const uint16_t value; + + bool broadcast() { + return static_cast<bool>(value & 0x01); + } + + bool read() { + return static_cast<bool>(value & 0x02); + } + + bool writeWithoutResponse() { + return static_cast<bool>(value & 0x04); + } + + bool write() { + return static_cast<bool>(value & 0x08); + } + + bool notify() { + return static_cast<bool>(value & 0x10); + } + + bool indicate() { + return static_cast<bool>(value & 0x20); + } + + bool authenticatedSignedWrites() { + return static_cast<bool>(value & 0x40); + } + + bool extendedProperties() { + return static_cast<bool>(value & 0x80); + } +}; + } // namespace bluetooth } // namespace trygvis |