@@ -81,7 +81,7 @@ void bleio_packet_buffer_update(bleio_packet_buffer_obj_t *self, mp_buffer_info_
81
81
82
82
void common_hal_bleio_packet_buffer_construct (
83
83
bleio_packet_buffer_obj_t * self , bleio_characteristic_obj_t * characteristic ,
84
- size_t buffer_size ) {
84
+ size_t buffer_size , size_t max_packet_size ) {
85
85
86
86
self -> characteristic = characteristic ;
87
87
self -> client = self -> characteristic -> service -> is_remote ;
@@ -101,7 +101,7 @@ void common_hal_bleio_packet_buffer_construct(
101
101
}
102
102
103
103
if (incoming ) {
104
- if (!ringbuf_alloc (& self -> ringbuf , buffer_size * (sizeof (uint16_t ) + characteristic -> max_length ), false)) {
104
+ if (!ringbuf_alloc (& self -> ringbuf , buffer_size * (sizeof (uint16_t ) + max_packet_size ), false)) {
105
105
mp_raise_ValueError (translate ("Buffer too large and unable to allocate" ));
106
106
}
107
107
}
@@ -110,12 +110,13 @@ void common_hal_bleio_packet_buffer_construct(
110
110
self -> packet_queued = false;
111
111
self -> pending_index = 0 ;
112
112
self -> pending_size = 0 ;
113
- self -> outgoing [0 ] = m_malloc (characteristic -> max_length , false);
114
- self -> outgoing [1 ] = m_malloc (characteristic -> max_length , false);
113
+ self -> outgoing [0 ] = m_malloc (max_packet_size , false);
114
+ self -> outgoing [1 ] = m_malloc (max_packet_size , false);
115
115
} else {
116
116
self -> outgoing [0 ] = NULL ;
117
117
self -> outgoing [1 ] = NULL ;
118
118
}
119
+ self -> max_packet_size = max_packet_size ;
119
120
120
121
bleio_characteristic_set_observer (self -> characteristic , self );
121
122
}
@@ -243,15 +244,16 @@ mp_int_t common_hal_bleio_packet_buffer_get_outgoing_packet_length(bleio_packet_
243
244
if (self -> conn_handle != BLE_CONN_HANDLE_INVALID ) {
244
245
bleio_connection_internal_t * connection = bleio_conn_handle_to_connection (self -> conn_handle );
245
246
if (connection ) {
246
- return MIN (common_hal_bleio_connection_get_max_packet_length (connection ),
247
- self -> characteristic -> max_length );
247
+ return MIN (MIN (common_hal_bleio_connection_get_max_packet_length (connection ),
248
+ self -> max_packet_size ),
249
+ self -> characteristic -> max_length );
248
250
}
249
251
}
250
252
// There's no current connection, so we don't know the MTU, and
251
253
// we can't tell what the largest outgoing packet length would be.
252
254
return -1 ;
253
255
}
254
- return self -> characteristic -> max_length ;
256
+ return MIN ( self -> characteristic -> max_length , self -> max_packet_size ) ;
255
257
}
256
258
257
259
bool common_hal_bleio_packet_buffer_deinited (bleio_packet_buffer_obj_t * self ) {
0 commit comments