FluxDC/components/FluxProtocol/FluxProtocol.c

297 lines
8.2 KiB
C
Raw Normal View History

/**
* @file FluxProtocol.c
* @brief
*
* 便
*
* @author wang xiang en
* @date 2025-04-18
* @version
* @copyright (C)2025, YUWELL MEDTECH Co.ltd
*/
#include <stdio.h>
#include "FluxProtocol.h"
2025-04-23 08:58:26 +08:00
#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};
2025-04-23 13:18:12 +08:00
/* 流量计六个挡位测试时间序列 */
int flux_test_time_series[6] = {40,30,24,20,18,15};
/* 定于用于存储当前测试阶段的枚举变量 */
enum Bs_test_Stage currentTestStage = BS_STAGE_NONE;
2025-04-23 09:36:19 +08:00
/* 应用 event_homePage 中的测试状态显示变量 */
extern bool is_bs_test_ing;
extern bool is_nom_test_ing;
extern void comulate_time_set(void);
2025-04-23 09:36:19 +08:00
2025-04-23 13:18:12 +08:00
/* 定义控制LED小灯的任务句柄 */
TaskHandle_t bs_stateLED_task_handle;
TaskHandle_t nom_stateLED_task_handle;
2025-04-23 13:18:12 +08:00
2025-04-23 08:58:26 +08:00
/*
* @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);
}
}
2025-04-23 08:58:26 +08:00
/**
* @brief BS测试的任务函数
*
* @param[in] arg not used
*
*/
void bs_test_task(void* arg)
{
2025-04-23 13:18:12 +08:00
/* 进行6次循环测计数 */
uint8_t testCount = 0;
2025-04-23 08:58:26 +08:00
while(1)
{
2025-04-23 13:18:12 +08:00
/* 恢复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]);
2025-04-23 08:58:26 +08:00
vTaskDelay(1000 / portTICK_PERIOD_MS);
2025-04-23 13:18:12 +08:00
/* 下发启动指令 */
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();
2025-04-23 08:58:26 +08:00
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");
2025-04-23 09:36:19 +08:00
/* 任务测试完毕 删除任务 */
lv_label_set_text(ui_pageHome_labelStartTest1,"Start Test BS");
is_bs_test_ing = false;
2025-04-23 13:18:12 +08:00
/* 挂起LED显示任务 */
BS_STATE_LED_TASK_SUSPEND;
2025-04-23 08:58:26 +08:00
vTaskDelete(NULL);
2025-04-23 13:18:12 +08:00
2025-04-23 08:58:26 +08:00
}
}
2025-04-23 09:36:19 +08:00
/**
* @brief 线
*
* LED小灯bling bling
*
* @param[in] arg not used
*
*/
void bs_test_led_task(void* arg)
{
while(1)
{
2025-04-23 13:18:12 +08:00
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);
2025-04-23 09:36:19 +08:00
2025-04-23 13:18:12 +08:00
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);
2025-04-23 09:36:19 +08:00
}
2025-04-23 13:18:12 +08:00
}
/**
* @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);
}
}
}
2025-04-23 13:18:12 +08:00
/**
* @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));
2025-04-23 09:36:19 +08:00
}