Skip to content

Commit

Permalink
Fixed issue in MacOS when notifying from standard UUIDs (#326)
Browse files Browse the repository at this point in the history
* Fixed issue in MacOS when notifying from standard UUIDs

* Rebased, updated changelog
  • Loading branch information
kdewald authored Jul 4, 2024
1 parent 0fd7881 commit 55329da
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The format is based on `Keep a Changelog`_, and this project adheres to `Semanti
**Fixed**

- (SimpleBluez) Fixed improper handling of non `org.Bluez.Service1` objects within a `org.bluez.Device1` object. *(Thanks Kober Engineering!)*
- (MacOS) Fixed incorrect storage and retrieval with standard Bluetooth UUIDs inside the peripheral class. *(Thanks TellowKrinkle!)*


[0.7.X]
Expand Down
18 changes: 9 additions & 9 deletions simpleble/src/backends/macos/PeripheralBaseMacOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ - (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]];
[self.characteristicExtras setObject:characteristicExtras forKey:uuidToString(characteristic.UUID)];
}
}
}
Expand Down Expand Up @@ -627,7 +627,7 @@ - (void)peripheral:(CBPeripheral*)peripheral
}

- (void)peripheral:(CBPeripheral*)peripheral didUpdateValueForCharacteristic:(CBCharacteristic*)characteristic error:(NSError*)error {
CharacteristicExtras* characteristicExtras = [self.characteristicExtras objectForKey:[[characteristic.UUID UUIDString] lowercaseString]];
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 +651,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 +663,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 +677,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 +688,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 55329da

Please sign in to comment.