aboutsummaryrefslogtreecommitdiff
path: root/Bluetooth.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Bluetooth.cpp')
-rw-r--r--Bluetooth.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/Bluetooth.cpp b/Bluetooth.cpp
index dd9e48e..f589d1f 100644
--- a/Bluetooth.cpp
+++ b/Bluetooth.cpp
@@ -1,7 +1,8 @@
+#include "Bluetooth.h"
+
#include <sstream>
#include <iomanip>
#include <string.h>
-#include "Bluetooth.h"
namespace trygvis {
using namespace std;
@@ -86,26 +87,31 @@ namespace trygvis {
AttPduType t = (AttPduType) bytes.get8();
if (t != type) {
- throw BluetoothException("Unexpected type: " + t);
+ throw BluetoothException("Unexpected type: " + to_string(t));
}
}
vector<AttributeData> AttPdu::parseReadByGroupType(ByteBuffer &bytes) {
+ DF;
+
checkType(bytes, READ_BY_GROUP_TYPE_RES);
if (bytes.getSize() < 4) {
- throw BluetoothException("Bad READ_BY_GROUP_TYPE_RES packet, expected at least 4 octets, got " + bytes.getSize());
+ throw BluetoothException("Bad READ_BY_GROUP_TYPE_RES packet, expected at least 4 octets, got " + to_string(bytes.getSize()));
}
uint8_t length = bytes.get8();
- DF << "length=" << (int) length;
+ D << "length=" << (int) length;
size_t count = (bytes.getSize() - 2) / length;
- DF << "count=" << count;
+ D << "count=" << count;
vector<AttributeData> values;
for (int i = 0; i < count; i++) {
- values.push_back(AttributeData::fromByteBuffer(bytes, length));
+ auto data = bytes.view(length);
+ D << "data, size=" << data.getSize() << ", bytes=" << data.toString();
+ bytes.skip(length);
+ values.push_back(AttributeData::fromByteBuffer(data));
}
return values;
@@ -115,11 +121,11 @@ namespace trygvis {
// AttributeData
// -----------------------------------------------------------------------
- AttributeData AttributeData::fromByteBuffer(ByteBuffer &bytes, uint8_t length) {
+ AttributeData AttributeData::fromByteBuffer(ByteBuffer &bytes) {
uint16_t handle = bytes.get16le();
uint16_t groupEndHandle = bytes.get16le();
- return AttributeData(handle, groupEndHandle, bytes.view(length));
+ return AttributeData(handle, groupEndHandle, bytes.view());
}
AttributeData::AttributeData(uint16_t handle, uint16_t groupEndHandle, ByteBuffer value) :