Skip to content

Commit 62e67b8

Browse files
ejtaglejamesarich
authored andcommitted
Wait until notification queue has enough room so no notifications of completed operations to the DFU app are lost
1 parent 5223a33 commit 62e67b8

1 file changed

Lines changed: 77 additions & 59 deletions

File tree

  • lib/sdk11/components/ble/ble_services/ble_dfu

lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c

Lines changed: 77 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -555,29 +555,35 @@ uint32_t ble_dfu_bytes_rcvd_report(ble_dfu_t * p_dfu, uint32_t num_of_firmware_b
555555
return NRF_ERROR_INVALID_STATE;
556556
}
557557

558-
ble_gatts_hvx_params_t hvx_params;
559-
uint16_t index = 0;
560-
561-
// Encode the Op Code.
562-
m_notif_buffer[index++] = OP_CODE_RESPONSE;
563-
564-
// Encode the Reqest Op Code.
565-
m_notif_buffer[index++] = OP_CODE_IMAGE_SIZE_REQ;
566-
567-
// Encode the Response Value.
568-
m_notif_buffer[index++] = (uint8_t)BLE_DFU_RESP_VAL_SUCCESS;
569-
570-
index += uint32_encode(num_of_firmware_bytes_rcvd, &m_notif_buffer[index]);
571-
572-
memset(&hvx_params, 0, sizeof(hvx_params));
573-
574-
hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle;
575-
hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
576-
hvx_params.offset = 0;
577-
hvx_params.p_len = &index;
578-
hvx_params.p_data = m_notif_buffer;
579-
580-
return sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params);
558+
uint32_t err_code;
559+
do {
560+
561+
ble_gatts_hvx_params_t hvx_params;
562+
uint16_t index = 0;
563+
564+
// Encode the Op Code.
565+
m_notif_buffer[index++] = OP_CODE_RESPONSE;
566+
567+
// Encode the Reqest Op Code.
568+
m_notif_buffer[index++] = OP_CODE_IMAGE_SIZE_REQ;
569+
570+
// Encode the Response Value.
571+
m_notif_buffer[index++] = (uint8_t)BLE_DFU_RESP_VAL_SUCCESS;
572+
573+
index += uint32_encode(num_of_firmware_bytes_rcvd, &m_notif_buffer[index]);
574+
575+
memset(&hvx_params, 0, sizeof(hvx_params));
576+
577+
hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle;
578+
hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
579+
hvx_params.offset = 0;
580+
hvx_params.p_len = &index;
581+
hvx_params.p_data = m_notif_buffer;
582+
583+
err_code = sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params);
584+
} while (err_code == NRF_ERROR_RESOURCES);
585+
586+
return err_code;
581587
}
582588

583589

@@ -593,22 +599,28 @@ uint32_t ble_dfu_pkts_rcpt_notify(ble_dfu_t * p_dfu, uint32_t num_of_firmware_by
593599
return NRF_ERROR_INVALID_STATE;
594600
}
595601

596-
ble_gatts_hvx_params_t hvx_params;
597-
uint16_t index = 0;
598-
599-
m_notif_buffer[index++] = OP_CODE_PKT_RCPT_NOTIF;
600-
601-
index += uint32_encode(num_of_firmware_bytes_rcvd, &m_notif_buffer[index]);
602-
603-
memset(&hvx_params, 0, sizeof(hvx_params));
604-
605-
hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle;
606-
hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
607-
hvx_params.offset = 0;
608-
hvx_params.p_len = &index;
609-
hvx_params.p_data = m_notif_buffer;
610-
611-
return sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params);
602+
uint32_t err_code;
603+
do {
604+
605+
ble_gatts_hvx_params_t hvx_params;
606+
uint16_t index = 0;
607+
608+
m_notif_buffer[index++] = OP_CODE_PKT_RCPT_NOTIF;
609+
610+
index += uint32_encode(num_of_firmware_bytes_rcvd, &m_notif_buffer[index]);
611+
612+
memset(&hvx_params, 0, sizeof(hvx_params));
613+
614+
hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle;
615+
hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
616+
hvx_params.offset = 0;
617+
hvx_params.p_len = &index;
618+
hvx_params.p_data = m_notif_buffer;
619+
620+
err_code = sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params);
621+
} while (err_code == NRF_ERROR_RESOURCES);
622+
623+
return err_code;
612624
}
613625

614626

@@ -626,24 +638,30 @@ uint32_t ble_dfu_response_send(ble_dfu_t * p_dfu,
626638
return NRF_ERROR_INVALID_STATE;
627639
}
628640

629-
ble_gatts_hvx_params_t hvx_params;
630-
uint16_t index = 0;
631-
632-
m_notif_buffer[index++] = OP_CODE_RESPONSE;
633-
634-
// Encode the Request Op code
635-
m_notif_buffer[index++] = (uint8_t)dfu_proc;
636-
637-
// Encode the Response Value.
638-
m_notif_buffer[index++] = (uint8_t)resp_val;
639-
640-
memset(&hvx_params, 0, sizeof(hvx_params));
641-
642-
hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle;
643-
hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
644-
hvx_params.offset = 0;
645-
hvx_params.p_len = &index;
646-
hvx_params.p_data = m_notif_buffer;
647-
648-
return sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params);
641+
uint32_t err_code;
642+
do {
643+
644+
ble_gatts_hvx_params_t hvx_params;
645+
uint16_t index = 0;
646+
647+
m_notif_buffer[index++] = OP_CODE_RESPONSE;
648+
649+
// Encode the Request Op code
650+
m_notif_buffer[index++] = (uint8_t)dfu_proc;
651+
652+
// Encode the Response Value.
653+
m_notif_buffer[index++] = (uint8_t)resp_val;
654+
655+
memset(&hvx_params, 0, sizeof(hvx_params));
656+
657+
hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle;
658+
hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
659+
hvx_params.offset = 0;
660+
hvx_params.p_len = &index;
661+
hvx_params.p_data = m_notif_buffer;
662+
663+
err_code = sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params);
664+
} while (err_code == NRF_ERROR_RESOURCES);
665+
666+
return err_code;
649667
}

0 commit comments

Comments
 (0)