From ad4a1b8f7148651b55ca2845213cc4e6dbf11fc5 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Thu, 8 Feb 2024 15:45:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=83=A8=E5=88=86=E4=BC=91?= =?UTF-8?q?=E7=9C=A0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 28 +++++++++++++++++++--------- app/src/app_ble_service.c | 35 +++++++++++++++++++++++++++++++---- app/src/board/board.h | 8 ++++++-- app/src/device_ctrl_service.c | 26 +++++++++++++++++--------- app/src/device_ctrl_service.h | 5 +++-- app/src/heart_wave_sample_service.c | 5 +++++ app/src/heart_wave_sample_service.h | 2 ++ ify_hrs_protocol | 2 +- libznordic | 2 +- 9 files changed, 85 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 89b5871..9bcf31d 100644 --- a/README.md +++ b/README.md @@ -18,23 +18,33 @@ 修改电量检测,电量过低时,指示灯闪烁三下后进入低功耗。OK +开始采集,蜂鸣器响一声,结束采集,蜂鸣器响一声。OK +采集中: + 1.如果蓝牙断开,停止采集(临时代码),切换到mainPage OK ,通过ENABLE_AUTO_STOP_WHEN_BLE_DISCONNECTED使能 + 2.如果蓝牙5分钟内没有收到任何消息,切换到mainPage OK + 3.如果采集超时时间超过设定时间,停止采集,切换到mainPage OK -开始采集,蜂鸣器响一声,结束采集,蜂鸣器响一声。 -添加心跳检测,1分钟内没有收到心跳包,设备自动断开蓝牙连接。 -设备断开连接后,停止采集(临时代码) +MainPage: + 1. 如果蓝牙断开,进入休眠 OK + 2. 如果蓝牙5分钟内没有收到任何消息,进入休眠 OK -添加一条新的开始采集指令,支持定时参数。(或者使用旧的开始采集指令) -导联断开检测触发后,上报事件(不停止采集),蜂鸣器响三声。 -低电量进入关机模式 -添加指令上传最新一条记录 +添加一条新的开始采集指令,支持定时参数。(或者使用旧的开始采集指令)OK +导联断开检测触发后,上报事件(不停止采集)。 +导联断开连接后,蜂鸣器一直报警。 电量过低上报低电量事件。电量不足%1时,设备自动断开连接,并关机。 -设备充电时候,不允许采集。 +低电量进入关机模式 +添加指令上传最新一条记录 +Final: 修改休眠周期为30秒 - + +... + +设备充电时不进入休眠(无法实现,无法检测当前设备是否正在充电) OK + ``` diff --git a/app/src/app_ble_service.c b/app/src/app_ble_service.c index c1853d9..77c9586 100644 --- a/app/src/app_ble_service.c +++ b/app/src/app_ble_service.c @@ -4,6 +4,7 @@ #include "app_event.h" #include "app_event_distribute.h" #include "app_scheduler.h" +#include "basic/device_version_info_mgr.h" #include "board/board.h" #include "board/board_battery_state.h" #include "device_ctrl_service.h" @@ -12,7 +13,6 @@ #include "zble_module.h" #include "zdatachannel_service.h" #include "znordic.h" -#include "basic/device_version_info_mgr.h" static uint8_t rxbufcache[256]; static bool is_rxbufcache_used = false; // 接收到的消息是否正在被处理中 @@ -70,7 +70,7 @@ static void send_error_receipt(ify_hrs_packet_t* rxpacket, int32_t errorcode) { txheader->cmd = rxpacket->cmd; txheader->frame_index = rxpacket->frame_index; txheader->frame_type = kifyhrs_pt_error_receipt; - receipt->errorcode = errorcode; + receipt->errorcode = errorcode; zdatachannel_data_send2(m_txbuf, sendlen); } @@ -124,7 +124,6 @@ void prvf_report_sample_data(uint32_t frameIndex, one_frame_data_t* data, int32_ * @brief 第一导联数据 */ for (int i = 0; i < ndata; i++) { - reportpacket->data[i * 9 + 0] = ((data[i].data0)) >> 0; reportpacket->data[i * 9 + 1] = ((data[i].data0)) >> 8; reportpacket->data[i * 9 + 2] = ((data[i].data0)) >> 16; @@ -273,8 +272,13 @@ static void prvf_process_ble_rx_data(void* p_event_data, uint16_t len) { ify_hrs_packet_t* rxheader = (ify_hrs_packet_t*)p_event_data; ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)m_txbuf; ify_hrs_cmd_t cmd = (ify_hrs_cmd_t)rxheader->cmd; + int paramLen = len - sizeof(ify_hrs_packet_t); memset(m_txbuf, 0, sizeof(m_txbuf)); + if (len < sizeof(ify_hrs_packet_t)) { + return; + } + ZLOGI("rx cmd:%d index:%d datalen:%d", cmd, rxheader->frame_index, len - sizeof(ify_hrs_packet_t)); NRF_LOG_HEXDUMP_INFO(p_event_data, len); @@ -358,10 +362,33 @@ static void prvf_process_ble_rx_data(void* p_event_data, uint16_t len) { send_error_receipt(rxheader, kifyhrs_ecode_device_busy); } - DeviceCtrl_startSample(); + DeviceCtrl_startSample(0); + send_success_receipt(rxheader, 0); + } + + else if (cmd == ify_hrs_cmd_start_capture_time_v2) { + // kifyhrs_ecode_parameter_error + // hwss_start_capture(); + + if (paramLen < 4) { + send_error_receipt(rxheader, kifyhrs_ecode_parameter_error); + return; + } + + int32_t capture_time_s = *(int32_t*)(&rxheader->data[0]); + + if (RecordUpload_is_uploading()) { + ZLOGI("uploading,can not start capture"); + send_error_receipt(rxheader, kifyhrs_ecode_device_busy); + } + + DeviceCtrl_startSample(capture_time_s); send_success_receipt(rxheader, 0); } + // + // ify_hrs_cmd_start_upload_record_v2 + else if (cmd == ify_hrs_cmd_stop_capture) { // hwss_stop_capture(); DeviceCtrl_stopSample(); diff --git a/app/src/board/board.h b/app/src/board/board.h index 353717f..272780e 100644 --- a/app/src/board/board.h +++ b/app/src/board/board.h @@ -29,7 +29,7 @@ *******************************************************************************/ #define ADS1293_SPI_INSTANCE 2 #define BEEP_PWM_INSTANCE 0 -#define LIGHT_PWM_INSTANCE 1 +#define LIGHT_PWM_INSTANCE 1 #define BATTERY_ADC_CHANNEL 1 // 不重复即可 /******************************************************************************* @@ -72,4 +72,8 @@ #define APP_BYTE_EACH_FRAME 9 #define APP_SENSOR_NUM 3 -#define APP_LOW_BATTERY_LIMIT 2 \ No newline at end of file +#define APP_LOW_BATTERY_LIMIT 2 + +#define BLE_UNCONNECTED_OVERTIME_S 300 + +#define ENABLE_AUTO_STOP_WHEN_BLE_DISCONNECTED 1 \ No newline at end of file diff --git a/app/src/device_ctrl_service.c b/app/src/device_ctrl_service.c index fe067bb..9df5377 100644 --- a/app/src/device_ctrl_service.c +++ b/app/src/device_ctrl_service.c @@ -15,6 +15,7 @@ APP_TIMER_DEF(m_state_machine_driver_tmr); // 状态 static device_state_t m_device_state = kdevice_state_standby; // 设备状态 static uint32_t m_change_to_cur_state_tp = 0; // 切换到当前状态的时间戳 static int m_sample_data_fd = -1; // 采集数据文件描述符 +static int m_sample_duration_ms; /******************************************************************************* * 函数列表 * @@ -170,6 +171,9 @@ static void app_event_listener(void* p_event_data, uint16_t event_size) { // if (!zble_module_is_connected() && DeviceCtrl_cur_state_haspassed_ms() > APP_AUTO_SLEEP_TIMEOUT_MS) { ZLOGI("auto sleep"); prvf_change_to_standby_state(); + } else if (zble_module_is_connected() && zdatachannel_last_rx_data_haspassed_s() >= BLE_UNCONNECTED_OVERTIME_S) { + ZLOGI("auto sleep because ble unconnected"); + prvf_change_to_standby_state(); } if (event->eventType == kevent_start_sample_cmd_event) { @@ -202,13 +206,6 @@ static void app_event_listener(void* p_event_data, uint16_t event_size) { // SampleDataMgr_write(m_sample_data_fd, (uint8_t*)event->val.block_sensor_data.data, event->val.block_sensor_data.len); } - uint8_t drop0 = hwss_get_drop_state0(); - uint8_t drop1 = hwss_get_drop_state1(); - - if ((drop0 || drop1) && event->eventType == kevent_tmr_scheduler) { - // ZLOGI("[%d] drop %s", znordic_getpower_on_ms(), dropstate(drop0, drop1)); - } - bool stopcapture = false; if (SampleDataMgr_getFileSizeByFd(m_sample_data_fd) > SDCARD_MAX_FILE_SIZE) { ZLOGI("stop sample because file size is too large"); @@ -216,7 +213,16 @@ static void app_event_listener(void* p_event_data, uint16_t event_size) { // } else if (event->eventType == kevent_stop_sample_cmd_event) { ZLOGI("stop sample because stop sample event"); stopcapture = true; + } else if (m_sample_duration_ms != 0 && DeviceCtrl_cur_state_haspassed_ms() > m_sample_duration_ms) { + ZLOGI("stop sample because sample timeout"); + stopcapture = true; } +#ifdef ENABLE_AUTO_STOP_WHEN_BLE_DISCONNECTED + else if (zdatachannel_last_rx_data_haspassed_s() > BLE_UNCONNECTED_OVERTIME_S) { + ZLOGI("stop sample because ble unconnected"); + stopcapture = true; + } +#endif if (stopcapture) { // 关闭文件 @@ -235,12 +241,14 @@ static void app_event_listener(void* p_event_data, uint16_t event_size) { // event.eventType = kevent_sample_stop_event; AppEvent_pushEvent(&event); } + BoardBeepCtrl_setEffect(kBoardBeepEffect_oneShortBeep); } } } -void DeviceCtrl_startSample() { - ZLOGI("start sample"); +void DeviceCtrl_startSample(int duration_ms) { + ZLOGI("start sample %d", duration_ms); + m_sample_duration_ms = duration_ms; static app_event_t event; event.eventType = kevent_start_sample_cmd_event; AppEvent_pushEvent(&event); diff --git a/app/src/device_ctrl_service.h b/app/src/device_ctrl_service.h index 42549e5..6c6b609 100644 --- a/app/src/device_ctrl_service.h +++ b/app/src/device_ctrl_service.h @@ -37,8 +37,9 @@ void DeviceCtrl_change_to_state(device_state_t state); uint32_t DeviceCtrl_cur_state_haspassed_ms(); device_state_t DeviceCtrl_now_state(); -void DeviceCtrl_startSample(); +void DeviceCtrl_startSample(int duration_ms); + void DeviceCtrl_stopSample(); void DeviceCtrl_schdeule(); -void DeviceCtrl_init() ; +void DeviceCtrl_init(); diff --git a/app/src/heart_wave_sample_service.c b/app/src/heart_wave_sample_service.c index 956a91f..0fb6fa9 100644 --- a/app/src/heart_wave_sample_service.c +++ b/app/src/heart_wave_sample_service.c @@ -61,6 +61,8 @@ static uint8_t m_lodstate1; volatile static bool m_drop_state_triggered = false; +static uint32_t m_capture_start_s; + /******************************************************************************* * CONFIG * *******************************************************************************/ @@ -476,11 +478,14 @@ void hwss_init(void) { void hwss_load(void) { ads1293_init(); } void hwss_unload(void) { ads1293_uninit(); } +uint32_t hwss_started_has_passed_s(void) { return znrf_rtc_get_timestamp_s() - m_capture_start_s; } + void hwss_start_capture(void) { m_drop_state_triggered = false; m_work_flag = true; m_frame_index = 0; m_frame_filter_index = 0; + m_capture_start_s = znrf_rtc_get_timestamp_s(); pLittleBlockCache_reset(); // ads1293_start_conversion(&m_ads1293_0); // ads1293_start_conversion(&m_ads1293_1); diff --git a/app/src/heart_wave_sample_service.h b/app/src/heart_wave_sample_service.h index 5b467a5..72753b5 100644 --- a/app/src/heart_wave_sample_service.h +++ b/app/src/heart_wave_sample_service.h @@ -31,5 +31,7 @@ void hwss_stop_capture(void); bool hwss_is_capturing(void); +uint32_t hwss_started_has_passed_s(void); + uint8_t hwss_get_drop_state0(); uint8_t hwss_get_drop_state1(); \ No newline at end of file diff --git a/ify_hrs_protocol b/ify_hrs_protocol index b93a513..da8e077 160000 --- a/ify_hrs_protocol +++ b/ify_hrs_protocol @@ -1 +1 @@ -Subproject commit b93a5139c4e230def8bed2ea23675267ca1f4b1c +Subproject commit da8e07706a41c157a3e42da3f69136f665f5a20f diff --git a/libznordic b/libznordic index e18fec7..a0a8566 160000 --- a/libznordic +++ b/libznordic @@ -1 +1 @@ -Subproject commit e18fec728b0d73b8d831df675796bed7e47e1e85 +Subproject commit a0a8566a64d4a417f93884b8cd28089a8dc03262