Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue in MacOS when notifying from standard UUIDs #326

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading