fix heap warning in espressif Adapter.c;fix error codes
This commit is contained in:
parent
f3920c49dc
commit
af1b8799a4
@ -128,6 +128,7 @@ bool common_hal_bleio_connection_get_connected(bleio_connection_obj_t *self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void common_hal_bleio_connection_disconnect(bleio_connection_internal_t *self) {
|
void common_hal_bleio_connection_disconnect(bleio_connection_internal_t *self) {
|
||||||
|
// Second argument is an HCI reason, not an HS error code.
|
||||||
ble_gap_terminate(self->conn_handle, BLE_ERR_REM_USER_CONN_TERM);
|
ble_gap_terminate(self->conn_handle, BLE_ERR_REM_USER_CONN_TERM);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,9 +163,9 @@ STATIC int _discovered_service_cb(uint16_t conn_handle,
|
|||||||
void *arg) {
|
void *arg) {
|
||||||
bleio_connection_internal_t *self = (bleio_connection_internal_t *)arg;
|
bleio_connection_internal_t *self = (bleio_connection_internal_t *)arg;
|
||||||
|
|
||||||
if (error->status != BLE_ERR_SUCCESS) {
|
if (error->status != 0) {
|
||||||
// Keep the first error in case it's due to memory.
|
// Keep the first error in case it's due to memory.
|
||||||
if (_last_discovery_status == BLE_ERR_SUCCESS) {
|
if (_last_discovery_status == 0) {
|
||||||
_last_discovery_status = error->status;
|
_last_discovery_status = error->status;
|
||||||
xTaskNotifyGive(discovery_task);
|
xTaskNotifyGive(discovery_task);
|
||||||
}
|
}
|
||||||
@ -173,7 +174,7 @@ STATIC int _discovered_service_cb(uint16_t conn_handle,
|
|||||||
|
|
||||||
// If any of these memory allocations fail, we set _last_discovery_status
|
// If any of these memory allocations fail, we set _last_discovery_status
|
||||||
// and let the process continue.
|
// and let the process continue.
|
||||||
if (_last_discovery_status != BLE_ERR_SUCCESS) {
|
if (_last_discovery_status != 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
bleio_service_obj_t *service = mp_obj_malloc(bleio_service_obj_t, &bleio_service_type);
|
bleio_service_obj_t *service = mp_obj_malloc(bleio_service_obj_t, &bleio_service_type);
|
||||||
@ -202,16 +203,16 @@ STATIC int _discovered_characteristic_cb(uint16_t conn_handle,
|
|||||||
void *arg) {
|
void *arg) {
|
||||||
bleio_service_obj_t *service = (bleio_service_obj_t *)arg;
|
bleio_service_obj_t *service = (bleio_service_obj_t *)arg;
|
||||||
|
|
||||||
if (error->status != BLE_ERR_SUCCESS) {
|
if (error->status != 0) {
|
||||||
// Keep the first error in case it's due to memory.
|
// Keep the first error in case it's due to memory.
|
||||||
if (_last_discovery_status == BLE_ERR_SUCCESS) {
|
if (_last_discovery_status == 0) {
|
||||||
_last_discovery_status = error->status;
|
_last_discovery_status = error->status;
|
||||||
xTaskNotifyGive(discovery_task);
|
xTaskNotifyGive(discovery_task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If any of these memory allocations fail, we set _last_discovery_status
|
// If any of these memory allocations fail, we set _last_discovery_status
|
||||||
// and let the process continue.
|
// and let the process continue.
|
||||||
if (_last_discovery_status != BLE_ERR_SUCCESS) {
|
if (_last_discovery_status != 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,16 +254,16 @@ STATIC int _discovered_descriptor_cb(uint16_t conn_handle,
|
|||||||
void *arg) {
|
void *arg) {
|
||||||
bleio_characteristic_obj_t *characteristic = (bleio_characteristic_obj_t *)arg;
|
bleio_characteristic_obj_t *characteristic = (bleio_characteristic_obj_t *)arg;
|
||||||
|
|
||||||
if (error->status != BLE_ERR_SUCCESS) {
|
if (error->status != 0) {
|
||||||
// Keep the first error in case it's due to memory.
|
// Keep the first error in case it's due to memory.
|
||||||
if (_last_discovery_status == BLE_ERR_SUCCESS) {
|
if (_last_discovery_status == 0) {
|
||||||
_last_discovery_status = error->status;
|
_last_discovery_status = error->status;
|
||||||
}
|
}
|
||||||
xTaskNotifyGive(discovery_task);
|
xTaskNotifyGive(discovery_task);
|
||||||
}
|
}
|
||||||
// If any of these memory allocations fail, we set _last_discovery_status
|
// If any of these memory allocations fail, we set _last_discovery_status
|
||||||
// and let the process continue.
|
// and let the process continue.
|
||||||
if (_last_discovery_status != BLE_ERR_SUCCESS) {
|
if (_last_discovery_status != 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,7 +307,7 @@ STATIC void discover_remote_services(bleio_connection_internal_t *self, mp_obj_t
|
|||||||
|
|
||||||
discovery_task = xTaskGetCurrentTaskHandle();
|
discovery_task = xTaskGetCurrentTaskHandle();
|
||||||
if (service_uuids_whitelist == mp_const_none) {
|
if (service_uuids_whitelist == mp_const_none) {
|
||||||
_last_discovery_status = BLE_ERR_SUCCESS;
|
_last_discovery_status = 0;
|
||||||
CHECK_NIMBLE_ERROR(ble_gattc_disc_all_svcs(self->conn_handle, _discovered_service_cb, self));
|
CHECK_NIMBLE_ERROR(ble_gattc_disc_all_svcs(self->conn_handle, _discovered_service_cb, self));
|
||||||
|
|
||||||
// Wait for sync.
|
// Wait for sync.
|
||||||
@ -324,7 +325,7 @@ STATIC void discover_remote_services(bleio_connection_internal_t *self, mp_obj_t
|
|||||||
}
|
}
|
||||||
bleio_uuid_obj_t *uuid = MP_OBJ_TO_PTR(uuid_obj);
|
bleio_uuid_obj_t *uuid = MP_OBJ_TO_PTR(uuid_obj);
|
||||||
|
|
||||||
_last_discovery_status = BLE_ERR_SUCCESS;
|
_last_discovery_status = 0;
|
||||||
// Make sure we start with a clean notification state
|
// Make sure we start with a clean notification state
|
||||||
ulTaskNotifyValueClear(discovery_task, 0xffffffff);
|
ulTaskNotifyValueClear(discovery_task, 0xffffffff);
|
||||||
CHECK_NIMBLE_ERROR(ble_gattc_disc_svc_by_uuid(self->conn_handle, &uuid->nimble_ble_uuid.u,
|
CHECK_NIMBLE_ERROR(ble_gattc_disc_svc_by_uuid(self->conn_handle, &uuid->nimble_ble_uuid.u,
|
||||||
@ -340,7 +341,7 @@ STATIC void discover_remote_services(bleio_connection_internal_t *self, mp_obj_t
|
|||||||
for (size_t i = 0; i < self->remote_service_list->len; i++) {
|
for (size_t i = 0; i < self->remote_service_list->len; i++) {
|
||||||
bleio_service_obj_t *service = MP_OBJ_TO_PTR(self->remote_service_list->items[i]);
|
bleio_service_obj_t *service = MP_OBJ_TO_PTR(self->remote_service_list->items[i]);
|
||||||
|
|
||||||
_last_discovery_status = BLE_ERR_SUCCESS;
|
_last_discovery_status = 0;
|
||||||
CHECK_NIMBLE_ERROR(ble_gattc_disc_all_chrs(self->conn_handle,
|
CHECK_NIMBLE_ERROR(ble_gattc_disc_all_chrs(self->conn_handle,
|
||||||
service->start_handle,
|
service->start_handle,
|
||||||
service->end_handle,
|
service->end_handle,
|
||||||
@ -375,7 +376,7 @@ STATIC void discover_remote_services(bleio_connection_internal_t *self, mp_obj_t
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
_last_discovery_status = BLE_ERR_SUCCESS;
|
_last_discovery_status = 0;
|
||||||
CHECK_NIMBLE_ERROR(ble_gattc_disc_all_dscs(self->conn_handle, characteristic->handle,
|
CHECK_NIMBLE_ERROR(ble_gattc_disc_all_dscs(self->conn_handle, characteristic->handle,
|
||||||
end_handle,
|
end_handle,
|
||||||
_discovered_descriptor_cb, characteristic));
|
_discovered_descriptor_cb, characteristic));
|
||||||
|
@ -112,7 +112,8 @@ void check_nimble_error(int rc, const char *file, size_t line) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void check_ble_error(int error_code, const char *file, size_t line) {
|
void check_ble_error(int error_code, const char *file, size_t line) {
|
||||||
if (error_code == BLE_ERR_SUCCESS) {
|
// 0 means success. For BLE_HS_* codes, there is no defined "SUCCESS" value.
|
||||||
|
if (error_code == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (error_code) {
|
switch (error_code) {
|
||||||
|
@ -353,7 +353,8 @@ STATIC mp_obj_t bleio_adapter_start_scan(size_t n_args, const mp_obj_t *pos_args
|
|||||||
prefix_bufinfo.len = 0;
|
prefix_bufinfo.len = 0;
|
||||||
if (args[ARG_prefixes].u_obj != MP_OBJ_NULL) {
|
if (args[ARG_prefixes].u_obj != MP_OBJ_NULL) {
|
||||||
mp_get_buffer_raise(args[ARG_prefixes].u_obj, &prefix_bufinfo, MP_BUFFER_READ);
|
mp_get_buffer_raise(args[ARG_prefixes].u_obj, &prefix_bufinfo, MP_BUFFER_READ);
|
||||||
if (gc_nbytes(prefix_bufinfo.buf) == 0) {
|
// An empty buffer may not be on the heap, but that doesn't matter.
|
||||||
|
if (prefix_bufinfo.len > 0 && gc_nbytes(prefix_bufinfo.buf) == 0) {
|
||||||
mp_raise_ValueError(MP_ERROR_TEXT("Prefix buffer must be on the heap"));
|
mp_raise_ValueError(MP_ERROR_TEXT("Prefix buffer must be on the heap"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user