From ed2ec4bb64052d3ed8d2357abdc080aea4341811 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 19 Feb 2015 09:09:56 +0100 Subject: o Successfully reading all characteristics. --- Bluetooth.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'Bluetooth.cpp') diff --git a/Bluetooth.cpp b/Bluetooth.cpp index 9c32740..e634233 100644 --- a/Bluetooth.cpp +++ b/Bluetooth.cpp @@ -86,23 +86,18 @@ void AttPdu::makeReadByType(ByteBuffer &bytes, uint16_t startHandle, uint16_t en bytes.write16le(uuid.value); } -void AttPdu::checkType(ByteBuffer &bytes, AttPduType type) { - if (bytes.getSize() == 0) { - throw BluetoothException("PDU is too small"); - } +vector AttPdu::parse(ByteBuffer &bytes, AttPduType type) { + DF << "bytes: " << bytes.toString(); - bytes.setCursor(0); AttPduType t = (AttPduType) bytes.read8(); + if (t == INVALID_HANDLE) { + return vector(); + } + if (t != type) { throw BluetoothException("Unexpected type: " + to_string(t)); } -} - -vector AttPdu::parse(ByteBuffer &bytes, AttPduType type) { - DF << "bytes: " << bytes.toString(); - - checkType(bytes, type); if (bytes.getSize() < 4) { throw BluetoothException("Bad READ_BY_GROUP_TYPE_RES packet, expected at least 4 octets, got " + to_string(bytes.getSize())); -- cgit v1.2.3