-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathoption.go
113 lines (98 loc) · 2.71 KB
/
option.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package ble
import (
"time"
"github.com/rigado/ble/linux/hci/cmd"
)
// DeviceOption is an interface which the device should implement to allow using configuration options
type DeviceOption interface {
SetDeviceID(int) error
SetDialerTimeout(time.Duration) error
SetListenerTimeout(time.Duration) error
SetConnParams(cmd.LECreateConnection) error
SetScanParams(cmd.LESetScanParameters) error
SetAdvParams(cmd.LESetAdvertisingParameters) error
SetPeripheralRole() error
SetCentralRole() error
SetAdvHandlerSync(bool) error
SetErrorHandler(handler func(error)) error
EnableSecurity(interface{}) error
}
// An Option is a configuration function, which configures the device.
type Option func(DeviceOption) error
// OptDeviceID sets HCI device ID.
func OptDeviceID(id int) Option {
return func(opt DeviceOption) error {
opt.SetDeviceID(id)
return nil
}
}
// OptDialerTimeout sets dialing timeout for Dialer.
func OptDialerTimeout(d time.Duration) Option {
return func(opt DeviceOption) error {
opt.SetDialerTimeout(d)
return nil
}
}
// OptListenerTimeout sets dialing timeout for Listener.
func OptListenerTimeout(d time.Duration) Option {
return func(opt DeviceOption) error {
opt.SetListenerTimeout(d)
return nil
}
}
// OptConnParams overrides default connection parameters.
func OptConnParams(param cmd.LECreateConnection) Option {
return func(opt DeviceOption) error {
opt.SetConnParams(param)
return nil
}
}
// OptScanParams overrides default scanning parameters.
func OptScanParams(param cmd.LESetScanParameters) Option {
return func(opt DeviceOption) error {
opt.SetScanParams(param)
return nil
}
}
// OptAdvParams overrides default advertising parameters.
func OptAdvParams(param cmd.LESetAdvertisingParameters) Option {
return func(opt DeviceOption) error {
opt.SetAdvParams(param)
return nil
}
}
// OptPeripheralRole configures the device to perform Peripheral tasks.
func OptPeripheralRole() Option {
return func(opt DeviceOption) error {
opt.SetPeripheralRole()
return nil
}
}
// OptCentralRole configures the device to perform Central tasks.
func OptCentralRole() Option {
return func(opt DeviceOption) error {
opt.SetCentralRole()
return nil
}
}
// OptAdvHandlerSync sets sync adv handling
func OptAdvHandlerSync(sync bool) Option {
return func(opt DeviceOption) error {
opt.SetAdvHandlerSync(sync)
return nil
}
}
// OptErrorHandler sets error handler
func OptErrorHandler(handler func(error)) Option {
return func(opt DeviceOption) error {
opt.SetErrorHandler(handler)
return nil
}
}
// OptEnableSecurity enables bonding with devices
func OptEnableSecurity(bondManager interface{}) Option {
return func(opt DeviceOption) error {
opt.EnableSecurity(bondManager)
return nil
}
}