parent
c5f62d3d6a
commit
c01717daac
|
@ -3,4 +3,17 @@
|
|||
|
||||
#include "apps_gather.h"
|
||||
|
||||
//选中cur,熄灭cur_prv
|
||||
void window_num_check(uint8_t cur, uint8_t cur_prv);
|
||||
|
||||
void window_num_set(uint8_t pos, uint8_t num);
|
||||
|
||||
void value2window(void);
|
||||
|
||||
void window2value(void);
|
||||
|
||||
void cursor_move(int8_t step);
|
||||
|
||||
void window_display(void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -289,18 +289,6 @@ uint8_t init_set_bar(uint8_t start, uint8_t end, uint16_t interval)
|
|||
|
||||
void scr_main_run(void)
|
||||
{
|
||||
//modbus主站功能测试
|
||||
if(tabdata.modbus_master_send_flag == 1)
|
||||
{
|
||||
tabdata.modbus_enable = 1;
|
||||
tabdata.modbus_type = SIG_MASTER;
|
||||
|
||||
tabdata.modbus_master_send_flag = 0;
|
||||
|
||||
modbus_rtu_master_load();
|
||||
modbus_rtu_master_send();
|
||||
}
|
||||
|
||||
//实时更新设定值
|
||||
sig_sv_update(); //不做延时,尽快响应
|
||||
|
||||
|
|
|
@ -142,8 +142,10 @@ void trx_items_check(MOD_TRX_ITEMS cur, MOD_TRX_ITEMS cur_prv)
|
|||
|
||||
void scr_modbus_config_recover(void)
|
||||
{
|
||||
//标题
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_label_title, text_pack.modbus_master_title);
|
||||
|
||||
//左列名称
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_label_device_addr, text_pack.modbus_master_item[0]);
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_label_start_addr, text_pack.modbus_master_item[1]);
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_label_bytes, text_pack.modbus_master_item[2]);
|
||||
|
@ -153,6 +155,23 @@ void scr_modbus_config_recover(void)
|
|||
lv_label_set_text(guider_ui.screen_modbus_config_label_calibration, text_pack.modbus_master_item[6]);
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_label_next, text_pack.modbus_master_item[7]);
|
||||
|
||||
char str_temp[16];
|
||||
//右列值
|
||||
sprintf(str_temp, "0x%02x", mod_master.target_id);
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_value_device_addr, str_temp);
|
||||
sprintf(str_temp, "0x%04x", mod_master.start_address);
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_value_start_addr, str_temp);
|
||||
sprintf(str_temp, "%d", mod_master.byte_num);
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_value_bytes, str_temp);
|
||||
sprintf(str_temp, "%d", mod_master.timeout);
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_value_timeout, str_temp);
|
||||
sprintf(str_temp, "0x%02x", mod_master.command_code);
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_value_cmd, str_temp);
|
||||
sprintf(str_temp, "%d", mod_master.register_num);
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_value_register_num, str_temp);
|
||||
//lv_label_set_text(guider_ui.screen_modbus_config_value_calibration, );
|
||||
//lv_label_set_text(guider_ui.screen_modbus_config_value_next, );
|
||||
|
||||
mod_mas_conf_cursor = MOD_CONF_SLAVE_ID; //配置项的游标
|
||||
mod_mas_conf_cursor_prv = MOD_CONF_NONE;
|
||||
config_items_check(mod_mas_conf_cursor, mod_mas_conf_cursor_prv);
|
||||
|
@ -160,6 +179,9 @@ void scr_modbus_config_recover(void)
|
|||
|
||||
void scr_modbus_trx_recover(void)
|
||||
{
|
||||
//根据当前语言,刷新标题
|
||||
lv_label_set_text(guider_ui.screen_modbus_trx_label_Data, text_pack.modbus_master_trx_item[0]);
|
||||
|
||||
//清空数据、发送、接收框
|
||||
lv_label_set_text(guider_ui.screen_modbus_trx_value_Data,"");
|
||||
lv_label_set_text(guider_ui.screen_modbus_trx_value_Tx,"");
|
||||
|
|
|
@ -208,8 +208,8 @@ void setting_items_page(ITEMS ite, uint8_t page)
|
|||
//特殊处理,避免其他选项卡也被染上颜色
|
||||
if(ite != ITEM_1)
|
||||
{
|
||||
set_obj_color(guider_ui.screen_setting_label_21, 7);
|
||||
set_obj_color(guider_ui.screen_setting_label_31, 7);
|
||||
set_obj_color(guider_ui.screen_setting_label_21, 6);
|
||||
set_obj_color(guider_ui.screen_setting_label_31, 6);
|
||||
}
|
||||
|
||||
switch (ite)
|
||||
|
|
|
@ -1,6 +1,325 @@
|
|||
#include "key_functions_modbus.h"
|
||||
|
||||
uint8_t mod_trx_set_flag = 0; //trx的屏幕是否加载过
|
||||
uint8_t window_cursor = 0; //弹窗游标位置
|
||||
uint8_t window_cursor_prv = 0;
|
||||
uint8_t window_num[4] = {0}; //窗口内的四个数字
|
||||
|
||||
void window_num_check(uint8_t cur, uint8_t cur_prv)
|
||||
{
|
||||
switch (cur)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
lv_obj_set_style_bg_color(guider_ui.screen_modbus_config_num_0, lv_color_hex(COLOR_CONTENTS_CHECKED), LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
{
|
||||
lv_obj_set_style_bg_color(guider_ui.screen_modbus_config_num_1, lv_color_hex(COLOR_CONTENTS_CHECKED), LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
{
|
||||
lv_obj_set_style_bg_color(guider_ui.screen_modbus_config_num_2, lv_color_hex(COLOR_CONTENTS_CHECKED), LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
{
|
||||
lv_obj_set_style_bg_color(guider_ui.screen_modbus_config_num_3, lv_color_hex(COLOR_CONTENTS_CHECKED), LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (cur_prv)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
lv_obj_set_style_bg_color(guider_ui.screen_modbus_config_num_0, lv_color_hex(COLOR_CONTENTS_UNCHECKED), LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
{
|
||||
lv_obj_set_style_bg_color(guider_ui.screen_modbus_config_num_1, lv_color_hex(COLOR_CONTENTS_UNCHECKED), LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
{
|
||||
lv_obj_set_style_bg_color(guider_ui.screen_modbus_config_num_2, lv_color_hex(COLOR_CONTENTS_UNCHECKED), LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
{
|
||||
lv_obj_set_style_bg_color(guider_ui.screen_modbus_config_num_3, lv_color_hex(COLOR_CONTENTS_UNCHECKED), LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void cursor_move(int8_t step)
|
||||
{
|
||||
switch (mod_mas_conf_cursor)
|
||||
{
|
||||
case MOD_CONF_SLAVE_ID:
|
||||
{
|
||||
window_cursor_prv = window_cursor;
|
||||
window_cursor = 3*(window_cursor == 2) + 2*(window_cursor == 3);
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_CONF_START_ADDRESS:
|
||||
{
|
||||
window_cursor_prv = window_cursor;
|
||||
window_cursor += step;
|
||||
if(window_cursor > 200)
|
||||
{
|
||||
window_cursor = 3;
|
||||
}
|
||||
else if (window_cursor > 3)
|
||||
{
|
||||
window_cursor = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_CONF_COMMAND:
|
||||
{
|
||||
window_cursor_prv = window_cursor;
|
||||
window_cursor = 3*(window_cursor == 2) + 2*(window_cursor == 3);
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_CONF_REGISTER_NUM:
|
||||
{
|
||||
window_cursor_prv = window_cursor;
|
||||
window_cursor += step;
|
||||
if(window_cursor < 1)
|
||||
{
|
||||
window_cursor = 3;
|
||||
}
|
||||
else if (window_cursor > 3)
|
||||
{
|
||||
window_cursor = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
window_num_check(window_cursor, window_cursor_prv);
|
||||
}
|
||||
|
||||
void window_num_set(uint8_t pos, uint8_t num)
|
||||
{
|
||||
char str_temp[8] = {0};
|
||||
|
||||
if( num <= 16 )
|
||||
{
|
||||
sprintf(str_temp, "%x", num);
|
||||
}
|
||||
else if (num == 20)
|
||||
{
|
||||
strcpy(str_temp, "0");
|
||||
}
|
||||
else if (num == 21)
|
||||
{
|
||||
strcpy(str_temp, "x");
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(str_temp, "-");
|
||||
}
|
||||
|
||||
switch (pos)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_num_0, str_temp);
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
{
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_num_1, str_temp);
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
{
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_num_2, str_temp);
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
{
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_num_3, str_temp);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void value2window(void)
|
||||
{}
|
||||
|
||||
void window2value(void)
|
||||
{
|
||||
char str_temp[16];
|
||||
|
||||
switch (mod_mas_conf_cursor)
|
||||
{
|
||||
case MOD_CONF_SLAVE_ID:
|
||||
{
|
||||
mod_master.target_id = window_num[2] & 0x0F;
|
||||
mod_master.target_id <<= 4;
|
||||
mod_master.target_id += window_num[3] & 0x0F;
|
||||
|
||||
sprintf(str_temp, "0x%02x", mod_master.target_id);
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_value_device_addr, str_temp);
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_CONF_START_ADDRESS:
|
||||
{
|
||||
mod_master.start_address = window_num[0] & 0x0F;
|
||||
mod_master.start_address <<= 4;
|
||||
mod_master.start_address += window_num[1] & 0x0F;
|
||||
mod_master.start_address <<= 4;
|
||||
mod_master.start_address += window_num[2] & 0x0F;
|
||||
mod_master.start_address <<= 4;
|
||||
mod_master.start_address += window_num[3] & 0x0F;
|
||||
|
||||
sprintf(str_temp, "0x%04x", mod_master.start_address);
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_value_start_addr, str_temp);
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_CONF_COMMAND:
|
||||
{
|
||||
mod_master.command_code= window_num[2];
|
||||
mod_master.command_code <<= 4;
|
||||
mod_master.command_code += window_num[3];
|
||||
|
||||
sprintf(str_temp, "0x%02x", mod_master.command_code);
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_value_cmd, str_temp);
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_CONF_REGISTER_NUM:
|
||||
{
|
||||
mod_master.register_num = window_num[1]*100 + window_num[2]*10 + window_num[3];
|
||||
|
||||
sprintf(str_temp, "%d", mod_master.register_num);
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_value_register_num, str_temp);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void window_display(void)
|
||||
{
|
||||
switch (mod_mas_conf_cursor)
|
||||
{
|
||||
case MOD_CONF_SLAVE_ID:
|
||||
{
|
||||
//前两位显示“0x”,游标从2开始,2-3
|
||||
window_num[0] = 20;
|
||||
window_num[1] = 21;
|
||||
window_num[2] = mod_master.target_id >> 4;
|
||||
window_num[3] = mod_master.target_id & 0x0F;
|
||||
for(uint8_t i = 0; i < 4; i++)
|
||||
{
|
||||
window_num_set(i, window_num[i]);
|
||||
}
|
||||
window_cursor = 2;
|
||||
window_cursor_prv = 99;
|
||||
window_num_check(window_cursor, window_cursor_prv);
|
||||
|
||||
lv_obj_clear_flag(guider_ui.screen_modbus_config_window_config, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_CONF_START_ADDRESS:
|
||||
{
|
||||
//游标从0开始,0-3
|
||||
window_num[0] = 0x000F & (mod_master.start_address >> 12);
|
||||
window_num[1] = 0x000F & (mod_master.start_address >> 8);
|
||||
window_num[2] = 0x000F & (mod_master.start_address >> 4);
|
||||
window_num[3] = 0x000F & (mod_master.start_address );
|
||||
for(uint8_t i = 0; i < 4; i++)
|
||||
{
|
||||
window_num_set(i, window_num[i]);
|
||||
}
|
||||
window_cursor = 0;
|
||||
window_cursor_prv = 99;
|
||||
window_num_check(window_cursor, window_cursor_prv);
|
||||
|
||||
lv_obj_clear_flag(guider_ui.screen_modbus_config_window_config, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_CONF_COMMAND:
|
||||
{
|
||||
//前两位显示“0x”,游标从2开始,2-3
|
||||
window_num[0] = 20;
|
||||
window_num[1] = 21;
|
||||
window_num[2] = mod_master.command_code >> 4;
|
||||
window_num[3] = mod_master.command_code & 0x0F;
|
||||
for(uint8_t i = 0; i < 4; i++)
|
||||
{
|
||||
window_num_set(i, window_num[i]);
|
||||
}
|
||||
window_cursor = 2;
|
||||
window_cursor_prv = 99;
|
||||
window_num_check(window_cursor, window_cursor_prv);
|
||||
|
||||
lv_obj_clear_flag(guider_ui.screen_modbus_config_window_config, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_CONF_REGISTER_NUM:
|
||||
{
|
||||
//第一位显示“0”,游标从1开始,1-3
|
||||
window_num[0] = 0;
|
||||
window_num[1] = mod_master.register_num / 100;
|
||||
window_num[2] = (mod_master.register_num / 10) % 10;
|
||||
window_num[3] = mod_master.register_num % 10;
|
||||
for(uint8_t i = 0; i < 4; i++)
|
||||
{
|
||||
window_num_set(i, window_num[i]);
|
||||
}
|
||||
window_cursor = 1;
|
||||
window_cursor_prv = 99;
|
||||
window_num_check(window_cursor, window_cursor_prv);
|
||||
|
||||
lv_obj_clear_flag(guider_ui.screen_modbus_config_window_config, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void key_functions_modbus(void)
|
||||
{
|
||||
if( key_pv.status == KEY_STATUS_DISABLE ) return;
|
||||
|
@ -35,6 +354,25 @@ void key_functions_modbus(void)
|
|||
}
|
||||
break;
|
||||
|
||||
case MODBUS_MASTER_CONFIG_MODIFY:
|
||||
{
|
||||
if( (mod_mas_conf_cursor == MOD_CONF_SLAVE_ID)||(mod_mas_conf_cursor == MOD_CONF_START_ADDRESS)||(mod_mas_conf_cursor == MOD_CONF_COMMAND) )
|
||||
{
|
||||
window_num[window_cursor] += 1;
|
||||
if(window_num[window_cursor] >= 16) window_num[window_cursor] = 0;
|
||||
|
||||
window_num_set(window_cursor, window_num[window_cursor]);
|
||||
}
|
||||
else if (mod_mas_conf_cursor == MOD_CONF_REGISTER_NUM)
|
||||
{
|
||||
window_num[window_cursor] += 1;
|
||||
if(window_num[window_cursor] >= 10) window_num[window_cursor] = 0;
|
||||
|
||||
window_num_set(window_cursor, window_num[window_cursor]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MODBUS_MASTER_TRX:
|
||||
{
|
||||
if(mod_mas_trx_cursor)
|
||||
|
@ -83,6 +421,25 @@ void key_functions_modbus(void)
|
|||
}
|
||||
break;
|
||||
|
||||
case MODBUS_MASTER_CONFIG_MODIFY:
|
||||
{
|
||||
if( (mod_mas_conf_cursor == MOD_CONF_SLAVE_ID)||(mod_mas_conf_cursor == MOD_CONF_START_ADDRESS)||(mod_mas_conf_cursor == MOD_CONF_COMMAND) )
|
||||
{
|
||||
window_num[window_cursor] -= 1;
|
||||
if(window_num[window_cursor] > 200) window_num[window_cursor] = 15;
|
||||
|
||||
window_num_set(window_cursor, window_num[window_cursor]);
|
||||
}
|
||||
else if (mod_mas_conf_cursor == MOD_CONF_REGISTER_NUM)
|
||||
{
|
||||
window_num[window_cursor] -= 1;
|
||||
if(window_num[window_cursor] > 200) window_num[window_cursor] = 9;
|
||||
|
||||
window_num_set(window_cursor, window_num[window_cursor]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MODBUS_MASTER_TRX:
|
||||
{
|
||||
if(!mod_mas_trx_cursor)
|
||||
|
@ -128,6 +485,59 @@ void key_functions_modbus(void)
|
|||
}
|
||||
break;
|
||||
|
||||
case MODBUS_MASTER_CONFIG_MODIFY:
|
||||
{
|
||||
switch (mod_mas_conf_cursor)
|
||||
{
|
||||
case MOD_CONF_SLAVE_ID:
|
||||
{}
|
||||
//break;
|
||||
|
||||
case MOD_CONF_START_ADDRESS:
|
||||
{}
|
||||
//break;
|
||||
|
||||
case MOD_CONF_COMMAND:
|
||||
{}
|
||||
//break;
|
||||
|
||||
case MOD_CONF_REGISTER_NUM:
|
||||
{
|
||||
cursor_move(-1);
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_CONF_BYTES:
|
||||
{
|
||||
char str_temp[16];
|
||||
|
||||
mod_master.byte_num -= 1;
|
||||
if( mod_master.byte_num > 200) mod_master.byte_num = 16;
|
||||
|
||||
sprintf(str_temp, "%d", mod_master.byte_num);
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_value_bytes, str_temp);
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_CONF_TIMEOUT:
|
||||
{
|
||||
char str_temp[16];
|
||||
|
||||
mod_master.timeout -= 100;
|
||||
if( mod_master.timeout > 60000) mod_master.timeout = 10000;
|
||||
|
||||
sprintf(str_temp, "%d", mod_master.timeout);
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_value_timeout, str_temp);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case MODBUS_MASTER_TRX:
|
||||
{
|
||||
if(mod_mas_trx_cursor)
|
||||
|
@ -177,6 +587,58 @@ void key_functions_modbus(void)
|
|||
}
|
||||
break;
|
||||
|
||||
case MODBUS_MASTER_CONFIG_MODIFY:
|
||||
{
|
||||
switch (mod_mas_conf_cursor)
|
||||
{
|
||||
case MOD_CONF_SLAVE_ID:
|
||||
{}
|
||||
//break;
|
||||
|
||||
case MOD_CONF_START_ADDRESS:
|
||||
{}
|
||||
//break;
|
||||
|
||||
case MOD_CONF_COMMAND:
|
||||
{}
|
||||
//break;
|
||||
|
||||
case MOD_CONF_REGISTER_NUM:
|
||||
{
|
||||
cursor_move(1);
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_CONF_BYTES:
|
||||
{
|
||||
char str_temp[16];
|
||||
|
||||
mod_master.byte_num += 1;
|
||||
if( mod_master.byte_num > 16) mod_master.byte_num = 0;
|
||||
|
||||
sprintf(str_temp, "%d", mod_master.byte_num);
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_value_bytes, str_temp);
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_CONF_TIMEOUT:
|
||||
{
|
||||
char str_temp[16];
|
||||
|
||||
mod_master.timeout += 100;
|
||||
if( mod_master.timeout > 10000) mod_master.timeout = 0;
|
||||
|
||||
sprintf(str_temp, "%d", mod_master.timeout);
|
||||
lv_label_set_text(guider_ui.screen_modbus_config_value_timeout, str_temp);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MODBUS_MASTER_TRX:
|
||||
{
|
||||
if(mod_mas_trx_cursor)
|
||||
|
@ -212,30 +674,92 @@ void key_functions_modbus(void)
|
|||
{
|
||||
case MODBUS_MASTER_CONFIG:
|
||||
{
|
||||
if(mod_mas_conf_cursor == MOD_CONF_NEXT)
|
||||
switch(mod_mas_conf_cursor)
|
||||
{
|
||||
if(!mod_trx_set_flag)
|
||||
case MOD_CONF_SLAVE_ID:
|
||||
{
|
||||
mod_trx_set_flag = 1;
|
||||
setup_scr_screen_modbus_trx(&guider_ui);
|
||||
delay_cnt(200); //不加延时有概率卡死
|
||||
window_display();
|
||||
current_operation = MODBUS_MASTER_CONFIG_MODIFY;
|
||||
}
|
||||
//加载trx界面
|
||||
scr_modbus_trx_recover();
|
||||
lv_scr_load(guider_ui.screen_modbus_trx);
|
||||
lv_obj_clear_flag(guider_ui.screen_modbus_trx, LV_OBJ_FLAG_HIDDEN);
|
||||
break;
|
||||
|
||||
menu_data.scr_now = SCREEN_MODBUS_MASTER_TRX;
|
||||
|
||||
//隐藏配置界面,熄灭当前游标
|
||||
lv_obj_add_flag(guider_ui.screen_modbus_config, LV_OBJ_FLAG_HIDDEN);
|
||||
config_items_check(MOD_CONF_NONE, mod_mas_conf_cursor);
|
||||
case MOD_CONF_START_ADDRESS:
|
||||
{
|
||||
window_display();
|
||||
current_operation = MODBUS_MASTER_CONFIG_MODIFY;
|
||||
}
|
||||
break;
|
||||
|
||||
current_operation = MODBUS_MASTER_TRX;
|
||||
case MOD_CONF_BYTES:
|
||||
{
|
||||
lv_obj_set_style_bg_color(guider_ui.screen_modbus_config_value_bytes, lv_color_hex(COLOR_CONTENTS_FOCUSED), LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||
current_operation = MODBUS_MASTER_CONFIG_MODIFY;
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_CONF_TIMEOUT:
|
||||
{
|
||||
lv_obj_set_style_bg_color(guider_ui.screen_modbus_config_value_timeout, lv_color_hex(COLOR_CONTENTS_FOCUSED), LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||
current_operation = MODBUS_MASTER_CONFIG_MODIFY;
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_CONF_COMMAND:
|
||||
{
|
||||
window_display();
|
||||
current_operation = MODBUS_MASTER_CONFIG_MODIFY;
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_CONF_REGISTER_NUM:
|
||||
{
|
||||
window_display();
|
||||
current_operation = MODBUS_MASTER_CONFIG_MODIFY;
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_CONF_CALIBRATION:
|
||||
{}
|
||||
break;
|
||||
|
||||
case MOD_CONF_NEXT:
|
||||
{
|
||||
if(!mod_trx_set_flag)
|
||||
{
|
||||
mod_trx_set_flag = 1;
|
||||
setup_scr_screen_modbus_trx(&guider_ui);
|
||||
delay_cnt(200); //不加延时有概率卡死
|
||||
}
|
||||
//加载trx界面
|
||||
scr_modbus_trx_recover();
|
||||
lv_scr_load(guider_ui.screen_modbus_trx);
|
||||
lv_obj_clear_flag(guider_ui.screen_modbus_trx, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
menu_data.scr_now = SCREEN_MODBUS_MASTER_TRX;
|
||||
|
||||
//隐藏配置界面,熄灭当前游标
|
||||
lv_obj_add_flag(guider_ui.screen_modbus_config, LV_OBJ_FLAG_HIDDEN);
|
||||
config_items_check(MOD_CONF_NONE, mod_mas_conf_cursor);
|
||||
|
||||
current_operation = MODBUS_MASTER_TRX;
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_CONF_NONE:
|
||||
{}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MODBUS_MASTER_CONFIG_MODIFY:
|
||||
{
|
||||
}
|
||||
break;
|
||||
|
||||
case MODBUS_MASTER_TRX:
|
||||
{
|
||||
switch (mod_mas_trx_cursor)
|
||||
|
@ -255,16 +779,54 @@ void key_functions_modbus(void)
|
|||
case MOD_TRX_SET:
|
||||
{
|
||||
trx_focus = 1;
|
||||
|
||||
trx_items_check(mod_mas_trx_cursor, MOD_TRX_NONE);
|
||||
|
||||
modbus_rtu_master_load();
|
||||
switch (mod_master.tx_error_message)
|
||||
{
|
||||
case TX_ERROR_WRONG_CMD:
|
||||
{
|
||||
lv_label_set_text(guider_ui.screen_modbus_trx_value_Tx, "EEROR: Wrong Command");
|
||||
}
|
||||
break;
|
||||
|
||||
case TX_ERROR_COIL_NUM:
|
||||
{
|
||||
lv_label_set_text(guider_ui.screen_modbus_trx_value_Tx, "EEROR: Wrong Coil Num");
|
||||
}
|
||||
break;
|
||||
|
||||
case TX_ERROR_HOLDREG_NUM:
|
||||
{
|
||||
lv_label_set_text(guider_ui.screen_modbus_trx_value_Tx, "EEROR: Wrong HoldReg Num");
|
||||
}
|
||||
break;
|
||||
|
||||
case TX_ERROR_NONE:
|
||||
{
|
||||
char str0[10] = {0};
|
||||
char str_temp[256] = {0};
|
||||
for(uint8_t i = 0; i < mod_master.data_tx_len; i++)
|
||||
{
|
||||
sprintf(str0, "%02x ", mod_master.data_tx[i]);
|
||||
strcat(str_temp, str0);
|
||||
}
|
||||
lv_label_set_text(guider_ui.screen_modbus_trx_value_Tx, str_temp);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_TRX_SEND:
|
||||
{
|
||||
trx_focus = 1;
|
||||
|
||||
trx_items_check(mod_mas_trx_cursor, MOD_TRX_NONE);
|
||||
|
||||
modbus_rtu_master_send();
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -327,6 +889,54 @@ void key_functions_modbus(void)
|
|||
}
|
||||
break;
|
||||
|
||||
case MODBUS_MASTER_CONFIG_MODIFY:
|
||||
{
|
||||
switch (mod_mas_conf_cursor)
|
||||
{
|
||||
case MOD_CONF_SLAVE_ID:
|
||||
{}
|
||||
//break;
|
||||
|
||||
case MOD_CONF_START_ADDRESS:
|
||||
{}
|
||||
//break;
|
||||
|
||||
case MOD_CONF_COMMAND:
|
||||
{}
|
||||
//break;
|
||||
|
||||
case MOD_CONF_REGISTER_NUM:
|
||||
{
|
||||
lv_obj_add_flag(guider_ui.screen_modbus_config_window_config, LV_OBJ_FLAG_HIDDEN);
|
||||
window_num_check(99, window_cursor);
|
||||
window_cursor = 0;
|
||||
window_cursor_prv = 99;
|
||||
|
||||
window2value();
|
||||
memset(window_num, 0, 4);
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_CONF_BYTES:
|
||||
{
|
||||
lv_obj_set_style_bg_color(guider_ui.screen_modbus_config_value_bytes, lv_color_hex(COLOR_CONTENTS_CHECKED), LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||
}
|
||||
break;
|
||||
|
||||
case MOD_CONF_TIMEOUT:
|
||||
{
|
||||
lv_obj_set_style_bg_color(guider_ui.screen_modbus_config_value_timeout, lv_color_hex(COLOR_CONTENTS_CHECKED), LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
current_operation = MODBUS_MASTER_CONFIG;
|
||||
}
|
||||
break;
|
||||
|
||||
case MODBUS_MASTER_TRX:
|
||||
{
|
||||
//加载配置界面
|
||||
|
|
|
@ -61,6 +61,8 @@ void duty_tim6(void)
|
|||
if( (sig2slave_step == 1)||(mod_master.tx_flag == TX_OK) )
|
||||
{
|
||||
sig2slave_current_tick++;
|
||||
mod_master.rx_error_message = RX_ERROR_NONE;
|
||||
|
||||
if(sig2slave_current_tick > mod_master.timeout)
|
||||
{
|
||||
if(sig2slave_step == 0)
|
||||
|
@ -74,8 +76,9 @@ void duty_tim6(void)
|
|||
__HAL_UART_CLEAR_IDLEFLAG(&huart2);
|
||||
|
||||
sig2slave_current_tick = 0;
|
||||
sig2slave_step++;
|
||||
sig2slave_step = 2; //无论是哪个阶段出现超时,均跳转至step2
|
||||
scom2_rs485.rx_flag = TRUE;
|
||||
sig_trans = TRANS_MODBUS_SIG_TO_SLAVE; //发送回调中会修改成none,因此在这里重新赋值(接收超时也属于接收的一种结果)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
#include "apps_gather.h"
|
||||
#include "modbus_rtu.h"
|
||||
|
||||
#define TX_BUFF_MAX 128
|
||||
#define TX_DATA_MAX 100
|
||||
#define TX_BUFF_MAX 32
|
||||
#define TX_DATA_MAX 16
|
||||
#define RX_BUFF_MAX 128
|
||||
|
||||
#define TX_NONE 0x00 //没有需要发送的数据
|
||||
|
@ -42,7 +42,7 @@ typedef struct
|
|||
uint16_t crc16; //MODBUS_CRC16校验码
|
||||
uint8_t byte_num; //需要写入的线圈、保持寄存器字节数
|
||||
uint8_t data_tx_value8[TX_DATA_MAX]; //需要写入的数值,8位
|
||||
uint16_t data_tx_value16[TX_DATA_MAX]; //需要写入的数值,16位
|
||||
uint16_t data_tx_value16[TX_DATA_MAX/2];//需要写入的数值,16位
|
||||
uint8_t data_tx[TX_BUFF_MAX]; //存放完整的发送数据报
|
||||
uint8_t data_rx[RX_BUFF_MAX]; //存放完整的接收数据报
|
||||
uint8_t data_tx_len; //发送的数据报长度
|
||||
|
|
|
@ -269,9 +269,9 @@ void trans_modbus_sig2slave(void)
|
|||
strcpy(mod_master.result_display, "ERROR: TIMEOUT");
|
||||
}
|
||||
//在屏幕上显示 mod_master.result_display 字符串
|
||||
lv_label_set_text(guider_ui.screen_modbus_trx_value_Rx, mod_master.result_display);
|
||||
|
||||
//处理完成后复位相关参数
|
||||
modbus_rtu_master_init();
|
||||
sig2slave_step = 0;
|
||||
sig_trans = TRANS_NONE;
|
||||
memset(scom2_rs485.rx_buff, 0, scom2_rs485.rx_len);
|
||||
|
|
|
@ -29,6 +29,7 @@ void modbus_rtu_master_load(void)
|
|||
mod_master.data_tx[0] = mod_master.target_id;
|
||||
mod_master.data_tx[1] = mod_master.command_code;
|
||||
memset(mod_master.data_rx, 0, sizeof(mod_master.data_rx));
|
||||
mod_master.tx_error_message = TX_ERROR_NONE;
|
||||
|
||||
switch (mod_master.data_tx[1])
|
||||
{
|
||||
|
|
|
@ -110,10 +110,10 @@ void setup_scr_screen_modbus_trx(lv_ui *ui)
|
|||
|
||||
//Write codes screen_modbus_trx_label_Rx
|
||||
ui->screen_modbus_trx_label_Rx = lv_label_create(ui->screen_modbus_trx);
|
||||
lv_label_set_text(ui->screen_modbus_trx_label_Rx, "Rx:");
|
||||
lv_label_set_text(ui->screen_modbus_trx_label_Rx, "(HEX)Rx:");
|
||||
lv_label_set_long_mode(ui->screen_modbus_trx_label_Rx, LV_LABEL_LONG_WRAP);
|
||||
lv_obj_set_pos(ui->screen_modbus_trx_label_Rx, 3, 150);
|
||||
lv_obj_set_size(ui->screen_modbus_trx_label_Rx, 40, 18);
|
||||
lv_obj_set_size(ui->screen_modbus_trx_label_Rx, 90, 18);
|
||||
|
||||
//Write style for screen_modbus_trx_label_Rx, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.
|
||||
lv_obj_set_style_border_width(ui->screen_modbus_trx_label_Rx, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||
|
@ -217,10 +217,10 @@ void setup_scr_screen_modbus_trx(lv_ui *ui)
|
|||
|
||||
//Write codes screen_modbus_trx_label_Tx
|
||||
ui->screen_modbus_trx_label_Tx = lv_label_create(ui->screen_modbus_trx);
|
||||
lv_label_set_text(ui->screen_modbus_trx_label_Tx, "Tx:");
|
||||
lv_label_set_text(ui->screen_modbus_trx_label_Tx, "(HEX)Tx:");
|
||||
lv_label_set_long_mode(ui->screen_modbus_trx_label_Tx, LV_LABEL_LONG_WRAP);
|
||||
lv_obj_set_pos(ui->screen_modbus_trx_label_Tx, 166, 3);
|
||||
lv_obj_set_size(ui->screen_modbus_trx_label_Tx, 40, 18);
|
||||
lv_obj_set_size(ui->screen_modbus_trx_label_Tx, 90, 18);
|
||||
|
||||
//Write style for screen_modbus_trx_label_Tx, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.
|
||||
lv_obj_set_style_border_width(ui->screen_modbus_trx_label_Tx, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue