/** * @file FluxProtocol.c * @brief 流量计通讯协议部分 * * 用于声明便携制氧机参数 * * @author wang xiang en * @date 2025-04-18 * @version 版本号 * @copyright 版权声明((C)2025, YUWELL MEDTECH Co.ltd) */ #include #include "FluxProtocol.h" #include "esp_log.h" /*记录spirits3的没分钟输出的体积*/ float Spirit3_Volume[4] = { 210,420,630,750}; float Spirit6_Volume[6] = { 210,420,630,840,1050,1200}; float YULite8_Volume[6] = { 210,420,630,840,1050,1200}; /* 流量计六个挡位测试时间序列 */ int flux_test_time_series[6] = {40,30,24,20,18,15}; /* 定于用于存储当前测试阶段的枚举变量 */ enum Bs_test_Stage currentTestStage = BS_STAGE_NONE; /* 应用 event_homePage 中的测试状态显示变量 */ extern bool is_bs_test_ing; extern bool is_nom_test_ing; extern void comulate_time_set(void); /* 定义控制LED小灯的任务句柄 */ TaskHandle_t bs_stateLED_task_handle; TaskHandle_t nom_stateLED_task_handle; /* * @brief 拼接测试过程中用于展示的字符串 * 1.时间设置发送成功 Time setting sent successfully * 2.开始测试 start testing * 3.等待测试结束 Waiting for the end of the test * 4.当前频率测试结束 The current frequency test has ended * 5.所有频率测试完毕,请记录。 All frequency tests have been completed, please record. * 6.设备已启动成功,请开始测试。 Device started successfully, please start testing. */ char *test_info[] = {"Time setting sent successfully!!",\ "start testing....",\ "Waiting for the end of the test...",\ "The current frequency test has ended!!",\ "All frequency tests have been completed!!",\ "Device started successfully!!!!" }; /* 导出协议数据结构体 */ struct FluxProtocol fluxProtocol; /** * @brief 新建用于进行带常规测试的任务函数 * * @param[in] arg not used * */ void nom_test_task(void* arg) { float time = 0; while (1) { /* 开始测试前 下发积分时间,确保测试时间正确 */ comulate_time_set(); time = (float)lv_spinbox_get_value(ui_pageFluxRead_spinboxTime); flux_test_time_set(time); lv_label_set_text(ui_pageHome_labelStartTest,"Cancel Test Nom"); lv_bar_set_value(ui_pageHome_barNomTest,0,LV_ANIM_ON); /* 恢复LED显示任务 */ vTaskResume(nom_stateLED_task_handle); /* 测试开始 */ vTaskDelay(time*1000 / portTICK_PERIOD_MS); /* 测试结束 */ lv_label_set_text(ui_pageHome_labelStartTest,"Start Test Nom"); is_nom_test_ing = false; /* 挂起LED显示任务 */ NOM_STATE_LED_TASK_SUSPEND; lv_bar_set_value(ui_pageHome_barNomTest,0,LV_ANIM_ON); vTaskDelete(NULL); } } /** * @brief 新建用于进行带BS测试的任务函数 * * @param[in] arg not used * */ void bs_test_task(void* arg) { /* 进行6次循环测计数 */ uint8_t testCount = 0; while(1) { /* 恢复LED显示任务 */ vTaskResume(bs_stateLED_task_handle); currentTestStage = BS_STAGE_START; for ( testCount = 0; testCount < sizeof(flux_test_time_series); testCount++) { } /* 显示测试开始 */ BS_HOMEPAGE_SHOW("15BPM start testing..."); FLUX_PROGRESS_BAR_CONTROL(10); /* 测试开始 15BPM */ /* 下发测试时间 */ flux_test_time_set(flux_test_time_series[0]); vTaskDelay(1000 / portTICK_PERIOD_MS); /* 下发启动指令 */ flux_test_start(); currentTestStage = BS_STAGE_15BPM; /* 等待测试时间 */ vTaskDelay(flux_test_time_series[0]*1000 / portTICK_PERIOD_MS); vTaskDelay(2000 / portTICK_PERIOD_MS); /* 15BPM测试结束 显示测试结束 */ BS_HOMEPAGE_SHOW("15BPM end test"); FLUX_PROGRESS_BAR_CONTROL(20); /* 读取测试结果 */ flux_test_result_get(); ESP_LOGI("bs_test_task", "bs_test_task"); vTaskDelay(4000 / portTICK_PERIOD_MS); ESP_LOGI("bs_test_task", "bs_test_task end?"); ESP_LOGI("bs_test_timer_func","hahahahhahah............"); /* 显示测试成功 */ lv_label_set_text(ui_pageHome_labelBSInfo,test_info[3]); vTaskDelay(4000/portTICK_PERIOD_MS); lv_label_set_text(ui_pageHome_labelBSInfo,test_info[4]); vTaskDelay(4000/portTICK_PERIOD_MS); lv_label_set_text(ui_pageHome_labelBSInfo,test_info[5]); vTaskDelay(4000/portTICK_PERIOD_MS); lv_label_set_text(ui_pageHome_labelBSInfo,test_info[1]); vTaskDelay(4000/portTICK_PERIOD_MS); lv_label_set_text(ui_pageHome_labelBSInfo,test_info[2]); ESP_LOGI("bs_test_timer_func","bs_test_timer_func end right"); /* 任务测试完毕 删除任务 */ lv_label_set_text(ui_pageHome_labelStartTest1,"Start Test BS"); is_bs_test_ing = false; /* 挂起LED显示任务 */ BS_STATE_LED_TASK_SUSPEND; vTaskDelete(NULL); } } /** * @brief 测试状态显示线程 * * 设置一个LED小灯,测试的时候bling bling 闪 * * @param[in] arg not used * */ void bs_test_led_task(void* arg) { while(1) { vTaskDelay(BS_LED_BLINK_INTERVAL_MS / portTICK_PERIOD_MS); lv_obj_set_style_bg_color(ui_pageHome_panelBSLEDing,lv_color_hex(0x00FF00),LV_PART_MAIN); vTaskDelay(BS_LED_BLINK_INTERVAL_MS / portTICK_PERIOD_MS); lv_obj_set_style_bg_color(ui_pageHome_panelBSLEDing,lv_color_hex(0xFFFFFF),LV_PART_MAIN); } } /** * @brief 测试状态显示线程 * * 设置一个LED小灯,测试的时候bling bling 闪 * * @param[in] arg not used * */ void nom_test_led_task(void* arg) { int32_t time_all = 0; int32_t bar_plus = 0; int32_t current_bar_value = 0; while(1) { vTaskDelay(NOM_LED_BLINK_INTERVAL_MS / portTICK_PERIOD_MS); lv_obj_set_style_bg_color(ui_pageHome_panelNomTest,lv_color_hex(0x00FF00),LV_PART_MAIN); vTaskDelay(NOM_LED_BLINK_INTERVAL_MS / portTICK_PERIOD_MS); lv_obj_set_style_bg_color(ui_pageHome_panelNomTest,lv_color_hex(0xFFFFFF),LV_PART_MAIN); /* 获取总的测试时间 */ time_all = lv_spinbox_get_value(ui_pageFluxRead_spinboxTime); /* 获取每次需要累加的值*/ bar_plus = lv_bar_get_max_value(ui_pageHome_barNomTest) / time_all; /* 获取当前的进度条值*/ current_bar_value = lv_bar_get_value(ui_pageHome_barNomTest); if (current_bar_value + bar_plus < lv_bar_get_max_value(ui_pageHome_barNomTest)) { lv_bar_set_value(ui_pageHome_barNomTest,current_bar_value+bar_plus,LV_ANIM_ON); } } } /** * @brief 向流量计下发测试时间 * * 时间下发 * * @param[in] time 向流量计下发测试的时间 * */ void flux_test_time_set(float var_time) { /* 设置15BPM测试时间 */ uint8_t bytes[4]; float time = var_time; memcpy(bytes, &time, 4); /* 下发命令 */ flux_frame.ADDR = FLUX_ADDR; flux_frame.FUNC = FLUX_FUNC_SET_SINGLE; flux_frame.DATA[0] = 0x00; flux_frame.DATA[1] = 0x02; flux_frame.DATA[2] = bytes[3]; flux_frame.DATA[3] = bytes[2]; /* 下发15BPM测试时间指令*/ ESP_ERROR_CHECK(ModbusRTU_Send_0306(ECHO_UART_PORT_NUM1,&flux_frame)); } /** * @brief 向流量计下发启动测试指令 * */ void flux_test_start(void) { /* 下发启动测试指令 */ flux_frame_start.ADDR = FLUX_ADDR; flux_frame_start.FUNC = FLUX_FUNC_SET_SINGLE; flux_frame_start.DATA[0] = 0x00; flux_frame_start.DATA[1] = 0x01; flux_frame_start.DATA[2] = 0x00; flux_frame_start.DATA[3] = 0x01; ESP_ERROR_CHECK(ModbusRTU_Send_0306(ECHO_UART_PORT_NUM1,&flux_frame_start)); } /** * @brief 向流量计下获取测试结果指令 * */ void flux_test_result_get(void) { /*下发数据获取指令*/ /* 起始地址为 0x00 */ flux_frame.DATA[0] = 0; flux_frame.DATA[1] = 0; /* 数据长度为 120 */ flux_frame.DATA[2] = 0; flux_frame.DATA[3] = 120; flux_frame.FUNC = FLUX_FUNC_READ; /*下发问询120个参数*/ ESP_ERROR_CHECK(ModbusRTU_Send_0306(ECHO_UART_PORT_NUM1,&flux_frame)); }