From f6649907d45acc4677d8bbbea6c862eef24c2af9 Mon Sep 17 00:00:00 2001
From: TotMaxim
Date: Mon, 10 Nov 2025 19:35:17 +0300
Subject: [PATCH] first init
---
.editorconfig | 4 +
.gitattributes | 2 +
.gitignore | 3 +
.idea/.gitignore | 3 +
.idea/imi_case_y5.iml | 8 ++
.../inspectionProfiles/profiles_settings.xml | 6 ++
.idea/misc.xml | 4 +
.idea/modules.xml | 8 ++
.idea/vcs.xml | 6 ++
icon.svg | 1 +
icon.svg.import | 37 ++++++++
main.gd | 24 ++++++
main.gd.uid | 1 +
main.tscn | 84 +++++++++++++++++++
project.godot | 26 ++++++
udp_broadcast.gd | 79 +++++++++++++++++
udp_broadcast.gd.uid | 1 +
17 files changed, 297 insertions(+)
create mode 100644 .editorconfig
create mode 100644 .gitattributes
create mode 100644 .gitignore
create mode 100644 .idea/.gitignore
create mode 100644 .idea/imi_case_y5.iml
create mode 100644 .idea/inspectionProfiles/profiles_settings.xml
create mode 100644 .idea/misc.xml
create mode 100644 .idea/modules.xml
create mode 100644 .idea/vcs.xml
create mode 100644 icon.svg
create mode 100644 icon.svg.import
create mode 100644 main.gd
create mode 100644 main.gd.uid
create mode 100644 main.tscn
create mode 100644 project.godot
create mode 100644 udp_broadcast.gd
create mode 100644 udp_broadcast.gd.uid
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..f28239b
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,4 @@
+root = true
+
+[*]
+charset = utf-8
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..8ad74f7
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+# Normalize EOL for all files that Git considers text files.
+* text=auto eol=lf
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0af181c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+# Godot 4+ specific ignores
+.godot/
+/android/
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/imi_case_y5.iml b/.idea/imi_case_y5.iml
new file mode 100644
index 0000000..f571432
--- /dev/null
+++ b/.idea/imi_case_y5.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 0000000..105ce2d
--- /dev/null
+++ b/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..060d2c5
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..20a4b7b
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/icon.svg b/icon.svg
new file mode 100644
index 0000000..9d8b7fa
--- /dev/null
+++ b/icon.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/icon.svg.import b/icon.svg.import
new file mode 100644
index 0000000..69d6d0c
--- /dev/null
+++ b/icon.svg.import
@@ -0,0 +1,37 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://beh7rub2lmwwk"
+path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://icon.svg"
+dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1
+svg/scale=1.0
+editor/scale_with_editor_scale=false
+editor/convert_colors_with_editor_theme=false
diff --git a/main.gd b/main.gd
new file mode 100644
index 0000000..de3ed89
--- /dev/null
+++ b/main.gd
@@ -0,0 +1,24 @@
+extends Control
+
+var dictionary_yau07: Dictionary
+
+func _ready() -> void:
+ var device_yau07: Array = get_tree().get_nodes_in_group('device-addr')
+ for device in device_yau07:
+ device.connect('toggled', on_modify_device.bind(device.get_meta('device')))
+
+
+func _exit_tree():
+ for device in dictionary_yau07:
+ if dictionary_yau07[device]:
+ dictionary_yau07[device].close_udp_unit()
+
+
+func on_modify_device(toggled: bool, name_device: String) -> void:
+ if toggled:
+ var udp_broadcast := UDPBroadcast.new(name_device)
+ udp_broadcast.add_timer_to_scene(self)
+ udp_broadcast.start_broadcast()
+ dictionary_yau07[name_device] = udp_broadcast
+ else:
+ dictionary_yau07[name_device].close_udp_unit()
diff --git a/main.gd.uid b/main.gd.uid
new file mode 100644
index 0000000..95df1f8
--- /dev/null
+++ b/main.gd.uid
@@ -0,0 +1 @@
+uid://d1qwoxkckvdbc
diff --git a/main.tscn b/main.tscn
new file mode 100644
index 0000000..3d385aa
--- /dev/null
+++ b/main.tscn
@@ -0,0 +1,84 @@
+[gd_scene load_steps=2 format=3 uid="uid://bxorauom63ib6"]
+
+[ext_resource type="Script" uid="uid://d1qwoxkckvdbc" path="res://main.gd" id="1_ig7tw"]
+
+[node name="Control" type="Control"]
+layout_mode = 3
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+script = ExtResource("1_ig7tw")
+
+[node name="Panel" type="Panel" parent="."]
+layout_mode = 0
+offset_right = 907.0
+offset_bottom = 607.0
+
+[node name="Yau-07-addr" type="GridContainer" parent="."]
+layout_mode = 0
+offset_left = 32.0
+offset_top = 24.0
+offset_right = 140.0
+offset_bottom = 440.0
+
+[node name="CheckButton" type="CheckButton" parent="Yau-07-addr" groups=["device-addr"]]
+layout_mode = 2
+text = "ПРД-Н1"
+metadata/device = "ПРД-Н1"
+
+[node name="CheckButton2" type="CheckButton" parent="Yau-07-addr" groups=["device-addr"]]
+layout_mode = 2
+text = "ПРД-В1"
+metadata/device = "ПРД-В1"
+
+[node name="CheckButton3" type="CheckButton" parent="Yau-07-addr" groups=["device-addr"]]
+layout_mode = 2
+text = "ПРД-К1"
+metadata/device = "ПРД-К1"
+
+[node name="CheckButton4" type="CheckButton" parent="Yau-07-addr" groups=["device-addr"]]
+layout_mode = 2
+text = "ПРД-Н2"
+metadata/device = "ПРД-Н2"
+
+[node name="CheckButton5" type="CheckButton" parent="Yau-07-addr" groups=["device-addr"]]
+layout_mode = 2
+text = "ПРД-В2"
+metadata/device = "ПРД-В2"
+
+[node name="CheckButton6" type="CheckButton" parent="Yau-07-addr" groups=["device-addr"]]
+layout_mode = 2
+text = "ПРД-К2"
+metadata/device = "ПРД-К2"
+
+[node name="CheckButton7" type="CheckButton" parent="Yau-07-addr" groups=["device-addr"]]
+layout_mode = 2
+text = "ПРД-Н3"
+metadata/device = "ПРД-Н3"
+
+[node name="CheckButton8" type="CheckButton" parent="Yau-07-addr" groups=["device-addr"]]
+layout_mode = 2
+text = "ПРД-В3"
+metadata/device = "ПРД-В3"
+
+[node name="CheckButton9" type="CheckButton" parent="Yau-07-addr" groups=["device-addr"]]
+layout_mode = 2
+text = "ПРД-К3"
+metadata/device = "ПРД-К3"
+
+[node name="CheckButton10" type="CheckButton" parent="Yau-07-addr" groups=["device-addr"]]
+layout_mode = 2
+text = "ПРД-Н4"
+metadata/device = "ПРД-Н4"
+
+[node name="CheckButton11" type="CheckButton" parent="Yau-07-addr" groups=["device-addr"]]
+layout_mode = 2
+text = "ПРД-В4"
+metadata/device = "ПРД-В4"
+
+[node name="CheckButton12" type="CheckButton" parent="Yau-07-addr" groups=["device-addr"]]
+layout_mode = 2
+text = "ПРД-К4"
+metadata/device = "ПРД-К4"
diff --git a/project.godot b/project.godot
new file mode 100644
index 0000000..771c659
--- /dev/null
+++ b/project.godot
@@ -0,0 +1,26 @@
+; Engine configuration file.
+; It's best edited using the editor UI and not directly,
+; since the parameters that go here are not all obvious.
+;
+; Format:
+; [section] ; section goes between []
+; param=value ; assign values to parameters
+
+config_version=5
+
+[application]
+
+config/name="imi_case_y5"
+run/main_scene="res://main.tscn"
+config/features=PackedStringArray("4.4", "GL Compatibility")
+config/icon="res://icon.svg"
+
+[display]
+
+window/size/viewport_width=900
+window/size/viewport_height=600
+
+[rendering]
+
+renderer/rendering_method="gl_compatibility"
+renderer/rendering_method.mobile="gl_compatibility"
diff --git a/udp_broadcast.gd b/udp_broadcast.gd
new file mode 100644
index 0000000..82b34c4
--- /dev/null
+++ b/udp_broadcast.gd
@@ -0,0 +1,79 @@
+class_name UDPBroadcast
+
+const addres_list: Dictionary = {
+ 'ПРД-Н1': [50011, "10.1.1.11"],
+ 'ПРД-В1': [50012, "10.1.1.12"],
+ 'ПРД-К1': [50013, "10.1.1.13"],
+ 'ПРД-Н2': [50021, "10.1.1.21"],
+ 'ПРД-В2': [50022, "10.1.1.22"],
+ 'ПРД-К2': [50023, "10.1.1.23"],
+ 'ПРД-Н3': [50031, "10.1.1.31"],
+ 'ПРД-В3': [50032, "10.1.1.32"],
+ 'ПРД-К3': [50033, "10.1.1.33"],
+ 'ПРД-Н4': [50041, "10.1.1.41"],
+ 'ПРД-В4': [50042, "10.1.1.42"],
+ 'ПРД-К4': [50043, "10.1.1.43"],
+}
+const broadcast_addr: Array = [50000, "10.1.1.255"]
+#const bind_addr: Array = [50_000, "10.1.1.70"] TODO: Порт по умолчанию
+var _socket: SocketUDP
+var self_name: String
+var _timer: Timer
+
+
+func _init(name: String):
+ self_name = name
+ _socket = SocketUDP.new()
+ _timer = Timer.new()
+ _timer.wait_time = 1.0 / 3.0
+ _timer.timeout.connect(_on_timer_timeout)
+
+ if addres_list.has(name):
+ var port: int = addres_list[name][0]
+ var addr: String = addres_list[name][1]
+ bind_unit_addres(port, addr)
+ else:
+ push_error("Неизвестное устройство: %s" % name)
+
+
+func bind_unit_addres(port_for_bind: int, addr_for_bind: String) -> void:
+ print('Привязка адреса: %s' % addr_for_bind)
+ var bind_result = _socket.bind(port_for_bind, addr_for_bind)
+ if bind_result != OK:
+ push_error("Не удалось привязаться к %s: %s" % [addr_for_bind, error_string(bind_result)])
+
+
+func start_broadcast() -> void:
+ _timer.start()
+
+
+func stop_broadcast() -> void:
+ _timer.stop()
+
+
+func send_broadcast(message: String) -> bool:
+ _socket.set_broadcast_enabled(true)
+ var data: PackedByteArray = message.to_utf8_buffer()
+ _socket.send_to(broadcast_addr[1], broadcast_addr[0], data)
+ return true
+
+
+func close_udp_unit() -> void:
+ _timer.stop()
+ _socket.close()
+
+
+func add_timer_to_scene(parent: Node) -> void:
+ parent.add_child(_timer)
+
+
+func _on_timer_timeout() -> void:
+ send_broadcast("hello")
+
+
+class SocketUDP extends PacketPeerUDP:
+ func send_to(addr: String, port: int, data: PackedByteArray):
+ set_dest_address(addr, port)
+ var rc: = put_packet(data)
+ if rc != OK:
+ push_error('%s: %s:%s' % [error_string(rc), addr, port])
diff --git a/udp_broadcast.gd.uid b/udp_broadcast.gd.uid
new file mode 100644
index 0000000..87a6bf7
--- /dev/null
+++ b/udp_broadcast.gd.uid
@@ -0,0 +1 @@
+uid://c6evva823qhqm