aboutsummaryrefslogtreecommitdiff
path: root/Bluetooth.cpp
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-02-17 20:14:34 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-02-17 23:30:04 +0100
commit254be95ff2f37df8adec7ce068448ba8abc8d734 (patch)
treef1483c2ff4c2e194cf90c59ce741d96917f7aaf5 /Bluetooth.cpp
parent0d0543e4daeb1c6b01d4799736026b6f3aef9779 (diff)
parent0d0749ff0f842f10fea6929dc466e4e1be458234 (diff)
downloadble-toys-254be95ff2f37df8adec7ce068448ba8abc8d734.tar.gz
ble-toys-254be95ff2f37df8adec7ce068448ba8abc8d734.tar.bz2
ble-toys-254be95ff2f37df8adec7ce068448ba8abc8d734.tar.xz
ble-toys-254be95ff2f37df8adec7ce068448ba8abc8d734.zip
Merge remote-tracking branch 'origin/master'
Conflicts: Bluetooth.cpp Bluetooth.h ByteBuffer.cpp CMakeLists.txt LinuxBluetooth.cpp main.cpp test/ByteBufferTest.cpp
Diffstat (limited to 'Bluetooth.cpp')
-rw-r--r--Bluetooth.cpp22
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) :