Add exception on small buffer and fix Connecion WRITE handling
This commit is contained in:
parent
3551b769a2
commit
8a5d3cd6c4
@ -162,7 +162,8 @@ bool connection_on_ble_evt(ble_evt_t *ble_evt, void *self_in) {
|
|||||||
self->do_bond_cccds = true;
|
self->do_bond_cccds = true;
|
||||||
self->do_bond_cccds_request_time = supervisor_ticks_ms64();
|
self->do_bond_cccds_request_time = supervisor_ticks_ms64();
|
||||||
}
|
}
|
||||||
break;
|
// Return false so other handlers get this event as well.
|
||||||
|
return false;
|
||||||
|
|
||||||
case BLE_GATTS_EVT_SYS_ATTR_MISSING:
|
case BLE_GATTS_EVT_SYS_ATTR_MISSING:
|
||||||
sd_ble_gatts_sys_attr_set(self->conn_handle, NULL, 0, 0);
|
sd_ble_gatts_sys_attr_set(self->conn_handle, NULL, 0, 0);
|
||||||
|
@ -148,6 +148,7 @@ STATIC bool packet_buffer_on_ble_server_evt(ble_evt_t *ble_evt, void *param) {
|
|||||||
// A client wrote to this server characteristic.
|
// A client wrote to this server characteristic.
|
||||||
|
|
||||||
ble_gatts_evt_write_t *evt_write = &ble_evt->evt.gatts_evt.params.write;
|
ble_gatts_evt_write_t *evt_write = &ble_evt->evt.gatts_evt.params.write;
|
||||||
|
|
||||||
// Event handle must match the handle for my characteristic.
|
// Event handle must match the handle for my characteristic.
|
||||||
if (evt_write->handle == self->characteristic->handle) {
|
if (evt_write->handle == self->characteristic->handle) {
|
||||||
if (self->conn_handle == BLE_CONN_HANDLE_INVALID) {
|
if (self->conn_handle == BLE_CONN_HANDLE_INVALID) {
|
||||||
@ -261,8 +262,7 @@ int common_hal_bleio_packet_buffer_readinto(bleio_packet_buffer_obj_t *self, uin
|
|||||||
sd_nvic_critical_region_enter(&is_nested_critical_region);
|
sd_nvic_critical_region_enter(&is_nested_critical_region);
|
||||||
|
|
||||||
if (packet_length > len) {
|
if (packet_length > len) {
|
||||||
// TODO: raise an exception.
|
return len - packet_length;
|
||||||
packet_length = len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ringbuf_get_n(&self->ringbuf, data, packet_length);
|
ringbuf_get_n(&self->ringbuf, data, packet_length);
|
||||||
|
@ -109,7 +109,12 @@ STATIC mp_obj_t bleio_packet_buffer_readinto(mp_obj_t self_in, mp_obj_t buffer_o
|
|||||||
mp_buffer_info_t bufinfo;
|
mp_buffer_info_t bufinfo;
|
||||||
mp_get_buffer_raise(buffer_obj, &bufinfo, MP_BUFFER_WRITE);
|
mp_get_buffer_raise(buffer_obj, &bufinfo, MP_BUFFER_WRITE);
|
||||||
|
|
||||||
return MP_OBJ_NEW_SMALL_INT(common_hal_bleio_packet_buffer_readinto(self, bufinfo.buf, bufinfo.len));
|
int size = common_hal_bleio_packet_buffer_readinto(self, bufinfo.buf, bufinfo.len);
|
||||||
|
if (size < 0) {
|
||||||
|
mp_raise_ValueError_varg(translate("Buffer too short by %d bytes"), size * -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return MP_OBJ_NEW_SMALL_INT(size);
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_packet_buffer_readinto_obj, bleio_packet_buffer_readinto);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_packet_buffer_readinto_obj, bleio_packet_buffer_readinto);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user