From 360fd8567545253f680ea544ce7313ab1ef43d14 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 17 Feb 2015 07:58:36 +0100 Subject: o Passing tests. --- Bluetooth.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'Bluetooth.cpp') 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 #include #include -#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 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 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) : -- cgit v1.2.3