Skip to content

Commit c5c6354

Browse files
author
Tzu-Jung Lee
committed
gatt: add Profind.Find() API
1 parent 911eead commit c5c6354

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

profile.go

+32
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,38 @@ type Profile struct {
3535
Services []*Service
3636
}
3737

38+
// Find searches discovered profile for the specified target's type and UUID.
39+
// The target must has the type of *Service, *Characteristic, or *Descriptor.
40+
func (p *Profile) Find(target interface{}) interface{} {
41+
switch target.(type) {
42+
case *Service:
43+
case *Characteristic:
44+
case *Descriptor:
45+
default:
46+
return nil
47+
}
48+
for _, s := range p.Services {
49+
ts, ok := target.(*Service)
50+
if ok && s.UUID.Equal(ts.UUID) {
51+
target = s
52+
return s
53+
}
54+
for _, c := range s.Characteristics {
55+
tc, ok := target.(*Characteristic)
56+
if ok && c.UUID.Equal(tc.UUID) {
57+
return c
58+
}
59+
for _, d := range c.Descriptors {
60+
td, ok := target.(*Descriptor)
61+
if ok && d.UUID.Equal(td.UUID) {
62+
return d
63+
}
64+
}
65+
}
66+
}
67+
return nil
68+
}
69+
3870
// A Service is a BLE service.
3971
type Service struct {
4072
UUID UUID

0 commit comments

Comments
 (0)