From dd6a36ea62b8c3e5f20f6d5fd432dec2275aac5a Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 17 Feb 2015 23:40:12 +0100 Subject: o Finally correct decoding of ATT response. --- ByteBuffer.cpp | 10 +++++----- ByteBuffer.h | 4 ++-- LinuxBluetooth.cpp | 9 ++++----- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/ByteBuffer.cpp b/ByteBuffer.cpp index 2d4a258..d60ad6f 100644 --- a/ByteBuffer.cpp +++ b/ByteBuffer.cpp @@ -73,12 +73,12 @@ ByteBuffer ByteBuffer::view(uint8_t *ptr, const uint8_t *end) const { } void ByteBuffer::checkAndUpdateEnd(size_t newBytes) { - uint8_t *newPtr = ptr + newBytes; - if (newPtr >= end) { - if (newPtr >= &zero[capacity]) { - throw ByteBufferException(string("New size is too large! cursor=") + to_string(getCursor()) + ", size=" + to_string(getSize()) + ", capacity=" + to_string(capacity)); + uint8_t *newEnd = ptr + newBytes; + if (newEnd >= end) { + if (newEnd >= &zero[capacity]) { + throw ByteBufferException(string("New size is too large! cursor=") + to_string(getCursor()) + ", size=" + to_string(getSize()) + ", capacity=" + to_string(capacity) + ", new bytes=" + to_string(newBytes)); } - end = newPtr; + end = newEnd; } } diff --git a/ByteBuffer.h b/ByteBuffer.h index d1d02bb..a572097 100644 --- a/ByteBuffer.h +++ b/ByteBuffer.h @@ -28,7 +28,7 @@ public: ByteBuffer(const uint8_t *bytes, size_t capacity, size_t zero, size_t size); inline size_t getSize() const { - DF << "end=" << (uint64_t)end << ", zero=" << (uint64_t)zero << ", size=" << (end - zero); +// DF << "end=" << (uint64_t)end << ", zero=" << (uint64_t)zero << ", size=" << (end - zero); return end - zero; } @@ -46,7 +46,7 @@ public: } inline void skip(size_t length) { - checkAndUpdateEnd(length); +// checkAndUpdateEnd(length); ptr += length; } diff --git a/LinuxBluetooth.cpp b/LinuxBluetooth.cpp index 2c0bffa..b886dde 100644 --- a/LinuxBluetooth.cpp +++ b/LinuxBluetooth.cpp @@ -1,9 +1,6 @@ #include "Bluetooth.h" #include -#include -#include -#include #include #include #include @@ -170,7 +167,7 @@ void LinuxBluetoothDevice::discoverServices() { throw BluetoothException(this, "read(): " + errnoAsString()); } - ByteBuffer in = ByteBuffer(buffer, r); + ByteBuffer in = ByteBuffer(buffer, (size_t) r); D << "read: " << r << " bytes: " << in.toString(); @@ -179,7 +176,9 @@ void LinuxBluetoothDevice::discoverServices() { D << "READ_BY_GROUP_TYPE response has " + to_string(values.size()) + " values"; for (auto &data: values) { - D << "handle: " << data.handle << ", groupEndHandle: " << data.groupEndHandle << ", value: " << data.value.toString(); + D << "handle: 0x" << setw(4) << setfill('0') << hex << data.handle << + ", groupEndHandle: 0x" << hex << setw(4) << setfill('0') << data.groupEndHandle << + ", value: " << data.value.toString(); } } -- cgit v1.2.3