|
|
@ -9,52 +9,6 @@ |
|
|
|
#include "one_conduction_board.h" |
|
|
|
#include "sample_data_manager.h" |
|
|
|
#include "znordic.h" |
|
|
|
#if 1 |
|
|
|
typedef enum { |
|
|
|
// 待机 |
|
|
|
kdevice_state_standby = 0, |
|
|
|
// 开机 |
|
|
|
kdevice_state_poweron, |
|
|
|
// 首页 |
|
|
|
kdevice_state_home, |
|
|
|
// 提示用户保持静止 |
|
|
|
kdevice_state_keep_still, |
|
|
|
// 采集中 |
|
|
|
kdevice_state_sampling, |
|
|
|
// 采集正常结束 |
|
|
|
// kdevice_state_sampling_end, |
|
|
|
// 存储中 |
|
|
|
// kdevice_state_storing, |
|
|
|
// 采集完成 |
|
|
|
kdevice_state_sampling_complete, |
|
|
|
// 采集异常 |
|
|
|
kdevice_state_sampling_error, |
|
|
|
// 充电中 |
|
|
|
kdevice_state_charging, |
|
|
|
} device_state_t; |
|
|
|
|
|
|
|
static const char* device_state_to_str(device_state_t ds) { |
|
|
|
switch (ds) { |
|
|
|
case kdevice_state_standby: |
|
|
|
return "standby"; |
|
|
|
case kdevice_state_poweron: |
|
|
|
return "poweron"; |
|
|
|
case kdevice_state_home: |
|
|
|
return "home"; |
|
|
|
case kdevice_state_keep_still: |
|
|
|
return "keep_still"; |
|
|
|
case kdevice_state_sampling: |
|
|
|
return "sampling"; |
|
|
|
case kdevice_state_sampling_complete: |
|
|
|
return "sampling_complete"; |
|
|
|
case kdevice_state_sampling_error: |
|
|
|
return "sampling_error"; |
|
|
|
case kdevice_state_charging: |
|
|
|
return "charging"; |
|
|
|
default: |
|
|
|
return "unknow"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/******************************************************************************* |
|
|
|
* GLOBAL * |
|
|
@ -64,9 +18,8 @@ ZDATACHANNEL_DEF(m_zhrs, 2 /* |
|
|
|
APP_TIMER_DEF(m_state_machine_driver_tmr); // 状态机驱动定时器 |
|
|
|
APP_TIMER_DEF(m_plod_state_event_detect_tmr); // 导联连接状态检测定时器 |
|
|
|
APP_TIMER_DEF(m_charge_event_detect_tmr); // 充电事件检测 |
|
|
|
extern uint32_t g_nrf_log_tx_pin; |
|
|
|
static device_state_t m_device_state = kdevice_state_standby; // 设备状态 |
|
|
|
static uint32_t m_change_to_cur_state_tp = 0; // 切换到当前状态的时间戳 |
|
|
|
extern uint32_t g_nrf_log_tx_pin; |
|
|
|
|
|
|
|
static int m_cur_fd; |
|
|
|
static sample_data_filename_t sampledata_file_name; |
|
|
|
|
|
|
@ -83,8 +36,6 @@ static sample_data_filename_t sampledata_file_name; |
|
|
|
*******************************************************************************/ |
|
|
|
|
|
|
|
// 导联连接状态事件生成器 |
|
|
|
static uint32_t m_plod_state_disconnect_timepoint = 0; |
|
|
|
static uint32_t m_plod_state_connect_timepoint = 0; |
|
|
|
static bool m_plod_state_connected_state = false; |
|
|
|
static uint32_t m_connecte_state_last_trigger_timepoint = 0; |
|
|
|
|
|
|
@ -107,15 +58,13 @@ static void m_plod_state_event_detect_tmr_cb(void* p_context) { // |
|
|
|
|
|
|
|
if (connecte_state_trigger_cnt == 15) { |
|
|
|
// 连接事件 |
|
|
|
appevent.eventType = kplod_connected_event; |
|
|
|
m_plod_state_connect_timepoint = znordic_getpower_on_ms(); |
|
|
|
m_plod_state_connected_state = true; |
|
|
|
appevent.eventType = kplod_connected_event; |
|
|
|
m_plod_state_connected_state = true; |
|
|
|
app_sched_event_put(&appevent, sizeof(appevent), app_event_process_cb); |
|
|
|
} else if (connecte_state_trigger_cnt_last_val >= 5 && connecte_state_trigger_cnt == 0) { |
|
|
|
// 断开事件 |
|
|
|
appevent.eventType = kplod_disconnected_event; |
|
|
|
m_plod_state_connected_state = false; |
|
|
|
m_plod_state_disconnect_timepoint = znordic_getpower_on_ms(); |
|
|
|
appevent.eventType = kplod_disconnected_event; |
|
|
|
m_plod_state_connected_state = false; |
|
|
|
app_sched_event_put(&appevent, sizeof(appevent), app_event_process_cb); |
|
|
|
} else if (connecte_state_trigger_cnt >= 10 && connecte_state_trigger_cnt % 10 == 0) { |
|
|
|
// 连接持续事件 |
|
|
@ -156,16 +105,8 @@ static void state_machine_driver_tmr_cb(void* p_context) { // |
|
|
|
/******************************************************************************* |
|
|
|
* 事件处理 * |
|
|
|
*******************************************************************************/ |
|
|
|
|
|
|
|
static void state_machine_change_to_state(device_state_t state) { |
|
|
|
ZLOGI("change state from %s to %s", device_state_to_str(m_device_state), device_state_to_str(state)); |
|
|
|
m_device_state = state; |
|
|
|
m_change_to_cur_state_tp = znordic_getpower_on_ms(); |
|
|
|
} |
|
|
|
|
|
|
|
static uint32_t cur_state_haspassed_ms() { return znordic_haspassed_ms(m_change_to_cur_state_tp); } |
|
|
|
static bool m_poweronflag; |
|
|
|
static void power_on() { |
|
|
|
static bool m_poweronflag; |
|
|
|
static void power_on() { |
|
|
|
if (m_poweronflag) { |
|
|
|
return; |
|
|
|
} |
|
|
@ -177,7 +118,7 @@ static void power_on() { |
|
|
|
hwss_init(); |
|
|
|
sample_data_mgr_init(); |
|
|
|
dsp_mgr_init(); |
|
|
|
zble_module_start_adv(); |
|
|
|
// zble_module_start_adv(); |
|
|
|
|
|
|
|
m_poweronflag = true; |
|
|
|
ZERROR_CHECK(app_timer_start(m_state_machine_driver_tmr, APP_TIMER_TICKS(100), NULL)); // 200HZ采样 |
|
|
@ -192,7 +133,7 @@ static void power_off() { |
|
|
|
SingleLeadECG_led_deinit(); |
|
|
|
SingleLeadECG_beep_deinit(); |
|
|
|
SingleLeadECG_adc_module_deinit(); |
|
|
|
zble_module_stop_adv(); |
|
|
|
// zble_module_stop_adv(); |
|
|
|
ZERROR_CHECK(app_timer_stop(m_state_machine_driver_tmr)); |
|
|
|
} |
|
|
|
/******************************************************************************* |
|
|
@ -202,16 +143,16 @@ static void power_off() { |
|
|
|
* @brief 切换到充电中状态 |
|
|
|
*/ |
|
|
|
static void state_machine__change_to_charging_state() { // |
|
|
|
if (m_device_state == kdevice_state_home) { |
|
|
|
if (ds_now_state() == kdevice_state_home) { |
|
|
|
// 已开机 DO Nothing |
|
|
|
} else if (m_device_state == kdevice_state_standby) { |
|
|
|
} else if (ds_now_state() == kdevice_state_standby) { |
|
|
|
power_on(); |
|
|
|
} else { |
|
|
|
ZASSERT(false); |
|
|
|
} |
|
|
|
// 切换到充电显示页面 |
|
|
|
dsp_mgr_change_to_chargingPage(); |
|
|
|
state_machine_change_to_state(kdevice_state_charging); |
|
|
|
ds_change_to_state(kdevice_state_charging); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -221,7 +162,7 @@ static void state_machine__change_to_charging_state() { // |
|
|
|
static void state_machine__change_to_standby_state() { |
|
|
|
ZLOGI_BLOCK("change to standby"); |
|
|
|
power_off(); |
|
|
|
state_machine_change_to_state(kdevice_state_standby); |
|
|
|
ds_change_to_state(kdevice_state_standby); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -230,21 +171,21 @@ static void state_machine__change_to_standby_state() { |
|
|
|
static void state_machine__change_to_poweroning_state() { |
|
|
|
power_on(); |
|
|
|
dsp_mgr_change_to_welcome(); |
|
|
|
state_machine_change_to_state(kdevice_state_poweron); |
|
|
|
ds_change_to_state(kdevice_state_poweron); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief 切换到首页 |
|
|
|
*/ |
|
|
|
static void state_machine__change_to_home_state() { |
|
|
|
state_machine_change_to_state(kdevice_state_home); |
|
|
|
ds_change_to_state(kdevice_state_home); |
|
|
|
dsp_mgr_change_to_main(); |
|
|
|
} |
|
|
|
void app_event_process_cb(void* p_event_data, uint16_t event_size) { |
|
|
|
if (!p_event_data) return; |
|
|
|
app_event_t* p_event = (app_event_t*)p_event_data; |
|
|
|
|
|
|
|
if (m_device_state == kdevice_state_standby) { |
|
|
|
if (ds_now_state() == kdevice_state_standby) { |
|
|
|
/******************************************************************************* |
|
|
|
* 待机状态 * |
|
|
|
*******************************************************************************/ |
|
|
@ -258,46 +199,46 @@ void app_event_process_cb(void* p_event_data, uint16_t event_size) { |
|
|
|
state_machine__change_to_poweroning_state(); |
|
|
|
} |
|
|
|
|
|
|
|
} else if (m_device_state == kdevice_state_charging) { |
|
|
|
} else if (ds_now_state() == kdevice_state_charging) { |
|
|
|
/******************************************************************************* |
|
|
|
* 充电状态 * |
|
|
|
*******************************************************************************/ |
|
|
|
if (!SingleLeadECG_battery_charge_get_state()) { |
|
|
|
state_machine__change_to_standby_state(); |
|
|
|
} |
|
|
|
} else if (m_device_state == kdevice_state_poweron) { |
|
|
|
} else if (ds_now_state() == kdevice_state_poweron) { |
|
|
|
/******************************************************************************* |
|
|
|
* 开机中 * |
|
|
|
*******************************************************************************/ |
|
|
|
if (cur_state_haspassed_ms() >= 1500) { |
|
|
|
if (ds_cur_state_haspassed_ms() >= 1500) { |
|
|
|
state_machine__change_to_home_state(); |
|
|
|
} |
|
|
|
} else if (m_device_state == kdevice_state_home) { |
|
|
|
} else if (ds_now_state() == kdevice_state_home) { |
|
|
|
/******************************************************************************* |
|
|
|
* 首页 * |
|
|
|
*******************************************************************************/ |
|
|
|
// 如果用户长时间不操作,自动切换到待机状态 |
|
|
|
if (!m_plod_state_connected_state && plod_state_has_disconnected_ms() >= 3000 && cur_state_haspassed_ms() >= 3000) { |
|
|
|
if (!plod_state_is_connected() && plod_state_has_disconnected_ms() >= 3000 && ds_cur_state_haspassed_ms() >= 3000) { |
|
|
|
state_machine__change_to_standby_state(); |
|
|
|
} |
|
|
|
// 如果用户继续保持静止,切换到采集页面 |
|
|
|
else if (m_plod_state_connected_state && cur_state_haspassed_ms() > 1500) { |
|
|
|
else if (plod_state_is_connected() && ds_cur_state_haspassed_ms() > 1500) { |
|
|
|
// dsp_mgr_change_to_preparePage |
|
|
|
state_machine_change_to_state(kdevice_state_keep_still); |
|
|
|
ds_change_to_state(kdevice_state_keep_still); |
|
|
|
dsp_mgr_change_to_preparePage(); |
|
|
|
} |
|
|
|
} else if (m_device_state == kdevice_state_keep_still) { |
|
|
|
} else if (ds_now_state() == kdevice_state_keep_still) { |
|
|
|
/******************************************************************************* |
|
|
|
* 保持静止页面 * |
|
|
|
*******************************************************************************/ |
|
|
|
if (!m_plod_state_connected_state) { |
|
|
|
if (!plod_state_is_connected()) { |
|
|
|
// 如果用户未保持静止,切换到首页 |
|
|
|
state_machine__change_to_home_state(); |
|
|
|
} else { |
|
|
|
/******************************************************************************* |
|
|
|
* 页面加载中 * |
|
|
|
*******************************************************************************/ |
|
|
|
if (cur_state_haspassed_ms() >= (500 * 5)) { |
|
|
|
if (ds_cur_state_haspassed_ms() >= (500 * 5)) { |
|
|
|
/** |
|
|
|
* @brief 保持静止2500ms后,切换到采集页面 |
|
|
|
* |
|
|
@ -305,7 +246,7 @@ void app_event_process_cb(void* p_event_data, uint16_t event_size) { |
|
|
|
* 2. 切换状态 |
|
|
|
* 3. 切换页面 |
|
|
|
*/ |
|
|
|
state_machine_change_to_state(kdevice_state_sampling); |
|
|
|
ds_change_to_state(kdevice_state_sampling); |
|
|
|
dsp_mgr_change_to_sampling(0, 0); |
|
|
|
hwss_start_capture(); |
|
|
|
static ztm_t tm; |
|
|
@ -320,25 +261,25 @@ void app_event_process_cb(void* p_event_data, uint16_t event_size) { |
|
|
|
sampledata_file_name.sec = tm.tm_sec; |
|
|
|
m_cur_fd = sample_data_mgr_open(&sampledata_file_name, kwrflag_write_only); |
|
|
|
|
|
|
|
} else if (cur_state_haspassed_ms() >= (500 * 4)) { |
|
|
|
} else if (ds_cur_state_haspassed_ms() >= (500 * 4)) { |
|
|
|
if (dsp_mgr_preparePage_get_progress() != 4) { |
|
|
|
dsp_mgr_preparePage_set_progress(4); |
|
|
|
} |
|
|
|
} else if (cur_state_haspassed_ms() >= (500 * 3)) { |
|
|
|
} else if (ds_cur_state_haspassed_ms() >= (500 * 3)) { |
|
|
|
if (dsp_mgr_preparePage_get_progress() != 3) { |
|
|
|
dsp_mgr_preparePage_set_progress(3); |
|
|
|
} |
|
|
|
} else if (cur_state_haspassed_ms() >= (500 * 2)) { |
|
|
|
} else if (ds_cur_state_haspassed_ms() >= (500 * 2)) { |
|
|
|
if (dsp_mgr_preparePage_get_progress() != 2) { |
|
|
|
dsp_mgr_preparePage_set_progress(2); |
|
|
|
} |
|
|
|
} else if (cur_state_haspassed_ms() >= (500 * 1)) { |
|
|
|
} else if (ds_cur_state_haspassed_ms() >= (500 * 1)) { |
|
|
|
if (dsp_mgr_preparePage_get_progress() != 1) { |
|
|
|
dsp_mgr_preparePage_set_progress(1); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (m_device_state == kdevice_state_sampling) { |
|
|
|
} else if (ds_now_state() == kdevice_state_sampling) { |
|
|
|
/******************************************************************************* |
|
|
|
* 采样页面逻辑 * |
|
|
|
*******************************************************************************/ |
|
|
@ -353,7 +294,7 @@ void app_event_process_cb(void* p_event_data, uint16_t event_size) { |
|
|
|
* ---> 切换到存储中 |
|
|
|
*/ |
|
|
|
|
|
|
|
bool always_capture = true; |
|
|
|
bool always_capture = false; |
|
|
|
if (p_event->eventType == kevent_capture_data_event) { |
|
|
|
if (hwss_has_captured_time_ms() <= (MAX_STORAGE_TIMEOUT_S * 1000)) { |
|
|
|
// ZLOGI("storage data 256 [%d]ms", hwss_has_captured_time_ms()); |
|
|
@ -365,7 +306,7 @@ void app_event_process_cb(void* p_event_data, uint16_t event_size) { |
|
|
|
*******************************************************************************/ |
|
|
|
if (!always_capture) { |
|
|
|
sample_data_mgr_close(m_cur_fd); |
|
|
|
state_machine_change_to_state(kdevice_state_sampling_complete); |
|
|
|
ds_change_to_state(kdevice_state_sampling_complete); |
|
|
|
hwss_stop_capture(); |
|
|
|
} |
|
|
|
} |
|
|
@ -379,7 +320,7 @@ void app_event_process_cb(void* p_event_data, uint16_t event_size) { |
|
|
|
sample_data_mgr_close(m_cur_fd); |
|
|
|
sample_data_mgr_delete_file(&sampledata_file_name); |
|
|
|
dsp_mgr_change_to_samplingError(); |
|
|
|
state_machine_change_to_state(kdevice_state_sampling_error); |
|
|
|
ds_change_to_state(kdevice_state_sampling_error); |
|
|
|
hwss_stop_capture(); |
|
|
|
} |
|
|
|
} else { |
|
|
@ -390,44 +331,22 @@ void app_event_process_cb(void* p_event_data, uint16_t event_size) { |
|
|
|
if (!always_capture) { |
|
|
|
sample_data_mgr_close(m_cur_fd); |
|
|
|
dsp_mgr_change_to_sampleSuc(); |
|
|
|
state_machine_change_to_state(kdevice_state_sampling_complete); |
|
|
|
ds_change_to_state(kdevice_state_sampling_complete); |
|
|
|
hwss_stop_capture(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (m_device_state == kdevice_state_sampling_complete) { |
|
|
|
if (cur_state_haspassed_ms() >= 2000) { |
|
|
|
ZLOGI("cur_state_haspassed_ms() %d> 2000", cur_state_haspassed_ms()); |
|
|
|
} else if (ds_now_state() == kdevice_state_sampling_complete) { |
|
|
|
if (ds_cur_state_haspassed_ms() >= 2000) { |
|
|
|
ZLOGI("ds_cur_state_haspassed_ms() %d> 2000", ds_cur_state_haspassed_ms()); |
|
|
|
state_machine__change_to_home_state(); |
|
|
|
} |
|
|
|
} else if (m_device_state == kdevice_state_sampling_error) { |
|
|
|
if ((cur_state_haspassed_ms() >= 2000) || (cur_state_haspassed_ms() >= 1000 && m_plod_state_connected_state)) { |
|
|
|
ZLOGI("cur_state_haspassed_ms() %d> 2000", cur_state_haspassed_ms()); |
|
|
|
} else if (ds_now_state() == kdevice_state_sampling_error) { |
|
|
|
if ((ds_cur_state_haspassed_ms() >= 2000) || (ds_cur_state_haspassed_ms() >= 1000 && m_plod_state_connected_state)) { |
|
|
|
ZLOGI("ds_cur_state_haspassed_ms() %d> 2000", ds_cur_state_haspassed_ms()); |
|
|
|
state_machine__change_to_home_state(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#if 0 |
|
|
|
if (p_event->eventType == kplod_connected_event) { |
|
|
|
ZLOGI("plod connected"); |
|
|
|
} else if (p_event->eventType == kplod_disconnected_event) { |
|
|
|
ZLOGI("plod disconnected"); |
|
|
|
} else if (p_event->eventType == kplod_connecting_event) { |
|
|
|
ZLOGI("plod connecting %d", p_event->val.plod_connected_accumulation_time); |
|
|
|
} |
|
|
|
|
|
|
|
if (p_event->eventType == kplod_start_charge_event) { |
|
|
|
/** |
|
|
|
* @brief 检测到充电装固态 |
|
|
|
*/ |
|
|
|
if (m_device_state == kdevice_state_standby || m_device_state == kdevice_state_home) { |
|
|
|
state_machine__change_to_charging_state(); |
|
|
|
} |
|
|
|
|
|
|
|
} else if (p_event->eventType == kplod_end_charge_event) { |
|
|
|
ZLOGI("end charge"); |
|
|
|
} |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -452,7 +371,6 @@ void on_service_init(void) { |
|
|
|
zdatachannle_init.data_handler = zdatachannel_data_handler; |
|
|
|
ZERROR_CHECK(zdatachannel_init(&m_zhrs, &zdatachannle_init)); |
|
|
|
} |
|
|
|
#if 1 |
|
|
|
void one_conduction_main() { |
|
|
|
APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, 20); |
|
|
|
g_nrf_log_tx_pin = 41; |
|
|
@ -469,10 +387,7 @@ void one_conduction_main() { |
|
|
|
}; |
|
|
|
zble_module_init(&cfg); |
|
|
|
hwss_init(); |
|
|
|
// power_on(); |
|
|
|
// hwss_start_capture(); |
|
|
|
|
|
|
|
#if 1 |
|
|
|
SingleLeadECG_ecg_io_init(); |
|
|
|
SingleLeadECG_battery_charge_detect_io_init(); |
|
|
|
ZERROR_CHECK(app_timer_create(&m_state_machine_driver_tmr, APP_TIMER_MODE_REPEATED, state_machine_driver_tmr_cb)); |
|
|
@ -481,131 +396,5 @@ void one_conduction_main() { |
|
|
|
|
|
|
|
ZERROR_CHECK(app_timer_start(m_plod_state_event_detect_tmr, APP_TIMER_TICKS(30), NULL)); |
|
|
|
ZERROR_CHECK(app_timer_start(m_charge_event_detect_tmr, APP_TIMER_TICKS(100), NULL)); |
|
|
|
#endif |
|
|
|
znordic_loop(); |
|
|
|
} |
|
|
|
#else |
|
|
|
|
|
|
|
void one_conduction_main() { |
|
|
|
APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, 20); |
|
|
|
g_nrf_log_tx_pin = 41; |
|
|
|
znordic_init(); |
|
|
|
static zble_module_cfg_t cfg = // |
|
|
|
{ |
|
|
|
.deviceName = BLE_NAME, |
|
|
|
.on_service_init = on_service_init, |
|
|
|
}; |
|
|
|
zble_module_init(&cfg); |
|
|
|
hwss_init(); |
|
|
|
|
|
|
|
NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100)); |
|
|
|
NRF_LOG_INTERNAL_FLUSH(); |
|
|
|
|
|
|
|
// SingleLeadECG_ecg_init(); |
|
|
|
// SingleLeadECG_adc_module_init(); |
|
|
|
SingleLeadECG_beep_init(); |
|
|
|
SingleLeadECG_led_init(); |
|
|
|
SingleLeadECG_ecg_init(); |
|
|
|
SingleLeadECG_battery_init(); |
|
|
|
// hwss_init(); |
|
|
|
// sample_data_mgr_init(); |
|
|
|
// dsp_mgr_init(); |
|
|
|
// zble_module_start_adv(); |
|
|
|
|
|
|
|
hwss_start_capture(); |
|
|
|
|
|
|
|
znordic_loop(); |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
// ZERROR_CHECK(app_timer_start(m_state_machine_driver_tmr, APP_TIMER_TICKS(5), NULL)); |
|
|
|
// zble_module_start_adv(); |
|
|
|
// dsp_mgr_init(); |
|
|
|
// dsp_mgr_poweron(); |
|
|
|
// dsp_mgr_change_to_sampling(); |
|
|
|
|
|
|
|
#else |
|
|
|
#include <stdarg.h> |
|
|
|
#if defined(UART_PRESENT) |
|
|
|
#include "nrf_uart.h" |
|
|
|
#endif |
|
|
|
#if defined(UARTE_PRESENT) |
|
|
|
#include "nrf_uarte.h" |
|
|
|
#endif |
|
|
|
#define UART_TX_BUF_SIZE 256 /**< UART TX buffer size. */ |
|
|
|
#define UART_RX_BUF_SIZE 256 /**< UART RX buffer size. */ |
|
|
|
uint32_t err_code; |
|
|
|
app_uart_comm_params_t const comm_params = // |
|
|
|
{ |
|
|
|
.rx_pin_no = UART_PIN_DISCONNECTED, |
|
|
|
.tx_pin_no = 41, |
|
|
|
.rts_pin_no = UART_PIN_DISCONNECTED, |
|
|
|
.cts_pin_no = UART_PIN_DISCONNECTED, |
|
|
|
.flow_control = APP_UART_FLOW_CONTROL_DISABLED, |
|
|
|
.use_parity = false, |
|
|
|
.baud_rate = NRF_UARTE_BAUDRATE_921600, |
|
|
|
}; |
|
|
|
|
|
|
|
void uart_error_handle(app_uart_evt_t* p_event) {} |
|
|
|
|
|
|
|
void uartinit() { |
|
|
|
APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_error_handle, APP_IRQ_PRIORITY_LOWEST, err_code); |
|
|
|
APP_ERROR_CHECK(err_code); |
|
|
|
} |
|
|
|
|
|
|
|
void zchip_log(const char* fmt, ...) { |
|
|
|
static char tx[256] = {0}; |
|
|
|
va_list args; |
|
|
|
va_start(args, fmt); |
|
|
|
|
|
|
|
vsprintf(tx, fmt, args); |
|
|
|
for (size_t i = 0; i < strlen(tx); i++) { |
|
|
|
app_uart_put(tx[i]); |
|
|
|
} |
|
|
|
|
|
|
|
va_end(args); |
|
|
|
} |
|
|
|
|
|
|
|
static void test_tx_timer_cb(void* p_context) { |
|
|
|
static uint32_t data; |
|
|
|
data++; |
|
|
|
// SingleLeadECG_ecg_nlod_get_connected_state(); |
|
|
|
// SingleLeadECG_ecg_plod_get_connected_state(); |
|
|
|
// SingleLeadECG_ecg_plod_get_ecg_val(); |
|
|
|
// ZLOGI("%d nlod %d plod %d ecg:%d", data, SingleLeadECG_ecg_nlod_get_connected_state(), SingleLeadECG_ecg_plod_get_connected_state(), SingleLeadECG_ecg_plod_get_ecg_val()); |
|
|
|
// ZLOGI("%d,%d,%d", SingleLeadECG_ecg_nlod_get_connected_state(), SingleLeadECG_ecg_plod_get_connected_state(), SingleLeadECG_ecg_plod_get_ecg_val()); |
|
|
|
|
|
|
|
// zchip_log("%d,%d,%d\n", SingleLeadECG_ecg_nlod_get_connected_state(), SingleLeadECG_ecg_plod_get_connected_state(), SingleLeadECG_ecg_plod_get_ecg_val()); |
|
|
|
ZLOGI("%d,%d,%d", SingleLeadECG_ecg_nlod_get_connected_state(), SingleLeadECG_ecg_plod_get_connected_state(), SingleLeadECG_ecg_plod_get_ecg_val()); |
|
|
|
// app_uart_put('c'); |
|
|
|
// app_uart_put('c'); |
|
|
|
// app_uart_put('c'); |
|
|
|
// app_uart_put('c'); |
|
|
|
// app_uart_put('c'); |
|
|
|
// NRF_LOG_INFO("......"); |
|
|
|
} |
|
|
|
void app_event_process_cb(void* p_event_data, uint16_t event_size) {} |
|
|
|
|
|
|
|
extern uint32_t g_nrf_log_tx_pin; |
|
|
|
APP_TIMER_DEF(m_test_tx_timer); |
|
|
|
|
|
|
|
void one_conduction_main() { |
|
|
|
g_nrf_log_tx_pin = 41; |
|
|
|
APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20); |
|
|
|
znordic_init(); |
|
|
|
SingleLeadECG_adc_module_init(); |
|
|
|
hwss_init(); |
|
|
|
|
|
|
|
// uartinit(); |
|
|
|
|
|
|
|
NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100)); |
|
|
|
NRF_LOG_INTERNAL_FLUSH(); |
|
|
|
|
|
|
|
SingleLeadECG_ecg_init(); |
|
|
|
hwss_start_capture(); |
|
|
|
|
|
|
|
ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb)); |
|
|
|
// ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(5), NULL)); |
|
|
|
znordic_loop(); |
|
|
|
} |
|
|
|
#endif |