Browse Source

添加部分休眠逻辑

master
zhaohe 1 year ago
parent
commit
ad4a1b8f71
  1. 28
      README.md
  2. 35
      app/src/app_ble_service.c
  3. 8
      app/src/board/board.h
  4. 26
      app/src/device_ctrl_service.c
  5. 5
      app/src/device_ctrl_service.h
  6. 5
      app/src/heart_wave_sample_service.c
  7. 2
      app/src/heart_wave_sample_service.h
  8. 2
      ify_hrs_protocol
  9. 2
      libznordic

28
README.md

@ -18,23 +18,33 @@
修改电量检测,电量过低时,指示灯闪烁三下后进入低功耗。OK 修改电量检测,电量过低时,指示灯闪烁三下后进入低功耗。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时,设备自动断开连接,并关机。 电量过低上报低电量事件。电量不足%1时,设备自动断开连接,并关机。
设备充电时候,不允许采集。
低电量进入关机模式
添加指令上传最新一条记录
Final:
修改休眠周期为30秒 修改休眠周期为30秒
...
设备充电时不进入休眠(无法实现,无法检测当前设备是否正在充电) OK
``` ```

35
app/src/app_ble_service.c

@ -4,6 +4,7 @@
#include "app_event.h" #include "app_event.h"
#include "app_event_distribute.h" #include "app_event_distribute.h"
#include "app_scheduler.h" #include "app_scheduler.h"
#include "basic/device_version_info_mgr.h"
#include "board/board.h" #include "board/board.h"
#include "board/board_battery_state.h" #include "board/board_battery_state.h"
#include "device_ctrl_service.h" #include "device_ctrl_service.h"
@ -12,7 +13,6 @@
#include "zble_module.h" #include "zble_module.h"
#include "zdatachannel_service.h" #include "zdatachannel_service.h"
#include "znordic.h" #include "znordic.h"
#include "basic/device_version_info_mgr.h"
static uint8_t rxbufcache[256]; static uint8_t rxbufcache[256];
static bool is_rxbufcache_used = false; // 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->cmd = rxpacket->cmd;
txheader->frame_index = rxpacket->frame_index; txheader->frame_index = rxpacket->frame_index;
txheader->frame_type = kifyhrs_pt_error_receipt; txheader->frame_type = kifyhrs_pt_error_receipt;
receipt->errorcode = errorcode;
receipt->errorcode = errorcode;
zdatachannel_data_send2(m_txbuf, sendlen); 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 * @brief
*/ */
for (int i = 0; i < ndata; i++) { for (int i = 0; i < ndata; i++) {
reportpacket->data[i * 9 + 0] = ((data[i].data0)) >> 0; reportpacket->data[i * 9 + 0] = ((data[i].data0)) >> 0;
reportpacket->data[i * 9 + 1] = ((data[i].data0)) >> 8; reportpacket->data[i * 9 + 1] = ((data[i].data0)) >> 8;
reportpacket->data[i * 9 + 2] = ((data[i].data0)) >> 16; 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* rxheader = (ify_hrs_packet_t*)p_event_data;
ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)m_txbuf; ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)m_txbuf;
ify_hrs_cmd_t cmd = (ify_hrs_cmd_t)rxheader->cmd; 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)); 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)); 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); 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); 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); send_success_receipt(rxheader, 0);
} }
//
// ify_hrs_cmd_start_upload_record_v2
else if (cmd == ify_hrs_cmd_stop_capture) { else if (cmd == ify_hrs_cmd_stop_capture) {
// hwss_stop_capture(); // hwss_stop_capture();
DeviceCtrl_stopSample(); DeviceCtrl_stopSample();

8
app/src/board/board.h

@ -29,7 +29,7 @@
*******************************************************************************/ *******************************************************************************/
#define ADS1293_SPI_INSTANCE 2 #define ADS1293_SPI_INSTANCE 2
#define BEEP_PWM_INSTANCE 0 #define BEEP_PWM_INSTANCE 0
#define LIGHT_PWM_INSTANCE 1
#define LIGHT_PWM_INSTANCE 1
#define BATTERY_ADC_CHANNEL 1 // ²»Öظ´¼´¿É #define BATTERY_ADC_CHANNEL 1 // ²»Öظ´¼´¿É
/******************************************************************************* /*******************************************************************************
@ -72,4 +72,8 @@
#define APP_BYTE_EACH_FRAME 9 #define APP_BYTE_EACH_FRAME 9
#define APP_SENSOR_NUM 3 #define APP_SENSOR_NUM 3
#define APP_LOW_BATTERY_LIMIT 2
#define APP_LOW_BATTERY_LIMIT 2
#define BLE_UNCONNECTED_OVERTIME_S 300
#define ENABLE_AUTO_STOP_WHEN_BLE_DISCONNECTED 1

26
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 device_state_t m_device_state = kdevice_state_standby; //
static uint32_t m_change_to_cur_state_tp = 0; // static uint32_t m_change_to_cur_state_tp = 0; //
static int m_sample_data_fd = -1; // 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) { if (!zble_module_is_connected() && DeviceCtrl_cur_state_haspassed_ms() > APP_AUTO_SLEEP_TIMEOUT_MS) {
ZLOGI("auto sleep"); ZLOGI("auto sleep");
prvf_change_to_standby_state(); 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) { 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); 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; bool stopcapture = false;
if (SampleDataMgr_getFileSizeByFd(m_sample_data_fd) > SDCARD_MAX_FILE_SIZE) { if (SampleDataMgr_getFileSizeByFd(m_sample_data_fd) > SDCARD_MAX_FILE_SIZE) {
ZLOGI("stop sample because file size is too large"); 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) { } else if (event->eventType == kevent_stop_sample_cmd_event) {
ZLOGI("stop sample because stop sample event"); ZLOGI("stop sample because stop sample event");
stopcapture = true; 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) { 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; event.eventType = kevent_sample_stop_event;
AppEvent_pushEvent(&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; static app_event_t event;
event.eventType = kevent_start_sample_cmd_event; event.eventType = kevent_start_sample_cmd_event;
AppEvent_pushEvent(&event); AppEvent_pushEvent(&event);

5
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(); uint32_t DeviceCtrl_cur_state_haspassed_ms();
device_state_t DeviceCtrl_now_state(); device_state_t DeviceCtrl_now_state();
void DeviceCtrl_startSample();
void DeviceCtrl_startSample(int duration_ms);
void DeviceCtrl_stopSample(); void DeviceCtrl_stopSample();
void DeviceCtrl_schdeule(); void DeviceCtrl_schdeule();
void DeviceCtrl_init() ;
void DeviceCtrl_init();

5
app/src/heart_wave_sample_service.c

@ -61,6 +61,8 @@ static uint8_t m_lodstate1;
volatile static bool m_drop_state_triggered = false; volatile static bool m_drop_state_triggered = false;
static uint32_t m_capture_start_s;
/******************************************************************************* /*******************************************************************************
* CONFIG * * CONFIG *
*******************************************************************************/ *******************************************************************************/
@ -476,11 +478,14 @@ void hwss_init(void) {
void hwss_load(void) { ads1293_init(); } void hwss_load(void) { ads1293_init(); }
void hwss_unload(void) { ads1293_uninit(); } 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) { void hwss_start_capture(void) {
m_drop_state_triggered = false; m_drop_state_triggered = false;
m_work_flag = true; m_work_flag = true;
m_frame_index = 0; m_frame_index = 0;
m_frame_filter_index = 0; m_frame_filter_index = 0;
m_capture_start_s = znrf_rtc_get_timestamp_s();
pLittleBlockCache_reset(); pLittleBlockCache_reset();
// ads1293_start_conversion(&m_ads1293_0); // ads1293_start_conversion(&m_ads1293_0);
// ads1293_start_conversion(&m_ads1293_1); // ads1293_start_conversion(&m_ads1293_1);

2
app/src/heart_wave_sample_service.h

@ -31,5 +31,7 @@ void hwss_stop_capture(void);
bool hwss_is_capturing(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_state0();
uint8_t hwss_get_drop_state1(); uint8_t hwss_get_drop_state1();

2
ify_hrs_protocol

@ -1 +1 @@
Subproject commit b93a5139c4e230def8bed2ea23675267ca1f4b1c
Subproject commit da8e07706a41c157a3e42da3f69136f665f5a20f

2
libznordic

@ -1 +1 @@
Subproject commit e18fec728b0d73b8d831df675796bed7e47e1e85
Subproject commit a0a8566a64d4a417f93884b8cd28089a8dc03262
Loading…
Cancel
Save