From 98be72fece07323861461633bef0a77bd0410d61 Mon Sep 17 00:00:00 2001
From: TotMaxim
Date: Fri, 14 Nov 2025 18:14:36 +0300
Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?=
=?UTF-8?q?=D0=BA=D0=B0=20=D0=9F=D0=A0=D0=94-=D0=9A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
main.gd | 131 ++++++++++++++++---------------
main.tscn | 225 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 292 insertions(+), 64 deletions(-)
diff --git a/main.gd b/main.gd
index f5a3be3..cc97a1c 100644
--- a/main.gd
+++ b/main.gd
@@ -40,15 +40,11 @@ func on_modify_device(toggled: bool, name_device: String) -> void:
func _process(_delta: float) -> void:
- for device in dictionary_yau07:
+ for device in dictionary_yau07.keys():
if dictionary_yau07[device]:
dictionary_yau07[device].poll_receive()
-static func _set_bit(bits: int, index: int, val: bool) -> int:
- return bits | (1 << index) if val else bits & ~(1 << index)
-
-
## Функция для установки статусов ячеек на связи (УГ, ЭМС-Г, УКП)
func _on_modify_sockets(toggled: bool, bit: int, device: String)->void:
if dictionary_yau07.has(device):
@@ -64,86 +60,91 @@ func _on_ukp_submitted(_new_text: String, device: String) -> void:
var prep_power_ukp1_array: Array = _on_text_power_changed(device, 1)
var prep_power_ukp2_array: Array = _on_text_power_changed(device, 2)
- var combine_data_ukp1: Array
- combine_data_ukp1 = _combine_arrays(combine_data_ukp1, prep_temperature_ukp1_array, prep_power_ukp1_array)
- var combine_data_ukp2: Array
- combine_data_ukp2 = _combine_arrays(combine_data_ukp2, prep_temperature_ukp2_array, prep_power_ukp2_array)
+ var combine_data_ukp1: Array = _combine_arrays(prep_temperature_ukp1_array, prep_power_ukp1_array)
+ var combine_data_ukp2: Array = _combine_arrays(prep_temperature_ukp2_array, prep_power_ukp2_array)
+
_form_buffers(device,combine_data_ukp1, 1, dictionary_yau07)
_form_buffers(device,combine_data_ukp2, 2, dictionary_yau07)
func _on_text_temperature_changed(device: String, number_device: int) -> Array:
+ return _process_ukp_data(device, number_device, "temperature_ukp", _convert_temperature)
+
+func _on_text_power_changed(device: String, number_device: int) -> Array:
+ return _process_ukp_data(device, number_device, "power_ukp", _convert_power)
+
+
+func _process_ukp_data(device: String, number_device: int, group_name: String, converter: Callable) -> Array:
+ var prd_module_arr = get_tree().get_nodes_in_group('prd')
+ var current_change: Array = _get_ukp_nodes_for_device(device, prd_module_arr, group_name)
+ var result_arr: Array = [0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff]
+ var config: Dictionary = _get_ukp_config(device, number_device)
+
+ for i in range(config.start_index, config.end_index):
+ if i < current_change.size() and not current_change[i].text.is_empty():
+ var value = _safe_convert_to_int(current_change[i].text)
+ var offset: int = config.offset if i == config.end_index-1 else 0
+ var result_index = i - config.start_index + offset
+ if result_index < result_arr.size():
+ result_arr[result_index] = converter.call(value)
+ return result_arr
+
+
+static func _get_ukp_nodes_for_device(device: String, prd_module_arr: Array, group_name: String) -> Array:
+ for prd in prd_module_arr:
+ if device == prd.get_meta('yau07'):
+ var nodes = []
+ for node in prd.get_tree().get_nodes_in_group(group_name):
+ if prd.is_ancestor_of(node):
+ nodes.append(node)
+ return nodes
+ return []
+
+
+static func _get_ukp_config(device: String, number_device: int) -> Dictionary:
+ var is_k_device = device in ['ПРД-К1', 'ПРД-К2', 'ПРД-К3', 'ПРД-К4']
+ if number_device == 1:
+ return {
+ "start_index": 0,
+ "end_index": 7 if is_k_device else 6,
+ "offset": 1 if is_k_device else 0
+ }
+ else:
+ return {
+ "start_index": 7 if is_k_device else 6,
+ "end_index": 13 if is_k_device else 12,
+ "offset": 0
+ }
+
+
+static func _convert_temperature(value: int) -> int:
const CONST_MIN_TEMP: int = -25
const MAXIMUM_CODE_ADC: int = 3796
const MINIMUM_CODE_AD: int = 2660
- const TEMP: float = 115.0 / (MAXIMUM_CODE_ADC - MINIMUM_CODE_AD)
+ const TEMP: float = 115.0 / (MAXIMUM_CODE_ADC - MINIMUM_CODE_AD)
- var current_change: Array
- for prd in get_tree().get_nodes_in_group('prd'):
- if device == prd.get_meta('yau07'):
- for temperature_node in prd.get_tree().get_nodes_in_group('temperature_ukp'):
- if prd.is_ancestor_of(temperature_node):
- current_change.append(temperature_node)
- break
-
- var temp_arr: Array = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]
- if number_device == 1:
- for i in 6:
- if not current_change[i].text == null:
- var value = _safe_convert_to_int(current_change[i].text)
- var normal_temp: int = MAXIMUM_CODE_ADC - (value - CONST_MIN_TEMP - 3) / TEMP
- temp_arr[i] = normal_temp
- elif number_device == 2:
- for i in 6:
- if not current_change[i+6].text == null:
- var value = _safe_convert_to_int(current_change[i+6].text)
- var normal_temp: int = MAXIMUM_CODE_ADC - (value - CONST_MIN_TEMP - 3) / TEMP
- temp_arr[i] = normal_temp
- return temp_arr
+ var result: float = MAXIMUM_CODE_ADC - (value - CONST_MIN_TEMP - 3) / TEMP
+ return int(result)
-func _on_text_power_changed(device: String, number_device: int) -> Array:
- var current_change: Array
- for prd in get_tree().get_nodes_in_group('prd'):
- if device == prd.get_meta('yau07'):
- for power_node in prd.get_tree().get_nodes_in_group('power_ukp'):
- if prd.is_ancestor_of(power_node):
- current_change.append(power_node)
- break
-
- var power_arr: Array = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]
-
- if number_device == 1:
- for i in 6:
- if not current_change[i].text == null:
- var value = _safe_convert_to_int(current_change[i].text)
- power_arr[i] = value
- elif number_device == 2:
- for i in 6:
- if not current_change[i+6].text == null:
- var value = _safe_convert_to_int(current_change[i+6].text)
- power_arr[i] = value
-
- return power_arr
- #_update_buffers(power_arr_1, device)
+static func _convert_power(value: int) -> int:
+ return value
static func _safe_convert_to_int(text: String) -> int:
- text = text.strip_edges()
+ text = text.strip_edges().to_lower()
if text.is_valid_int():
return int(text)
+ elif text.is_valid_float():
+ return roundi(float(text))
elif text.begins_with("0x") and text.substr(2).is_valid_hex_number():
return text.hex_to_int()
else:
return 0
-static func _combine_arrays(ukp_data: Array, power_arr: Array, temp_arr: Array)-> Array:
- for i in temp_arr.size():
- ukp_data.append(temp_arr[i])
- for i in power_arr.size():
- ukp_data.append(power_arr[i])
- return ukp_data
+static func _combine_arrays(power_arr: Array, temp_arr: Array)-> Array:
+ return temp_arr + power_arr
static func _form_buffers(device: String, ukp_data: Array, number_device: int, dic_yau07: Dictionary):
@@ -157,3 +158,7 @@ static func _form_buffers(device: String, ukp_data: Array, number_device: int, d
udp_unit.ukp0_data = buffer
elif number_device == 2:
udp_unit.ukp1_data = buffer
+
+
+static func _set_bit(bits: int, index: int, val: bool) -> int:
+ return bits | (1 << index) if val else bits & ~(1 << index)
diff --git a/main.tscn b/main.tscn
index 11a0ccd..6744367 100644
--- a/main.tscn
+++ b/main.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=5 format=3 uid="uid://bxorauom63ib6"]
+[gd_scene load_steps=6 format=3 uid="uid://bxorauom63ib6"]
[ext_resource type="Script" uid="uid://d1qwoxkckvdbc" path="res://main.gd" id="1_ig7tw"]
@@ -10,6 +10,9 @@ bg_color = Color(0.1167, 0.351514, 0.35159, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_h2yge"]
bg_color = Color(0.69546, 0.406261, 0.37248, 1)
+[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_1bvp3"]
+bg_color = Color(0.323337, 0.235865, 0.51797, 1)
+
[node name="Control" type="Control"]
layout_mode = 3
anchors_preset = 15
@@ -561,6 +564,7 @@ metadata/device = "ПРД-В1"
[node name="ПРД-К1" type="Panel" parent="TabContainer" groups=["prd"]]
visible = false
layout_mode = 2
+theme_override_styles/panel = SubResource("StyleBoxFlat_1bvp3")
metadata/_tab_index = 2
metadata/yau07 = "ПРД-К1"
@@ -597,6 +601,225 @@ text = "Загрузка ЭМС"
metadata/bit = 4
metadata/device = "ПРД-К1"
+[node name="ukp_1" type="GridContainer" parent="TabContainer/ПРД-К1"]
+offset_left = 205.0
+offset_top = 7.0
+offset_right = 939.0
+offset_bottom = 95.0
+columns = 7
+
+[node name="Label" type="Label" parent="TabContainer/ПРД-К1/ukp_1"]
+custom_minimum_size = Vector2(0, 30)
+layout_mode = 2
+theme_override_styles/normal = SubResource("StyleBoxFlat_ig7tw")
+text = "Температуры"
+horizontal_alignment = 1
+
+[node name="TextEdit" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_1" groups=["temperature_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 0
+metadata/device = "ПРД-К1"
+
+[node name="TextEdit2" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_1" groups=["temperature_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 1
+metadata/device = "ПРД-К1"
+
+[node name="TextEdit3" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_1" groups=["temperature_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 2
+metadata/device = "ПРД-К1"
+
+[node name="TextEdit4" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_1" groups=["temperature_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 3
+metadata/device = "ПРД-К1"
+
+[node name="TextEdit5" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_1" groups=["temperature_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 4
+metadata/device = "ПРД-К1"
+
+[node name="TextEdit6" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_1" groups=["temperature_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 5
+metadata/device = "ПРД-К1"
+
+[node name="Label2" type="Label" parent="TabContainer/ПРД-К1/ukp_1"]
+custom_minimum_size = Vector2(0, 30)
+layout_mode = 2
+theme_override_styles/normal = SubResource("StyleBoxFlat_ig7tw")
+text = "Мощность"
+horizontal_alignment = 1
+
+[node name="TextEdit7" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_1" groups=["power_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 0
+metadata/device = "ПРД-К1"
+
+[node name="TextEdit8" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_1" groups=["power_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 1
+metadata/device = "ПРД-К1"
+
+[node name="TextEdit9" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_1" groups=["power_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 2
+metadata/device = "ПРД-К1"
+
+[node name="TextEdit10" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_1" groups=["power_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 3
+metadata/device = "ПРД-К1"
+
+[node name="TextEdit11" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_1" groups=["power_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 4
+metadata/device = "ПРД-К1"
+
+[node name="TextEdit12" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_1" groups=["power_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 5
+metadata/device = "ПРД-К1"
+
+[node name="ukp_1_lit_1" type="GridContainer" parent="TabContainer/ПРД-К1"]
+offset_left = 205.0
+offset_top = 195.0
+offset_right = 939.0
+offset_bottom = 283.0
+columns = 2
+
+[node name="Label" type="Label" parent="TabContainer/ПРД-К1/ukp_1_lit_1"]
+custom_minimum_size = Vector2(0, 30)
+layout_mode = 2
+theme_override_styles/normal = SubResource("StyleBoxFlat_ig7tw")
+text = "Температуры"
+horizontal_alignment = 1
+
+[node name="TextEdit" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_1_lit_1" groups=["temperature_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 0
+metadata/device = "ПРД-К1"
+
+[node name="Label2" type="Label" parent="TabContainer/ПРД-К1/ukp_1_lit_1"]
+custom_minimum_size = Vector2(0, 30)
+layout_mode = 2
+theme_override_styles/normal = SubResource("StyleBoxFlat_ig7tw")
+text = "Мощность"
+horizontal_alignment = 1
+
+[node name="TextEdit7" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_1_lit_1" groups=["power_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 0
+metadata/device = "ПРД-К1"
+
+[node name="ukp_2" type="GridContainer" parent="TabContainer/ПРД-К1"]
+offset_left = 205.0
+offset_top = 103.0
+offset_right = 939.0
+offset_bottom = 191.0
+columns = 7
+
+[node name="Label" type="Label" parent="TabContainer/ПРД-К1/ukp_2"]
+custom_minimum_size = Vector2(0, 30)
+layout_mode = 2
+theme_override_styles/normal = SubResource("StyleBoxFlat_ig7tw")
+text = "Температуры"
+horizontal_alignment = 1
+
+[node name="TextEdit" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_2" groups=["temperature_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 8
+metadata/device = "ПРД-К1"
+
+[node name="TextEdit2" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_2" groups=["temperature_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 9
+metadata/device = "ПРД-К1"
+
+[node name="TextEdit3" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_2" groups=["temperature_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 10
+metadata/device = "ПРД-К1"
+
+[node name="TextEdit4" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_2" groups=["temperature_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 11
+metadata/device = "ПРД-К1"
+
+[node name="TextEdit5" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_2" groups=["temperature_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 12
+metadata/device = "ПРД-К1"
+
+[node name="TextEdit6" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_2" groups=["temperature_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 13
+metadata/device = "ПРД-К1"
+
+[node name="Label2" type="Label" parent="TabContainer/ПРД-К1/ukp_2"]
+custom_minimum_size = Vector2(0, 30)
+layout_mode = 2
+theme_override_styles/normal = SubResource("StyleBoxFlat_ig7tw")
+text = "Мощность"
+horizontal_alignment = 1
+
+[node name="TextEdit7" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_2" groups=["power_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 8
+metadata/device = "ПРД-К1"
+
+[node name="TextEdit8" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_2" groups=["power_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 9
+metadata/device = "ПРД-К1"
+
+[node name="TextEdit9" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_2" groups=["power_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 10
+metadata/device = "ПРД-К1"
+
+[node name="TextEdit10" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_2" groups=["power_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 11
+metadata/device = "ПРД-К1"
+
+[node name="TextEdit11" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_2" groups=["power_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 12
+metadata/device = "ПРД-К1"
+
+[node name="TextEdit12" type="LineEdit" parent="TabContainer/ПРД-К1/ukp_2" groups=["power_ukp"]]
+custom_minimum_size = Vector2(100, 35)
+layout_mode = 2
+metadata/place = 13
+metadata/device = "ПРД-К1"
+
[node name="ПРД-Н2" type="Panel" parent="TabContainer" groups=["prd"]]
visible = false
layout_mode = 2