|
|
@ -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); |
|
|
|