From: 1624952103 Date: Thu, 11 Jun 2026 07:56:44 +0000 (+0800) Subject: 优化获取ECG房颤结果接口 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=91d3f3ee695e6c01983d535e2197774b6ab120b3;p=mirrors%2FFD230.git 优化获取ECG房颤结果接口 --- diff --git a/code/sdk/zhihui/drivers/ppg/hal/ppg_hal.c b/code/sdk/zhihui/drivers/ppg/hal/ppg_hal.c index ee2880931..8ce83b1d4 100644 --- a/code/sdk/zhihui/drivers/ppg/hal/ppg_hal.c +++ b/code/sdk/zhihui/drivers/ppg/hal/ppg_hal.c @@ -180,7 +180,7 @@ uint32_t ppg_read_ecg_raw(int32_t *buf, uint32_t buf_len) #endif } -void ppg_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result) +void ppg_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result, uint8_t *status) { if (ecg_hr != NULL) { *ecg_hr = 0; @@ -188,9 +188,12 @@ void ppg_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result) if (afib_result != NULL) { *afib_result = PPG_ECG_AFIB_RESULT_INVALID; } + if (status != NULL) { + *status = PPG_ECG_AFIB_STATUS_IDLE; + } #if defined PPG_PAH831X - pah831x_get_ecg_afib(ecg_hr, afib_result); + pah831x_get_ecg_afib(ecg_hr, afib_result, status); #endif } diff --git a/code/sdk/zhihui/drivers/ppg/hal/ppg_hal.h b/code/sdk/zhihui/drivers/ppg/hal/ppg_hal.h index 423779c97..d1bc7edf0 100644 --- a/code/sdk/zhihui/drivers/ppg/hal/ppg_hal.h +++ b/code/sdk/zhihui/drivers/ppg/hal/ppg_hal.h @@ -85,12 +85,18 @@ bool is_ppg_bp_need_cali(void); * 开始/停止 ecgbp、ecgafib、ecgraw 时驱动内部自动清缓冲。 */ uint32_t ppg_read_ecg_raw(int32_t *buf, uint32_t buf_len); +#define PPG_ECG_AFIB_STATUS_IDLE 0 /* 未开始测量 */ +#define PPG_ECG_AFIB_STATUS_MEASURING 1 /* 测量中 */ +#define PPG_ECG_AFIB_STATUS_FAILED 2 /* 测量失败(ready sqi>0 停测、超时等) */ +#define PPG_ECG_AFIB_STATUS_SUCCESS 3 /* 测量成功,已出结论 */ + /* 获取 ECG 房颤测试结果。 * ecg_hr: ECG 心率(bpm),测量过程中持续更新; - * afib_result: 房颤结论,测试未完成时为 0xFF + * afib_result: 房颤结论,未开始/测量中/失败时为 0xFF * 0 窦性心律 1 不确定(不规则) 2 可能房颤 - * 3 不确定(信号/特征) 4 心率过低 5 心率过高 */ -void ppg_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result); + * 3 不确定(信号/特征) 4 心率过低 5 心率过高 + * status: 0 未开始 1 测量中 2 测量失败 3 测量成功(已出结论) */ +void ppg_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result, uint8_t *status); #define PPG_ECG_BP_STATUS_MEASURING 0 /* 测量中 */ #define PPG_ECG_BP_STATUS_WEAK_SIGNAL 1 /* ECG已停止,疑似信号弱,请重新测试 */ diff --git a/code/sdk/zhihui/drivers/ppg/pah831x/PXI_ALG/ECG_AFIB/V2022/pah_ecg_afib_alg.c b/code/sdk/zhihui/drivers/ppg/pah831x/PXI_ALG/ECG_AFIB/V2022/pah_ecg_afib_alg.c index 5ee975cbe..f2cfa4c0d 100644 --- a/code/sdk/zhihui/drivers/ppg/pah831x/PXI_ALG/ECG_AFIB/V2022/pah_ecg_afib_alg.c +++ b/code/sdk/zhihui/drivers/ppg/pah831x/PXI_ALG/ECG_AFIB/V2022/pah_ecg_afib_alg.c @@ -61,6 +61,7 @@ static uint8_t ReadyFlag = 0; static uint8_t AFIB_ReadyFlag = 0; static uint8_t ecg_afib_result = PAH_ECG_AFIB_RESULT_INVALID; static uint8_t ecg_afib_hr = 0; +static uint8_t has_ecg_stop = 0; static uint16_t ecg_ready_count = 0; static int32_t ecg_frame_count = 0; @@ -295,6 +296,7 @@ static uint8_t run_afib_pxialg(uint32_t duration, const uint32_t* ecg_data, uint }else { if(PXIAFIB_GETEcgStopFlag(_state.pxialg_state_afib) == 1) {//ready sqi > 0, need to stop . _state.has_got_AFIB=1; + has_ecg_stop = 1; ecg_afib_algorithm_close(); ALG_PRINT("ready sqi > 0, need to stop \n"); return 1; @@ -405,6 +407,7 @@ void ecg_afib_algorithm_init(void) AFIB_ReadyFlag = 0; ecg_afib_result = PAH_ECG_AFIB_RESULT_INVALID; ecg_afib_hr = 0; + has_ecg_stop = 0; _state.has_got_AFIB=0; _state.has_time_out=0; _state.pxialg_data.frame_count = 0 ; @@ -441,3 +444,22 @@ uint8_t pah_ecg_afib_get_hr(void) { return ecg_afib_hr; } + +uint8_t pah_ecg_afib_get_status(void) +{ +#if defined(ENABLE_PXI_ALG_ECG_AFIB) + if (!_state.has_got_AFIB) { + if (_state.pxialg_has_init) { + return PAH_ECG_AFIB_STATUS_MEASURING; + } + return PAH_ECG_AFIB_STATUS_IDLE; + } + if (_state.has_time_out || has_ecg_stop || + ecg_afib_result == PAH_ECG_AFIB_RESULT_INVALID) { + return PAH_ECG_AFIB_STATUS_FAILED; + } + return PAH_ECG_AFIB_STATUS_SUCCESS; +#else + return PAH_ECG_AFIB_STATUS_IDLE; +#endif +} diff --git a/code/sdk/zhihui/drivers/ppg/pah831x/PXI_ALG/ECG_AFIB/V2022/pah_ecg_afib_alg.h b/code/sdk/zhihui/drivers/ppg/pah831x/PXI_ALG/ECG_AFIB/V2022/pah_ecg_afib_alg.h index b88020e9a..2cd1d9feb 100644 --- a/code/sdk/zhihui/drivers/ppg/pah831x/PXI_ALG/ECG_AFIB/V2022/pah_ecg_afib_alg.h +++ b/code/sdk/zhihui/drivers/ppg/pah831x/PXI_ALG/ECG_AFIB/V2022/pah_ecg_afib_alg.h @@ -41,8 +41,14 @@ void ecg_afib_algorithm_close(void); #define PAH_ECG_AFIB_RESULT_INVALID 0xFF +#define PAH_ECG_AFIB_STATUS_IDLE 0 /* 未开始测量 */ +#define PAH_ECG_AFIB_STATUS_MEASURING 1 /* 测量中 */ +#define PAH_ECG_AFIB_STATUS_FAILED 2 /* 测量失败(ready sqi>0需停止、超时等) */ +#define PAH_ECG_AFIB_STATUS_SUCCESS 3 /* 测量成功,afib_result 已有效 */ + uint8_t pah_ecg_afib_get_hr(void); uint8_t pah_ecg_afib_get_result(void); +uint8_t pah_ecg_afib_get_status(void); #endif // header guard diff --git a/code/sdk/zhihui/drivers/ppg/pah831x/pah_sensor/pah831x_main.c b/code/sdk/zhihui/drivers/ppg/pah831x/pah_sensor/pah831x_main.c index 29603f9ab..8254cabe2 100644 --- a/code/sdk/zhihui/drivers/ppg/pah831x/pah_sensor/pah831x_main.c +++ b/code/sdk/zhihui/drivers/ppg/pah831x/pah_sensor/pah831x_main.c @@ -154,6 +154,7 @@ static uint8_t ret_spo2 = 0; static uint8_t ret_hrv = 0; static uint8_t ret_ecg_afib_hr = 0; static uint8_t ret_ecg_afib_result = PAH_ECG_AFIB_RESULT_INVALID; +static uint8_t ret_ecg_afib_status = PAH_ECG_AFIB_STATUS_IDLE; static uint8_t ret_ecg_bp_status = PAH_ECG_BP_STATUS_MEASURING; static uint8_t ret_wear = 0; static ecg_data_out _ecg_data_out_alg; @@ -1546,6 +1547,7 @@ static void pah831x_ecg_afib_timer_handler(void) ret_ecg_afib_hr = pah_ecg_afib_get_hr(); ret_ecg_afib_result = pah_ecg_afib_get_result(); + ret_ecg_afib_status = pah_ecg_afib_get_status(); clear_ecg_data_ready(); } @@ -1811,10 +1813,10 @@ void pah831x_ecg_afib_start(void) { ret_ecg_afib_hr = 0; ret_ecg_afib_result = PAH_ECG_AFIB_RESULT_INVALID; + ret_ecg_afib_status = PAH_ECG_AFIB_STATUS_MEASURING; + ecg_afib_algorithm_init(); pah831x_sensor_init(); pah831x_sensor_start(PAH831X_WORK_POLLING ,PAH831X_INIT_ALWAYS_RUN,PAH831X_PPG_REG_SETTING_IDLE ,PAH831X_ECG_REG_SETTING_1,256,3.91f ); - ecg_afib_algorithm_init(); - } @@ -1872,6 +1874,11 @@ void pah831x_ecg_afib_stop(void) { pah_sensor_stop(); ecg_afib_algorithm_close(); + ecg_afib_algorithm_init(); + + ret_ecg_afib_hr = 0; + ret_ecg_afib_result = PAH_ECG_AFIB_RESULT_INVALID; + ret_ecg_afib_status = PAH_ECG_AFIB_STATUS_IDLE; } void pah831x_stress_stop(void) @@ -1980,6 +1987,7 @@ void pah831x_sensor_stop(void) ret_wear = 0; ret_ecg_afib_hr = 0; ret_ecg_afib_result = PAH_ECG_AFIB_RESULT_INVALID; + ret_ecg_afib_status = PAH_ECG_AFIB_STATUS_IDLE; ret_ecg_bp_status = PAH_ECG_BP_STATUS_MEASURING; history_wear_status = -1; @@ -2167,7 +2175,7 @@ uint8_t pah831x_get_hrv(void) return ret_hrv; } -void pah831x_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result) +void pah831x_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result, uint8_t *status) { if (ecg_hr != NULL) { *ecg_hr = ret_ecg_afib_hr; @@ -2175,6 +2183,9 @@ void pah831x_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result) if (afib_result != NULL) { *afib_result = ret_ecg_afib_result; } + if (status != NULL) { + *status = ret_ecg_afib_status; + } } void pah831x_get_ecg_bp(int *sbp, int *dbp, uint8_t *status) diff --git a/code/sdk/zhihui/drivers/ppg/pah831x/pah_sensor/pah831x_main.h b/code/sdk/zhihui/drivers/ppg/pah831x/pah_sensor/pah831x_main.h index abf20499a..b790fb117 100644 --- a/code/sdk/zhihui/drivers/ppg/pah831x/pah_sensor/pah831x_main.h +++ b/code/sdk/zhihui/drivers/ppg/pah831x/pah_sensor/pah831x_main.h @@ -369,7 +369,7 @@ uint8_t pah831x_get_spo2(void); uint8_t pah831x_get_hrv(void); -void pah831x_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result); +void pah831x_get_ecg_afib(uint8_t *ecg_hr, uint8_t *afib_result, uint8_t *status); void pah831x_get_ecg_bp(int *sbp, int *dbp, uint8_t *status);