25
25
26
26
#include < cstdint>
27
27
#include < cstring>
28
+ #include < strings.h>
28
29
#include < utility>
29
30
30
31
#include < bluetooth.h>
@@ -55,31 +56,16 @@ std::unique_ptr<ChipDeviceScanner> ChipDeviceScanner::Create(ChipDeviceScannerDe
55
56
return std::make_unique<ChipDeviceScanner>(delegate);
56
57
}
57
58
58
- static void __CleanupServiceData ( bt_adapter_le_service_data_s * dataList, size_t count )
59
+ static void __PrintLEScanData ( const bt_adapter_le_service_data_s & data )
59
60
{
60
- VerifyOrReturn (dataList != nullptr );
61
- VerifyOrReturn (count != 0 );
62
-
63
- for (size_t i = 0 ; i < count; i++)
64
- {
65
- g_free (dataList[i].service_uuid );
66
- g_free (dataList[i].service_data );
67
- }
68
- g_free (dataList);
69
- }
70
-
71
- static void __PrintLEScanData (bt_adapter_le_service_data_s * dataList, size_t idx)
72
- {
73
- VerifyOrReturn (dataList != nullptr );
74
-
75
61
// Print Service UUID in the Service Data
76
62
ChipLogDetail (DeviceLayer, " ======Service UUID========" );
77
- ChipLogDetail (DeviceLayer, " Service UUID::[%s]" , dataList[idx] .service_uuid );
63
+ ChipLogDetail (DeviceLayer, " Service UUID::[%s]" , data .service_uuid );
78
64
79
65
// Print Service Data
80
66
ChipLogDetail (DeviceLayer, " ======Service Data========" );
81
- ChipLogDetail (DeviceLayer, " Service Data Length::[%d]" , dataList[idx] .service_data_len );
82
- ChipLogByteSpan (DeviceLayer, ByteSpan (reinterpret_cast <uint8_t *>(dataList[idx] .service_data ), dataList[idx] .service_data_len ));
67
+ ChipLogDetail (DeviceLayer, " Service Data Length::[%d]" , data .service_data_len );
68
+ ChipLogByteSpan (DeviceLayer, ByteSpan (reinterpret_cast <uint8_t *>(data .service_data ), data .service_data_len ));
83
69
}
84
70
85
71
static bool __IsChipThingDevice (bt_adapter_le_device_scan_result_info_s * info,
@@ -91,25 +77,22 @@ static bool __IsChipThingDevice(bt_adapter_le_device_scan_result_info_s * info,
91
77
bt_adapter_le_service_data_s * dataList = nullptr ;
92
78
bool isChipDevice = false ;
93
79
94
- ChipLogProgress (DeviceLayer, " Is [%s] ChipThingDevice ?: Check now" , info->remote_address );
95
-
96
80
if (bt_adapter_le_get_scan_result_service_data_list (info, BT_ADAPTER_LE_PACKET_ADVERTISING, &dataList, &count) == BT_ERROR_NONE)
97
81
{
98
82
for (int i = 0 ; i < count; i++)
99
83
{
100
- if (g_strcmp0 (dataList[i].service_uuid , chip::Ble::CHIP_BLE_CHAR_1_UUID_STR ) == 0 ||
101
- g_strcmp0 (dataList[i].service_uuid , chip::Ble::CHIP_BLE_SERVICE_SHORT_UUID_STR) == 0 )
84
+ if (strcasecmp (dataList[i].service_uuid , chip::Ble::CHIP_BLE_SERVICE_LONG_UUID_STR ) == 0 ||
85
+ strcasecmp (dataList[i].service_uuid , chip::Ble::CHIP_BLE_SERVICE_SHORT_UUID_STR) == 0 )
102
86
{
103
- ChipLogProgress (DeviceLayer, " CHIP Thing Device Found! [Service Data UUID] = %s" , dataList[i].service_uuid );
104
- // Print full Service Data
105
- __PrintLEScanData (dataList, i);
87
+ __PrintLEScanData (dataList[i]);
106
88
memcpy (&aDeviceInfo, dataList[i].service_data , dataList[i].service_data_len );
107
89
isChipDevice = true ;
108
90
break ;
109
91
}
110
92
}
111
93
}
112
- __CleanupServiceData (dataList, count);
94
+
95
+ bt_adapter_le_free_service_data_list (dataList, count);
113
96
return isChipDevice;
114
97
}
115
98
@@ -120,17 +103,12 @@ void ChipDeviceScanner::LeScanResultCb(int result, bt_adapter_le_device_scan_res
120
103
auto self = reinterpret_cast <ChipDeviceScanner *>(userData);
121
104
chip::Ble::ChipBLEDeviceIdentificationInfo deviceInfo;
122
105
123
- ChipLogProgress (DeviceLayer, " LE Device Reported!! remote addr [%s]" , info->remote_address );
106
+ ChipLogProgress (DeviceLayer, " LE device reported: %s" , info->remote_address );
107
+ VerifyOrReturn (__IsChipThingDevice (info, deviceInfo),
108
+ ChipLogDetail (Ble, " Device %s does not look like a CHIP device" , info->remote_address ));
124
109
125
- if (__IsChipThingDevice (info, deviceInfo))
126
- {
127
- // Looks like a CHIP Thing Device: Service UUID matched
128
- ChipLogProgress (DeviceLayer, " Looks Like Got a CHIP Thing Device: Process further" );
129
- // Report probable CHIP Thing Device to BLEMgrImp class
130
- self->mDelegate ->OnChipDeviceScanned (info, deviceInfo);
131
- }
132
- else
133
- ChipLogProgress (DeviceLayer, " Does not Look like a CHIP Device, Skip....." );
110
+ // Report probable CHIP device to BLEMgrImp class
111
+ self->mDelegate ->OnChipDeviceScanned (info, deviceInfo);
134
112
}
135
113
136
114
gboolean ChipDeviceScanner::TimerExpiredCb (gpointer userData)
0 commit comments