Skip to content

Commit fbd688e

Browse files
authored
fix(darwin): Device.DiscoverServices() filters discovered services (#428)
* fix(darwin): Device.DiscoverServices() filters discovered services Currently, even if you pass a slice of services to discover. CoreBluetooth still discover ALL services. As per the CoreBluetooth documentation: "If the servicesUUIDs parameter is nil, this method returns all of the peripheral’s available services. This is much slower than providing an array of service UUIDs to search for." * fix(darwin): Device.DiscoverCharacteristics() filters discovered characteristics Currently, even if you pass a slice of characteristics to discover. CoreBluetooth still discover ALL characteristics. As per the CoreBluetooth documentation: " If the characteristicUUIDs parameter is nil, this method returns all of the service’s characteristics. This is much slower than providing an array of characteristic UUIDs to search for."
1 parent 5372045 commit fbd688e

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

gattc_darwin.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@ import (
1616
// Passing a nil slice of UUIDs will return a complete list of
1717
// services.
1818
func (d Device) DiscoverServices(uuids []UUID) ([]DeviceService, error) {
19-
d.prph.DiscoverServices([]cbgo.UUID{})
19+
cbuuids := make([]cbgo.UUID, len(uuids))
20+
for i, u := range uuids {
21+
cbuuid, err := cbgo.ParseUUID(u.String())
22+
if err != nil {
23+
return nil, err
24+
}
25+
cbuuids[i] = cbuuid
26+
}
27+
28+
d.prph.DiscoverServices(cbuuids)
2029

2130
// clear cache of services
2231
d.services = make(map[UUID]DeviceService)
@@ -106,7 +115,14 @@ func (s DeviceService) UUID() UUID {
106115
// Passing a nil slice of UUIDs will return a complete list of
107116
// characteristics.
108117
func (s DeviceService) DiscoverCharacteristics(uuids []UUID) ([]DeviceCharacteristic, error) {
109-
cbuuids := []cbgo.UUID{}
118+
cbuuids := make([]cbgo.UUID, len(uuids))
119+
for i, u := range uuids {
120+
cbuuid, err := cbgo.ParseUUID(u.String())
121+
if err != nil {
122+
return nil, err
123+
}
124+
cbuuids[i] = cbuuid
125+
}
110126

111127
s.device.prph.DiscoverCharacteristics(cbuuids, s.service)
112128

0 commit comments

Comments
 (0)