aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-02-17 23:40:12 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-02-17 23:40:12 +0100
commitdd6a36ea62b8c3e5f20f6d5fd432dec2275aac5a (patch)
tree40174dc2bd5ab8342da433eb4adea939c0df712f
parent08c735d7520e858868bc2c724572139998e39ada (diff)
downloadble-toys-dd6a36ea62b8c3e5f20f6d5fd432dec2275aac5a.tar.gz
ble-toys-dd6a36ea62b8c3e5f20f6d5fd432dec2275aac5a.tar.bz2
ble-toys-dd6a36ea62b8c3e5f20f6d5fd432dec2275aac5a.tar.xz
ble-toys-dd6a36ea62b8c3e5f20f6d5fd432dec2275aac5a.zip
o Finally correct decoding of ATT response.
-rw-r--r--ByteBuffer.cpp10
-rw-r--r--ByteBuffer.h4
-rw-r--r--LinuxBluetooth.cpp9
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 <string.h>
-#include <stropts.h>
-#include <sys/select.h>
-#include <unistd.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
@@ -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();
}
}