fix #3228 for nrf; still needs to be fixed for HCI; tested
This commit is contained in:
parent
92cf56004f
commit
06f3b4048a
@ -47,7 +47,8 @@ void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self,
|
||||
self->props = props;
|
||||
self->read_perm = read_perm;
|
||||
self->write_perm = write_perm;
|
||||
self->descriptor_list = NULL;
|
||||
self->descriptor_linked_list = mp_obj_new_list(0, NULL);
|
||||
self->watchers_list = mp_obj_new_list(0, NULL);
|
||||
|
||||
const mp_int_t max_length_max = 512;
|
||||
if (max_length < 0 || max_length > max_length_max) {
|
||||
@ -67,8 +68,8 @@ void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self,
|
||||
}
|
||||
}
|
||||
|
||||
bleio_descriptor_obj_t *common_hal_bleio_characteristic_get_descriptor_list(bleio_characteristic_obj_t *self) {
|
||||
return self->descriptor_list;
|
||||
bleio_descriptor_obj_t *common_hal_bleio_characteristic_get_descriptor_linked_list(bleio_characteristic_obj_t *self) {
|
||||
return self->descriptor_linked_list;
|
||||
}
|
||||
|
||||
bleio_service_obj_t *common_hal_bleio_characteristic_get_service(bleio_characteristic_obj_t *self) {
|
||||
@ -153,8 +154,8 @@ void common_hal_bleio_characteristic_add_descriptor(bleio_characteristic_obj_t *
|
||||
self->service->end_handle = descriptor->handle;
|
||||
|
||||
// Link together all the descriptors for this characteristic.
|
||||
descriptor->next = self->descriptor_list;
|
||||
self->descriptor_list = descriptor;
|
||||
descriptor->next = self->descriptor_linked_list;
|
||||
self->descriptor_linked_list = descriptor;
|
||||
}
|
||||
|
||||
void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self, bool notify, bool indicate) {
|
||||
@ -201,3 +202,20 @@ void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self,
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
bool bleio_characteristic_set_local_value(bleio_characteristic_obj_t *self, mp_buffer_info_t *bufinfo) {
|
||||
if (self->fixed_length && bufinfo->len != self->max_length) {
|
||||
return false;
|
||||
}
|
||||
if (bufinfo->len > self->max_length) {
|
||||
bool
|
||||
}
|
||||
|
||||
mp_buffer_info_t char_bufinfo;
|
||||
if (!mp_get_buffer(characteristic->value, &bufinfo, MP_BUFFER_WRITE)) {
|
||||
return false;
|
||||
}
|
||||
memcpy(&char_bufinfo->buf, bufinfo->buf, bufinfo->len);
|
||||
|
||||
for (size_t i; i < characteristic->set_callbacks.
|
||||
}
|
||||
|
@ -40,6 +40,8 @@ typedef struct _bleio_characteristic_obj {
|
||||
bleio_service_obj_t *service;
|
||||
bleio_uuid_obj_t *uuid;
|
||||
mp_obj_t value;
|
||||
mp_obj_list_t watcher_list;
|
||||
mp_obj_list_t descriptor_linked_list;
|
||||
uint16_t max_length;
|
||||
bool fixed_length;
|
||||
uint16_t decl_handle;
|
||||
@ -47,7 +49,7 @@ typedef struct _bleio_characteristic_obj {
|
||||
bleio_characteristic_properties_t props;
|
||||
bleio_attribute_security_mode_t read_perm;
|
||||
bleio_attribute_security_mode_t write_perm;
|
||||
bleio_descriptor_obj_t *descriptor_list;
|
||||
bleio_descriptor_obj_t *descriptor_linked_list;
|
||||
uint16_t user_desc_handle;
|
||||
uint16_t cccd_handle;
|
||||
uint16_t sccd_handle;
|
||||
|
@ -319,7 +319,7 @@ static volatile bool m_discovery_successful;
|
||||
// }
|
||||
|
||||
void bleio_connection_clear(bleio_connection_internal_t *self) {
|
||||
self->remote_service_list = NULL;
|
||||
self->remote_service_linked_list = NULL;
|
||||
|
||||
//FIX self->conn_handle = BLE_CONN_HANDLE_INVALID;
|
||||
self->pair_status = PAIR_NOT_PAIRED;
|
||||
@ -449,7 +449,7 @@ void common_hal_bleio_connection_set_connection_interval(bleio_connection_intern
|
||||
// }
|
||||
|
||||
// STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *response, bleio_connection_internal_t* connection) {
|
||||
// bleio_service_obj_t* tail = connection->remote_service_list;
|
||||
// bleio_service_obj_t* tail = connection->remote_service_linked_list;
|
||||
|
||||
// for (size_t i = 0; i < response->count; ++i) {
|
||||
// ble_gattc_service_t *gattc_service = &response->services[i];
|
||||
@ -482,7 +482,7 @@ void common_hal_bleio_connection_set_connection_interval(bleio_connection_intern
|
||||
// tail = service;
|
||||
// }
|
||||
|
||||
// connection->remote_service_list = tail;
|
||||
// connection->remote_service_linked_list = tail;
|
||||
|
||||
// if (response->count > 0) {
|
||||
// m_discovery_successful = true;
|
||||
@ -581,7 +581,7 @@ void common_hal_bleio_connection_set_connection_interval(bleio_connection_intern
|
||||
// GATT_MAX_DATA_LENGTH, false, mp_const_empty_bytes);
|
||||
// descriptor->handle = gattc_desc->handle;
|
||||
|
||||
// mp_obj_list_append(m_desc_discovery_characteristic->descriptor_list, MP_OBJ_FROM_PTR(descriptor));
|
||||
// mp_obj_list_append(m_desc_discovery_characteristic->descriptor_linked_list, MP_OBJ_FROM_PTR(descriptor));
|
||||
// }
|
||||
|
||||
// if (response->count > 0) {
|
||||
@ -622,7 +622,7 @@ void common_hal_bleio_connection_set_connection_interval(bleio_connection_intern
|
||||
// ble_drv_add_event_handler(discovery_on_ble_evt, self);
|
||||
|
||||
// // Start over with an empty list.
|
||||
// self->remote_service_list = NULL;
|
||||
// self->remote_service_linked_list = NULL;
|
||||
|
||||
// if (service_uuids_whitelist == mp_const_none) {
|
||||
// // List of service UUID's not given, so discover all available services.
|
||||
@ -634,7 +634,7 @@ void common_hal_bleio_connection_set_connection_interval(bleio_connection_intern
|
||||
|
||||
// // Get the most recently discovered service, and then ask for services
|
||||
// // whose handles start after the last attribute handle inside that service.
|
||||
// const bleio_service_obj_t *service = self->remote_service_list;
|
||||
// const bleio_service_obj_t *service = self->remote_service_linked_list;
|
||||
// next_service_start_handle = service->end_handle + 1;
|
||||
// }
|
||||
// } else {
|
||||
@ -658,7 +658,7 @@ void common_hal_bleio_connection_set_connection_interval(bleio_connection_intern
|
||||
// }
|
||||
|
||||
|
||||
// bleio_service_obj_t *service = self->remote_service_list;
|
||||
// bleio_service_obj_t *service = self->remote_service_linked_list;
|
||||
// while (service != NULL) {
|
||||
// // Skip the service if it had an unknown (unregistered) UUID.
|
||||
// if (service->uuid == NULL) {
|
||||
@ -707,14 +707,14 @@ void common_hal_bleio_connection_set_connection_interval(bleio_connection_intern
|
||||
|
||||
// // Stop when we go past the end of the range of handles for this service or
|
||||
// // discovery call returns nothing.
|
||||
// // discover_next_descriptors() appends to the descriptor_list.
|
||||
// // discover_next_descriptors() appends to the descriptor_linked_list.
|
||||
// while (next_desc_start_handle <= service->end_handle &&
|
||||
// next_desc_start_handle <= next_desc_end_handle &&
|
||||
// discover_next_descriptors(self, characteristic,
|
||||
// next_desc_start_handle, next_desc_end_handle)) {
|
||||
// // Get the most recently discovered descriptor, and then ask for descriptors
|
||||
// // whose handles start after that descriptor's handle.
|
||||
// const bleio_descriptor_obj_t *descriptor = characteristic->descriptor_list;
|
||||
// const bleio_descriptor_obj_t *descriptor = characteristic->descriptor_linked_list;
|
||||
// next_desc_start_handle = descriptor->handle + 1;
|
||||
// }
|
||||
// }
|
||||
@ -730,8 +730,8 @@ mp_obj_tuple_t *common_hal_bleio_connection_discover_remote_services(bleio_conne
|
||||
//FIX discover_remote_services(self->connection, service_uuids_whitelist);
|
||||
bleio_connection_ensure_connected(self);
|
||||
// Convert to a tuple and then clear the list so the callee will take ownership.
|
||||
mp_obj_tuple_t *services_tuple = service_linked_list_to_tuple(self->connection->remote_service_list);
|
||||
self->connection->remote_service_list = NULL;
|
||||
mp_obj_tuple_t *services_tuple = service_linked_list_to_tuple(self->connection->remote_service_linked_list);
|
||||
self->connection->remote_service_linked_list = NULL;
|
||||
|
||||
return services_tuple;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ typedef struct {
|
||||
uint16_t conn_handle;
|
||||
bool is_central;
|
||||
// Remote services discovered when this peripheral is acting as a client.
|
||||
bleio_service_obj_t *remote_service_list;
|
||||
bleio_service_obj_t *remote_service_linked_list;
|
||||
// The advertising data and scan response buffers are held by us, not by the SD, so we must
|
||||
// maintain them and not change it. If we need to change the contents during advertising,
|
||||
// there are tricks to get the SD to notice (see DevZone - TBS).
|
||||
|
@ -352,6 +352,8 @@ void common_hal_bleio_adapter_set_enabled(bleio_adapter_obj_t *self, bool enable
|
||||
if (enabled) {
|
||||
for (size_t i = 0; i < BLEIO_TOTAL_CONNECTION_COUNT; i++) {
|
||||
bleio_connection_internal_t *connection = &bleio_connections[i];
|
||||
// Reset connection.
|
||||
bleio_connection_clear(connection);
|
||||
connection->conn_handle = BLE_CONN_HANDLE_INVALID;
|
||||
}
|
||||
bleio_adapter_reset_name(self);
|
||||
@ -576,6 +578,7 @@ mp_obj_t common_hal_bleio_adapter_connect(bleio_adapter_obj_t *self, bleio_addre
|
||||
for (size_t i = 0; i < BLEIO_TOTAL_CONNECTION_COUNT; i++) {
|
||||
bleio_connection_internal_t *connection = &bleio_connections[i];
|
||||
if (connection->conn_handle == conn_handle) {
|
||||
connection->is_central = true;
|
||||
return bleio_connection_new_from_internal(connection);
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self,
|
||||
self->props = props;
|
||||
self->read_perm = read_perm;
|
||||
self->write_perm = write_perm;
|
||||
self->descriptor_list = NULL;
|
||||
self->descriptor_list = mp_obj_new_list(0, NULL);
|
||||
|
||||
const mp_int_t max_length_max = fixed_length ? BLE_GATTS_FIX_ATTR_LEN_MAX : BLE_GATTS_VAR_ATTR_LEN_MAX;
|
||||
if (max_length < 0 || max_length > max_length_max) {
|
||||
@ -111,8 +111,8 @@ void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self,
|
||||
}
|
||||
}
|
||||
|
||||
bleio_descriptor_obj_t *common_hal_bleio_characteristic_get_descriptor_list(bleio_characteristic_obj_t *self) {
|
||||
return self->descriptor_list;
|
||||
mp_obj_tuple_t *common_hal_bleio_characteristic_get_descriptors(bleio_characteristic_obj_t *self) {
|
||||
return mp_obj_new_tuple(self->descriptor_list->len, self->descriptor_list->items);
|
||||
}
|
||||
|
||||
bleio_service_obj_t *common_hal_bleio_characteristic_get_service(bleio_characteristic_obj_t *self) {
|
||||
@ -218,8 +218,8 @@ void common_hal_bleio_characteristic_add_descriptor(bleio_characteristic_obj_t *
|
||||
|
||||
check_nrf_error(sd_ble_gatts_descriptor_add(self->handle, &desc_attr, &descriptor->handle));
|
||||
|
||||
descriptor->next = self->descriptor_list;
|
||||
self->descriptor_list = descriptor;
|
||||
mp_obj_list_append(MP_OBJ_FROM_PTR(self->descriptor_list),
|
||||
MP_OBJ_FROM_PTR(descriptor));
|
||||
}
|
||||
|
||||
void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self, bool notify, bool indicate) {
|
||||
|
@ -46,7 +46,7 @@ typedef struct _bleio_characteristic_obj {
|
||||
bleio_characteristic_properties_t props;
|
||||
bleio_attribute_security_mode_t read_perm;
|
||||
bleio_attribute_security_mode_t write_perm;
|
||||
bleio_descriptor_obj_t *descriptor_list;
|
||||
mp_obj_list_t *descriptor_list;
|
||||
uint16_t user_desc_handle;
|
||||
uint16_t cccd_handle;
|
||||
uint16_t sccd_handle;
|
||||
|
@ -325,10 +325,11 @@ bool connection_on_ble_evt(ble_evt_t *ble_evt, void *self_in) {
|
||||
}
|
||||
|
||||
void bleio_connection_clear(bleio_connection_internal_t *self) {
|
||||
self->remote_service_list = NULL;
|
||||
mp_obj_list_clear(MP_OBJ_FROM_PTR(self->remote_service_list));
|
||||
|
||||
self->conn_handle = BLE_CONN_HANDLE_INVALID;
|
||||
self->pair_status = PAIR_NOT_PAIRED;
|
||||
self->is_central = false;
|
||||
bonding_clear_keys(&self->bonding_keys);
|
||||
}
|
||||
|
||||
@ -452,8 +453,6 @@ STATIC bool discover_next_descriptors(bleio_connection_internal_t* connection, b
|
||||
}
|
||||
|
||||
STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *response, bleio_connection_internal_t* connection) {
|
||||
bleio_service_obj_t* tail = connection->remote_service_list;
|
||||
|
||||
for (size_t i = 0; i < response->count; ++i) {
|
||||
ble_gattc_service_t *gattc_service = &response->services[i];
|
||||
|
||||
@ -481,12 +480,10 @@ STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *res
|
||||
service->uuid = NULL;
|
||||
}
|
||||
|
||||
service->next = tail;
|
||||
tail = service;
|
||||
mp_obj_list_append(MP_OBJ_FROM_PTR(connection->remote_service_list),
|
||||
MP_OBJ_FROM_PTR(service));
|
||||
}
|
||||
|
||||
connection->remote_service_list = tail;
|
||||
|
||||
if (response->count > 0) {
|
||||
m_discovery_successful = true;
|
||||
}
|
||||
@ -528,7 +525,8 @@ STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio
|
||||
GATT_MAX_DATA_LENGTH, false, // max_length, fixed_length: values may not matter for gattc
|
||||
NULL);
|
||||
|
||||
mp_obj_list_append(m_char_discovery_service->characteristic_list, MP_OBJ_FROM_PTR(characteristic));
|
||||
mp_obj_list_append(MP_OBJ_FROM_PTR(m_char_discovery_service->characteristic_list),
|
||||
MP_OBJ_FROM_PTR(characteristic));
|
||||
}
|
||||
|
||||
if (response->count > 0) {
|
||||
@ -584,7 +582,8 @@ STATIC void on_desc_discovery_rsp(ble_gattc_evt_desc_disc_rsp_t *response, bleio
|
||||
GATT_MAX_DATA_LENGTH, false, mp_const_empty_bytes);
|
||||
descriptor->handle = gattc_desc->handle;
|
||||
|
||||
mp_obj_list_append(m_desc_discovery_characteristic->descriptor_list, MP_OBJ_FROM_PTR(descriptor));
|
||||
mp_obj_list_append(MP_OBJ_FROM_PTR(m_desc_discovery_characteristic->descriptor_list),
|
||||
MP_OBJ_FROM_PTR(descriptor));
|
||||
}
|
||||
|
||||
if (response->count > 0) {
|
||||
@ -625,7 +624,7 @@ STATIC void discover_remote_services(bleio_connection_internal_t *self, mp_obj_t
|
||||
ble_drv_add_event_handler(discovery_on_ble_evt, self);
|
||||
|
||||
// Start over with an empty list.
|
||||
self->remote_service_list = NULL;
|
||||
self->remote_service_list = mp_obj_new_list(0, NULL);
|
||||
|
||||
if (service_uuids_whitelist == mp_const_none) {
|
||||
// List of service UUID's not given, so discover all available services.
|
||||
@ -637,7 +636,9 @@ STATIC void discover_remote_services(bleio_connection_internal_t *self, mp_obj_t
|
||||
|
||||
// Get the most recently discovered service, and then ask for services
|
||||
// whose handles start after the last attribute handle inside that service.
|
||||
const bleio_service_obj_t *service = self->remote_service_list;
|
||||
// There must be at least one if discover_next_services() returned true.
|
||||
const bleio_service_obj_t *service =
|
||||
self->remote_service_list->items[self->remote_service_list->len - 1];
|
||||
next_service_start_handle = service->end_handle + 1;
|
||||
}
|
||||
} else {
|
||||
@ -661,11 +662,10 @@ STATIC void discover_remote_services(bleio_connection_internal_t *self, mp_obj_t
|
||||
}
|
||||
|
||||
|
||||
bleio_service_obj_t *service = self->remote_service_list;
|
||||
while (service != NULL) {
|
||||
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]);
|
||||
// Skip the service if it had an unknown (unregistered) UUID.
|
||||
if (service->uuid == NULL) {
|
||||
service = service->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -677,9 +677,9 @@ STATIC void discover_remote_services(bleio_connection_internal_t *self, mp_obj_t
|
||||
while (next_char_start_handle <= service->end_handle &&
|
||||
discover_next_characteristics(self, service, next_char_start_handle)) {
|
||||
|
||||
|
||||
// Get the most recently discovered characteristic, and then ask for characteristics
|
||||
// whose handles start after the last attribute handle inside that characteristic.
|
||||
// There must be at least one if discover_next_characteristics() returned true.
|
||||
const bleio_characteristic_obj_t *characteristic =
|
||||
MP_OBJ_TO_PTR(service->characteristic_list->items[service->characteristic_list->len - 1]);
|
||||
|
||||
@ -717,24 +717,26 @@ STATIC void discover_remote_services(bleio_connection_internal_t *self, mp_obj_t
|
||||
next_desc_start_handle, next_desc_end_handle)) {
|
||||
// Get the most recently discovered descriptor, and then ask for descriptors
|
||||
// whose handles start after that descriptor's handle.
|
||||
const bleio_descriptor_obj_t *descriptor = characteristic->descriptor_list;
|
||||
// There must be at least one if discover_next_descriptors() returned true.
|
||||
const bleio_descriptor_obj_t *descriptor =
|
||||
characteristic->descriptor_list->items[characteristic->descriptor_list->len - 1];
|
||||
next_desc_start_handle = descriptor->handle + 1;
|
||||
}
|
||||
}
|
||||
service = service->next;
|
||||
}
|
||||
|
||||
// This event handler is no longer needed.
|
||||
ble_drv_remove_event_handler(discovery_on_ble_evt, self);
|
||||
|
||||
}
|
||||
|
||||
mp_obj_tuple_t *common_hal_bleio_connection_discover_remote_services(bleio_connection_obj_t *self, mp_obj_t service_uuids_whitelist) {
|
||||
discover_remote_services(self->connection, service_uuids_whitelist);
|
||||
bleio_connection_ensure_connected(self);
|
||||
// Convert to a tuple and then clear the list so the callee will take ownership.
|
||||
mp_obj_tuple_t *services_tuple = service_linked_list_to_tuple(self->connection->remote_service_list);
|
||||
self->connection->remote_service_list = NULL;
|
||||
mp_obj_tuple_t *services_tuple =
|
||||
mp_obj_new_tuple(self->connection->remote_service_list->len,
|
||||
self->connection->remote_service_list->items);
|
||||
mp_obj_list_clear(MP_OBJ_FROM_PTR(self->connection->remote_service_list));
|
||||
|
||||
return services_tuple;
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ typedef struct {
|
||||
uint16_t conn_handle;
|
||||
bool is_central;
|
||||
// Remote services discovered when this peripheral is acting as a client.
|
||||
bleio_service_obj_t *remote_service_list;
|
||||
mp_obj_list_t *remote_service_list;
|
||||
// The advertising data and scan response buffers are held by us, not by the SD, so we must
|
||||
// maintain them and not change it. If we need to change the contents during advertising,
|
||||
// there are tricks to get the SD to notice (see DevZone - TBS).
|
||||
@ -67,7 +67,7 @@ typedef struct {
|
||||
ble_gap_conn_params_t conn_params;
|
||||
volatile bool conn_params_updating;
|
||||
uint16_t mtu;
|
||||
// Request that CCCD values for this conenction be saved, using sys_attr values.
|
||||
// Request that CCCD values for this connection be saved, using sys_attr values.
|
||||
volatile bool do_bond_cccds;
|
||||
// Request that security key info for this connection be saved.
|
||||
volatile bool do_bond_keys;
|
||||
@ -83,6 +83,7 @@ typedef struct {
|
||||
uint8_t disconnect_reason;
|
||||
} bleio_connection_obj_t;
|
||||
|
||||
void bleio_connection_clear(bleio_connection_internal_t *self);
|
||||
bool connection_on_ble_evt(ble_evt_t *ble_evt, void *self_in);
|
||||
|
||||
uint16_t bleio_connection_get_conn_handle(bleio_connection_obj_t *self);
|
||||
|
@ -47,7 +47,6 @@ typedef struct _bleio_descriptor_obj {
|
||||
uint16_t handle;
|
||||
bleio_attribute_security_mode_t read_perm;
|
||||
bleio_attribute_security_mode_t write_perm;
|
||||
struct _bleio_descriptor_obj* next;
|
||||
} bleio_descriptor_obj_t;
|
||||
|
||||
#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_DESCRIPTOR_H
|
||||
|
@ -73,8 +73,8 @@ bleio_uuid_obj_t *common_hal_bleio_service_get_uuid(bleio_service_obj_t *self) {
|
||||
return self->uuid;
|
||||
}
|
||||
|
||||
mp_obj_list_t *common_hal_bleio_service_get_characteristic_list(bleio_service_obj_t *self) {
|
||||
return self->characteristic_list;
|
||||
mp_obj_tuple_t *common_hal_bleio_service_get_characteristics(bleio_service_obj_t *self) {
|
||||
return mp_obj_new_tuple(self->characteristic_list->len, self->characteristic_list->items);
|
||||
}
|
||||
|
||||
bool common_hal_bleio_service_get_is_remote(bleio_service_obj_t *self) {
|
||||
|
@ -46,7 +46,6 @@ typedef struct bleio_service_obj {
|
||||
// Range of attribute handles of this remote service.
|
||||
uint16_t start_handle;
|
||||
uint16_t end_handle;
|
||||
struct bleio_service_obj* next;
|
||||
} bleio_service_obj_t;
|
||||
|
||||
void bleio_service_from_connection(bleio_service_obj_t *self, mp_obj_t connection);
|
||||
|
@ -212,26 +212,14 @@ const mp_obj_property_t bleio_characteristic_value_obj = {
|
||||
};
|
||||
|
||||
//| descriptors: Descriptor
|
||||
//| """A tuple of :py:class:`Descriptor` that describe this characteristic. (read-only)"""
|
||||
//| """A tuple of :py:class:`Descriptor` objects related to this characteristic. (read-only)"""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_characteristic_get_descriptors(mp_obj_t self_in) {
|
||||
bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
// Return list as a tuple so user won't be able to change it.
|
||||
bleio_descriptor_obj_t *descriptors = common_hal_bleio_characteristic_get_descriptor_list(self);
|
||||
bleio_descriptor_obj_t *head = descriptors;
|
||||
size_t len = 0;
|
||||
while (head != NULL) {
|
||||
len++;
|
||||
head = head->next;
|
||||
}
|
||||
mp_obj_tuple_t * t = MP_OBJ_TO_PTR(mp_obj_new_tuple(len, NULL));
|
||||
head = descriptors;
|
||||
for (size_t i = len - 1; i >= 0; i--) {
|
||||
t->items[i] = MP_OBJ_FROM_PTR(head);
|
||||
head = head->next;
|
||||
}
|
||||
return MP_OBJ_FROM_PTR(t);
|
||||
return MP_OBJ_FROM_PTR(common_hal_bleio_characteristic_get_descriptors(self));
|
||||
}
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_descriptors_obj, bleio_characteristic_get_descriptors);
|
||||
|
||||
const mp_obj_property_t bleio_characteristic_descriptors_obj = {
|
||||
|
@ -36,14 +36,14 @@
|
||||
|
||||
extern const mp_obj_type_t bleio_characteristic_type;
|
||||
|
||||
extern void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, bleio_service_obj_t *service, uint16_t handle, bleio_uuid_obj_t *uuid, bleio_characteristic_properties_t props, bleio_attribute_security_mode_t read_perm, bleio_attribute_security_mode_t write_perm, mp_int_t max_length, bool fixed_length, mp_buffer_info_t *initial_value_bufinfo);
|
||||
extern size_t common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self, uint8_t* buf, size_t len);
|
||||
extern void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self, mp_buffer_info_t *bufinfo);
|
||||
extern bleio_characteristic_properties_t common_hal_bleio_characteristic_get_properties(bleio_characteristic_obj_t *self);
|
||||
extern bleio_uuid_obj_t *common_hal_bleio_characteristic_get_uuid(bleio_characteristic_obj_t *self);
|
||||
extern bleio_descriptor_obj_t *common_hal_bleio_characteristic_get_descriptor_list(bleio_characteristic_obj_t *self);
|
||||
extern mp_obj_tuple_t *common_hal_bleio_characteristic_get_descriptors(bleio_characteristic_obj_t *self);
|
||||
extern bleio_service_obj_t *common_hal_bleio_characteristic_get_service(bleio_characteristic_obj_t *self);
|
||||
extern bleio_uuid_obj_t *common_hal_bleio_characteristic_get_uuid(bleio_characteristic_obj_t *self);
|
||||
extern size_t common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self, uint8_t* buf, size_t len);
|
||||
extern void common_hal_bleio_characteristic_add_descriptor(bleio_characteristic_obj_t *self, bleio_descriptor_obj_t *descriptor);
|
||||
extern void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, bleio_service_obj_t *service, uint16_t handle, bleio_uuid_obj_t *uuid, bleio_characteristic_properties_t props, bleio_attribute_security_mode_t read_perm, bleio_attribute_security_mode_t write_perm, mp_int_t max_length, bool fixed_length, mp_buffer_info_t *initial_value_bufinfo);
|
||||
extern void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self, bool notify, bool indicate);
|
||||
extern void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self, mp_buffer_info_t *bufinfo);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CHARACTERISTIC_H
|
||||
|
@ -79,9 +79,7 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
//|
|
||||
STATIC mp_obj_t bleio_service_get_characteristics(mp_obj_t self_in) {
|
||||
bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
// Return list as a tuple so user won't be able to change it.
|
||||
mp_obj_list_t *char_list = common_hal_bleio_service_get_characteristic_list(self);
|
||||
return mp_obj_new_tuple(char_list->len, char_list->items);
|
||||
return MP_OBJ_FROM_PTR(common_hal_bleio_service_get_characteristics(self));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_service_get_characteristics_obj, bleio_service_get_characteristics);
|
||||
|
||||
@ -151,7 +149,7 @@ STATIC const mp_rom_map_elem_t bleio_service_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_characteristics), MP_ROM_PTR(&bleio_service_characteristics_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_secondary), MP_ROM_PTR(&bleio_service_secondary_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_uuid), MP_ROM_PTR(&bleio_service_uuid_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_remote), MP_ROM_PTR(&bleio_service_remote_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_remote), MP_ROM_PTR(&bleio_service_remote_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(bleio_service_locals_dict, bleio_service_locals_dict_table);
|
||||
|
||||
@ -173,21 +171,3 @@ const mp_obj_type_t bleio_service_type = {
|
||||
.print = bleio_service_print,
|
||||
.locals_dict = (mp_obj_dict_t*)&bleio_service_locals_dict
|
||||
};
|
||||
|
||||
// Helper for classes that store lists of services.
|
||||
mp_obj_tuple_t* service_linked_list_to_tuple(bleio_service_obj_t * services) {
|
||||
// Return list as a tuple so user won't be able to change it.
|
||||
bleio_service_obj_t *head = services;
|
||||
size_t len = 0;
|
||||
while (head != NULL) {
|
||||
len++;
|
||||
head = head->next;
|
||||
}
|
||||
mp_obj_tuple_t * t = MP_OBJ_TO_PTR(mp_obj_new_tuple(len, NULL));
|
||||
head = services;
|
||||
for (int32_t i = len - 1; i >= 0; i--) {
|
||||
t->items[i] = MP_OBJ_FROM_PTR(head);
|
||||
head = head->next;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
@ -41,11 +41,9 @@ extern uint32_t _common_hal_bleio_service_construct(bleio_service_obj_t *self, b
|
||||
extern void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_obj_t *uuid, bool is_secondary);
|
||||
extern void common_hal_bleio_service_from_remote_service(bleio_service_obj_t *self, bleio_connection_obj_t* connection, bleio_uuid_obj_t *uuid, bool is_secondary);
|
||||
extern bleio_uuid_obj_t *common_hal_bleio_service_get_uuid(bleio_service_obj_t *self);
|
||||
extern mp_obj_list_t *common_hal_bleio_service_get_characteristic_list(bleio_service_obj_t *self);
|
||||
extern mp_obj_tuple_t *common_hal_bleio_service_get_characteristics(bleio_service_obj_t *self);
|
||||
extern bool common_hal_bleio_service_get_is_remote(bleio_service_obj_t *self);
|
||||
extern bool common_hal_bleio_service_get_is_secondary(bleio_service_obj_t *self);
|
||||
extern void common_hal_bleio_service_add_characteristic(bleio_service_obj_t *self, bleio_characteristic_obj_t *characteristic, mp_buffer_info_t *initial_value_bufinfo);
|
||||
|
||||
mp_obj_tuple_t* service_linked_list_to_tuple(bleio_service_obj_t * services);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SERVICE_H
|
||||
|
@ -63,7 +63,6 @@ NORETURN void mp_raise_bleio_SecurityError(const compressed_string_t* msg, ...);
|
||||
void common_hal_bleio_check_connected(uint16_t conn_handle);
|
||||
|
||||
uint16_t common_hal_bleio_device_get_conn_handle(mp_obj_t device);
|
||||
mp_obj_list_t *common_hal_bleio_device_get_remote_service_list(mp_obj_t device);
|
||||
void common_hal_bleio_device_discover_remote_services(mp_obj_t device, mp_obj_t service_uuids_whitelist);
|
||||
|
||||
size_t common_hal_bleio_gatts_read(uint16_t handle, uint16_t conn_handle, uint8_t* buf, size_t len);
|
||||
|
Loading…
Reference in New Issue
Block a user