|
47 | 47 | from pc_ble_driver_py.exceptions import NordicSemiException, IllegalStateException
|
48 | 48 | from pc_ble_driver_py.ble_driver import BLEDriver, BLEDriverObserver, BLEEnableParams, BLEUUIDBase, BLEGapSecKDist, BLEGapSecParams, \
|
49 | 49 | BLEGapIOCaps, BLEUUID, BLEAdvData, BLEGapConnParams, NordicSemiErrorCheck, BLEGapSecStatus, driver
|
50 |
| -from pc_ble_driver_py.ble_driver import ATT_MTU_DEFAULT, BLEConfig, BLEConfigConnGatt |
| 50 | +from pc_ble_driver_py.ble_driver import ATT_MTU_DEFAULT, BLEConfig, BLEConfigConnGatt, BLEConfigConnGap |
51 | 51 | from pc_ble_driver_py.ble_adapter import BLEAdapter, BLEAdapterObserver, EvtSync
|
52 | 52 |
|
53 | 53 | logger = logging.getLogger(__name__)
|
@@ -120,6 +120,9 @@ def open(self):
|
120 | 120 | BLEConfig.conn_gatt,
|
121 | 121 | BLEConfigConnGatt(att_mtu=DFUAdapter.LOCAL_ATT_MTU),
|
122 | 122 | )
|
| 123 | + self.adapter.driver.ble_cfg_set( |
| 124 | + BLEConfig.conn_gap, |
| 125 | + BLEConfigConnGap(event_length=5)) # Event length 5 is required for max data length |
123 | 126 | self.adapter.driver.ble_enable()
|
124 | 127 |
|
125 | 128 | self.adapter.driver.ble_vs_uuid_add(DFUAdapter.BASE_UUID)
|
@@ -168,6 +171,13 @@ def connect(self, target_device_name, target_device_addr):
|
168 | 171 | if DFUAdapter.LOCAL_ATT_MTU > ATT_MTU_DEFAULT:
|
169 | 172 | logger.info('BLE: Enabling longer ATT MTUs')
|
170 | 173 | self.att_mtu = self.adapter.att_mtu_exchange(self.conn_handle, DFUAdapter.LOCAL_ATT_MTU)
|
| 174 | + |
| 175 | + logger.info('BLE: Enabling longer Data Length') |
| 176 | + max_data_length = 251 # Max data length for SD v5 |
| 177 | + data_length = self.att_mtu + 4 # ATT PDU overhead is 4 |
| 178 | + if data_length > max_data_length: |
| 179 | + data_length = max_data_length |
| 180 | + self.adapter.data_length_update(self.conn_handle, data_length) |
171 | 181 | else:
|
172 | 182 | logger.info('BLE: Using default ATT MTU')
|
173 | 183 |
|
|
0 commit comments