7
7
"errors"
8
8
"runtime/volatile"
9
9
"time"
10
+ "unsafe"
10
11
)
11
12
12
13
/*
@@ -40,12 +41,12 @@ func (a *Adapter) Scan(callback func(*Adapter, ScanResult)) error {
40
41
scanParams := C.ble_gap_scan_params_t {}
41
42
scanParams .set_bitfield_extended (0 )
42
43
scanParams .set_bitfield_active (0 )
43
- scanParams .interval = uint16 (NewDuration (40 * time .Millisecond ))
44
- scanParams .window = uint16 (NewDuration (30 * time .Millisecond ))
44
+ scanParams .interval = C . uint16_t (NewDuration (40 * time .Millisecond ))
45
+ scanParams .window = C . uint16_t (NewDuration (30 * time .Millisecond ))
45
46
scanParams .timeout = C .BLE_GAP_SCAN_TIMEOUT_UNLIMITED
46
47
scanReportBufferInfo := C.ble_data_t {
47
- p_data : & scanReportBuffer .data [0 ],
48
- len : uint16 (len (scanReportBuffer .data )),
48
+ p_data : ( * C . uint8_t )( unsafe . Pointer ( & scanReportBuffer .data [0 ])) ,
49
+ len : C . uint16_t (len (scanReportBuffer .data )),
49
50
}
50
51
errCode := C .sd_ble_gap_scan_start (& scanParams , & scanReportBufferInfo )
51
52
if errCode != 0 {
@@ -93,13 +94,13 @@ func (a *Adapter) StopScan() error {
93
94
94
95
// Device is a connection to a remote peripheral.
95
96
type Device struct {
96
- connectionHandle uint16
97
+ connectionHandle C. uint16_t
97
98
}
98
99
99
100
// In-progress connection attempt.
100
101
var connectionAttempt struct {
101
102
state volatile.Register8 // 0 means unused, 1 means connecting, 2 means ready (connected or timeout)
102
- connectionHandle uint16
103
+ connectionHandle C. uint16_t
103
104
}
104
105
105
106
// Connect starts a connection attempt to the given peripheral device address.
@@ -111,7 +112,7 @@ var connectionAttempt struct {
111
112
func (a * Adapter ) Connect (address Address , params ConnectionParams ) (* Device , error ) {
112
113
// Construct an address object as used in the SoftDevice.
113
114
var addr C.ble_gap_addr_t
114
- addr .addr = address .MAC
115
+ addr .addr = makeSDAddress ( address .MAC )
115
116
if address .IsRandom () {
116
117
switch address .MAC [5 ] >> 6 {
117
118
case 0b11 :
@@ -142,13 +143,13 @@ func (a *Adapter) Connect(address Address, params ConnectionParams) (*Device, er
142
143
scanParams := C.ble_gap_scan_params_t {}
143
144
scanParams .set_bitfield_extended (0 )
144
145
scanParams .set_bitfield_active (0 )
145
- scanParams .interval = uint16 (NewDuration (40 * time .Millisecond ))
146
- scanParams .window = uint16 (NewDuration (30 * time .Millisecond ))
147
- scanParams .timeout = uint16 (params .ConnectionTimeout )
146
+ scanParams .interval = C . uint16_t (NewDuration (40 * time .Millisecond ))
147
+ scanParams .window = C . uint16_t (NewDuration (30 * time .Millisecond ))
148
+ scanParams .timeout = C . uint16_t (params .ConnectionTimeout )
148
149
149
150
connectionParams := C.ble_gap_conn_params_t {
150
- min_conn_interval : uint16 (params .MinInterval ) / 2 ,
151
- max_conn_interval : uint16 (params .MaxInterval ) / 2 ,
151
+ min_conn_interval : C . uint16_t (params .MinInterval ) / 2 ,
152
+ max_conn_interval : C . uint16_t (params .MaxInterval ) / 2 ,
152
153
slave_latency : 0 , // mostly relevant to connected keyboards etc
153
154
conn_sup_timeout : 200 , // 2 seconds (in 10ms units), the minimum recommended by Apple
154
155
}
0 commit comments