softdevice: add address of connecting device
I thought it wasn't available, but in fact it is. So let's make it available in the connect handler.
This commit is contained in:
parent
735333aa1a
commit
6e0df0ec3c
4 changed files with 25 additions and 6 deletions
|
@ -43,7 +43,9 @@ func handleEvent() {
|
|||
switch id {
|
||||
case C.BLE_GAP_EVT_CONNECTED:
|
||||
currentConnection.handle.Reg = uint16(gapEvent.conn_handle)
|
||||
DefaultAdapter.connectHandler(Address{}, true)
|
||||
connectEvent := gapEvent.params.unionfield_connected()
|
||||
address := Address{makeMACAddress(connectEvent.peer_addr)}
|
||||
DefaultAdapter.connectHandler(address, true)
|
||||
case C.BLE_GAP_EVT_DISCONNECTED:
|
||||
if defaultAdvertisement.isAdvertising.Get() != 0 {
|
||||
// The advertisement was running but was automatically stopped
|
||||
|
@ -111,3 +113,11 @@ func (a *Adapter) Address() (MACAddress, error) {
|
|||
}
|
||||
return MACAddress{MAC: makeAddress(addr.addr)}, nil
|
||||
}
|
||||
|
||||
// Convert a C.ble_gap_addr_t to a MACAddress struct.
|
||||
func makeMACAddress(addr C.ble_gap_addr_t) MACAddress {
|
||||
return MACAddress{
|
||||
MAC: makeAddress(addr.addr),
|
||||
isRandom: addr.addr_type != 0,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,20 +25,21 @@ func handleEvent() {
|
|||
switch id {
|
||||
case C.BLE_GAP_EVT_CONNECTED:
|
||||
connectEvent := gapEvent.params.unionfield_connected()
|
||||
address := Address{makeMACAddress(connectEvent.peer_addr)}
|
||||
switch connectEvent.role {
|
||||
case C.BLE_GAP_ROLE_PERIPH:
|
||||
if debug {
|
||||
println("evt: connected in peripheral role")
|
||||
}
|
||||
currentConnection.handle.Reg = uint16(gapEvent.conn_handle)
|
||||
DefaultAdapter.connectHandler(Address{}, true)
|
||||
DefaultAdapter.connectHandler(address, true)
|
||||
case C.BLE_GAP_ROLE_CENTRAL:
|
||||
if debug {
|
||||
println("evt: connected in central role")
|
||||
}
|
||||
connectionAttempt.connectionHandle = gapEvent.conn_handle
|
||||
connectionAttempt.state.Set(2) // connection was successful
|
||||
DefaultAdapter.connectHandler(Address{}, true)
|
||||
DefaultAdapter.connectHandler(address, true)
|
||||
}
|
||||
case C.BLE_GAP_EVT_DISCONNECTED:
|
||||
if debug {
|
||||
|
@ -81,8 +82,7 @@ func handleEvent() {
|
|||
scanReportBuffer.len = byte(advReport.data.len)
|
||||
globalScanResult.RSSI = int16(advReport.rssi)
|
||||
globalScanResult.Address = Address{
|
||||
MACAddress{MAC: makeAddress(advReport.peer_addr.addr),
|
||||
isRandom: advReport.peer_addr.bitfield_addr_type() != 0},
|
||||
makeMACAddress(advReport.peer_addr),
|
||||
}
|
||||
globalScanResult.AdvertisementPayload = &scanReportBuffer
|
||||
// Signal to the main thread that there was a scan report.
|
||||
|
|
|
@ -28,7 +28,8 @@ func handleEvent() {
|
|||
println("evt: connected in peripheral role")
|
||||
}
|
||||
currentConnection.handle.Reg = uint16(gapEvent.conn_handle)
|
||||
DefaultAdapter.connectHandler(Address{}, true)
|
||||
connectEvent := gapEvent.params.unionfield_connected()
|
||||
DefaultAdapter.connectHandler(Address{makeMACAddress(connectEvent.peer_addr)}, true)
|
||||
case C.BLE_GAP_EVT_DISCONNECTED:
|
||||
if debug {
|
||||
println("evt: disconnected")
|
||||
|
|
|
@ -59,3 +59,11 @@ func (a *Adapter) Address() (MACAddress, error) {
|
|||
}
|
||||
return MACAddress{MAC: makeAddress(addr.addr)}, nil
|
||||
}
|
||||
|
||||
// Convert a C.ble_gap_addr_t to a MACAddress struct.
|
||||
func makeMACAddress(addr C.ble_gap_addr_t) MACAddress {
|
||||
return MACAddress{
|
||||
MAC: makeAddress(addr.addr),
|
||||
isRandom: addr.bitfield_addr_type() != 0,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue