Skip to content

Commit

Permalink
Cleanup, update s113v7
Browse files Browse the repository at this point in the history
  • Loading branch information
rdnt committed Oct 6, 2024
1 parent 22f1116 commit a719fbf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 0 additions & 2 deletions adapter_nrf528xx-full.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ func handleEvent() {
// way to handle it, ignore it.
C.sd_ble_gatts_sys_attr_set(gattsEvent.conn_handle, nil, 0, 0)
case C.BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST:
// This event is generated by some devices. While we could support
// larger MTUs, this default MTU is supported everywhere.
rsp := gattsEvent.params.unionfield_exchange_mtu_request()
effectiveMtu := min(DefaultAdapter.cfg.Gatt.AttMtu, uint16(rsp.client_rx_mtu))
if debug {
Expand Down
20 changes: 17 additions & 3 deletions adapter_nrf528xx-peripheral.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,16 @@ func handleEvent() {
// way to handle it, ignore it.
C.sd_ble_gatts_sys_attr_set(gattsEvent.conn_handle, nil, 0, 0)
case C.BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST:
// This event is generated by some devices. While we could support
// larger MTUs, this default MTU is supported everywhere.
C.sd_ble_gatts_exchange_mtu_reply(gattsEvent.conn_handle, C.BLE_GATT_ATT_MTU_DEFAULT)
rsp := gattsEvent.params.unionfield_exchange_mtu_request()
effectiveMtu := min(DefaultAdapter.cfg.Gatt.AttMtu, uint16(rsp.client_rx_mtu))
if debug {
println("mtu exchange requested. self:", DefaultAdapter.cfg.Gatt.AttMtu, ", peer:", rsp.client_rx_mtu, ", effective:", effectiveMtu)
}

var errCode = C.sd_ble_gatts_exchange_mtu_reply(gattsEvent.conn_handle, C.uint16_t(effectiveMtu))
if debug {
println("mtu exchange replied, err:", Error(errCode).Error())
}
case C.BLE_GATTS_EVT_HVN_TX_COMPLETE:
// ignore confirmation of a notification successfully sent
default:
Expand All @@ -107,3 +114,10 @@ func handleEvent() {
}
}
}

func min(a, b uint16) uint16 {
if a < b {
return a
}
return b
}

0 comments on commit a719fbf

Please sign in to comment.