Skip to content

Commit c67a1db

Browse files
vivien-applepull[bot]
authored andcommitted
[Darwin] Add more logging related to the cache in src/platform/Darwin/BleConnectionDelegateImpl.mm (#26748)
1 parent 43350c9 commit c67a1db

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/platform/Darwin/BleConnectionDelegateImpl.mm

+20
Original file line numberDiff line numberDiff line change
@@ -651,9 +651,16 @@ - (void)addPeripheralToCache:(CBPeripheral *)peripheral data:(NSData *)data
651651
{
652652
dispatch_source_t timeoutTimer;
653653

654+
bool shouldLogData = true;
654655
if ([_cachedPeripherals objectForKey:peripheral]) {
656+
shouldLogData = ![data isEqualToData:_cachedPeripherals[peripheral][@"data"]];
657+
if (shouldLogData) {
658+
ChipLogProgress(Ble, "Updating peripheral %p from the cache", peripheral);
659+
}
660+
655661
timeoutTimer = _cachedPeripherals[peripheral][@"timer"];
656662
} else {
663+
ChipLogProgress(Ble, "Adding peripheral %p to the cache", peripheral);
657664
auto delegate = _scannerDelegate;
658665
if (delegate) {
659666
dispatch_async(_chipWorkQueue, ^{
@@ -678,12 +685,25 @@ - (void)addPeripheralToCache:(CBPeripheral *)peripheral data:(NSData *)data
678685
@"data" : data,
679686
@"timer" : timeoutTimer,
680687
};
688+
689+
if (shouldLogData) {
690+
ChipBLEDeviceIdentificationInfo info;
691+
auto bytes = (const uint8_t *) [data bytes];
692+
memcpy(&info, bytes, sizeof(info));
693+
694+
ChipLogProgress(Ble, " - Version: %u", info.GetAdvertisementVersion());
695+
ChipLogProgress(Ble, " - Discriminator: %u", info.GetDeviceDiscriminator());
696+
ChipLogProgress(Ble, " - VendorId: %u", info.GetVendorId());
697+
ChipLogProgress(Ble, " - ProductId: %u", info.GetVendorId());
698+
}
681699
}
682700

683701
- (void)removePeripheralFromCache:(CBPeripheral *)peripheral
684702
{
685703
auto entry = [_cachedPeripherals objectForKey:peripheral];
686704
if (entry) {
705+
ChipLogProgress(Ble, "Removing peripheral %p from the cache", peripheral);
706+
687707
dispatch_source_cancel(entry[@"timer"]);
688708
[_cachedPeripherals removeObjectForKey:peripheral];
689709

0 commit comments

Comments
 (0)