Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Add data_length_update to BLE DFU (#293)
Browse files Browse the repository at this point in the history
* Add data length update for ble dfu

Data length update needs to be called explicitly in SD v5, it's not automatically adjusted with ATT MTU exchange as in SD v3

* Update required version for pc_ble_driver_py

Need pc_ble_driver_py 0.14.1 to get data_length_update feature
  • Loading branch information
bihanssen authored Dec 20, 2019
1 parent 7b3627d commit aa033ad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion nordicsemi/dfu/dfu_transport_ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
from pc_ble_driver_py.exceptions import NordicSemiException, IllegalStateException
from pc_ble_driver_py.ble_driver import BLEDriver, BLEDriverObserver, BLEEnableParams, BLEUUIDBase, BLEGapSecKDist, BLEGapSecParams, \
BLEGapIOCaps, BLEUUID, BLEAdvData, BLEGapConnParams, NordicSemiErrorCheck, BLEGapSecStatus, driver
from pc_ble_driver_py.ble_driver import ATT_MTU_DEFAULT, BLEConfig, BLEConfigConnGatt
from pc_ble_driver_py.ble_driver import ATT_MTU_DEFAULT, BLEConfig, BLEConfigConnGatt, BLEConfigConnGap
from pc_ble_driver_py.ble_adapter import BLEAdapter, BLEAdapterObserver, EvtSync

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -120,6 +120,9 @@ def open(self):
BLEConfig.conn_gatt,
BLEConfigConnGatt(att_mtu=DFUAdapter.LOCAL_ATT_MTU),
)
self.adapter.driver.ble_cfg_set(
BLEConfig.conn_gap,
BLEConfigConnGap(event_length=5)) # Event length 5 is required for max data length
self.adapter.driver.ble_enable()

self.adapter.driver.ble_vs_uuid_add(DFUAdapter.BASE_UUID)
Expand Down Expand Up @@ -168,6 +171,13 @@ def connect(self, target_device_name, target_device_addr):
if DFUAdapter.LOCAL_ATT_MTU > ATT_MTU_DEFAULT:
logger.info('BLE: Enabling longer ATT MTUs')
self.att_mtu = self.adapter.att_mtu_exchange(self.conn_handle, DFUAdapter.LOCAL_ATT_MTU)

logger.info('BLE: Enabling longer Data Length')
max_data_length = 251 # Max data length for SD v5
data_length = self.att_mtu + 4 # ATT PDU overhead is 4
if data_length > max_data_length:
data_length = max_data_length
self.adapter.data_length_update(self.conn_handle, data_length)
else:
logger.info('BLE: Using default ATT MTU')

Expand Down
2 changes: 1 addition & 1 deletion requirements-frozen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ecdsa==0.13.3
intelhex==2.2.1
ipaddress==1.0.22
libusb1==1.7.1
pc-ble-driver-py==0.14.0
pc-ble-driver-py==0.14.1
piccata==2.0.1
protobuf==3.10.0
pyserial==3.4
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ crcmod
ecdsa
intelhex
libusb1
pc_ble_driver_py >= 0.14.0
pc_ble_driver_py >= 0.14.1
piccata
protobuf
pyserial
Expand Down

0 comments on commit aa033ad

Please sign in to comment.