Доработка класса по загрузке конфигураций контроля
This commit is contained in:
@@ -452,7 +452,6 @@ patch_margin_right = 16
|
||||
patch_margin_bottom = 16
|
||||
|
||||
[node name="connect_pribor" type="AnimatedSprite2D" parent="pribor_prd_n_1"]
|
||||
visible = false
|
||||
light_mask = 3
|
||||
position = Vector2(35, -10)
|
||||
scale = Vector2(0.625, 0.625)
|
||||
@@ -988,7 +987,6 @@ patch_margin_right = 16
|
||||
patch_margin_bottom = 16
|
||||
|
||||
[node name="connect_pribor" type="AnimatedSprite2D" parent="pribor_prd_n_2"]
|
||||
visible = false
|
||||
light_mask = 3
|
||||
position = Vector2(37, -10)
|
||||
scale = Vector2(0.625, 0.625)
|
||||
@@ -1881,9 +1879,9 @@ vertical_alignment = 1
|
||||
|
||||
[node name="chk_show_functional" type="CheckButton" parent="lbl_header"]
|
||||
layout_mode = 0
|
||||
offset_left = 972.0
|
||||
offset_left = 940.0
|
||||
offset_top = -1.0
|
||||
offset_right = 1351.0
|
||||
offset_right = 1319.0
|
||||
offset_bottom = 33.0
|
||||
theme_override_font_sizes/font_size = 22
|
||||
text = "Показть функциональную схему Э2"
|
||||
|
||||
161
scripts/prd-ctl-config.gd
Normal file
161
scripts/prd-ctl-config.gd
Normal file
@@ -0,0 +1,161 @@
|
||||
class_name PRDConfigManager
|
||||
extends RefCounted
|
||||
|
||||
## Менеджер конфигурации для системы контроля ПРД
|
||||
## Загружает и управляет настройками из JSON-конфигурации
|
||||
|
||||
#region CONSTANTS
|
||||
const CONFIG_PATH = "user://config/setting_prd_control.json"
|
||||
const DEFAULT_CONFIG_PATH = "res://config/setting_prd_control.json"
|
||||
#endregion
|
||||
|
||||
#region PRIVATE_VARIABLES
|
||||
var _config_data: Dictionary # Все данные конфигурации
|
||||
var _device_constants: Dictionary # Константы устройств
|
||||
var _base_configs: Dictionary # Базовые конфигурации
|
||||
var _device_configs: Dictionary # Конфигурации устройств
|
||||
var _data_indices: Dictionary # Индексы данных
|
||||
var _fs_keys: Dictionary # Ключи ФС (функциональных систем)
|
||||
var _temperature_constants: Dictionary # Константы температуры
|
||||
var _ems_input_bits_config: Dictionary # Конфигурация битов ввода ЭМС
|
||||
var _fs_rules: Array # Правила ФС
|
||||
|
||||
var _is_loaded: bool = false # Флаг успешной загрузки
|
||||
#endregion
|
||||
|
||||
#region INITIALIZATION
|
||||
func _init() -> void:
|
||||
"""Инициализация менеджера конфигурации"""
|
||||
_load_configuration()
|
||||
#endregion
|
||||
|
||||
#region PUBLIC_API
|
||||
## Проверяет, успешно ли загружена конфигурация
|
||||
func is_loaded() -> bool:
|
||||
return _is_loaded
|
||||
|
||||
## Возвращает все данные конфигурации
|
||||
func get_config_data() -> Dictionary:
|
||||
return _config_data.duplicate(true)
|
||||
|
||||
## Возвращает константы устройств
|
||||
func get_device_constants() -> Dictionary:
|
||||
return _device_constants.duplicate(true)
|
||||
|
||||
## Возвращает базовые конфигурации
|
||||
func get_base_configs() -> Dictionary:
|
||||
return _base_configs.duplicate(true)
|
||||
|
||||
## Возвращает конфигурации устройств
|
||||
func get_device_configs() -> Dictionary:
|
||||
return _device_configs.duplicate(true)
|
||||
|
||||
## Возвращает индексы данных
|
||||
func get_data_indices() -> Dictionary:
|
||||
return _data_indices.duplicate(true)
|
||||
|
||||
## Возвращает ключи ФС
|
||||
func get_fs_keys() -> Dictionary:
|
||||
return _fs_keys.duplicate(true)
|
||||
|
||||
## Возвращает константы температуры
|
||||
func get_temperature_constants() -> Dictionary:
|
||||
return _temperature_constants.duplicate(true)
|
||||
|
||||
## Возвращает конфигурацию битов ввода ЭМС
|
||||
func get_ems_input_bits_config() -> Dictionary:
|
||||
return _ems_input_bits_config.duplicate(true)
|
||||
|
||||
## Возвращает правила ФС
|
||||
func get_fs_rules() -> Array:
|
||||
return _fs_rules.duplicate(true)
|
||||
|
||||
## Возвращает индекс данных по ключу
|
||||
func get_data_index(key: String) -> int:
|
||||
return _data_indices.get(key, -1)
|
||||
#endregion
|
||||
|
||||
#region PRIVATE_METHODS
|
||||
## Загружает конфигурацию из JSON файла
|
||||
func _load_configuration() -> void:
|
||||
if not _ensure_config_exists():
|
||||
_is_loaded = false
|
||||
return
|
||||
|
||||
var config_file = FileAccess.open(CONFIG_PATH, FileAccess.READ)
|
||||
if config_file:
|
||||
var json_text = config_file.get_as_text()
|
||||
config_file.close()
|
||||
|
||||
var json = JSON.new()
|
||||
var parse_result = json.parse(json_text)
|
||||
if parse_result == OK:
|
||||
_config_data = json.data
|
||||
_parse_config_data()
|
||||
_is_loaded = true
|
||||
else:
|
||||
push_error("Ошибка разбора JSON конфигурации: " + json.get_error_message())
|
||||
_is_loaded = false
|
||||
else:
|
||||
push_error("Ошибка загрузки файла конфигурации: " + CONFIG_PATH)
|
||||
_is_loaded = false
|
||||
|
||||
|
||||
## Парсит данные конфигурации по секциям
|
||||
func _parse_config_data() -> void:
|
||||
_device_constants = _convert_numbers(_config_data.get("device_constants", {}))
|
||||
_base_configs = _convert_numbers(_config_data.get("base_configs", {}))
|
||||
_device_configs = _convert_numbers(_config_data.get("device_configs", {}))
|
||||
_data_indices = _convert_numbers(_config_data.get("data_indices", {}))
|
||||
_fs_keys = _convert_numbers(_config_data.get("fs_keys", {}))
|
||||
_temperature_constants = _convert_numbers(_config_data.get("temperature_constants", {}))
|
||||
_ems_input_bits_config = _convert_numbers(_config_data.get("ems_input_bits_config", {}))
|
||||
_fs_rules = _convert_numbers(_config_data.get("fs_rules", []))
|
||||
|
||||
|
||||
## Конвертирует числовые значения в правильные типы (float -> int если возможно)
|
||||
static func _convert_numbers(value):
|
||||
if value is float:
|
||||
# Конвертируем float в int если нет дробной части
|
||||
if value == int(value):
|
||||
return int(value)
|
||||
return value
|
||||
elif value is Dictionary:
|
||||
var result = {}
|
||||
for key in value:
|
||||
result[key] = _convert_numbers(value[key])
|
||||
return result
|
||||
elif value is Array:
|
||||
var result = []
|
||||
for item in value:
|
||||
result.append(_convert_numbers(item))
|
||||
return result
|
||||
else:
|
||||
return value
|
||||
|
||||
|
||||
## Обеспечивает существование файла конфигурации
|
||||
## Создает папку и копирует дефолтный файл если нужно
|
||||
func _ensure_config_exists() -> bool:
|
||||
# Создаем папку конфигурации если не существует
|
||||
DirAccess.make_dir_recursive_absolute("user://config")
|
||||
|
||||
# Если файл уже существует - все ок
|
||||
if FileAccess.file_exists(CONFIG_PATH):
|
||||
return true
|
||||
|
||||
# Если дефолтного файла нет - ошибка
|
||||
if not FileAccess.file_exists(DEFAULT_CONFIG_PATH):
|
||||
return false
|
||||
|
||||
# Копируем дефолтный конфиг в user директорию
|
||||
var src := FileAccess.open(DEFAULT_CONFIG_PATH, FileAccess.READ)
|
||||
var dst := FileAccess.open(CONFIG_PATH, FileAccess.WRITE)
|
||||
if src == null or dst == null:
|
||||
return false
|
||||
|
||||
dst.store_string(src.get_as_text())
|
||||
src.close()
|
||||
dst.close()
|
||||
return true
|
||||
#endregion
|
||||
1
scripts/prd-ctl-config.gd.uid
Normal file
1
scripts/prd-ctl-config.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bi7elq60squds
|
||||
@@ -1,8 +1,6 @@
|
||||
class_name TestPRD
|
||||
extends Node
|
||||
# Константы
|
||||
const CONFIG_PATH = "user://config/setting_prd_control.json"
|
||||
const DEFAULT_CONFIG_PATH = "res://config/setting_prd_control.json"
|
||||
|
||||
# Добавляем константы для прогресса
|
||||
const PROGRESS_INIT: float = 5.0
|
||||
const PROGRESS_FS_TURN_ON: float = 10.0
|
||||
@@ -64,21 +62,20 @@ var ems_g_sock_dic: Dictionary = {
|
||||
'ems_output_2': 0,
|
||||
'ems_output_lit_1': 0,
|
||||
}
|
||||
|
||||
# Загруженные конфигурации
|
||||
var config_data: Dictionary
|
||||
var device_constants: Dictionary
|
||||
var base_configs: Dictionary
|
||||
var device_configs: Dictionary
|
||||
var data_indices: Dictionary
|
||||
var fs_keys: Dictionary
|
||||
var temperature_constants: Dictionary
|
||||
var ems_input_bits_config: Dictionary
|
||||
var fs_rules: Array
|
||||
|
||||
var _ray_state_mapping: Dictionary
|
||||
var _ray_state_enums: Dictionary = {}
|
||||
# Загруженные конфигурации (приватные)
|
||||
var _device_constants: Dictionary
|
||||
var _base_configs: Dictionary
|
||||
var _device_configs: Dictionary
|
||||
var _data_indices: Dictionary
|
||||
var _fs_keys: Dictionary
|
||||
var _temperature_constants: Dictionary
|
||||
var _ems_input_bits_config: Dictionary
|
||||
var _fs_rules: Array
|
||||
# Переменные класса
|
||||
var config_manager: PRDConfigManager
|
||||
var unit_prd: Object
|
||||
var constants: Dictionary
|
||||
var pribor_config: Dictionary
|
||||
var fs_parameters: Dictionary
|
||||
@@ -100,7 +97,6 @@ var flag_in_control: bool = false
|
||||
var flag_control_is_over: bool = false
|
||||
var flag_no_trust_yau07: bool = false
|
||||
var flag_only_fs: bool = false
|
||||
var unit_prd: Object
|
||||
var control_timer: Timer = Timer.new()
|
||||
var ems_6666_timer: Timer = Timer.new()
|
||||
var machine_timer: Timer = Timer.new()
|
||||
@@ -131,11 +127,27 @@ var progress_value: float:
|
||||
func _init(init_data: Dictionary, cmd_array_from_prd: Array) -> void:
|
||||
unit_prd = init_data['unit_prd']
|
||||
cmd_array = cmd_array_from_prd
|
||||
_load_configuration()
|
||||
config_manager = PRDConfigManager.new()
|
||||
_initialize_config_from_manager()
|
||||
_initialize_ray_mapping()
|
||||
_initialize_power_structure()
|
||||
|
||||
|
||||
func _initialize_config_from_manager() -> void:
|
||||
if not config_manager.is_loaded():
|
||||
push_error("ConfigManager не загружен!")
|
||||
return
|
||||
|
||||
_device_constants = config_manager.get_device_constants()
|
||||
_base_configs = config_manager.get_base_configs()
|
||||
_device_configs = config_manager.get_device_configs()
|
||||
_data_indices = config_manager.get_data_indices()
|
||||
_fs_keys = config_manager.get_fs_keys()
|
||||
_temperature_constants = config_manager.get_temperature_constants()
|
||||
_ems_input_bits_config = config_manager.get_ems_input_bits_config()
|
||||
_fs_rules = config_manager.get_fs_rules()
|
||||
|
||||
|
||||
func _initialize_power_structure() -> void:
|
||||
power_for_litera = {}
|
||||
for litera in range(1, 8):
|
||||
@@ -155,71 +167,6 @@ func _get_ray_key(machine_state: int) -> String:
|
||||
return _ray_state_mapping.get(machine_state, "")
|
||||
|
||||
|
||||
func _ensure_config_exists() -> bool:
|
||||
DirAccess.make_dir_recursive_absolute("user://config")
|
||||
if FileAccess.file_exists(CONFIG_PATH):
|
||||
return true
|
||||
if not FileAccess.file_exists(DEFAULT_CONFIG_PATH):
|
||||
return false
|
||||
var src := FileAccess.open(DEFAULT_CONFIG_PATH, FileAccess.READ)
|
||||
var dst := FileAccess.open(CONFIG_PATH, FileAccess.WRITE)
|
||||
if src == null or dst == null:
|
||||
return false
|
||||
dst.store_string(src.get_as_text())
|
||||
src.close()
|
||||
dst.close()
|
||||
return true
|
||||
|
||||
|
||||
func _load_configuration() -> void:
|
||||
if not _ensure_config_exists(): return
|
||||
var config_file = FileAccess.open(CONFIG_PATH, FileAccess.READ)
|
||||
if config_file:
|
||||
var json_text = config_file.get_as_text()
|
||||
config_file.close()
|
||||
|
||||
var json = JSON.new()
|
||||
var parse_result = json.parse(json_text)
|
||||
if parse_result == OK:
|
||||
config_data = json.data
|
||||
_parse_config_data()
|
||||
else:
|
||||
push_error("Ошибка разбора JSON конфигурации: " + json.get_error_message())
|
||||
else:
|
||||
push_error("Ошибка to load config file: " + CONFIG_PATH)
|
||||
|
||||
|
||||
func _parse_config_data() -> void:
|
||||
device_constants = _convert_numbers(config_data.get("device_constants", {}))
|
||||
base_configs = _convert_numbers(config_data.get("base_configs", {}))
|
||||
device_configs = _convert_numbers(config_data.get("device_configs", {}))
|
||||
data_indices = _convert_numbers(config_data.get("data_indices", {}))
|
||||
fs_keys = _convert_numbers(config_data.get("fs_keys", {}))
|
||||
temperature_constants = _convert_numbers(config_data.get("temperature_constants", {}))
|
||||
ems_input_bits_config = _convert_numbers(config_data.get("ems_input_bits_config", {}))
|
||||
fs_rules = _convert_numbers(config_data.get("fs_rules", []))
|
||||
|
||||
|
||||
static func _convert_numbers(value):
|
||||
if value is float:
|
||||
# Если float без дробной части - конвертируем в int
|
||||
if value == int(value):
|
||||
return int(value)
|
||||
return value
|
||||
elif value is Dictionary:
|
||||
var result = {}
|
||||
for key in value:
|
||||
result[key] = _convert_numbers(value[key])
|
||||
return result
|
||||
elif value is Array:
|
||||
var result = []
|
||||
for item in value:
|
||||
result.append(_convert_numbers(item))
|
||||
return result
|
||||
else:
|
||||
return value
|
||||
|
||||
|
||||
func _initialize_ray_mapping() -> void:
|
||||
_ray_state_mapping = {
|
||||
STATE_MACHINE.UG_SET_RAY_0: "RAY_m5",
|
||||
@@ -256,49 +203,44 @@ func on_data_received(unit_pribor: Object) -> void:
|
||||
power_for_litera[current_litera] = tek_litera
|
||||
|
||||
|
||||
# Методы для работы с JSON
|
||||
func _get_data_index(key: String) -> int:
|
||||
return data_indices.get(key, -1)
|
||||
|
||||
|
||||
func socket_status_ems_g(packet_form_yau_07: PackedByteArray) -> void:
|
||||
if self_name in ['1н', '2н', '3н', '4н']:
|
||||
ems_g_sock_dic.ems_input_1 = (packet_form_yau_07.decode_u16(_get_data_index('IN_BLANK_PRD')) & (1 << 9)) != 0
|
||||
ems_g_sock_dic.ems_input_2 = (packet_form_yau_07.decode_u16(_get_data_index('IN_BLANK_PRD')) & (1 << 10)) != 0
|
||||
ems_g_sock_dic.ems_input_1 = (packet_form_yau_07.decode_u16(config_manager.get_data_index('IN_BLANK_PRD')) & (1 << 9)) != 0
|
||||
ems_g_sock_dic.ems_input_2 = (packet_form_yau_07.decode_u16(config_manager.get_data_index('IN_BLANK_PRD')) & (1 << 10)) != 0
|
||||
if self_name in ['1в', '2в', '3в', '4в']:
|
||||
ems_g_sock_dic.ems_input_1 = (packet_form_yau_07.decode_u16(_get_data_index('IN_BLANK_PRD')) & (1 << 11)) != 0
|
||||
ems_g_sock_dic.ems_input_2 = (packet_form_yau_07.decode_u16(_get_data_index('IN_BLANK_PRD')) & (1 << 12)) != 0
|
||||
ems_g_sock_dic.ems_input_1 = (packet_form_yau_07.decode_u16(config_manager.get_data_index('IN_BLANK_PRD')) & (1 << 11)) != 0
|
||||
ems_g_sock_dic.ems_input_2 = (packet_form_yau_07.decode_u16(config_manager.get_data_index('IN_BLANK_PRD')) & (1 << 12)) != 0
|
||||
if self_name in ['1к', '2к', '3к', '4к']:
|
||||
ems_g_sock_dic.ems_input_lit_1 = (packet_form_yau_07.decode_u16(_get_data_index('IN_BLANK_PRD')) & (1 << 8)) != 0
|
||||
ems_g_sock_dic.ems_input_1 = (packet_form_yau_07.decode_u16(_get_data_index('IN_BLANK_PRD')) & (1 << 13)) != 0
|
||||
ems_g_sock_dic.ems_input_2 = (packet_form_yau_07.decode_u16(_get_data_index('IN_BLANK_PRD')) & (1 << 14)) != 0
|
||||
ems_g_sock_dic.ems_input_lit_1 = (packet_form_yau_07.decode_u16(config_manager.get_data_index('IN_BLANK_PRD')) & (1 << 8)) != 0
|
||||
ems_g_sock_dic.ems_input_1 = (packet_form_yau_07.decode_u16(config_manager.get_data_index('IN_BLANK_PRD')) & (1 << 13)) != 0
|
||||
ems_g_sock_dic.ems_input_2 = (packet_form_yau_07.decode_u16(config_manager.get_data_index('IN_BLANK_PRD')) & (1 << 14)) != 0
|
||||
|
||||
ems_g_sock_dic.ems_output_1 = (packet_form_yau_07.decode_u16(_get_data_index('OUT_BLANK_PRD')) & (1 << 4)) != 0
|
||||
ems_g_sock_dic.ems_output_2 = (packet_form_yau_07.decode_u16(_get_data_index('OUT_BLANK_PRD')) & (1 << 5)) != 0
|
||||
ems_g_sock_dic.ems_output_lit_1 = (packet_form_yau_07.decode_u16(_get_data_index('OUT_BLANK_PRD')) & (1 << 3)) != 0
|
||||
ems_g_sock_dic.ems_output_1 = (packet_form_yau_07.decode_u16(config_manager.get_data_index('OUT_BLANK_PRD')) & (1 << 4)) != 0
|
||||
ems_g_sock_dic.ems_output_2 = (packet_form_yau_07.decode_u16(config_manager.get_data_index('OUT_BLANK_PRD')) & (1 << 5)) != 0
|
||||
ems_g_sock_dic.ems_output_lit_1 = (packet_form_yau_07.decode_u16(config_manager.get_data_index('OUT_BLANK_PRD')) & (1 << 3)) != 0
|
||||
|
||||
var number_socket_input: int
|
||||
if current_litera >= 1 and current_litera <= 7:
|
||||
number_socket_input = current_litera + 7
|
||||
|
||||
var in_blank: int = packet_form_yau_07.decode_u16(_get_data_index('IN_BLANK_PRD'))
|
||||
var in_blank: int = packet_form_yau_07.decode_u16(config_manager.get_data_index('IN_BLANK_PRD'))
|
||||
flag_si_fs_input = (in_blank & (1 << number_socket_input)) != 0 ## Флаг СИ от ФС входа в ЭМС-Г для текущей литеры
|
||||
|
||||
var number_socket_output: int
|
||||
number_socket_output = 4 if current_litera in [2, 4, 6] else 3 if current_litera == 1 else 5
|
||||
|
||||
var out_blank: int = packet_form_yau_07.decode_u16(_get_data_index('OUT_BLANK_PRD'))
|
||||
var out_blank: int = packet_form_yau_07.decode_u16(config_manager.get_data_index('OUT_BLANK_PRD'))
|
||||
flag_si_fs_output = (out_blank & (1 << number_socket_output)) != 0 ## Флаг Модуляции УМ ЭМС-Г для текущей литеры
|
||||
|
||||
|
||||
## Пакеты от MP550Service
|
||||
func on_fs_update_state(packet_type_7: Dictionary, fs_mapping: Dictionary) -> void:
|
||||
var fs_key: String = fs_keys.get(str(current_litera), '')
|
||||
var fs_key: String = _fs_keys.get(str(current_litera), '')
|
||||
if fs_key.is_empty():
|
||||
return
|
||||
|
||||
var fs_result := {fs_key: 0}
|
||||
fs_result = on_fs_state(packet_type_7, fs_mapping, fs_result, fs_rules)
|
||||
fs_result = on_fs_state(packet_type_7, fs_mapping, fs_result, _fs_rules)
|
||||
control_results[fs_key] = fs_result[fs_key]
|
||||
flag_fs_status_ok = control_results[fs_key] == 1
|
||||
|
||||
@@ -586,8 +528,8 @@ func _determine_self_name() -> void:
|
||||
if device_type.is_empty():
|
||||
return
|
||||
|
||||
var device_config = device_constants.get(device_type, {})
|
||||
var device_data_config = device_configs.get(device_type, {})
|
||||
var device_config = _device_constants.get(device_type, {})
|
||||
var device_data_config = _device_configs.get(device_type, {})
|
||||
|
||||
# Загружаем конфигурацию устройства
|
||||
constants = device_config.get("constants", {})
|
||||
@@ -622,7 +564,7 @@ func _determine_self_name() -> void:
|
||||
|
||||
func _load_block_config(config, config_type: String) -> Dictionary:
|
||||
if config is String and config == "base":
|
||||
return base_configs.get(config_type, {}).duplicate(true)
|
||||
return _base_configs.get(config_type, {}).duplicate(true)
|
||||
elif config is Dictionary:
|
||||
return config.duplicate(true)
|
||||
return {}
|
||||
@@ -763,7 +705,7 @@ func on_mode_changed(in_tree: bool) -> void:
|
||||
|
||||
|
||||
func _process_dkm_status(status: PackedByteArray) -> void:
|
||||
if not control_results.has(_get_current_fs_key(current_litera, fs_keys)):
|
||||
if not control_results.has(_get_current_fs_key(current_litera, _fs_keys)):
|
||||
return
|
||||
var dkm_bit = _get_dkm_bit_for_current_fs(current_litera, constants)
|
||||
if dkm_bit == 0:
|
||||
|
||||
Reference in New Issue
Block a user