aboutsummaryrefslogtreecommitdiff
path: root/ble/misc.cpp
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2018-09-05 14:14:42 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2018-09-05 14:14:42 +0200
commit91e54cf9150b37036447d423857d2bd18e4bf02b (patch)
tree7738db9a61cb6385f0abc6359b5b89aaa1ff104d /ble/misc.cpp
parent25d82b0c52120c81cfed5bc1f245408f08203b7b (diff)
downloadble-toys-91e54cf9150b37036447d423857d2bd18e4bf02b.tar.gz
ble-toys-91e54cf9150b37036447d423857d2bd18e4bf02b.tar.bz2
ble-toys-91e54cf9150b37036447d423857d2bd18e4bf02b.tar.xz
ble-toys-91e54cf9150b37036447d423857d2bd18e4bf02b.zip
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.
Diffstat (limited to 'ble/misc.cpp')
-rw-r--r--ble/misc.cpp44
1 files changed, 44 insertions, 0 deletions
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 <ios>
+#include <ostream>
+#include <iomanip>
+#include <ble/misc.h>
+
+
+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