сохранение/загрузка в эмс-г на доработке

This commit is contained in:
2025-03-11 18:47:53 +03:00
parent 05143f6f45
commit 228d1dfd19
12 changed files with 257 additions and 220 deletions

View File

@@ -2,6 +2,7 @@ extends Node2D
signal read_ems_g_start()
signal read_ems_g_finish()
signal write_ems_g_start()
var timer_modul_um: Timer = Timer.new()
@@ -21,7 +22,7 @@ var att_fs_1: float
var att_fs_2: float
var att_fs_3: float
var status_pribor = null
var save_path = "D://PRD-TU-MP550//"
var save_path = "res://saves/"
const need_port: Array = [0x122, 0x124, 0x126, 0x128, 0x12A]
var current_meta: Array = [Constants.META.MODUL_UM_1, Constants.META.MODUL_UM_2, Constants.META.MODUL_UM_3, Constants.META.MODUL_UM_28]
var modul_um: Array = [0, 0, 0, 0]
@@ -31,11 +32,11 @@ func _ready() -> void:
$Background/lbl_commit.text = commit.VCS_HEAD
# Считывание аргументов с консоли (путь сохранения)
var args = OS.get_cmdline_user_args()
for i in range(args.size()):
if args[i] == "testsave-path" and i + 1 < args.size():
save_path = args[i + 1]
break
#var args = OS.get_cmdline_user_args()
#for i in range(args.size()):
#if args[i] == "testsave-path" and i + 1 < args.size():
#save_path = args[i + 1]
#break
# Таблица 1 УКП-1 (Температура, Мощность)
node_select1 = $TabContainer/PRD/body_grid/litera_2_4_6/table_ukp_1
@@ -209,7 +210,6 @@ func _ready() -> void:
node_select_fs_2.get_node2(1, 5).get_child(1, false).connect('toggled', Callable(self, '_on_get_status_2'))
node_select_fs_2.get_node2(1, 7).connect('text_submitted', Callable(self, '_on_set_base_can_macro_2'))
node_select_fs_2.get_node2(1, 8).get_child(1, false).connect('toggled', Callable(self, '_on_status_can_macro_2'))
## FS 3
node_select_fs_3.get_node2(1, 2).connect('text_submitted', Callable(self, '_on_set_ferq_3'))
node_select_fs_3.get_node2(1, 3).connect('text_submitted', Callable(self, '_on_set_att_3'))
@@ -229,6 +229,7 @@ func _ready() -> void:
self.add_child(timer_modul_um)
timer_modul_um.connect('timeout', Callable(self, '_on_timer_modul_um'))
self.connect('write_ems_g_start', _on_write_ems_g)
func add_signs_scene():
@@ -324,21 +325,23 @@ func _on_read_isa(unit_isa_ports: Dictionary) -> void:
for key in unit_isa_ports.keys():
isa_data[key] = unit_isa_ports[key]
if isa_data.has(Constants.BASE_PORTS.EMS_G+2):
var tmp = isa_data[Constants.BASE_PORTS.EMS_G+2]
isa_data.erase(Constants.BASE_PORTS.EMS_G+2)
if isa_data.has(Constants.BASE_PORTS.EMS_G+2):
var tmp = isa_data[Constants.BASE_PORTS.EMS_G+2]
isa_data.erase(Constants.BASE_PORTS.EMS_G+2)
var found = false
for i in range(Constants.EMS_G_PORT_DATA_HOLDER.size()):
if Constants.EMS_G_PORT_DATA_HOLDER[i][0] == tmp:
Constants.EMS_G_PORT_DATA_HOLDER[i][1] = isa_data
found = true
break
if not found:
Constants.EMS_G_PORT_DATA_HOLDER.append([tmp, isa_data])
var found = false
for i in range(Constants.EMS_G_PORT_DATA_HOLDER.size()):
if Constants.EMS_G_PORT_DATA_HOLDER[i][0] == tmp:
Constants.EMS_G_PORT_DATA_HOLDER[i][1] = isa_data
found = true
break
if not found:
Constants.EMS_G_PORT_DATA_HOLDER.append([tmp, isa_data])
$load_status_yau.value += 1
if len(Constants.EMS_G_PORT_DATA_HOLDER) == 32:
emit_signal('read_ems_g_finish')
$ISA.text = 'ISA: ' + str(len(Constants.EMS_G_PORT_DATA_HOLDER))
$load_status_yau.visible = false
$TabContainer/EMS_G/load_boadr/win_load.material.set('shader_parameter/dot_color_end', Color(0.8, 0.5, 1.0, 1.0 - 0.05 * len(Constants.EMS_G_PORT_DATA_HOLDER)))
@@ -373,10 +376,6 @@ func _on_read_isa(unit_isa_ports: Dictionary) -> void:
var data_dict = Constants.EMS_G_PORT_DATA_HOLDER[index][1]
if Constants.BASE_PORTS.EMS_G+8 in data_dict:
$TabContainer/PRD/body_grid/litera_3_5_7/yau07b_control.get_node2(1,1).get_child(1).button_pressed = data_dict[Constants.BASE_PORTS.EMS_G+8] >> 14
if tmp_device_mode == Constants.META.CI_3_B_UF:
var data_dict = Constants.EMS_G_PORT_DATA_HOLDER[index][1]
if Constants.BASE_PORTS.EMS_G+8 in data_dict:
$TabContainer/PRD/body_grid/litera_3_5_7/yau07b_control.get_node2(1,1).get_child(1).button_pressed = data_dict[Constants.BASE_PORTS.EMS_G+8] >> 13
if tmp_device_mode == Constants.META.MODUL_UM_1:
var data_dict = Constants.EMS_G_PORT_DATA_HOLDER[index][1]
if Constants.BASE_PORTS.EMS_G+8 in data_dict:
@@ -500,9 +499,9 @@ func _on_data_fs_3(fs_3_data):
func _process(_delta: float) -> void:
# FS 1
var node_freq_fs_1 = node_select_fs_1.get_node2(1, 2)
var node_freq_fs_1 = node_select_fs_1.get_node2(1, 2).get_text()
var node_freq_fs_1_mod = node_select_fs_1.get_node2(0, 2)
if (int(node_freq_fs_1.get_text()) != freq_fs_1) and node_freq_fs_1.get_text() != '':
if (int(node_freq_fs_1) != freq_fs_1) and node_freq_fs_1 != '':
node_freq_fs_1_mod.modulate = Color.AQUAMARINE
node_freq_fs_1_mod.text = 'Частота*'
else:
@@ -577,18 +576,17 @@ func set_frame(node: Node, val: int): node.set_frame(val)
func _on_save_config():
var da = DirAccess.open(save_path)
var base_path = save_path + "save//"
if da == null:
return
else:
da.dir_exists(base_path)
da.make_dir_recursive(base_path)
da.dir_exists(save_path)
da.make_dir_recursive(save_path)
var file_dialog = FileDialog.new()
file_dialog.title = "Сохранить файл как"
file_dialog.set_size(Vector2(600, 400))
file_dialog.mode = FileDialog.FILE_MODE_SAVE_FILE
file_dialog.current_dir = base_path
file_dialog.set_current_file("ЭМС-Г" + "-" + status_pribor)
file_dialog.current_dir = save_path
file_dialog.set_current_file("ЭМС-Г")
file_dialog.connect("file_selected", Callable(self, "_save_selected_file"))
add_child(file_dialog)
file_dialog.popup_centered()
@@ -597,7 +595,6 @@ func _on_save_config():
func _save_selected_file(file_path: String):
var data = Constants.EMS_G_PORT_DATA_HOLDER
var param_ems_g: Dictionary = {}
var other_data: Dictionary = {}
# Формируем словари
for item in data:
var regist: Dictionary = {}
@@ -605,60 +602,75 @@ func _save_selected_file(file_path: String):
for key in item[1]:
if key in need_port:
regist[key] = item[1][key]
else:
other_data[key] = item[1]
print(regist)
param_ems_g[item[0]] = regist
# Переменные для сохранения
var ems_g_file = file_path
var other_name = "others" + "-" + status_pribor
var other_path = save_path + other_name
var other_names = other_name
var other_counter = 1
var dir = DirAccess.open(file_path.get_base_dir())
# Сохранение данных ЭМС-Г
var file = FileAccess.open(ems_g_file, FileAccess.WRITE)
var file = FileAccess.open(file_path, FileAccess.WRITE)
if file != null:
file.store_string(JSON.stringify(param_ems_g))
file.close()
# Сохранение данных других
var save_other = $save_other.is_pressed()
if save_other:
while dir.file_exists(other_names):
other_names = other_name + "_" + str(other_counter)
other_path = save_path + other_names
other_counter += 1
var other_file = FileAccess.open(other_path, FileAccess.WRITE)
if other_file != null:
other_file.store_string(JSON.stringify(other_data))
other_file.close()
func _on_file_selected(file_path: String):
var file = FileAccess.open(file_path, FileAccess.READ)
# Проверка на открытие/чтение файла
if file != OK:
return
var file_content = file.get_as_text()
file.close()
var json = JSON.new()
var data = json.parse(file_content)
# Проверка на разбор содержимого файла
if data.error != OK:
return
Constants.EMS_G_PORT_DATA_HOLDER = data.result
$Background/switch_panel/save_config/notice.visible = true
$Background/switch_panel/save_config/notice.text = '✅ Файл %s записан успешно!' % file_path
await get_tree().create_timer(2.0).timeout
$Background/switch_panel/save_config/notice.visible = false
func _on_load_config():
var file_dialog = FileDialog.new()
var base_path = save_path + "save//"
file_dialog.set_title("Выберите файл")
file_dialog.set_size(Vector2(600, 400))
file_dialog.access = FileDialog.ACCESS_FILESYSTEM
file_dialog.current_dir = base_path
file_dialog.mode = FileDialog.FILE_MODE_OPEN_FILE
file_dialog.current_dir = save_path
file_dialog.connect("file_selected", Callable(self, "_load_selected_file"))
add_child(file_dialog)
file_dialog.popup_centered()
func _load_selected_file():
var file_path: String = 'res://saves/%s' % Constants.ADDRESSES[$TabContainer/PRD/select_dev.get_node2(1, 0).get_selected_id()][0]
var file = FileAccess.open(file_path, FileAccess.READ)
# Проверка на открытие/чтение файла
if file == null:
return
var file_content: String = file.get_as_text()
file.close()
var json: JSON = JSON.new()
var error = json.parse(file_content)
if error == OK:
var data_received: Dictionary = json.data
if typeof(data_received) == TYPE_DICTIONARY:
$Background/switch_panel/load_config/notice.visible = true
$Background/switch_panel/load_config/notice.text = '✅ Файл %s прочитан успешно' % file_path
await get_tree().create_timer(2.0).timeout
$Background/switch_panel/load_config/notice.visible = false
emit_signal('write_ems_g_start', data_received)
else:
print("Несоответствующий тип данных!")
else:
print("JSON Parse Error: ", json.get_error_message(), " in ", file_content, " at line ", json.get_error_line())
func _on_write_ems_g(data_to_ems_g: Dictionary):
for key in data_to_ems_g.keys():
#if int(key) < 17:
#print('Constants.BASE_PORTS.EMS_G+2: ', data_to_ems_g[key][str(Constants.BASE_PORTS.EMS_G+0x2)])
#print('Constants.BASE_PORTS.EMS_G+0xA: ', data_to_ems_g[key][str(Constants.BASE_PORTS.EMS_G+0xA)])
#Network.write_port_isa(Constants.BASE_PORTS.EMS_G+2, data_to_ems_g[key][str(Constants.BASE_PORTS.EMS_G+0x2)])
#Network.write_port_isa(Constants.BASE_PORTS.EMS_G+0xA, data_to_ems_g[key][str(Constants.BASE_PORTS.EMS_G+0xA)])
#Network.read_port_isa([Constants.BASE_PORTS.EMS_G+0xA])
if int(key) > 46:
print('Constants.BASE_PORTS.EMS_G+2: ', data_to_ems_g[key][str(Constants.BASE_PORTS.EMS_G+0x2)])
#print('Constants.BASE_PORTS.EMS_G+8', data_to_ems_g[key][str(Constants.BASE_PORTS.EMS_G+0x8)])
print('Constants.BASE_PORTS.EMS_G+4: ', data_to_ems_g[key][str(Constants.BASE_PORTS.EMS_G+0x4)])
Network.write_port_isa(Constants.BASE_PORTS.EMS_G+2, data_to_ems_g[key][str(Constants.BASE_PORTS.EMS_G+0x2)])
#Network.write_port_isa(Constants.BASE_PORTS.EMS_G+4, data_to_ems_g[key][str(Constants.BASE_PORTS.EMS_G+0x8)])
Network.write_port_isa(Constants.BASE_PORTS.EMS_G+4, data_to_ems_g[key][str(Constants.BASE_PORTS.EMS_G+0x4)])
#Network.read_port_isa([Constants.BASE_PORTS.EMS_G+4, Constants.BASE_PORTS.EMS_G+8])
func on_mode_select(intem_from_sector: int) -> void:
var node_select_device: GDTable = $TabContainer/PRD/select_dev
var get_select_device = node_select_device.get_node2(1, 0)
@@ -667,12 +679,13 @@ func on_mode_select(intem_from_sector: int) -> void:
add_signs_scene()
Network.on_command_change_device(meta)
Network.read_port_isa([Constants.BASE_PORTS.UG+8, Constants.BASE_PORTS.UG+6, Constants.BASE_PORTS.UG+0xA])
Network.start_work_fs()
Network.start_work_fs_2()
Network.start_work_fs_1(Constants.ADDRESSES[intem_from_sector][0])
Network.start_work_fs_2(Constants.ADDRESSES[intem_from_sector][0])
if meta[2] == Constants.MODE.PRD_K:
Network.start_work_fs_3()
Network.start_work_fs_3(Constants.ADDRESSES[intem_from_sector][0])
$load_status_yau.value = 0
emit_signal('read_ems_g_start')
#_on_read_isa(Network.unit.isa_ports)
$load_status_yau.visible = true
func _on_zapret_1(toggled_on: bool) -> void:
@@ -726,11 +739,9 @@ func _on_modul_um(item_from_ray_1: int, node: Node):
## Таймер для модуляции УМ
func _on_timer_modul_um():
print('Модуляция вызывается')
if modul_um.has(0x2000):
for i in range(3):
if modul_um[i] == 0x2000:
print('Модуляция есть ', modul_um)
Network.write_port_isa(Constants.BASE_PORTS.EMS_G + 2, current_meta[i])
Network.write_port_isa(Constants.BASE_PORTS.EMS_G + 8, modul_um[i])
@@ -864,6 +875,7 @@ func _on_set_ferq_1(freq: String):
func _on_set_att_1(att: String):
Network.set_fs_attenuation(float(att))
save_settings(float(att), 0)
func _on_set_base_can_macro(can_freq: String):
@@ -901,6 +913,7 @@ func _on_set_ferq_2(freq: String):
func _on_set_att_2(att: String):
Network.set_fs_attenuation_2(float(att))
save_settings(float(att), 1)
func _on_set_base_can_macro_2(can_freq: String):
@@ -945,6 +958,7 @@ func _on_set_ferq_3(freq: String):
func _on_set_att_3(att: String):
Network.set_fs_attenuation_3(float(att))
save_settings(float(att), 2)
func _on_set_base_can_macro_3(can_freq: String):
@@ -964,6 +978,7 @@ func _on_modul_fs_3(modulation_select_3) -> void:
## Switch panel
func _on_prd_select() -> void:
$load_status_yau.value = 0
emit_signal('read_ems_g_start')
set_tab_and_buttons(0, 'select_prd', 'texture_prd')
Network.get_gen_state_1()
@@ -976,6 +991,7 @@ func _on_control_button() -> void:
func _on_emsg_select() -> void:
$load_status_yau.value = 0
emit_signal('read_ems_g_start')
set_tab_and_buttons(2, 'select_ems_g', 'texture_ems_g')
@@ -1027,32 +1043,27 @@ func set_tab_and_buttons(tab_index: int, button_name: String, txt_button_name: S
if button is Button or TextureButton:
if button.name != 'burgerButton':
button.button_pressed = (button.name == button_name or button.name == txt_button_name)
if button.name == 'select_control' or button.name == 'texture_control':
if button_name == 'select_control' or button_name == 'texture_control':
$load_status_yau.visible = false
else:
$load_status_yau.visible = true
func _on_connect_prd_pressed() -> void:
on_mode_select($TabContainer/PRD/select_dev.get_node2(1, 0).get_selected_id())
func save_settings():
var settings = {
"test": 1,
"test2": 2,
"test3": 303,
}
var file = FileAccess.open("res://saves/fs_setting.txt", FileAccess.WRITE)
if file:
file.store_var(settings)
file.close()
func read_file():
var file = FileAccess.open("res://saves/fs_setting.txt", FileAccess.READ)
func save_settings(to_att_change: float, mode: int):
if Constants.ADDRESSES[$TabContainer/PRD/select_dev.get_node2(1, 0).get_selected_id()][0] in Constants.FS_ATT:
var read_temp = Constants.FS_ATT[Constants.ADDRESSES[$TabContainer/PRD/select_dev.get_node2(1, 0).get_selected_id()][0]]
read_temp[mode] = to_att_change
Constants.FS_ATT[Constants.ADDRESSES[$TabContainer/PRD/select_dev.get_node2(1, 0).get_selected_id()][0]] = read_temp
else:
return
var file = FileAccess.open("res://saves/fs_setting", FileAccess.WRITE)
if file:
var settings = file.get_var()
file.store_var(Constants.FS_ATT)
file.close()
if 'test3' in settings:
var read_test = settings['test3']
print(read_test)
else:
print('var not found in file')
Constants.read_file()