diff --git a/README.md b/README.md
index 1e4cd91..f1dfd34 100644
--- a/README.md
+++ b/README.md
@@ -220,4 +220,18 @@ TODO:
1. eeprom的文件扇区信息没有存储,也就是说每次电池用没了之后,数据会丢失
2. 如果要实现不丢数据,需要在eeprom中存储文件扇区信息,同时由于扇区的大小大于256字节,所以需要优化eeprom的写入函数。
+单导蓝牙使用注意事项:
+ 1. 蓝牙的广播的启停独立控制和设备开机关机逻辑分开
+ 开启广播:开机时候,如果当前没有开启广播,则打开广播
+ 关闭广播: 关机后30s内无连接关闭广播
+ 断开连接后30s关闭广播
+
+ 2. 蓝牙状态指示灯:
+ 1. 蓝牙广播打开:指示灯闪烁
+ 2. 蓝牙广播关闭:指示灯关闭
+
+ 3. 采样时不支持电量上报
+ 4. 采样时不支持记录查询相关指令
+ 5. 不支持删除采样记录
+
```
\ No newline at end of file
diff --git a/app/app.uvoptx b/app/app.uvoptx
index 5527a63..0c3dc85 100644
--- a/app/app.uvoptx
+++ b/app/app.uvoptx
@@ -595,6 +595,30 @@
0
0
+
+ 1
+ 20
+ 1
+ 0
+ 0
+ 0
+ .\src\one_conduction\device_state.c
+ device_state.c
+ 0
+ 0
+
+
+ 1
+ 21
+ 1
+ 0
+ 0
+ 0
+ .\src\one_conduction\ble_cmd_process_service.c
+ ble_cmd_process_service.c
+ 0
+ 0
+
@@ -605,7 +629,7 @@
0
2
- 20
+ 22
1
0
0
@@ -625,7 +649,7 @@
0
3
- 21
+ 23
1
0
0
@@ -637,7 +661,7 @@
3
- 22
+ 24
1
0
0
@@ -657,7 +681,7 @@
0
4
- 23
+ 25
1
0
0
@@ -677,7 +701,7 @@
0
5
- 24
+ 26
1
0
0
@@ -689,7 +713,7 @@
5
- 25
+ 27
1
0
0
@@ -701,7 +725,7 @@
5
- 26
+ 28
1
0
0
@@ -713,7 +737,7 @@
5
- 27
+ 29
1
0
0
@@ -725,7 +749,7 @@
5
- 28
+ 30
1
0
0
@@ -737,7 +761,7 @@
5
- 29
+ 31
1
0
0
@@ -749,7 +773,7 @@
5
- 30
+ 32
1
0
0
@@ -761,7 +785,7 @@
5
- 31
+ 33
1
0
0
@@ -781,7 +805,7 @@
0
6
- 32
+ 34
1
0
0
@@ -801,7 +825,7 @@
0
7
- 33
+ 35
1
0
0
@@ -813,7 +837,7 @@
7
- 34
+ 36
1
0
0
@@ -825,7 +849,7 @@
7
- 35
+ 37
1
0
0
@@ -837,7 +861,7 @@
7
- 36
+ 38
1
0
0
@@ -849,7 +873,7 @@
7
- 37
+ 39
1
0
0
@@ -861,7 +885,7 @@
7
- 38
+ 40
1
0
0
@@ -873,7 +897,7 @@
7
- 39
+ 41
1
0
0
@@ -885,7 +909,7 @@
7
- 40
+ 42
1
0
0
@@ -897,7 +921,7 @@
7
- 41
+ 43
1
0
0
@@ -909,7 +933,7 @@
7
- 42
+ 44
1
0
0
@@ -921,7 +945,7 @@
7
- 43
+ 45
1
0
0
@@ -933,7 +957,7 @@
7
- 44
+ 46
1
0
0
@@ -945,7 +969,7 @@
7
- 45
+ 47
1
0
0
@@ -957,7 +981,7 @@
7
- 46
+ 48
1
0
0
@@ -969,7 +993,7 @@
7
- 47
+ 49
1
0
0
@@ -981,7 +1005,7 @@
7
- 48
+ 50
1
0
0
@@ -993,7 +1017,7 @@
7
- 49
+ 51
1
0
0
@@ -1005,7 +1029,7 @@
7
- 50
+ 52
1
0
0
@@ -1017,7 +1041,7 @@
7
- 51
+ 53
1
0
0
@@ -1029,7 +1053,7 @@
7
- 52
+ 54
1
0
0
@@ -1049,7 +1073,7 @@
0
8
- 53
+ 55
1
0
0
@@ -1061,7 +1085,7 @@
8
- 54
+ 56
1
0
0
@@ -1073,7 +1097,7 @@
8
- 55
+ 57
1
0
0
@@ -1085,7 +1109,7 @@
8
- 56
+ 58
1
0
0
@@ -1097,7 +1121,7 @@
8
- 57
+ 59
1
0
0
@@ -1109,7 +1133,7 @@
8
- 58
+ 60
1
0
0
@@ -1121,7 +1145,7 @@
8
- 59
+ 61
1
0
0
@@ -1133,7 +1157,7 @@
8
- 60
+ 62
1
0
0
@@ -1145,7 +1169,7 @@
8
- 61
+ 63
1
0
0
@@ -1157,7 +1181,7 @@
8
- 62
+ 64
1
0
0
@@ -1169,7 +1193,7 @@
8
- 63
+ 65
1
0
0
@@ -1181,7 +1205,7 @@
8
- 64
+ 66
1
0
0
@@ -1193,7 +1217,7 @@
8
- 65
+ 67
1
0
0
@@ -1205,7 +1229,7 @@
8
- 66
+ 68
1
0
0
@@ -1217,7 +1241,7 @@
8
- 67
+ 69
1
0
0
@@ -1229,7 +1253,7 @@
8
- 68
+ 70
1
0
0
@@ -1241,7 +1265,7 @@
8
- 69
+ 71
1
0
0
@@ -1253,7 +1277,7 @@
8
- 70
+ 72
1
0
0
@@ -1265,7 +1289,7 @@
8
- 71
+ 73
1
0
0
@@ -1277,7 +1301,7 @@
8
- 72
+ 74
1
0
0
@@ -1289,7 +1313,7 @@
8
- 73
+ 75
1
0
0
@@ -1301,7 +1325,7 @@
8
- 74
+ 76
1
0
0
@@ -1313,7 +1337,7 @@
8
- 75
+ 77
1
0
0
@@ -1325,7 +1349,7 @@
8
- 76
+ 78
1
0
0
@@ -1337,7 +1361,7 @@
8
- 77
+ 79
1
0
0
@@ -1349,7 +1373,7 @@
8
- 78
+ 80
1
0
0
@@ -1361,7 +1385,7 @@
8
- 79
+ 81
1
0
0
@@ -1381,7 +1405,7 @@
0
9
- 80
+ 82
1
0
0
@@ -1393,7 +1417,7 @@
9
- 81
+ 83
1
0
0
@@ -1405,7 +1429,7 @@
9
- 82
+ 84
1
0
0
@@ -1417,7 +1441,7 @@
9
- 83
+ 85
1
0
0
@@ -1429,7 +1453,7 @@
9
- 84
+ 86
1
0
0
@@ -1441,7 +1465,7 @@
9
- 85
+ 87
1
0
0
@@ -1461,7 +1485,7 @@
0
10
- 86
+ 88
1
0
0
@@ -1473,7 +1497,7 @@
10
- 87
+ 89
1
0
0
@@ -1485,7 +1509,7 @@
10
- 88
+ 90
1
0
0
@@ -1505,7 +1529,7 @@
0
11
- 89
+ 91
1
0
0
@@ -1517,7 +1541,7 @@
11
- 90
+ 92
1
0
0
@@ -1529,7 +1553,7 @@
11
- 91
+ 93
1
0
0
@@ -1549,7 +1573,7 @@
0
12
- 92
+ 94
1
0
0
@@ -1569,7 +1593,7 @@
0
13
- 93
+ 95
1
0
0
@@ -1581,7 +1605,7 @@
13
- 94
+ 96
1
0
0
diff --git a/app/app.uvprojx b/app/app.uvprojx
index a8d5c9a..cea356e 100644
--- a/app/app.uvprojx
+++ b/app/app.uvprojx
@@ -478,6 +478,16 @@
1
.\src\one_conduction\heart_wave_sample_service.c
+
+ device_state.c
+ 1
+ .\src\one_conduction\device_state.c
+
+
+ ble_cmd_process_service.c
+ 1
+ .\src\one_conduction\ble_cmd_process_service.c
+
@@ -4302,6 +4312,16 @@
1
.\src\one_conduction\heart_wave_sample_service.c
+
+ device_state.c
+ 1
+ .\src\one_conduction\device_state.c
+
+
+ ble_cmd_process_service.c
+ 1
+ .\src\one_conduction\ble_cmd_process_service.c
+
diff --git a/app/src/basic/heart_rate_sensor.c b/app/src/basic/heart_rate_sensor.c
new file mode 100644
index 0000000..e69de29
diff --git a/app/src/basic/heart_rate_sensor_protocol.h b/app/src/basic/heart_rate_sensor_protocol.h
new file mode 100644
index 0000000..c20aee5
--- /dev/null
+++ b/app/src/basic/heart_rate_sensor_protocol.h
@@ -0,0 +1,55 @@
+#pragma once
+
+#include
+
+#pragma pack(push, 1)
+
+typedef struct {
+ uint8_t frame_type;
+ uint8_t frame_index;
+ uint8_t cmd;
+ uint8_t data[];
+} ify_hrs_packet_t;
+
+typedef enum {
+ kifyhrs_ecode_success = 0,
+ kifyhrs_ecode_unkown_error = 1,
+ kifyhrs_ecode_cmd_not_support = 2,
+ kifyhrs_ecode_illegal_parameter = 3,
+ kifyhrs_ecode_device_busy = 4,
+ kifyhrs_ecode_hardware_error = 5,
+ kifyhrs_ecode_sensor_drop = 6,
+} ify_hrs_error_code_t;
+
+typedef enum {
+ kifyhrs_pt_cmd = 0,
+ kifyhrs_pt_cmd_receipt = 1,
+ kifyhrs_pt_report = 2,
+ kifyhrs_pt_error_receipt = 3,
+} ify_hrs_packet_type_t;
+
+typedef enum {
+ kifyhrs_sensor_pos_none = 0, // 无指定位置
+ kifyhrs_sensor_pos_I = 1, // I
+ kifyhrs_sensor_pos_II = 2, // II
+ kifyhrs_sensor_pos_III = 3, // III
+ kifyhrs_sensor_pos_V1 = 4, // V1
+ kifyhrs_sensor_pos_V5 = 5, // V5
+} ify_hrs_sensor_pos_t;
+
+typedef enum {
+ ify_hrs_cmd_read_device_version = 1,
+ ify_hrs_cmd_read_sensor_info = 2,
+ ify_hrs_cmd_read_device_state = 3,
+ ify_hrs_cmd_read_time = 4,
+ ify_hrs_cmd_sync_time = 5,
+ ify_hrs_cmd_start_capture = 6,
+ ify_hrs_cmd_stop_capture = 7,
+ ify_hrs_cmd_start_realtime_report = 8,
+ ify_hrs_cmd_stop_realtime_report = 9,
+ ify_hrs_cmd_read_records_info = 10,
+ ify_hrs_cmd_del_record = 11,
+
+
+} ify_hrs_cmd_t;
+#pragma pack(pop)
diff --git a/app/src/basic/ssd1306/wave_drawer.c b/app/src/basic/ssd1306/wave_drawer.c
index 0bb9b67..a98fe9f 100644
--- a/app/src/basic/ssd1306/wave_drawer.c
+++ b/app/src/basic/ssd1306/wave_drawer.c
@@ -75,7 +75,7 @@ void wave_drawer_draw_next_point(wave_drawer_t *dw, uint8_t y) {
ssd1306_gram_write_point(ssd1306_handler(), xpos + 1, dw->ybottom - yoff, 0);
}
}
- for (uint8_t i = 2; i < 2 + 20; i++) {
+ for (uint8_t i = 2; i < 2 + 5; i++) {
if (xpos + i <= dw->xright) {
ssd1306_gram_write_point(ssd1306_handler(), xpos + i, dw->ybottom - yoff, 0);
}
diff --git a/app/src/one_conduction/app_event.h b/app/src/one_conduction/app_event.h
index fbdaf37..cc128f6 100644
--- a/app/src/one_conduction/app_event.h
+++ b/app/src/one_conduction/app_event.h
@@ -1,25 +1 @@
-#pragma once
-#include
-
-typedef enum {
- kplod_connected_event = 0, // 导联连接事件
- kplod_disconnected_event, // 导联断开事件
- kplod_connecting_event, // 导联连接中事件
-
- kplod_start_charge_event, // 充电事件
- kplod_charging_event, // 充电中
- kplod_end_charge_event, // 充电结束事件
-
- kevent_tmr_scheduler_event, // 定时器调度事件
- kevent_capture_data_event, // 采样数据回调
-} app_event_type_t;
-
-typedef struct {
- app_event_type_t eventType;
- union {
- uint32_t plod_connected_accumulation_time; // 导联连接累计时间
- uint8_t* capture_data_cache; // 实时采样数据,数据长度为256字节
- } val;
-} app_event_t;
-
-void app_event_process_cb(void* p_event_data, uint16_t event_size);
+#include "device_state.h"
\ No newline at end of file
diff --git a/app/src/one_conduction/ble_cmd_process_service.c b/app/src/one_conduction/ble_cmd_process_service.c
new file mode 100644
index 0000000..e69de29
diff --git a/app/src/one_conduction/ble_cmd_process_service.h b/app/src/one_conduction/ble_cmd_process_service.h
new file mode 100644
index 0000000..d1b3bf6
--- /dev/null
+++ b/app/src/one_conduction/ble_cmd_process_service.h
@@ -0,0 +1,5 @@
+#pragma once
+
+#include "basic/heart_rate_sensor_protocol.h"
+#include "device_state.h"
+
diff --git a/app/src/one_conduction/device_state.c b/app/src/one_conduction/device_state.c
new file mode 100644
index 0000000..ed49810
--- /dev/null
+++ b/app/src/one_conduction/device_state.c
@@ -0,0 +1,15 @@
+
+#include "device_state.h"
+
+#include "znordic.h"
+static device_state_t m_device_state = kdevice_state_standby; // 设备状态
+static uint32_t m_change_to_cur_state_tp = 0; // 切换到当前状态的时间戳
+
+void ds_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();
+}
+
+uint32_t ds_cur_state_haspassed_ms() { return znordic_haspassed_ms(m_change_to_cur_state_tp); }
+device_state_t ds_now_state() { return m_device_state; }
\ No newline at end of file
diff --git a/app/src/one_conduction/device_state.h b/app/src/one_conduction/device_state.h
new file mode 100644
index 0000000..4f5d0c8
--- /dev/null
+++ b/app/src/one_conduction/device_state.h
@@ -0,0 +1,71 @@
+#pragma once
+#include
+
+typedef enum {
+ kplod_connected_event = 0, // 导联连接事件
+ kplod_disconnected_event, // 导联断开事件
+ kplod_connecting_event, // 导联连接中事件
+
+ kplod_start_charge_event, // 充电事件
+ kplod_charging_event, // 充电中
+ kplod_end_charge_event, // 充电结束事件
+
+ kevent_tmr_scheduler_event, // 定时器调度事件
+ kevent_capture_data_event, // 采样数据回调
+} app_event_type_t;
+
+typedef struct {
+ app_event_type_t eventType;
+ union {
+ uint32_t plod_connected_accumulation_time; // 导联连接累计时间
+ uint8_t* capture_data_cache; // 实时采样数据,数据长度为256字节
+ } val;
+} app_event_t;
+
+typedef enum {
+ // 待机
+ kdevice_state_standby = 0,
+ // 开机
+ kdevice_state_poweron,
+ // 首页
+ kdevice_state_home,
+ // 提示用户保持静止
+ kdevice_state_keep_still,
+ // 采集中
+ kdevice_state_sampling,
+ // 采集完成
+ 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";
+ }
+}
+
+void app_event_process_cb(void* p_event_data, uint16_t event_size);
+
+void ds_change_to_state(device_state_t state);
+uint32_t ds_cur_state_haspassed_ms();
+device_state_t ds_now_state();
diff --git a/app/src/one_conduction/one_conduction_main.c b/app/src/one_conduction/one_conduction_main.c
index 77d9ad0..5658f92 100644
--- a/app/src/one_conduction/one_conduction_main.c
+++ b/app/src/one_conduction/one_conduction_main.c
@@ -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
-#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
\ No newline at end of file