aboutsummaryrefslogtreecommitdiff
path: root/Bluetooth.cpp
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-02-17 07:58:36 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-02-17 07:58:36 +0100
commit360fd8567545253f680ea544ce7313ab1ef43d14 (patch)
tree06fb409ddee9b370a4d0a76884b433e8e93f0de2 /Bluetooth.cpp
parent60d5440dd3514e71b87948ff5ed30ee38445b8a5 (diff)
downloadble-toys-360fd8567545253f680ea544ce7313ab1ef43d14.tar.gz
ble-toys-360fd8567545253f680ea544ce7313ab1ef43d14.tar.bz2
ble-toys-360fd8567545253f680ea544ce7313ab1ef43d14.tar.xz
ble-toys-360fd8567545253f680ea544ce7313ab1ef43d14.zip
o Passing tests.
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) :