cmcu为stm32h743IIt6
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

398 lines
13 KiB

/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2026-02-04 Administrator the first version
*/
#include <rtthread.h>
#include <string.h>
#include <applications/data/Variable.h>
#include <applications/data/SC828_DATA_table.h>
#include <board.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <guider/custom/custom.h>
#include <guider/generated/events_init.h>
#include <guider/generated/gui_guider.h>
#include <guider/generated/widgets_init.h>
#include "lvgl.h"
#include <ui_data_labels.h>
#include "libcsv.h"
// 全局或静态数组
char buf[8];
lv_obj_t *di_led_array[64];
lv_obj_t *do_led_array[64];
lv_obj_t *di_labels[24]; // DI: AIO4001 ~ AIO4024 (24个)
lv_obj_t *do_labels[16]; // DO: AIO5001 ~ AIO5016 (16个)
WorkOrder_DATA_tab * WorkDATA_tab=NULL;
Program_DATA_tab * ProgramDATA_tab=NULL;
STEP_DATA_tab * StepDATA_tab=NULL;
extern struct rt_memheap sram_SRAM1,sdram_heap;
/**
* 输入输出状态刷新
* DIO,AIO
*/
void ui_init_io(lv_ui *ui) {
WorkDATA_tab = rt_memheap_alloc(&sdram_heap, sizeof(WorkOrder_DATA_tab)*128);
ProgramDATA_tab = rt_memheap_alloc(&sdram_heap, sizeof(Program_DATA_tab)*512);
StepDATA_tab = rt_memheap_alloc(&sdram_heap, sizeof(STEP_DATA_tab)*256);
//di
di_led_array[0] = ui->screen_di1;
di_led_array[1] = ui->screen_di2;
di_led_array[2] = ui->screen_di3;
di_led_array[3] = ui->screen_di4;
di_led_array[4] = ui->screen_di5;
di_led_array[5] = ui->screen_di6;
di_led_array[6] = ui->screen_di7;
di_led_array[7] = ui->screen_di8;
di_led_array[8] = ui->screen_di9;
di_led_array[9] = ui->screen_di10;
di_led_array[10] = ui->screen_di11;
di_led_array[11] = ui->screen_di12;
di_led_array[12] = ui->screen_di13;
di_led_array[13] = ui->screen_di14;
di_led_array[14] = ui->screen_di15;
di_led_array[15] = ui->screen_di16;
di_led_array[16] = ui->screen_di17;
di_led_array[17] = ui->screen_di18;
di_led_array[18] = ui->screen_di19;
di_led_array[19] = ui->screen_di20;
di_led_array[20] = ui->screen_di21;
di_led_array[21] = ui->screen_di22;
di_led_array[22] = ui->screen_di23;
di_led_array[23] = ui->screen_di24;
di_led_array[24] = ui->screen_di25;
di_led_array[25] = ui->screen_di26;
di_led_array[26] = ui->screen_di27;
di_led_array[27] = ui->screen_di28;
di_led_array[28] = ui->screen_di29;
di_led_array[29] = ui->screen_di30;
di_led_array[30] = ui->screen_di31;
di_led_array[31] = ui->screen_di32;
di_led_array[32] = ui->screen_di33;
di_led_array[33] = ui->screen_di34;
di_led_array[34] = ui->screen_di35;
di_led_array[35] = ui->screen_di36;
di_led_array[36] = ui->screen_di37;
di_led_array[37] = ui->screen_di38;
di_led_array[38] = ui->screen_di39;
di_led_array[39] = ui->screen_di40;
di_led_array[40] = ui->screen_di41;
di_led_array[41] = ui->screen_di42;
di_led_array[42] = ui->screen_di43;
di_led_array[43] = ui->screen_di44;
di_led_array[44] = ui->screen_di45;
di_led_array[45] = ui->screen_di46;
di_led_array[46] = ui->screen_di47;
di_led_array[47] = ui->screen_di48;
di_led_array[48] = ui->screen_di49;
di_led_array[49] = ui->screen_di50;
di_led_array[50] = ui->screen_di51;
di_led_array[51] = ui->screen_di52;
di_led_array[52] = ui->screen_di53;
di_led_array[53] = ui->screen_di54;
di_led_array[54] = ui->screen_di55;
di_led_array[55] = ui->screen_di56;
di_led_array[56] = ui->screen_di57;
di_led_array[57] = ui->screen_di58;
di_led_array[58] = ui->screen_di59;
di_led_array[59] = ui->screen_di60;
di_led_array[60] = ui->screen_di61;
di_led_array[61] = ui->screen_di62;
di_led_array[62] = ui->screen_di63;
di_led_array[63] = ui->screen_di64;
//do
do_led_array[0] = ui->screen_do0;
do_led_array[1] = ui->screen_do1;
do_led_array[2] = ui->screen_do2;
do_led_array[3] = ui->screen_do3;
do_led_array[4] = ui->screen_do4;
do_led_array[5] = ui->screen_do5;
do_led_array[6] = ui->screen_do6;
do_led_array[7] = ui->screen_do7;
do_led_array[8] = ui->screen_do8;
do_led_array[9] = ui->screen_do9;
do_led_array[10] = ui->screen_do10;
do_led_array[11] = ui->screen_do11;
do_led_array[12] = ui->screen_do12;
do_led_array[13] = ui->screen_do13;
do_led_array[14] = ui->screen_do14;
do_led_array[15] = ui->screen_do15;
do_led_array[16] = ui->screen_do16;
do_led_array[17] = ui->screen_do17;
do_led_array[18] = ui->screen_do18;
do_led_array[19] = ui->screen_do19;
do_led_array[20] = ui->screen_do20;
do_led_array[21] = ui->screen_do21;
do_led_array[22] = ui->screen_do22;
do_led_array[23] = ui->screen_do23;
do_led_array[24] = ui->screen_do24;
do_led_array[25] = ui->screen_do25;
do_led_array[26] = ui->screen_do26;
do_led_array[27] = ui->screen_do27;
do_led_array[28] = ui->screen_do28;
do_led_array[29] = ui->screen_do29;
do_led_array[30] = ui->screen_do30;
do_led_array[31] = ui->screen_do31;
do_led_array[32] = ui->screen_do32;
do_led_array[33] = ui->screen_do33;
do_led_array[34] = ui->screen_do34;
do_led_array[35] = ui->screen_do35;
do_led_array[36] = ui->screen_do36;
do_led_array[37] = ui->screen_do37;
do_led_array[38] = ui->screen_do38;
do_led_array[39] = ui->screen_do39;
do_led_array[40] = ui->screen_do40;
do_led_array[41] = ui->screen_do41;
do_led_array[42] = ui->screen_do42;
do_led_array[43] = ui->screen_do43;
do_led_array[44] = ui->screen_do44;
do_led_array[45] = ui->screen_do45;
do_led_array[46] = ui->screen_do46;
do_led_array[47] = ui->screen_do47;
do_led_array[48] = ui->screen_do48;
do_led_array[49] = ui->screen_do49;
do_led_array[50] = ui->screen_do50;
do_led_array[51] = ui->screen_do51;
do_led_array[52] = ui->screen_do52;
do_led_array[53] = ui->screen_do53;
do_led_array[54] = ui->screen_do54;
do_led_array[55] = ui->screen_do55;
do_led_array[56] = ui->screen_do56;
do_led_array[57] = ui->screen_do57;
do_led_array[58] = ui->screen_do58;
do_led_array[59] = ui->screen_do59;
do_led_array[60] = ui->screen_do60;
do_led_array[61] = ui->screen_do61;
do_led_array[62] = ui->screen_do62;
do_led_array[63] = ui->screen_do63;
//ai
di_labels[0] = ui->screen_AIO4001;
di_labels[1] = ui->screen_AIO4002;
di_labels[2] = ui->screen_AIO4003;
di_labels[3] = ui->screen_AIO4004;
di_labels[4] = ui->screen_AIO4005;
di_labels[5] = ui->screen_AIO4006;
di_labels[6] = ui->screen_AIO4007;
di_labels[7] = ui->screen_AIO4008;
di_labels[8] = ui->screen_AIO4009;
di_labels[9] = ui->screen_AIO4010;
di_labels[10] = ui->screen_AIO4011;
di_labels[11] = ui->screen_AIO4012;
di_labels[12] = ui->screen_AIO4013;
di_labels[13] = ui->screen_AIO4014;
di_labels[14] = ui->screen_AIO4015;
di_labels[15] = ui->screen_AIO4016;
di_labels[16] = ui->screen_AIO4017;
di_labels[17] = ui->screen_AIO4018;
di_labels[18] = ui->screen_AIO4019;
di_labels[19] = ui->screen_AIO4020;
di_labels[20] = ui->screen_AIO4021;
di_labels[21] = ui->screen_AIO4022;
di_labels[22] = ui->screen_AIO4023;
di_labels[23] = ui->screen_AIO4024;
//ao
do_labels[0] = ui->screen_AIO5001;
do_labels[1] = ui->screen_AIO5002;
do_labels[2] = ui->screen_AIO5003;
do_labels[3] = ui->screen_AIO5004;
do_labels[4] = ui->screen_AIO5005;
do_labels[5] = ui->screen_AIO5006;
do_labels[6] = ui->screen_AIO5007;
do_labels[7] = ui->screen_AIO5008;
do_labels[8] = ui->screen_AIO5009;
do_labels[9] = ui->screen_AIO5010;
do_labels[10] = ui->screen_AIO5011;
do_labels[11] = ui->screen_AIO5012;
do_labels[12] = ui->screen_AIO5013;
do_labels[13] = ui->screen_AIO5014;
do_labels[14] = ui->screen_AIO5015;
do_labels[15] = ui->screen_AIO5016;
}
void update_io_labels(void)
{
for (int i = 0; i < 24; i++) {
snprintf(buf, sizeof(buf), "%d", ai_table[i].current_Value);
lv_label_set_text(di_labels[i], buf);
}
for (int i = 0; i < 16; i++) {
snprintf(buf, sizeof(buf), "%d", ao_table[i].current_Value);
lv_label_set_text(do_labels[i], buf);
}
}
void update_led_i(void)
{
for (int i = 0; i < 64; i++)
{
if(di_table[i].current_state)
{
lv_led_on(di_led_array[i]);
}
else
{
lv_led_off(di_led_array[i]);
}
}
}
void update_led_o(void)
{
for (int i = 0; i < 64; i++)
{
if(do_table[i].current_state)
{
lv_led_on(do_led_array[i]);
}
else
{
lv_led_off(do_led_array[i]);
}
}
}
/**
* 获取当前时间字符串,格式:2025/01/25 13:55:11
* @param buf 输出缓冲区
* @param size 缓冲区大小(建议 >= 22)
* @return 成功返回 buf,失败返回 NULL
*/
char* get_time_str(char *buf, size_t size)
{
time_t now;
struct tm *tm_info;
if (buf == RT_NULL || size < 22)
return RT_NULL;
time(&now); // 获取当前时间戳(秒)
tm_info = localtime(&now); // 转为本地时间
if (tm_info == RT_NULL)
{
rt_strncpy(buf, "invalid", size - 1);
buf[size - 1] = '\0';
return buf;
}
// 格式:2025/01/25 13:55:11 (注意两个空格)
strftime(buf, size, "%Y/%m/%d %H:%M:%S", tm_info);
return buf;
}
/**
* 数据信息显示
**/
#include <guider/custom/custom.h>
#include <guider/generated/events_init.h>
#include <guider/generated/gui_guider.h>
#include <guider/generated/widgets_init.h>
#include "sql/DB_SQLite.h"
#include"ui_data_csv.h"
int Work_Program_DATA=0;
char select_data_ui[4096]= {0};
char sqlSELECT[512] = {0}; // 初始化为 0
//工单页面的工艺/工单表
void Work_Program_ui(void)
{
//清楚点击行记录
Work_row = -1;
Work_step_row = -1;
Work_Program_DATA = ~Work_Program_DATA;
if(Work_Program_DATA==0)
{
char time_str[32];
if (get_time_str(time_str, sizeof(time_str)) != RT_NULL)
{
// 安全格式化
rt_snprintf(sqlSELECT, sizeof(sqlSELECT),"%s'%s' LIMIT 16;",select_WorkOrder_DATA,time_str);
db_send_select(DB_CMD_SELECT, sqlSELECT, 500,select_data_ui);
// 表格绘图
parse_csv_to_table(guider_ui.screen_list_inf, select_data_ui,0);
}
}
else
{
// 查询工艺数据
db_send_select(DB_CMD_SELECT, select_Program_DATA, 500,select_data_ui);
// 表格绘图
parse_csv_to_table(guider_ui.screen_list_inf, select_data_ui,0);
}
lv_table_set_col_cnt(guider_ui.screen_w_list,2);
lv_table_set_row_cnt(guider_ui.screen_w_list,1);
lv_table_set_col_width(guider_ui.screen_w_list, 0, 50);
lv_table_set_col_width(guider_ui.screen_w_list, 1, 250);
}
//工单页面的步骤信息表
void Work_Program_step_ui(char* str_data)
{
if(Work_Program_DATA==0)
{
// 安全格式化
rt_snprintf(sqlSELECT, sizeof(sqlSELECT),"%s'%s' ORDER BY Step ASC;",select_WorkorderSteps_DATA,str_data);
db_send_select(DB_CMD_SELECT, sqlSELECT, 500,select_data_ui);
// 表格绘图
if((select_data_ui[0]=='N')&&(select_data_ui[1]=='o'))return;
parse_csv_to_table(guider_ui.screen_w_list, select_data_ui,1);
lv_table_set_col_width(guider_ui.screen_w_list, 0, 50);
lv_table_set_col_width(guider_ui.screen_w_list, 1, 250);
rt_snprintf(sqlSELECT, sizeof(sqlSELECT),"%s WorkOrder = '%s' LIMIT 1;",select_Workorderinf_DATA,str_data);
db_send_select(DB_CMD_SELECT, sqlSELECT, 500,select_data_ui);
//信息显示
parse_csv_to_inf(guider_ui.screen_text_inf,select_data_ui,550,230);
}
else
{
// 安全格式化
rt_snprintf(sqlSELECT, sizeof(sqlSELECT),"%s'%s' ORDER BY Step ASC;",select_ProgramSteps_DATA,str_data);
db_send_select(DB_CMD_SELECT, sqlSELECT, 500,select_data_ui);
// 表格绘图
if((select_data_ui[0]=='N')&&(select_data_ui[1]=='o'))return;
parse_csv_to_table(guider_ui.screen_w_list, select_data_ui,1);
lv_table_set_col_width(guider_ui.screen_w_list, 0, 50);
lv_table_set_col_width(guider_ui.screen_w_list, 1, 250);
parse_csv_to_inf(guider_ui.screen_text_inf,"",550,230);
}
}
//工单页面的步骤详细
void Work_Program_stepINF_ui(char* str_data)
{
if(Work_Program_DATA==0)
{
// 安全格式化
rt_snprintf(sqlSELECT, sizeof(sqlSELECT),"%s WorkOrder = '%s LIMIT 1;",select_WorkorderStepsinf_DATA,str_data);
db_send_select(DB_CMD_SELECT, sqlSELECT, 500,select_data_ui);
//信息显示
parse_csv_to_inf(guider_ui.screen_text_inf,select_data_ui,550,230);
}
else
{
// 安全格式化
rt_snprintf(sqlSELECT, sizeof(sqlSELECT),"%s ProgramID = '%s LIMIT 1;",select_ProgramStepsinf_DATA,str_data);
db_send_select(DB_CMD_SELECT, sqlSELECT, 500,select_data_ui);
//信息显示
parse_csv_to_inf(guider_ui.screen_text_inf,select_data_ui,550,230);
}
}