|
|
@ -7,54 +7,107 @@ |
|
|
|
#include "sample_data_manager.h" |
|
|
|
#include "znordic.h" |
|
|
|
|
|
|
|
ZDATACHANNEL_DEF(m_zhrs, 2 /*鍥炶皟浜嬩欢浼樺厛??*/, 1 /*client num*/); |
|
|
|
/******************************************************************************* |
|
|
|
* GLOBAL * |
|
|
|
*******************************************************************************/ |
|
|
|
|
|
|
|
ZDATACHANNEL_DEF(m_zhrs, 2 /*优先级*/, 1 /*client num*/); // 蓝牙服务 |
|
|
|
APP_TIMER_DEF(m_state_machine_driver_tmr); // 状态机驱动定时器 |
|
|
|
APP_TIMER_DEF(m_plod_state_event_detect_tmr); // 导联连接状态检测定时器 |
|
|
|
extern uint32_t g_nrf_log_tx_pin; |
|
|
|
#define SCHED_MAX_EVENT_DATA_SIZE APP_TIMER_SCHED_EVENT_DATA_SIZE /**< Maximum size of scheduler events. */ |
|
|
|
|
|
|
|
typedef enum { |
|
|
|
kplod_connected_event = 0, // 导联连接事件 |
|
|
|
kplod_disconnected_event, // 导联断开事件 |
|
|
|
kplod_connecting_event, // 导联连接中事件 |
|
|
|
} app_event_type_t; |
|
|
|
|
|
|
|
typedef struct { |
|
|
|
app_event_type_t eventType; |
|
|
|
union { |
|
|
|
uint32_t plod_connected_accumulation_time; // 导联连接累计时间 |
|
|
|
} val; |
|
|
|
} app_event_t; |
|
|
|
|
|
|
|
/******************************************************************************* |
|
|
|
* TOOLS * |
|
|
|
* 函数声明 * |
|
|
|
*******************************************************************************/ |
|
|
|
|
|
|
|
void zdatachannel_data_handler(zdatachannel_evt_t* p_evt) { |
|
|
|
/** |
|
|
|
* @brief 鎺ユ敹鍒版寚浠ゆ暟?? |
|
|
|
*/ |
|
|
|
if (p_evt->type == ZDATACHANNEL_EVT_RX_DATA) { |
|
|
|
ZLOGI("rx:%s", hex2str(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length)); |
|
|
|
// 业务事件处理函数 |
|
|
|
static void app_event_process_cb(void* p_event_data, uint16_t event_size); |
|
|
|
|
|
|
|
/******************************************************************************* |
|
|
|
* 事件生成器 * |
|
|
|
*******************************************************************************/ |
|
|
|
|
|
|
|
// 导联连接状态事件生成器 |
|
|
|
static void m_plod_state_event_detect_tmr_cb(void* p_context) { // |
|
|
|
static uint32_t connecte_state_trigger_cnt = 0; |
|
|
|
static uint32_t connecte_state_trigger_cnt_last_val = 0; |
|
|
|
static app_event_t appevent; |
|
|
|
memset(&appevent, 0, sizeof(appevent)); |
|
|
|
|
|
|
|
connecte_state_trigger_cnt_last_val = connecte_state_trigger_cnt; |
|
|
|
if (!SingleLeadECG_ecg_plod_get_connected_state()) { |
|
|
|
connecte_state_trigger_cnt++; |
|
|
|
} else { |
|
|
|
connecte_state_trigger_cnt = 0; |
|
|
|
} |
|
|
|
|
|
|
|
if (connecte_state_trigger_cnt == 5) { |
|
|
|
// 连接事件 |
|
|
|
appevent.eventType = kplod_connected_event; |
|
|
|
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; |
|
|
|
app_sched_event_put(&appevent, sizeof(appevent), app_event_process_cb); |
|
|
|
} else if (connecte_state_trigger_cnt >= 10 && connecte_state_trigger_cnt % 10 == 0) { |
|
|
|
// 连接持续事件 |
|
|
|
appevent.eventType = kplod_connecting_event; |
|
|
|
appevent.val.plod_connected_accumulation_time = connecte_state_trigger_cnt / 10; |
|
|
|
app_sched_event_put(&appevent, sizeof(appevent), app_event_process_cb); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static void test_tx_timer_cb(void* p_context) { |
|
|
|
#if 0 |
|
|
|
/******************************************************************************* |
|
|
|
* EEPROM读写测试 * |
|
|
|
* 事件处理 * |
|
|
|
*******************************************************************************/ |
|
|
|
sample_data_mgr_init(); |
|
|
|
static sample_data_filename_t filename = {0x00, 0x02, 0x03, 0x04, 0x05}; |
|
|
|
static uint8_t wd[256]; |
|
|
|
static uint8_t rdcache[256]; |
|
|
|
|
|
|
|
int fd = sample_data_mgr_open(&filename, kwrflag_write_only); |
|
|
|
for (size_t i = 0; i < 10; i++) { |
|
|
|
for (size_t j = 0; j < 256; j++) wd[j] = j + i; |
|
|
|
sample_data_mgr_write(fd, wd, 256); |
|
|
|
} |
|
|
|
sample_data_mgr_close(fd); |
|
|
|
|
|
|
|
fd = sample_data_mgr_open(&filename, kwrflag_read_only); |
|
|
|
for (size_t i = 0; i < 10; i++) { |
|
|
|
sample_data_mgr_read(fd, rdcache, 256); |
|
|
|
NRF_LOG_HEXDUMP_INFO(rdcache, 256); |
|
|
|
static 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 (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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
sample_data_mgr_dump_fileinfo_list(); |
|
|
|
sample_data_mgr_uninit(); |
|
|
|
#endif |
|
|
|
/** |
|
|
|
* @brief 蓝牙消息解析 |
|
|
|
*/ |
|
|
|
void zdatachannel_data_handler(zdatachannel_evt_t* p_evt) { |
|
|
|
/** |
|
|
|
* @brief |
|
|
|
*/ |
|
|
|
if (p_evt->type == ZDATACHANNEL_EVT_RX_DATA) { |
|
|
|
ZLOGI("rx:%s", hex2str(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
extern uint32_t g_nrf_log_tx_pin; |
|
|
|
APP_TIMER_DEF(m_drawpoint_timer); |
|
|
|
/** |
|
|
|
* @brief 测试定时器回调 |
|
|
|
*/ |
|
|
|
static void state_machine_driver_tmr_cb(void* p_context) { // |
|
|
|
} |
|
|
|
|
|
|
|
/******************************************************************************* |
|
|
|
* INIT * |
|
|
|
* MAIN_CODE * |
|
|
|
*******************************************************************************/ |
|
|
|
void on_service_init(void) { |
|
|
|
ZLOGI("init zdatachannel service"); |
|
|
@ -65,9 +118,9 @@ void on_service_init(void) { |
|
|
|
} |
|
|
|
|
|
|
|
void one_conduction_main() { |
|
|
|
APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, 20); |
|
|
|
g_nrf_log_tx_pin = 41; |
|
|
|
|
|
|
|
APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20); |
|
|
|
znordic_init(0, 20); |
|
|
|
NRF_LOG_INFO("compile time :%s", __TIME__); |
|
|
|
NRF_LOG_INFO("Version :%d", VERSION); |
|
|
@ -79,17 +132,17 @@ void one_conduction_main() { |
|
|
|
.on_service_init = on_service_init, |
|
|
|
}; |
|
|
|
zble_module_init(&cfg); |
|
|
|
zble_module_start_adv(); |
|
|
|
|
|
|
|
dsp_mgr_init(); |
|
|
|
|
|
|
|
dsp_mgr_poweron(); |
|
|
|
dsp_mgr_change_to_sampling(); |
|
|
|
|
|
|
|
// SingleLeadECG_eeprom_write(0, eepromw_test_data, 256); |
|
|
|
|
|
|
|
ZERROR_CHECK(app_timer_create(&m_drawpoint_timer, APP_TIMER_MODE_SINGLE_SHOT, test_tx_timer_cb)); |
|
|
|
ZERROR_CHECK(app_timer_start(m_drawpoint_timer, APP_TIMER_TICKS(100), NULL)); |
|
|
|
SingleLeadECG_ecg_io_init(); |
|
|
|
ZERROR_CHECK(app_timer_create(&m_state_machine_driver_tmr, APP_TIMER_MODE_REPEATED, state_machine_driver_tmr_cb)); |
|
|
|
ZERROR_CHECK(app_timer_create(&m_plod_state_event_detect_tmr, APP_TIMER_MODE_REPEATED, m_plod_state_event_detect_tmr_cb)); |
|
|
|
|
|
|
|
ZERROR_CHECK(app_timer_start(m_plod_state_event_detect_tmr, APP_TIMER_TICKS(100), NULL)); |
|
|
|
znordic_loop(); |
|
|
|
} |
|
|
|
|
|
|
|
// 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(); |