File tree 1 file changed +32
-0
lines changed
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,38 @@ type Profile struct {
35
35
Services []* Service
36
36
}
37
37
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
+
38
70
// A Service is a BLE service.
39
71
type Service struct {
40
72
UUID UUID
You can’t perform that action at this time.
0 commit comments