|
|
@ -8,7 +8,8 @@ |
|
|
|
#include "one_conduction_board.h" |
|
|
|
#include "sample_data_manager.h" |
|
|
|
|
|
|
|
APP_TIMER_DEF(m_record_upload_tmr); // 数据上报定时器 |
|
|
|
APP_TIMER_DEF(m_record_upload_tmr); // 数据上报定时器 |
|
|
|
APP_TIMER_DEF(m_record_upload_finish_packet_report_tmr); // 数据上报完成上报定时器 |
|
|
|
static uint8_t txbuf[128]; |
|
|
|
static uint8_t reportbuf[128]; |
|
|
|
static bool m_realtime_report_state = false; |
|
|
@ -17,6 +18,7 @@ static bool m_ble_cmder_is_inited = false; |
|
|
|
static uint32_t m_report_data_sumcheckcode = 0; |
|
|
|
|
|
|
|
static void record_upload_tmr_cb(void* p_context); |
|
|
|
static void record_upload_finish_packet_report_tmr_cb(void* p_context); |
|
|
|
int ble_stop_upload_record(); |
|
|
|
/******************************************************************************* |
|
|
|
* 广播控制 * |
|
|
@ -36,6 +38,7 @@ void ble_cmder_stop_adv() { |
|
|
|
void ble_cmder_init() { |
|
|
|
if (!m_ble_cmder_is_inited) { |
|
|
|
ZERROR_CHECK(app_timer_create(&m_record_upload_tmr, APP_TIMER_MODE_REPEATED, record_upload_tmr_cb)); |
|
|
|
ZERROR_CHECK(app_timer_create(&m_record_upload_finish_packet_report_tmr, APP_TIMER_MODE_SINGLE_SHOT, record_upload_finish_packet_report_tmr_cb)); |
|
|
|
} |
|
|
|
m_ble_cmder_is_inited = true; |
|
|
|
} |
|
|
@ -91,7 +94,7 @@ void ble_cmder_report_upload_finish_event(uint32_t sumcheckcode) { |
|
|
|
ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; |
|
|
|
uint16_t sendlen = sizeof(ify_hrs_packet_t) + 4; |
|
|
|
|
|
|
|
txheader->cmd = ify_hrs_report_record_upload_end; |
|
|
|
txheader->cmd = ify_hrs_report_record_upload_end; // 6A |
|
|
|
txheader->frame_index = 0; |
|
|
|
txheader->frame_type = kifyhrs_pt_report; |
|
|
|
|
|
|
@ -119,8 +122,19 @@ void ble_cmder_report_sample_finish_event() { |
|
|
|
*******************************************************************************/ |
|
|
|
static int m_upload_fd; |
|
|
|
static uint8_t datacache[256]; |
|
|
|
static uint8_t m_remaindatalen = 0; |
|
|
|
static void record_upload_tmr_cb(void* p_context) { // |
|
|
|
static int m_remaindatalen = 0; |
|
|
|
/** |
|
|
|
* @brief 数据上报定时器回调 |
|
|
|
* |
|
|
|
* @param p_context |
|
|
|
*/ |
|
|
|
static void record_upload_finish_packet_report_tmr_cb(void* p_context) { // |
|
|
|
ble_cmder_report_upload_finish_event(m_report_data_sumcheckcode); |
|
|
|
} |
|
|
|
|
|
|
|
static void record_upload_tmr_cb(void* p_context) { // |
|
|
|
|
|
|
|
if (!m_isupload_data_state) return; |
|
|
|
|
|
|
|
// sample_data_mgr_read |
|
|
|
if (m_remaindatalen == 0) { |
|
|
@ -128,18 +142,23 @@ static void record_upload_tmr_cb(void* p_context) { // |
|
|
|
int32_t rdsize = sample_data_mgr_read(m_upload_fd, datacache, sizeof(datacache)); |
|
|
|
if (rdsize <= 0) { |
|
|
|
ZLOGI("read file end,stop upload"); |
|
|
|
ble_cmder_report_upload_finish_event(m_report_data_sumcheckcode); |
|
|
|
ZERROR_CHECK(app_timer_start(m_record_upload_finish_packet_report_tmr, APP_TIMER_TICKS(30), (void*)m_report_data_sumcheckcode)); |
|
|
|
ble_stop_upload_record(); |
|
|
|
return; |
|
|
|
} |
|
|
|
m_remaindatalen = rdsize; |
|
|
|
} |
|
|
|
if (m_remaindatalen == 0) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
int32_t mtusize = zble_module_get_mtu_size(); |
|
|
|
mtusize = mtusize < 128 ? mtusize : 128; |
|
|
|
|
|
|
|
uint8_t* data = datacache + (sizeof(datacache) - m_remaindatalen); |
|
|
|
uint8_t len = m_remaindatalen > mtusize ? mtusize : m_remaindatalen; |
|
|
|
int len = m_remaindatalen > mtusize ? mtusize : m_remaindatalen; |
|
|
|
|
|
|
|
ZLOGI("upload %d %d %d", len, m_remaindatalen, mtusize); |
|
|
|
if (!zdatachannel_is_connected()) { |
|
|
|
ZLOGI("ble is disconnected,stop upload"); |
|
|
|
ble_stop_upload_record(); |
|
|
@ -153,7 +172,7 @@ static void record_upload_tmr_cb(void* p_context) { // |
|
|
|
ZLOGI("ble unenable notify,stop upload"); |
|
|
|
ble_stop_upload_record(); |
|
|
|
return; |
|
|
|
} else if (suc == NRF_ERROR_BUSY) { |
|
|
|
} else if (suc == NRF_ERROR_BUSY || suc == NRF_ERROR_RESOURCES) { |
|
|
|
// 等待下次发送 |
|
|
|
return; |
|
|
|
} else { |
|
|
@ -402,7 +421,13 @@ void ble_cmder_process_rx(uint8_t* rx, int len) { |
|
|
|
|
|
|
|
int ecode = ble_start_upload_record(&filename); |
|
|
|
if (ecode == 0) { |
|
|
|
send_success_receipt(rxheader); |
|
|
|
ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; |
|
|
|
uint16_t sendlen = sizeof(ify_hrs_packet_t) + 1; // 凑齐4BYTE,方便调试 |
|
|
|
txheader->cmd = rxheader->cmd; |
|
|
|
txheader->frame_index = rxheader->frame_index; |
|
|
|
txheader->frame_type = kifyhrs_pt_cmd_receipt; |
|
|
|
|
|
|
|
zdatachannel_data_send2(txbuf, sendlen); |
|
|
|
} else { |
|
|
|
send_error_receipt(rxheader, ecode); |
|
|
|
} |
|
|
|