diff options
| author | Glenn Ruben Bakke <glennbakke@gmail.com> | 2017-05-30 19:29:46 +0200 |
|---|---|---|
| committer | Glenn Ruben Bakke <glennbakke@gmail.com> | 2017-05-30 19:29:46 +0200 |
| commit | 66db0791927daf63b8b68da9b5851bf72a5c7024 (patch) | |
| tree | 90f392bf4e0fdc578f8286a6b955d8725cccd973 | |
| parent | 8b9f14244dd1a8856d6d24b3e0af9bdf68bb1202 (diff) | |
nrf5/drivers/bluetooth: Updating ble_drv_attr_c_write with possibility to do client write with response. Blocking call.
| -rw-r--r-- | nrf5/drivers/bluetooth/ble_drv.c | 36 | ||||
| -rw-r--r-- | nrf5/drivers/bluetooth/ble_drv.h | 2 |
2 files changed, 26 insertions, 12 deletions
diff --git a/nrf5/drivers/bluetooth/ble_drv.c b/nrf5/drivers/bluetooth/ble_drv.c index 418c1f4a3..52009b3ea 100644 --- a/nrf5/drivers/bluetooth/ble_drv.c +++ b/nrf5/drivers/bluetooth/ble_drv.c @@ -77,6 +77,7 @@ static mp_obj_t mp_gatts_observer; #if (BLUETOOTH_SD == 130) || (BLUETOOTH_SD == 132) static volatile bool m_primary_service_found; static volatile bool m_characteristic_found; +static volatile bool m_write_done; static volatile ble_drv_adv_evt_callback_t adv_event_handler; static volatile ble_drv_gattc_evt_callback_t gattc_event_handler; @@ -89,6 +90,7 @@ static mp_obj_t mp_gattc_observer; static mp_obj_t mp_gattc_disc_service_observer; static mp_obj_t mp_gattc_disc_char_observer; static mp_obj_t mp_gattc_char_data_observer; +static mp_obj_t mp_gattc_char_data_observer; #endif #if (BLUETOOTH_SD != 100) && (BLUETOOTH_SD != 110) @@ -679,23 +681,34 @@ void ble_drv_attr_c_read(uint16_t conn_handle, uint16_t handle, mp_obj_t obj, bl } } -void ble_drv_attr_c_write(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data) { +void ble_drv_attr_c_write(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data, bool w_response) { + + ble_gattc_write_params_t write_params; + + if (w_response) { + write_params.write_op = BLE_GATT_OP_WRITE_REQ; + } else { + write_params.write_op = BLE_GATT_OP_WRITE_CMD; + } - ble_gattc_write_params_t write_params; + write_params.flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_CANCEL; + write_params.handle = handle; + write_params.offset = 0; + write_params.len = len; + write_params.p_value = p_data; - write_params.write_op = BLE_GATT_OP_WRITE_CMD; - write_params.flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_CANCEL; - write_params.handle = handle; - write_params.offset = 0; - write_params.len = len; - write_params.p_value = p_data; + uint32_t err_code = sd_ble_gattc_write(conn_handle, &write_params); - uint32_t err_code = sd_ble_gattc_write(conn_handle, &write_params); + m_write_done = !w_response; - if (err_code != 0) { + if (err_code != 0) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Can not write attribute value. status: 0x" HEX2_FMT, (uint16_t)err_code)); - } + } + + while (m_write_done != true) { + ; + } } void ble_drv_scan_start(void) { @@ -1007,6 +1020,7 @@ static void ble_evt_handler(ble_evt_t * p_ble_evt) { case BLE_GATTC_EVT_WRITE_RSP: BLE_DRIVER_LOG("BLE EVT WRITE RESPONSE\n"); + m_write_done = true; break; case BLE_GATTC_EVT_HVX: diff --git a/nrf5/drivers/bluetooth/ble_drv.h b/nrf5/drivers/bluetooth/ble_drv.h index dc3cf168e..e038f5cc9 100644 --- a/nrf5/drivers/bluetooth/ble_drv.h +++ b/nrf5/drivers/bluetooth/ble_drv.h @@ -104,7 +104,7 @@ void ble_drv_attr_s_write(uint16_t conn_handle, uint16_t handle, uint16_t len, u void ble_drv_attr_s_notify(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data); -void ble_drv_attr_c_write(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data); +void ble_drv_attr_c_write(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data, bool w_response); void ble_drv_scan_start(void); |
