Контроль ИП, настройка адресов

This commit is contained in:
2024-11-14 16:35:27 +03:00
parent 6648a8ba89
commit d9ac0b3961
6 changed files with 178 additions and 108 deletions

3
.idea/misc.xml generated
View File

@@ -1,4 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.12" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
</project>

100
PRD.gd
View File

@@ -3,7 +3,7 @@ extends Node2D
var unit = Yau07.YaU07.new('ЯУ07')
var soc_unicast: Socket
var soc_brodcast: Socket
var address: String
var address: String = '0.0.0.0'
var ports_wr: Dictionary # Словарь с портами для записи
var port: int
var broadcast_packet: PackedByteArray
@@ -26,20 +26,19 @@ func poll_receive(sock: Socket) -> bool: ## Приёмник
var addr_receive = sock.get_packet_ip()
var port_receive = sock.get_packet_port()
if broadcast_packet:
$Controlpanel/yau07.text = 'ЯУ-07Б НА СВЯЗИ'
$Controlpanel/yau07.modulate = Constants.GREEN
if (broadcast_packet) and (address == addr_receive) and (port == port_receive):
$control_dev/control_dev.get_node2(0, 0).text = 'ЯУ-07Б НА СВЯЗИ'
$control_dev/control_dev.get_node2(0, 0).modulate = Constants.GREEN
flag_yau_control = true
last_update_time = 0.0
if (address == addr_receive) and (port == port_receive):
unit.parse(broadcast_packet)
#unit.parse(broadcast_packet)
else:
if sock.get_available_packet_count():
last_update_time = 0.0
else:
$Controlpanel/yau07.text = 'НЕТ СВЯЗИ С ЯУ-07Б'
$Controlpanel/yau07.modulate = Constants.RED
$control_dev/control_dev.get_node2(0, 0).text = 'НЕТ СВЯЗИ С ЯУ-07Б'
$control_dev/control_dev.get_node2(0, 0).modulate = Constants.RED
flag_yau_control = false
return false
@@ -49,6 +48,24 @@ func _ready() -> void:
node_select1 = $scroll1/table1
draw_tabl(node_select1, Constants.ROWS_REGS_DATA, Constants.ROWS_REGS_DATA.size())
# Выбор прибора для подключения
var node_select_device = $select_dev/select_dev
draw_tabl(node_select_device, Constants.SELECT_DEVIСE, Constants.SELECT_DEVIСE.size())
var get_select_device = node_select_device.get_node2(1, 0)
# Заполнение адресов
for i_addr in Constants.ADDRESSES.size():
get_select_device.add_item(Constants.ADDRESSES[i_addr][0])
get_select_device.set_item_metadata(i_addr, Constants.ADDRESSES[i_addr].slice(1,3))
get_select_device.connect('item_selected', Callable(self, 'on_btn_select'))
node_select_device.get_node2(0,0).text = 'НАЗВАНИЕ ПРИБОРА'
node_select_device.set_columns_min_size([200, 100])
# Контроль
var node_control_device = $control_dev/control_dev
draw_tabl(node_control_device, Constants.CONTROL_DEVICE, Constants.CONTROL_DEVICE.size())
node_control_device.set_columns_min_size([300])
# Привязка для принятия широковещательного канала
soc_brodcast = Socket.new()
var rc = soc_brodcast.bind(Constants.BROADCAST_PORT, '*')
@@ -74,7 +91,7 @@ func draw_tabl(tbl, row: Array, count_row: int):
func _process(delta: float) -> void:
last_update_time += delta
poll_receive(soc_brodcast)
if broadcast_packet:
if broadcast_packet and flag_yau_control:
parse_broadcast(broadcast_packet)
match unit.process(delta):
@@ -85,23 +102,52 @@ func _process(delta: float) -> void:
func parse_broadcast(packet):
var power: int # Мощность с широковещания
var temperature: int # Температура с широковещания
var dry_contact: int # Контроль сухих контактов
var DKM: int
var EMS_G: int
var status_board = packet.decode_u8(8)
var node_control_device = $control_dev/control_dev
$Packet.text = 'broadcast: ' + str(packet)
for i in 4:
if i == 0:
$Controlpanel/EMS_G.modulate = Constants.GREEN if status_board & (1 << i) and flag_yau_control else Constants.RED
node_control_device.get_node2(0, i+2).text = 'ЯЧЕЙКА ЭМС-Г НА СВЯЗИ' if status_board & (1 << i) and flag_yau_control else 'ЯЧЕЙКИ ЭМС-Г НЕТ НА СВЯЗИ'
node_control_device.get_node2(0, i+2).modulate = Constants.GREEN if status_board & (1 << i) and flag_yau_control else Constants.RED
elif i == 1:
$Controlpanel/UG.modulate = Constants.GREEN if status_board & (1 << i) and flag_yau_control else Constants.RED
node_control_device.get_node2(0, i+2).text = 'ЯЧЕЙКА УГ НА СВЯЗИ' if status_board & (1 << i) and flag_yau_control else 'ЯЧЕЙКИ УГ НЕТ НА СВЯЗИ'
node_control_device.get_node2(0, i+2).modulate = Constants.GREEN if status_board & (1 << i) and flag_yau_control else Constants.RED
elif i == 2:
$Controlpanel/UKP1.modulate = Constants.GREEN if status_board & (1 << i) and flag_yau_control else Constants.RED
node_control_device.get_node2(0, i+2).text = 'ЯЧЕЙКА УКП №1 НА СВЯЗИ' if status_board & (1 << i) and flag_yau_control else 'ЯЧЕЙКИ УКП №1 НЕТ НА СВЯЗИ'
node_control_device.get_node2(0, i+2).modulate = Constants.GREEN if status_board & (1 << i) and flag_yau_control else Constants.RED
elif i == 3:
$Controlpanel/UKP2.modulate = Constants.GREEN if status_board & (1 << i) and flag_yau_control else Constants.RED
node_control_device.get_node2(0, i+2).text = 'ЯЧЕЙКА УКП №2 НА СВЯЗИ' if status_board & (1 << i) and flag_yau_control else 'ЯЧЕЙКИ УКП №2 НЕТ НА СВЯЗИ'
node_control_device.get_node2(0, i+2).modulate = Constants.GREEN if status_board & (1 << i) and flag_yau_control else Constants.RED
$Packet.text = 'broadcast: ' + str(packet)
dry_contact = packet.decode_u16(35)
var dry_contact: int = packet.decode_u16(35) # Контроль сухих контактов (ИП УГ)
node_select1.set_node_text(2, 0, '%d' % dry_contact)
for i in 9:
if i == 0:
node_control_device.get_node2(0, i+6).text = 'ОШИБКА. КОНТРОЛЬ ИП МАА №1' if dry_contact & (1 << i) and flag_yau_control else 'ИП МАА №1'
node_control_device.get_node2(0, i+6).modulate = Constants.RED if dry_contact & (1 << i) and flag_yau_control else Constants.GREEN
elif i == 1:
node_control_device.get_node2(0, i+6).text = 'ОШИБКА. КОНТРОЛЬ ИП МАА №2' if dry_contact & (1 << i) and flag_yau_control else 'ИП МАА №2'
node_control_device.get_node2(0, i+6).modulate = Constants.RED if dry_contact & (1 << i) and flag_yau_control else Constants.GREEN
elif i == 2:
node_control_device.get_node2(0, i+6).text = 'ОШИБКА. КОНТРОЛЬ ИП9-50 №1' if dry_contact & (1 << i) and flag_yau_control else 'ИП9-50 №1'
node_control_device.get_node2(0, i+6).modulate = Constants.RED if dry_contact & (1 << i) and flag_yau_control else Constants.GREEN
elif i == 3:
node_control_device.get_node2(0, i+6).text = 'ОШИБКА. КОНТРОЛЬ ИП9-50 №2' if dry_contact & (1 << i) and flag_yau_control else 'ИП9-50 №2'
node_control_device.get_node2(0, i+6).modulate = Constants.RED if dry_contact & (1 << i) and flag_yau_control else Constants.GREEN
#elif i == 4:
#node_control_device.get_node2(0, i+6).text = 'ОШИБКА. КОНТРОЛЬ ИП9-50 №3' if dry_contact & (1 << i) and flag_yau_control else 'ИП9-50 №3'
#node_control_device.get_node2(0, i+6).modulate = Constants.RED if dry_contact & (1 << i) and flag_yau_control else Constants.GREEN
elif i == 4:
node_control_device.get_node2(0, i+6).text = 'ОШИБКА. КОНТРОЛЬ ИП12-50 №1' if dry_contact & (1 << i) and flag_yau_control else 'ИП12-50 №1'
node_control_device.get_node2(0, i+6).modulate = Constants.RED if dry_contact & (1 << i) and flag_yau_control else Constants.GREEN
#elif i == 6:
#node_control_device.get_node2(0, i+6).text = 'ОШИБКА. КОНТРОЛЬ ИП12-50 №2' if dry_contact & (1 << i) and flag_yau_control else 'ИП12-50 №2'
#node_control_device.get_node2(0, i+6).modulate = Constants.RED if dry_contact & (1 << i) and flag_yau_control else Constants.GREEN
elif i == 7:
node_control_device.get_node2(0, i+6).text = 'ОШИБКА. КОНТРОЛЬ ИП5-25' if dry_contact & (1 << i) and flag_yau_control else 'ИП5-25'
node_control_device.get_node2(0, i+6).modulate = Constants.RED if dry_contact & (1 << i) and flag_yau_control else Constants.GREEN
DKM = packet.decode_u16(37)
node_select1.set_node_text(3, 0, '%d' % DKM)
@@ -127,7 +173,7 @@ func parse_broadcast(packet):
for i in range(15):
EMS_G = packet.decode_u16(9 + 2 * i)
node_select1.set_node_text(3, i+2, '%d' % EMS_G)
node_select1.set_node_text(3, i+1, '%d' % EMS_G)
func on_line_changed(_unit) -> void:
@@ -148,4 +194,22 @@ func on_command_done(_unit) -> void:
func _on_control_button(toggled_on: bool) -> void:
pass # Replace with function body.
$control_dev.visible = toggled_on
$Controlpanel.visible = toggled_on
func on_btn_select(intem_from_sector):
var node_select_device = $select_dev/select_dev
var get_select_device = node_select_device.get_node2(1, 0)
var meta = get_select_device.get_item_metadata(intem_from_sector)
address = meta[0]
port = meta[1]
func fill_item(node, i_column: int, i_row: int, arr: Dictionary, select: int = 0):
var optionbutton = node.get_node2(i_column, i_row) as OptionButton
for key in arr.keys():
var item_text = key + " - " + str(arr[key])
optionbutton.add_item(item_text)
if select < arr.size():
optionbutton.select(select)

View File

@@ -3,15 +3,17 @@
[ext_resource type="Script" path="res://PRD.gd" id="1_v273n"]
[ext_resource type="Script" path="res://table/table.gd" id="2_vmbyo"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ovl8a"]
bg_color = Color(0.388235, 0.227451, 0.290196, 1)
corner_detail = 1
anti_aliasing = false
[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_5yjx2"]
[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_kofy6"]
[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_hdj8q"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ovl8a"]
bg_color = Color(0.0426611, 0.0872922, 0.0207804, 1)
[node name="Node2D" type="Node2D"]
script = ExtResource("1_v273n")
@@ -21,34 +23,66 @@ offset_bottom = 1153.0
color = Color(0.356863, 0.278431, 0.356863, 1)
metadata/_edit_lock_ = true
[node name="select_dev" type="ScrollContainer" parent="."]
offset_left = 24.0
offset_top = 22.0
offset_right = 387.0
offset_bottom = 54.0
metadata/_edit_lock_ = true
[node name="select_dev" type="GridContainer" parent="select_dev"]
layout_mode = 2
script = ExtResource("2_vmbyo")
metadata/_edit_lock_ = true
[node name="control_button" type="Button" parent="."]
offset_left = 24.0
offset_top = 53.0
offset_right = 118.0
offset_bottom = 81.0
focus_mode = 0
theme_override_font_sizes/font_size = 14
theme_override_styles/pressed = SubResource("StyleBoxFlat_ovl8a")
toggle_mode = true
button_pressed = true
text = "КОНТРОЛЬ"
[node name="Controlpanel" type="ColorRect" parent="."]
offset_left = 118.0
offset_top = 53.0
offset_right = 465.0
offset_bottom = 487.0
color = Color(0.390334, 0.227948, 0.288326, 1)
metadata/_edit_lock_ = true
[node name="control_dev" type="ScrollContainer" parent="."]
offset_left = 142.0
offset_top = 63.0
offset_right = 477.0
offset_bottom = 487.0
metadata/_edit_lock_ = true
[node name="control_dev" type="GridContainer" parent="control_dev"]
layout_mode = 2
script = ExtResource("2_vmbyo")
metadata/_edit_lock_ = true
[node name="scroll1" type="ScrollContainer" parent="."]
offset_left = 586.0
offset_top = 45.0
offset_top = 22.0
offset_right = 949.0
offset_bottom = 629.0
offset_bottom = 606.0
[node name="table1" type="GridContainer" parent="scroll1"]
layout_mode = 2
script = ExtResource("2_vmbyo")
metadata/_edit_lock_ = true
[node name="TextEdit" type="TextEdit" parent="."]
offset_left = 1027.0
offset_top = 633.0
offset_right = 1139.0
offset_bottom = 671.0
theme_override_colors/font_readonly_color = Color(1, 1, 1, 1)
theme_override_styles/normal = SubResource("StyleBoxTexture_5yjx2")
theme_override_styles/focus = SubResource("StyleBoxTexture_kofy6")
theme_override_styles/read_only = SubResource("StyleBoxTexture_hdj8q")
text = "Test PRD"
editable = false
[node name="Packet" type="TextEdit" parent="."]
offset_left = 23.0
offset_top = 532.0
offset_top = 606.0
offset_right = 1121.0
offset_bottom = 712.0
offset_bottom = 786.0
theme_override_colors/font_readonly_color = Color(1, 1, 1, 1)
theme_override_styles/normal = SubResource("StyleBoxTexture_5yjx2")
theme_override_styles/focus = SubResource("StyleBoxTexture_kofy6")
@@ -57,68 +91,4 @@ text = "broadcast"
editable = false
wrap_mode = 1
[node name="Button" type="Button" parent="."]
offset_left = 22.0
offset_top = 22.0
offset_right = 148.0
offset_bottom = 54.0
theme_override_styles/pressed = SubResource("StyleBoxFlat_ovl8a")
text = "КОНТРОЛЬ"
[node name="Controlpanel" type="ColorRect" parent="."]
offset_left = 23.0
offset_top = 66.0
offset_right = 356.0
offset_bottom = 416.0
color = Color(0.390334, 0.227948, 0.288326, 1)
metadata/_edit_lock_ = true
[node name="yau07" type="Label" parent="Controlpanel"]
offset_left = 8.0
offset_top = 12.0
offset_right = 250.0
offset_bottom = 35.0
text = "ЯУ-07Б НА СВЯЗИ"
metadata/_edit_lock_ = true
[node name="FS" type="Label" parent="Controlpanel"]
offset_left = 8.0
offset_top = 35.0
offset_right = 250.0
offset_bottom = 58.0
text = "ФС НА СВЯЗИ"
metadata/_edit_lock_ = true
[node name="EMS_G" type="Label" parent="Controlpanel"]
offset_left = 8.0
offset_top = 58.0
offset_right = 250.0
offset_bottom = 81.0
text = "НАЛИЧИЕ ЯЧЕЙКИ ЭМС Г"
metadata/_edit_lock_ = true
[node name="UG" type="Label" parent="Controlpanel"]
offset_left = 8.0
offset_top = 81.0
offset_right = 250.0
offset_bottom = 104.0
text = "НАЛИЧИЕ ЯЧЕЙКИ УГ"
metadata/_edit_lock_ = true
[node name="UKP1" type="Label" parent="Controlpanel"]
offset_left = 8.0
offset_top = 104.0
offset_right = 250.0
offset_bottom = 127.0
text = "НАЛИЧИЕ ЯЧЕЙКИ УКП 1"
metadata/_edit_lock_ = true
[node name="UKP2" type="Label" parent="Controlpanel"]
offset_left = 8.0
offset_top = 127.0
offset_right = 250.0
offset_bottom = 150.0
text = "НАЛИЧИЕ ЯЧЕЙКИ УКП 2"
metadata/_edit_lock_ = true
[connection signal="toggled" from="Button" to="." method="_on_control_button"]
[connection signal="toggled" from="control_button" to="." method="_on_control_button"]

View File

@@ -2,8 +2,8 @@ extends Node
const UNICAST_PORT: int = 50003
const UNICAST_ADDRESS: String = '10.1.1.3'
const BROADCAST_PORT: int = 50000
const DEFAULT_ADDRESS: String = '10.1.1.52'
const DEFAULT_PORT: String = '50052'
const DEFAULT_ADDRESS: String = '10.1.1.43'
const DEFAULT_PORT: String = '50043'
const BASE_ADDR: int = 0x100
const RED = Color(1, 0, 0, 1)
const GREEN = Color(0, 1, 0, 1)
@@ -12,6 +12,24 @@ const MAXIMUM_CODE_ADC: int = 3796
const MINIMUM_CODE_AD: int = 2660
const TEMP: float = 115.0 / (MAXIMUM_CODE_ADC - MINIMUM_CODE_AD)
const TableNode = preload("res://table/node.tscn")
const TableList = preload("res://table/node_list.tscn")
const SELECT_DEVIСE: Array = [[TableNode, TableList]]
const CONTROL_DEVICE: Array = [
[TableNode],
[TableNode],
[TableNode],
[TableNode],
[TableNode],
[TableNode],
[TableNode],
[TableNode],
[TableNode],
[TableNode],
[TableNode],
[TableNode],
[TableNode],
[TableNode],
[TableNode],]
const ROWS_REGS_DATA: Array = [
[TableNode, TableNode, TableNode, TableNode],
[TableNode, TableNode, TableNode, TableNode],
@@ -28,5 +46,18 @@ const ROWS_REGS_DATA: Array = [
[TableNode, TableNode, TableNode, TableNode],
[TableNode, TableNode, TableNode, TableNode],
[TableNode, TableNode, TableNode, TableNode],
[TableNode, TableNode, TableNode, TableNode],
[TableNode, TableNode, TableNode, TableNode],]
const ADDRESSES: Array = [
['ПРД-Н1', '10.1.1.11', 50011],
['ПРД-Н2', '10.1.1.21', 50021],
['ПРД-Н3', '10.1.1.31', 50031],
['ПРД-Н4', '10.1.1.41', 50041],
['ПРД-В1', '10.1.1.12', 50012],
['ПРД-В2', '10.1.1.22', 50022],
['ПРД-В3', '10.1.1.32', 50032],
['ПРД-В4', '10.1.1.42', 50042],
['ПРД-К1', '10.1.1.13', 50013],
['ПРД-К2', '10.1.1.23', 50023],
['ПРД-К3', '10.1.1.33', 50033],
['ПРД-К4', '10.1.1.43', 50043],
]

View File

@@ -15,7 +15,7 @@ anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_top = -103.0
offset_right = -279.0
offset_right = -477.0
offset_bottom = -714.0
grow_horizontal = 2
grow_vertical = 2
@@ -25,6 +25,7 @@ theme_override_colors/font_uneditable_color = Color(1, 1, 1, 1)
theme_override_font_sizes/font_size = 17
theme_override_styles/normal = SubResource("StyleBoxFlat_hrhif")
theme_override_styles/read_only = SubResource("StyleBoxFlat_q1ixs")
alignment = 1
editable = false
caret_blink = true
caret_blink_interval = 0.5

View File

@@ -4,7 +4,8 @@
bg_color = Color(0, 0, 0, 1)
[node name="OptionButton" type="OptionButton"]
offset_right = 170.0
offset_bottom = 20.0
offset_right = 130.0
offset_bottom = 25.0
focus_mode = 0
theme_override_styles/normal = SubResource("StyleBoxFlat_ddnjm")
alignment = 1