diff options
Diffstat (limited to 'Bluetooth.cpp')
| -rw-r--r-- | Bluetooth.cpp | 22 | 
1 files changed, 13 insertions, 9 deletions
| diff --git a/Bluetooth.cpp b/Bluetooth.cpp index e6d6d28..ebdd527 100644 --- a/Bluetooth.cpp +++ b/Bluetooth.cpp @@ -1,8 +1,9 @@ +#include "Bluetooth.h" +#include "BluetoothImpl.h" +  #include <sstream>  #include <iomanip>  #include <string.h> -#include "Bluetooth.h" -#include "BluetoothImpl.h"  namespace trygvis {  namespace bluetooth { @@ -88,7 +89,7 @@ void AttPdu::checkType(ByteBuffer &bytes, AttPduType type) {      AttPduType t = (AttPduType) bytes.get8();      if (t != type) { -        throw BluetoothException("Unexpected type: " + t); +        throw BluetoothException("Unexpected type: " + to_string(t));      }  } @@ -98,18 +99,21 @@ vector<AttributeData> AttPdu::parseReadByGroupType(ByteBuffer &bytes) {      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; @@ -119,11 +123,11 @@ vector<AttributeData> AttPdu::parseReadByGroupType(ByteBuffer &bytes) {  // 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 - 4)); +    return AttributeData(handle, groupEndHandle, bytes.view());  }  AttributeData::AttributeData(uint16_t handle, uint16_t groupEndHandle, ByteBuffer value) : | 
