Skip to content

Commit

Permalink
Fixed issue in MacOS when notifying from standard UUIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
kdewald committed Jul 3, 2024
1 parent 608d225 commit 6ac37c7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
20 changes: 11 additions & 9 deletions simpleble/src/backends/macos/PeripheralBaseMacOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,13 @@ - (void)connect {
for (CBDescriptor* descriptor in characteristic.descriptors) {
@synchronized(self) {
[characteristicExtras.descriptorExtras setObject:[[DescriptorExtras alloc] init]
forKey:[[descriptor.UUID UUIDString] lowercaseString]];
forKey:uuidToString(descriptor.UUID)];
}
}

@synchronized(self) {
[self.characteristicExtras setObject:characteristicExtras forKey:[[characteristic.UUID UUIDString] lowercaseString]];
NSLog(@"Characteristic %@ loaded", [characteristic.UUID UUIDString]);
[self.characteristicExtras setObject:characteristicExtras forKey:uuidToString(characteristic.UUID)];
}
}
}
Expand Down Expand Up @@ -627,7 +628,8 @@ - (void)peripheral:(CBPeripheral*)peripheral
}

- (void)peripheral:(CBPeripheral*)peripheral didUpdateValueForCharacteristic:(CBCharacteristic*)characteristic error:(NSError*)error {
CharacteristicExtras* characteristicExtras = [self.characteristicExtras objectForKey:[[characteristic.UUID UUIDString] lowercaseString]];
NSLog(@"Characteristic %@ updated", [characteristic.UUID UUIDString]);
CharacteristicExtras* characteristicExtras = [self.characteristicExtras objectForKey:uuidToString(characteristic.UUID)];

if (characteristic.isNotifying) {
// If the characteristic is notifying, just save the value and trigger the callback.
Expand All @@ -651,7 +653,7 @@ - (void)peripheral:(CBPeripheral*)peripheral didUpdateValueForCharacteristic:(CB
}

- (void)peripheral:(CBPeripheral*)peripheral didWriteValueForCharacteristic:(CBCharacteristic*)characteristic error:(NSError*)error {
CharacteristicExtras* characteristicExtras = [self.characteristicExtras objectForKey:[[characteristic.UUID UUIDString] lowercaseString]];
CharacteristicExtras* characteristicExtras = [self.characteristicExtras objectForKey:uuidToString(characteristic.UUID)];
BleTask* task = characteristicExtras.task;

@synchronized(self) {
Expand All @@ -663,7 +665,7 @@ - (void)peripheral:(CBPeripheral*)peripheral didWriteValueForCharacteristic:(CBC
- (void)peripheral:(CBPeripheral*)peripheral
didUpdateNotificationStateForCharacteristic:(CBCharacteristic*)characteristic
error:(NSError*)error {
CharacteristicExtras* characteristicExtras = [self.characteristicExtras objectForKey:[[characteristic.UUID UUIDString] lowercaseString]];
CharacteristicExtras* characteristicExtras = [self.characteristicExtras objectForKey:uuidToString(characteristic.UUID)];
BleTask* task = characteristicExtras.task;

@synchronized(self) {
Expand All @@ -677,8 +679,8 @@ - (void)peripheralIsReadyToSendWriteWithoutResponse:(CBPeripheral*)peripheral {
}

- (void)peripheral:(CBPeripheral*)peripheral didUpdateValueForDescriptor:(CBDescriptor*)descriptor error:(NSError*)error {
CharacteristicExtras* characteristicExtras = [self.characteristicExtras objectForKey:[[descriptor.characteristic.UUID UUIDString] lowercaseString]];
DescriptorExtras* descriptorExtras = [characteristicExtras.descriptorExtras objectForKey:[[descriptor.UUID UUIDString] lowercaseString]];
CharacteristicExtras* characteristicExtras = [self.characteristicExtras objectForKey:uuidToString(descriptor.characteristic.UUID)];
DescriptorExtras* descriptorExtras = [characteristicExtras.descriptorExtras objectForKey:uuidToString(descriptor.UUID)];
BleTask* task = descriptorExtras.task;

@synchronized(self) {
Expand All @@ -688,8 +690,8 @@ - (void)peripheral:(CBPeripheral*)peripheral didUpdateValueForDescriptor:(CBDesc
}

- (void)peripheral:(CBPeripheral*)peripheral didWriteValueForDescriptor:(CBDescriptor*)descriptor error:(NSError*)error {
CharacteristicExtras* characteristicExtras = [self.characteristicExtras objectForKey:[[descriptor.characteristic.UUID UUIDString] lowercaseString]];
DescriptorExtras* descriptorExtras = [characteristicExtras.descriptorExtras objectForKey:[[descriptor.UUID UUIDString] lowercaseString]];
CharacteristicExtras* characteristicExtras = [self.characteristicExtras objectForKey:uuidToString(descriptor.characteristic.UUID)];
DescriptorExtras* descriptorExtras = [characteristicExtras.descriptorExtras objectForKey:uuidToString(descriptor.UUID)];
BleTask* task = descriptorExtras.task;

@synchronized(self) {
Expand Down
1 change: 1 addition & 0 deletions simpleble/src/backends/macos/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
#include <simpleble/Types.h>

SimpleBLE::BluetoothUUID uuidToSimpleBLE(CBUUID* uuid);
NSString* uuidToString(CBUUID* uuid);
10 changes: 10 additions & 0 deletions simpleble/src/backends/macos/Utils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@
return uuid_raw;
}
}

NSString* uuidToString(CBUUID* uuid) {
NSString* uuidString = [[uuid UUIDString] lowercaseString];

if ([uuidString length] == 4) {
return [NSString stringWithFormat:@"0000%@-0000-1000-8000-00805f9b34fb", uuidString];
} else {
return uuidString;
}
}

0 comments on commit 6ac37c7

Please sign in to comment.