From 91e54cf9150b37036447d423857d2bd18e4bf02b Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 5 Sep 2018 14:14:42 +0200 Subject: Major overhaul of BLE code: o Starting to remove shared_ptr. The code shouldn't be shared between threads, any thread safety will have to be built on the outside. o Better service discovery, don't fail when there are multiple requests that have to be done. o AttributeData was buggy, now it is just less than ideal. o Much better ByteBuffer. Now it is a simple view + cursor. --- ble/misc.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 ble/misc.cpp (limited to 'ble/misc.cpp') diff --git a/ble/misc.cpp b/ble/misc.cpp new file mode 100644 index 0000000..afd89cb --- /dev/null +++ b/ble/misc.cpp @@ -0,0 +1,44 @@ +#include "ble/misc.h" + +#include +#include +#include +#include + + +namespace trygvis { +namespace bluetooth { + +std::ostream &operator<<(std::ostream &s, Uuid const &uuid) { + s << uuid.str(); + return s; +} + +std::string Uuid::str() const { + auto v = value; + + std::stringstream s; + s << std::hex << std::setw(2) << + int(v[0]) << int(v[1]) << ":" << + int(v[2]) << int(v[3]) << ":" << + int(v[4]) << int(v[5]) << ":" << + int(v[6]) << int(v[7]) << ":" << + int(v[8]) << int(v[9]) << ":" << + int(v[10]) << int(v[11]) << ":" << + int(v[12]) << int(v[13]) << ":" << + int(v[14]) << int(v[15]) << ":" << + std::resetiosflags(std::ios_base::basefield); + + return s.str(); +} + +Uuid makeUuid(const Uuid &base, uint8_t a, uint8_t b) { + uint8_t value[16]; + memcpy(value, base.value, 16); + value[2] = a; + value[3] = b; + return Uuid{value}; +} + +} // namespace bluetooth +} // namespace trygvis -- cgit v1.2.3