From d88eee8fcf23e20ae76b3dd346b36af693849ccd Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 22 Nov 2018 19:30:14 +0100 Subject: o Working enabling of notifications. --- include/ble/misc.h | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'include/ble/misc.h') 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 +#include "ByteBuffer.h" +#include #include #include #include @@ -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(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(value & 0x01); + } + + bool read() { + return static_cast(value & 0x02); + } + + bool writeWithoutResponse() { + return static_cast(value & 0x04); + } + + bool write() { + return static_cast(value & 0x08); + } + + bool notify() { + return static_cast(value & 0x10); + } + + bool indicate() { + return static_cast(value & 0x20); + } + + bool authenticatedSignedWrites() { + return static_cast(value & 0x40); + } + + bool extendedProperties() { + return static_cast(value & 0x80); + } +}; + } // namespace bluetooth } // namespace trygvis -- cgit v1.2.3