diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-03-01 21:15:01 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-03-01 21:15:01 +0100 |
commit | e64d925b45ff4802fe924ea2e8108bb1932b4d01 (patch) | |
tree | 3f9b524c9526834b5830030562e9cb581235f2d6 /ble/LinuxBluetooth.cpp | |
parent | 1b09c7d0547fb430e957b863bdbb3bf54c85f52a (diff) | |
download | ble-toys-e64d925b45ff4802fe924ea2e8108bb1932b4d01.tar.gz ble-toys-e64d925b45ff4802fe924ea2e8108bb1932b4d01.tar.bz2 ble-toys-e64d925b45ff4802fe924ea2e8108bb1932b4d01.tar.xz ble-toys-e64d925b45ff4802fe924ea2e8108bb1932b4d01.zip |
o Replacing boost::logging with log4cplus.
Diffstat (limited to 'ble/LinuxBluetooth.cpp')
-rw-r--r-- | ble/LinuxBluetooth.cpp | 60 |
1 files changed, 23 insertions, 37 deletions
diff --git a/ble/LinuxBluetooth.cpp b/ble/LinuxBluetooth.cpp index 435dd63..80e68cb 100644 --- a/ble/LinuxBluetooth.cpp +++ b/ble/LinuxBluetooth.cpp @@ -27,7 +27,7 @@ class LinuxBluetoothAdapter; class LinuxBluetoothManager; -class LinuxBluetoothAdapter : public BluetoothAdapter { +class LinuxBluetoothAdapter : public DefaultBluetoothAdapter { public: LinuxBluetoothAdapter(int hciDeviceId); @@ -141,7 +141,7 @@ LinuxBluetoothGatt::~LinuxBluetoothGatt() { void LinuxBluetoothGatt::connect() { struct sockaddr_l2 addr; - D << "connect: mac=" << device.getMac().str(); + LOG_DEBUG("connect: mac=" << device.getMac().str()); l2cap = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP); if (l2cap < 0) { @@ -186,7 +186,7 @@ void LinuxBluetoothGatt::connect() { } void LinuxBluetoothGatt::disconnect() { - DF << "mac = " << device.getMac().str(); + LOG_DEBUG("mac = " << device.getMac().str()); close(l2cap); } @@ -227,9 +227,7 @@ uuid_t readUuid(BluetoothDevice *device, const ByteBuffer &bytes) { } void LinuxBluetoothGatt::writeValue(const BluetoothGattCharacteristic &c, const ByteBuffer &bytes) { - DF; - - D << "Writing to characteristic " << c.getUuid() << ": " << bytes.toString(); + LOG_DEBUG("Writing to characteristic " << c.getUuid() << ": " << bytes.toString()); shared_ptr<uint8_t> buffer(new uint8_t[MAX_MTU]); ByteBuffer out = ByteBuffer(buffer, MAX_MTU); @@ -242,8 +240,6 @@ void LinuxBluetoothGatt::writeValue(const BluetoothGattCharacteristic &c, const } ByteBuffer LinuxBluetoothGatt::readValue(const BluetoothGattCharacteristic &c) { - DF; - shared_ptr<uint8_t> buffer(new uint8_t[MAX_MTU]); ByteBuffer out = ByteBuffer(buffer, MAX_MTU); @@ -257,7 +253,7 @@ ByteBuffer LinuxBluetoothGatt::readValue(const BluetoothGattCharacteristic &c) { auto response = in.view(); - D << "Value of characteristic " << c.getUuid() << "=" << response.toString(); + LOG_DEBUG("Value of characteristic " << c.getUuid() << "=" << response.toString()); return response; } @@ -347,10 +343,10 @@ void LinuxBluetoothGatt::discoverServices() { } ByteBuffer LinuxBluetoothGatt::writeAndRead(ByteBuffer &out, shared_ptr<uint8_t> buffer, size_t size) { - D << "pdu size=" << out.getCursor(); + LOG_DEBUG("pdu size=" << out.getCursor()); ssize_t written = write(l2cap, buffer.get(), out.getCursor()); - D << "written=" << written; + LOG_DEBUG("written=" << written); ssize_t r = read(l2cap, buffer.get(), size); @@ -360,14 +356,12 @@ ByteBuffer LinuxBluetoothGatt::writeAndRead(ByteBuffer &out, shared_ptr<uint8_t> auto in = ByteBuffer(buffer, (size_t) r, (size_t) r); - D << "read: " << r << " bytes: " << in.toString(); + LOG_DEBUG("read: " << r << " bytes: " << in.toString()); return in; } vector<AttributeData> LinuxBluetoothGatt::discoverServices(uint16_t startHandle) { - DF; - shared_ptr<uint8_t> buffer(new uint8_t[MAX_MTU]); ByteBuffer out = ByteBuffer(buffer, MAX_MTU); @@ -377,14 +371,12 @@ vector<AttributeData> LinuxBluetoothGatt::discoverServices(uint16_t startHandle) vector<AttributeData> values = AttPdu::parseReadByGroupType(in); - D << "READ_BY_GROUP_TYPE response has " + to_string(values.size()) + " values"; + LOG_DEBUG("READ_BY_GROUP_TYPE response has " + to_string(values.size()) + " values"); return values; } vector<AttributeData> LinuxBluetoothGatt::discoverCharacteristics(uint16_t startHandle, uint16_t endHandle) { - DF; - shared_ptr<uint8_t> buffer(new uint8_t[MAX_MTU]); ByteBuffer out = ByteBuffer(buffer, MAX_MTU); @@ -394,7 +386,7 @@ vector<AttributeData> LinuxBluetoothGatt::discoverCharacteristics(uint16_t start vector<AttributeData> values = AttPdu::parseReadByType(in); - D << "READ_BY_TYPE response has " + to_string(values.size()) + " values"; + LOG_DEBUG("READ_BY_TYPE response has " + to_string(values.size()) + " values"); return values; } @@ -405,12 +397,12 @@ vector<AttributeData> LinuxBluetoothGatt::discoverCharacteristics(uint16_t start LinuxBluetoothAdapter::LinuxBluetoothAdapter(int hciDeviceId) : scanning(false) { - DF << "hciDeviceId=" << hciDeviceId; + LOG_DEBUG("hciDeviceId=" << hciDeviceId); this->hciDeviceId = hciDeviceId; hciSocket = ::hci_open_dev(hciDeviceId); - D << "HCI socket: " << hciSocket; + LOG_DEBUG("HCI socket: " << hciSocket); if (hciSocket == -1) { throw BluetoothException(this, "Could not open HCI device " + to_string(hciDeviceId)); @@ -424,8 +416,6 @@ LinuxBluetoothAdapter::LinuxBluetoothAdapter(int hciDeviceId) : } LinuxBluetoothAdapter::~LinuxBluetoothAdapter() { - DF; - stopScan(); close(hciSocket); @@ -436,22 +426,20 @@ LinuxBluetoothAdapter::~LinuxBluetoothAdapter() { } void LinuxBluetoothAdapter::startScan() { - DF; - struct hci_dev_info di; if (hci_devinfo(hciDeviceId, &di) < 0) { 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=" << 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); - D << "hciDeviceId.flags ISCAN = " << hci_test_bit(HCI_ISCAN, &di.flags); - D << "hciDeviceId.name=" << di.name; + LOG_DEBUG("hciDeviceId.dev_id=" << di.dev_id); + LOG_DEBUG("hciDeviceId.bdaddr=" << parseMac(di.bdaddr).str()); + LOG_DEBUG("hciDeviceId.flags=" << setw(8) << setfill('0') << hex << di.flags); + LOG_DEBUG("hciDeviceId.flags RUNNING = " << hci_test_bit(HCI_RUNNING, &di.flags)); + LOG_DEBUG("hciDeviceId.flags UP = " << hci_test_bit(HCI_UP, &di.flags)); + LOG_DEBUG("hciDeviceId.flags PSCAN = " << hci_test_bit(HCI_PSCAN, &di.flags)); + LOG_DEBUG("hciDeviceId.flags ISCAN = " << hci_test_bit(HCI_ISCAN, &di.flags)); + LOG_DEBUG("hciDeviceId.name=" << di.name); int up = hci_test_bit(HCI_UP, &di.flags); @@ -471,8 +459,6 @@ void LinuxBluetoothAdapter::startScan() { } void LinuxBluetoothAdapter::stopScan() { - DF; - if (!scanning) { return; } @@ -480,7 +466,7 @@ void LinuxBluetoothAdapter::stopScan() { scanning = false; if (hci_le_set_scan_enable(hciSocket, 0, 0, 1000) < 0) { - W << "stopScan: hci_le_set_scan_enable: " << errnoAsString(); + LOG_WARN("stopScan: hci_le_set_scan_enable: " << errnoAsString()); } } @@ -516,7 +502,7 @@ void LinuxBluetoothAdapter::runScan(void (*callback)(BluetoothDevice &device)) { } if (selected == 0) { - D << "timeout"; + LOG_DEBUG("timeout"); // Timeout, just continue continue; } @@ -527,7 +513,7 @@ void LinuxBluetoothAdapter::runScan(void (*callback)(BluetoothDevice &device)) { evt_le_meta_event *metaEvent = (evt_le_meta_event *) (hciEventBuf + (1 + HCI_EVENT_HDR_SIZE)); len -= (1 + HCI_EVENT_HDR_SIZE); - D << "metaEvent->subevent = " << std::hex << (int) metaEvent->subevent; + LOG_DEBUG("metaEvent->subevent = " << std::hex << (int) metaEvent->subevent); if (metaEvent->subevent == EVT_LE_ADVERTISING_REPORT) { le_advertising_info *advertisingInfo = (le_advertising_info *) (metaEvent->data + 1); |