diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-02-17 20:14:34 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-02-17 23:30:04 +0100 |
commit | 254be95ff2f37df8adec7ce068448ba8abc8d734 (patch) | |
tree | f1483c2ff4c2e194cf90c59ce741d96917f7aaf5 /LinuxBluetooth.cpp | |
parent | 0d0543e4daeb1c6b01d4799736026b6f3aef9779 (diff) | |
parent | 0d0749ff0f842f10fea6929dc466e4e1be458234 (diff) | |
download | ble-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 'LinuxBluetooth.cpp')
-rw-r--r-- | LinuxBluetooth.cpp | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/LinuxBluetooth.cpp b/LinuxBluetooth.cpp index 5a00f53..3efa7e5 100644 --- a/LinuxBluetooth.cpp +++ b/LinuxBluetooth.cpp @@ -1,3 +1,5 @@ +#include "Bluetooth.h" + #include <string.h> #include <stropts.h> #include <sys/select.h> @@ -10,8 +12,6 @@ #include <sstream> #include <iomanip> -#include "Bluetooth.h" - // Got to love magic constants. Taken from bluez.git/tools/btgatt-client.c #define ATT_CID 4 @@ -33,7 +33,7 @@ public: ~LinuxBluetoothAdapter(); - void runScan(void (*callback)(BluetoothDevice &device)); + void runScan(void (*callback)(BluetoothDevice &device)) override; BluetoothDevice &getDevice(Mac &mac) override; @@ -155,7 +155,7 @@ void LinuxBluetoothDevice::discoverServices() { 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); @@ -165,9 +165,14 @@ void LinuxBluetoothDevice::discoverServices() { 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<AttributeData> values = AttPdu::parseReadByGroupType(in); @@ -192,7 +197,7 @@ LinuxBluetoothAdapter::LinuxBluetoothAdapter(int hciDeviceId) : 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); @@ -222,12 +227,12 @@ void LinuxBluetoothAdapter::startScan() { struct hci_dev_info di; if (hci_devinfo(hciDeviceId, &di) < 0) { - throw BluetoothException(this, "hci_devinfo: " + hciDeviceId); + throw BluetoothException(this, "HCI adapter is not up: " + to_string(hciDeviceId)); } D << "hciDeviceId.dev_id=" << di.dev_id; D << "hciDeviceId.bdaddr=" << parseMac(di.bdaddr).str(); - D << "hciDeviceId.flags=" << hex << setw(8) << setfill('0') << di.flags; + D << "hciDeviceId.flags=" << setw(8) << setfill('0') << hex << di.flags; D << "hciDeviceId.flags RUNNING = " << hci_test_bit(HCI_RUNNING, &di.flags); D << "hciDeviceId.flags UP = " << hci_test_bit(HCI_UP, &di.flags); D << "hciDeviceId.flags PSCAN = " << hci_test_bit(HCI_PSCAN, &di.flags); |