@@ -252,6 +252,9 @@ void common_hal_bleio_packet_buffer_construct(
252
252
}
253
253
254
254
mp_int_t common_hal_bleio_packet_buffer_readinto (bleio_packet_buffer_obj_t * self , uint8_t * data , size_t len ) {
255
+ if (self -> conn_handle == BLE_CONN_HANDLE_INVALID ) {
256
+ mp_raise_ConnectionError (translate ("Not connected" ));
257
+ }
255
258
if (ringbuf_num_filled (& self -> ringbuf ) < 2 ) {
256
259
return 0 ;
257
260
}
@@ -357,8 +360,7 @@ mp_int_t common_hal_bleio_packet_buffer_get_incoming_packet_length(bleio_packet_
357
360
if (self -> conn_handle != BLE_CONN_HANDLE_INVALID ) {
358
361
bleio_connection_internal_t * connection = bleio_conn_handle_to_connection (self -> conn_handle );
359
362
if (connection ) {
360
- return MIN (common_hal_bleio_connection_get_max_packet_length (connection ),
361
- self -> characteristic -> max_length );
363
+ return common_hal_bleio_connection_get_max_packet_length (connection );
362
364
}
363
365
}
364
366
// There's no current connection, so we don't know the MTU, and
@@ -396,6 +398,18 @@ mp_int_t common_hal_bleio_packet_buffer_get_outgoing_packet_length(bleio_packet_
396
398
// we can't tell what the largest outgoing packet length would be.
397
399
return -1 ;
398
400
}
401
+ // If we are talking to a remote service, we'll be bound by the MTU. (We don't actually
402
+ // know the max size of the remote characteristic.)
403
+ if (self -> characteristic -> service != NULL &&
404
+ self -> characteristic -> service -> is_remote ) {
405
+ // We are talking to a remote service so we're writing.
406
+ if (self -> conn_handle != BLE_CONN_HANDLE_INVALID ) {
407
+ bleio_connection_internal_t * connection = bleio_conn_handle_to_connection (self -> conn_handle );
408
+ if (connection ) {
409
+ return common_hal_bleio_connection_get_max_packet_length (connection );
410
+ }
411
+ }
412
+ }
399
413
return self -> characteristic -> max_length ;
400
414
}
401
415
0 commit comments