Improve PacketBuffer packet lengths for remote service
This commit is contained in:
parent
58835e5a5b
commit
e3b3f97fa6
@ -252,6 +252,9 @@ void common_hal_bleio_packet_buffer_construct(
|
|||||||
}
|
}
|
||||||
|
|
||||||
mp_int_t common_hal_bleio_packet_buffer_readinto(bleio_packet_buffer_obj_t *self, uint8_t *data, size_t len) {
|
mp_int_t common_hal_bleio_packet_buffer_readinto(bleio_packet_buffer_obj_t *self, uint8_t *data, size_t len) {
|
||||||
|
if (self->conn_handle == BLE_CONN_HANDLE_INVALID) {
|
||||||
|
mp_raise_ConnectionError(translate("Not connected"));
|
||||||
|
}
|
||||||
if (ringbuf_num_filled(&self->ringbuf) < 2) {
|
if (ringbuf_num_filled(&self->ringbuf) < 2) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -357,8 +360,7 @@ mp_int_t common_hal_bleio_packet_buffer_get_incoming_packet_length(bleio_packet_
|
|||||||
if (self->conn_handle != BLE_CONN_HANDLE_INVALID) {
|
if (self->conn_handle != BLE_CONN_HANDLE_INVALID) {
|
||||||
bleio_connection_internal_t *connection = bleio_conn_handle_to_connection(self->conn_handle);
|
bleio_connection_internal_t *connection = bleio_conn_handle_to_connection(self->conn_handle);
|
||||||
if (connection) {
|
if (connection) {
|
||||||
return MIN(common_hal_bleio_connection_get_max_packet_length(connection),
|
return common_hal_bleio_connection_get_max_packet_length(connection);
|
||||||
self->characteristic->max_length);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// There's no current connection, so we don't know the MTU, and
|
// 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_
|
|||||||
// we can't tell what the largest outgoing packet length would be.
|
// we can't tell what the largest outgoing packet length would be.
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
// If we are talking to a remote service, we'll be bound by the MTU. (We don't actually
|
||||||
|
// know the max size of the remote characteristic.)
|
||||||
|
if (self->characteristic->service != NULL &&
|
||||||
|
self->characteristic->service->is_remote) {
|
||||||
|
// We are talking to a remote service so we're writing.
|
||||||
|
if (self->conn_handle != BLE_CONN_HANDLE_INVALID) {
|
||||||
|
bleio_connection_internal_t *connection = bleio_conn_handle_to_connection(self->conn_handle);
|
||||||
|
if (connection) {
|
||||||
|
return common_hal_bleio_connection_get_max_packet_length(connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return self->characteristic->max_length;
|
return self->characteristic->max_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user