Skip to content

Commit

Permalink
[Darwin] Add more logging related to the cache in src/platform/Darwin…
Browse files Browse the repository at this point in the history
…/BleConnectionDelegateImpl.mm (#26748)
  • Loading branch information
vivien-apple authored and pull[bot] committed Oct 5, 2023
1 parent 43350c9 commit c67a1db
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/platform/Darwin/BleConnectionDelegateImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -651,9 +651,16 @@ - (void)addPeripheralToCache:(CBPeripheral *)peripheral data:(NSData *)data
{
dispatch_source_t timeoutTimer;

bool shouldLogData = true;
if ([_cachedPeripherals objectForKey:peripheral]) {
shouldLogData = ![data isEqualToData:_cachedPeripherals[peripheral][@"data"]];
if (shouldLogData) {
ChipLogProgress(Ble, "Updating peripheral %p from the cache", peripheral);
}

timeoutTimer = _cachedPeripherals[peripheral][@"timer"];
} else {
ChipLogProgress(Ble, "Adding peripheral %p to the cache", peripheral);
auto delegate = _scannerDelegate;
if (delegate) {
dispatch_async(_chipWorkQueue, ^{
Expand All @@ -678,12 +685,25 @@ - (void)addPeripheralToCache:(CBPeripheral *)peripheral data:(NSData *)data
@"data" : data,
@"timer" : timeoutTimer,
};

if (shouldLogData) {
ChipBLEDeviceIdentificationInfo info;
auto bytes = (const uint8_t *) [data bytes];
memcpy(&info, bytes, sizeof(info));

ChipLogProgress(Ble, " - Version: %u", info.GetAdvertisementVersion());
ChipLogProgress(Ble, " - Discriminator: %u", info.GetDeviceDiscriminator());
ChipLogProgress(Ble, " - VendorId: %u", info.GetVendorId());
ChipLogProgress(Ble, " - ProductId: %u", info.GetVendorId());
}
}

- (void)removePeripheralFromCache:(CBPeripheral *)peripheral
{
auto entry = [_cachedPeripherals objectForKey:peripheral];
if (entry) {
ChipLogProgress(Ble, "Removing peripheral %p from the cache", peripheral);

dispatch_source_cancel(entry[@"timer"]);
[_cachedPeripherals removeObjectForKey:peripheral];

Expand Down

0 comments on commit c67a1db

Please sign in to comment.