From 0f930cddefe386c6b6f65b8b11342c9e76876a9b Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Mon, 29 Jan 2018 19:06:59 +0100 Subject: Add manufacturer data to QBluetoothDeviceInfo The initial patch was contributed by Thiemo van Engelen. Change-Id: I45fad793ba092ab2820e606d8bf8807afa3e911e Reviewed-by: Oliver Wolff --- src/bluetooth/osx/osxbtledeviceinquiry.mm | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/bluetooth/osx') diff --git a/src/bluetooth/osx/osxbtledeviceinquiry.mm b/src/bluetooth/osx/osxbtledeviceinquiry.mm index 2cece15b..e61968ed 100644 --- a/src/bluetooth/osx/osxbtledeviceinquiry.mm +++ b/src/bluetooth/osx/osxbtledeviceinquiry.mm @@ -45,6 +45,7 @@ #include #include +#include #include @@ -81,6 +82,7 @@ struct AdvertisementData { // For now, we "parse": QString localName; QList serviceUuids; + QHash manufacturerData; // TODO: other keys probably? AdvertisementData(NSDictionary *AdvertisementData); }; @@ -105,6 +107,12 @@ AdvertisementData::AdvertisementData(NSDictionary *advertisementData) for (CBUUID *cbUuid in uuids) serviceUuids << qt_uuid(cbUuid); } + + value = [advertisementData objectForKey:CBAdvertisementDataManufacturerDataKey]; + if (value && [value isKindOfClass:[NSData class]]) { + QByteArray data = QByteArray::fromNSData(static_cast(value)); + manufacturerData.insert(qFromLittleEndian(data.constData()), data.mid(2)); + } } } @@ -321,6 +329,10 @@ QT_USE_NAMESPACE QBluetoothDeviceInfo::DataIncomplete); } + const QList keys = qtAdvData.manufacturerData.keys(); + for (quint16 key : keys) + newDeviceInfo.setManufacturerData(key, qtAdvData.manufacturerData.value(key)); + // CoreBluetooth scans only for LE devices. newDeviceInfo.setCoreConfigurations(QBluetoothDeviceInfo::LowEnergyCoreConfiguration); emit notifier->deviceDiscovered(newDeviceInfo); -- cgit v1.2.1