aboutsummaryrefslogtreecommitdiff
path: root/ble/misc.cpp
diff options
context:
space:
mode:
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