From 360fd8567545253f680ea544ce7313ab1ef43d14 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 17 Feb 2015 07:58:36 +0100 Subject: o Passing tests. --- LinuxBluetooth.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'LinuxBluetooth.cpp') diff --git a/LinuxBluetooth.cpp b/LinuxBluetooth.cpp index c30a2b7..1399161 100644 --- a/LinuxBluetooth.cpp +++ b/LinuxBluetooth.cpp @@ -1,3 +1,5 @@ +#include "Bluetooth.h" + #include #include #include @@ -10,8 +12,6 @@ #include #include -#include "Bluetooth.h" - // Got to love magic constants. Taken from bluez.git/tools/btgatt-client.c #define ATT_CID 4 @@ -31,14 +31,15 @@ namespace trygvis { ~LinuxBluetoothAdapter(); - void runScan(void (*callback)(BluetoothDevice &device)); + void runScan(void (*callback)(BluetoothDevice &device)) override; BluetoothDevice &getDevice(Mac &mac) override; - private: - void startScan(); + void startScan() override; - void stopScan(); + void stopScan() override; + + private: int hciDeviceId; int hciSocket; @@ -151,7 +152,7 @@ namespace trygvis { DF; uint8_t buffer[MAX_MTU]; - ByteBuffer out = ByteBuffer(buffer, MAX_MTU, 0); + ByteBuffer out = ByteBuffer(buffer, MAX_MTU); AttPdu::makeReadByGroupType(out, 0x0001, 0xffff, UUID_PRIMARY_SERVICE); @@ -161,9 +162,14 @@ namespace trygvis { D << "written=" << written; ssize_t r = read(l2cap, buffer, MAX_MTU); - ByteBuffer in = ByteBuffer(buffer, MAX_MTU, r); - D << "read: " << r << " bytes"; + if (r == -1) { + throw BluetoothException(this, "read(): " + errnoAsString()); + } + + ByteBuffer in = ByteBuffer(buffer, r); + + D << "read: " << r << " bytes: " << in.toString(); vector values = AttPdu::parseReadByGroupType(in); @@ -188,7 +194,7 @@ namespace trygvis { D << "HCI socket: " << hciSocket; if (hciSocket == -1) { - throw BluetoothException(this, "Could not open HCI device " + hciDeviceId); + throw BluetoothException(this, "Could not open HCI device " + to_string(hciDeviceId)); } hci_filter_clear(&hciFilter); @@ -212,7 +218,7 @@ namespace trygvis { struct hci_dev_info di; if (hci_devinfo(hciDeviceId, &di) < 0) { - throw BluetoothException(this, "hci_devinfo: " + hciDeviceId); + throw BluetoothException(this, "hci_devinfo: " + to_string(hciDeviceId)); } D << "hciDeviceId.dev_id=" << di.dev_id; @@ -227,7 +233,7 @@ namespace trygvis { int up = hci_test_bit(HCI_UP, &di.flags); if (!up) { - throw BluetoothException(this, "HCI adapter is not up: " + hciDeviceId); + throw BluetoothException(this, "HCI adapter is not up: " + to_string(hciDeviceId)); } if (hci_le_set_scan_parameters(hciSocket, 0x01, htobs(0x0010), htobs(0x0010), 0x00, 0, 1000) < 0) { -- cgit v1.2.3