aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-02-19 09:09:56 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-02-19 09:09:56 +0100
commited2ec4bb64052d3ed8d2357abdc080aea4341811 (patch)
tree5a0484d4b4bde449e16b9370d830a92b16b11c7f
parent5460c461809294bb302be8aa6e80533ec30e28e4 (diff)
downloadble-toys-ed2ec4bb64052d3ed8d2357abdc080aea4341811.tar.gz
ble-toys-ed2ec4bb64052d3ed8d2357abdc080aea4341811.tar.bz2
ble-toys-ed2ec4bb64052d3ed8d2357abdc080aea4341811.tar.xz
ble-toys-ed2ec4bb64052d3ed8d2357abdc080aea4341811.zip
o Successfully reading all characteristics.
-rw-r--r--Bluetooth.cpp17
-rw-r--r--Bluetooth.h7
-rw-r--r--LinuxBluetooth.cpp2
3 files changed, 14 insertions, 12 deletions
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<AttributeData> AttPdu::parse(ByteBuffer &bytes, AttPduType type) {
+ DF << "bytes: " << bytes.toString();
- bytes.setCursor(0);
AttPduType t = (AttPduType) bytes.read8();
+ if (t == INVALID_HANDLE) {
+ return vector<AttributeData>();
+ }
+
if (t != type) {
throw BluetoothException("Unexpected type: " + to_string(t));
}
-}
-
-vector<AttributeData> 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()));
diff --git a/Bluetooth.h b/Bluetooth.h
index 80e0193..e840f37 100644
--- a/Bluetooth.h
+++ b/Bluetooth.h
@@ -79,6 +79,9 @@ private:
class BluetoothGattCharacteristic {
public:
+ virtual ~BluetoothGattCharacteristic() {
+ };
+
virtual BluetoothGattService &getService() const = 0;
virtual const boost::uuids::uuid getUuid() const = 0;
@@ -86,6 +89,9 @@ public:
class BluetoothGattService {
public:
+ virtual ~BluetoothGattService() {
+ };
+
virtual BluetoothDevice &getDevice() const = 0;
virtual boost::uuids::uuid getUuid() const = 0;
@@ -134,6 +140,7 @@ protected:
enum AttPduType {
ERROR = 0x00,
+ INVALID_HANDLE = 0x01,
READ_BY_TYPE_REQ = 0x08,
READ_BY_TYPE_RES = 0x09,
READ_BY_GROUP_TYPE_REQ = 0x10,
diff --git a/LinuxBluetooth.cpp b/LinuxBluetooth.cpp
index 7733592..3d5cded 100644
--- a/LinuxBluetooth.cpp
+++ b/LinuxBluetooth.cpp
@@ -213,7 +213,7 @@ void LinuxBluetoothDevice::discoverServices() {
} while (startHandle != 0xffff);
for (auto &s : services) {
- D << "service: " << to_string(s->getUuid());
+ D << "service: " << to_string(s->getUuid()) << ", handle: " << s->getHandle() << ", end group handle: " << s->getEndGroupHandle();
}
for (auto &s : services) {