Browse Source

nrf/modules/ubluepy: Use mp_obj_str_get_data to extract str data.

Instead of GET_STR_DATA_LEN, which is intended to be a private macro.

Signed-off-by: Damien George <damien@micropython.org>
pull/8987/head
Damien George 2 years ago
parent
commit
787bd99919
  1. 8
      ports/nrf/modules/ubluepy/ubluepy_peripheral.c
  2. 3
      ports/nrf/modules/ubluepy/ubluepy_uuid.c

8
ports/nrf/modules/ubluepy/ubluepy_peripheral.c

@ -193,9 +193,8 @@ STATIC mp_obj_t peripheral_advertise(mp_uint_t n_args, const mp_obj_t *pos_args,
memset(&adv_data, 0, sizeof(ubluepy_advertise_data_t));
if (device_name_obj != mp_const_none && mp_obj_is_str(device_name_obj)) {
GET_STR_DATA_LEN(device_name_obj, str_data, str_len);
adv_data.p_device_name = (uint8_t *)str_data;
size_t str_len;
adv_data.p_device_name = (uint8_t *)mp_obj_str_get_data(device_name_obj, &str_len);
adv_data.device_name_len = str_len;
}
@ -357,7 +356,8 @@ STATIC mp_obj_t peripheral_connect(mp_uint_t n_args, const mp_obj_t *pos_args, m
ble_drv_gap_event_handler_set(MP_OBJ_FROM_PTR(self), gap_event_handler);
if (mp_obj_is_str(dev_addr)) {
GET_STR_DATA_LEN(dev_addr, str_data, str_len);
size_t str_len;
const byte *str_data = (const byte *)mp_obj_str_get_data(dev_addr, &str_len);
if (str_len == 17) { // Example "11:22:33:aa:bb:cc"
uint8_t * p_addr = m_new(uint8_t, 6);

3
ports/nrf/modules/ubluepy/ubluepy_uuid.c

@ -70,7 +70,8 @@ STATIC mp_obj_t ubluepy_uuid_make_new(const mp_obj_type_t *type, size_t n_args,
s->value[1] = (((uint16_t)mp_obj_get_int(uuid_obj)) >> 8) & 0xFF;
s->value[0] = ((uint8_t)mp_obj_get_int(uuid_obj)) & 0xFF;
} else if (mp_obj_is_str(uuid_obj)) {
GET_STR_DATA_LEN(uuid_obj, str_data, str_len);
size_t str_len;
const byte *str_data = (const byte *)mp_obj_str_get_data(uuid_obj, &str_len);
if (str_len == 6) { // Assume hex digit prefixed with 0x
s->type = UBLUEPY_UUID_16_BIT;
s->value[0] = unichar_xdigit_value(str_data[5]);

Loading…
Cancel
Save