aboutsummaryrefslogtreecommitdiff
path: root/LinuxBluetooth.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'LinuxBluetooth.cpp')
-rw-r--r--LinuxBluetooth.cpp30
1 files changed, 18 insertions, 12 deletions
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 <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
@@ -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<AttributeData> 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) {