Compare commits

...

10 Commits

8 changed files with 670 additions and 151 deletions

378
Main.gd
View File

@@ -1,7 +1,5 @@
extends Node2D
var TableNode = preload("res://table/node.tscn")
## Класс для отправки данных в сокет
class Socket extends PacketPeerUDP:
func send_to(addr: String, port: int, data: PackedByteArray):
@@ -9,25 +7,25 @@ class Socket extends PacketPeerUDP:
self.put_packet(data)
var node_select: Node
var timer = Timer.new()
var soc_unicast: Socket = Socket.new()
var soc_brodcast: Socket = Socket.new()
var soc_unicast: Socket
var soc_brodcast: Socket
var unit = yau07.YaU07.new('ЯУ07')
var state: int = 0 # Флаг для машины состояния
var state = Constants.STATE.WAIT # Флаг для машины состояния
var flag_online: bool = false # Флаг для подключения
var flag_interval: bool = false # Флаг для включения непрерывной передачи с интервалом
var ports_wr: Dictionary # Словарь с портами для записи
var flag_write_isa: bool = false # Флаг для записи в ИСА
var flag_read_isa: bool = true # Флаг для чтения из ИСА
var flag_two_ports: bool = false # Флаг наличия работы с двумя портами
var ports_wr: Dictionary # Словарь с портами для записи
var ports_wr_2: Dictionary
var port_select: int = Constants.BASE_ADDR # Выбранный порд для чтения/записи
var port_select_2: int = Constants.BASE_ADDR # Выбранный порд для чтения/записи
var port: int
var dt: float # Дельта
var address: String
var rx_data: PackedByteArray # Буфер принятый
var addr_receive: String # Адрес обращения к ПРД
var port_receive: int # Порт обращения к ПРД
var ROWS_REGS_DATA: Array = [
[TableNode, TableNode, TableNode, TableNode, TableNode],
[TableNode, TableNode, TableNode, TableNode, TableNode],
[TableNode, TableNode, TableNode, TableNode, TableNode]]
var dt: float # Дельта
var timer: Timer = Timer.new()
var timeout: float = yau07.ONLINE_TIMEOUT
var last_update_time: float = 0.0
func _ready():
@@ -35,16 +33,17 @@ func _ready():
timer.connect('timeout', Callable(self, 'on_timer'))
# Таблица 1
node_select = $scroll1/table1
draw_tabl(node_select, ROWS_REGS_DATA, ROWS_REGS_DATA.size())
draw_tabl(node_select, Constants.ROWS_REGS_DATA, Constants.ROWS_REGS_DATA.size())
node_select.set_columns_min_size([250, 160, 150, 190, 150])
node_select.set_node_text(0, 0, ' НЕТ СВЯЗИ С ЯУ-07')
node_select.set_node_text(1, 0, ' IP-АДРЕС')
node_select.set_node_text(2, 0, '10.1.1.70')
node_select.set_node_text(3, 0, ' IP-ПОРТ')
node_select.set_node_text(4, 0, '50070')
node_select.set_node_text(0, 1, ' ПОРТ ЯЧЕЙКИ (hex)')
node_select.set_node_text(1, 2, ' ИНТЕРВАЛ')
node_select.set_node_text(0, 0, ' НЕТ СВЯЗИ С ЯУ-07')
node_select.set_node_text(1, 0, ' IP-АДРЕС')
node_select.set_node_text(2, 0, Constants.DEFAULT_ADDRESS)
node_select.set_node_text(3, 0, ' IP-ПОРТ')
node_select.set_node_text(4, 0, Constants.DEFAULT_PORT)
node_select.set_node_text(0, 1, ' 1 ПОРТ ЯЧЕЙКИ (hex)')
node_select.set_node_text(1, 2, ' ИНТЕРВАЛ')
node_select.set_node_text(0, 3, ' 2 ПОРТ ЯЧЕЙКИ (hex)')
# Поле для ввода (запись IP-адреса)
var edit_ip = node_select.get_node2(2, 0)
edit_ip.editable = true
@@ -52,34 +51,63 @@ func _ready():
var edit_port = node_select.get_node2(4, 0)
edit_port.editable = true
edit_port.placeholder_text = 'Ввод значения'
# Поле для ввода (запись в порт)
var edit_node = node_select.get_node2(2, 1)
edit_node.editable = true
edit_node.placeholder_text = 'Ввод значения'
edit_node.connect('text_submitted', Callable(self, '_on_written_text_submitted'))
edit_node.connect('text_submitted', Callable(self, '_on_written_port'))
# Кнопка для включения
$Turn_on.connect('toggled', Callable(self, '_on_button_pressed'))
# Поле для ввода (запись в порт_2)
var edit_node_2 = node_select.get_node2(2, 3)
edit_node_2.editable = true
edit_node_2.placeholder_text = 'Ввод значения'
edit_node_2.connect('text_submitted', Callable(self, '_on_written_port_2'))
$read_ISA.disabled = true
$write_ISA.disabled = true
$read_ISA2.disabled = true
$write_ISA2.disabled = true
# Поле для ввода (базовый порт)
var edit_addr = node_select.get_node2(0, 2)
edit_addr.editable = true
edit_addr.placeholder_text = ' 0x%x' % port_select
edit_addr.text = '%x' % port_select
edit_addr.connect('text_submitted', Callable(self, '_on_written_addres'))
# Поле для ввода 2 (базовый порт №2)
var edit_addr_2 = node_select.get_node2(0, 4)
edit_addr_2.editable = true
edit_addr_2.placeholder_text = 'Ввод -> Enter'
edit_addr_2.connect('text_submitted', Callable(self, '_on_written_addres_2'))
# Поле для ввода (интервал непрерывной записи)
var edit_interval = node_select.get_node2(2, 2)
edit_interval.editable = true
edit_interval.placeholder_text = 'Ввод значения'
edit_interval.connect('text_submitted', Callable(self, '_on_written_interval'))
var node_select2 = $scroll2/table2
draw_tabl(node_select2, Constants.ROWS_BLOCK_DATA, Constants.ROWS_BLOCK_DATA.size())
node_select2.set_columns_min_size([250, 160, 150, 190, 150])
node_select2.set_node_text(0, 0, ' ЧТЕНИЕ ИСА БЛОКА')
node_select2.set_node_text(1, 0, ' ПОРТ БЛОКА')
node_select2.set_node_text(3, 0, ' ДЛИНА СЛОВ')
# Привязка для принятия широковещательного канала
soc_brodcast = Socket.new()
var rc = soc_brodcast.bind(Constants.BROADCAST_PORT, '*')
if rc != OK:
print('Ошибка: Неудачная привязка широковещательного адреса')
ports_wr[port_select] = 0
soc_unicast = Socket.new()
rc = soc_unicast.bind(Constants.UNICAST_PORT, Constants.UNICAST_ADDRESS)
if rc != OK:
print('Ошибка: неудачная привязка адреса: ', address)
unit.connect('line_changed', Callable(self, 'on_line_changed'))
unit.connect('command_fail', Callable(self, 'on_command_fail'))
unit.connect('command_done', Callable(self, 'on_command_done'))
@@ -91,134 +119,246 @@ func draw_tabl(tbl, row: Array, count_row: int):
tbl.add_row(row[i_row])
func poll_receive(sock: Socket, _unit, addr: String, _port: int) -> bool: ## Приёмник
while sock.get_available_packet_count() > 0:
rx_data = sock.get_packet()
addr_receive = sock.get_packet_ip()
port_receive = sock.get_packet_port()
if (addr == addr_receive) and (port == port_receive):
unit.parse(rx_data)
func poll_receive(sock: Socket) -> bool: ## Приёмник
if timeout - last_update_time > 0:
while sock.get_available_packet_count() > 0:
var rx_data = sock.get_packet()
var addr_receive = sock.get_packet_ip()
var port_receive = sock.get_packet_port()
if rx_data:
$BROADCAST.text = 'BROADCAST: ' + str(rx_data)
$BROADCAST.modulate = Color(1, 1, 1, 1)
var line_yau07_control = node_select.get_node2(0, 0)
line_yau07_control.text = ' ЯУ-07Б НА СВЯЗИ'
line_yau07_control.modulate = Constants.GREEN
last_update_time = 0.0
if (address == addr_receive) and (port == port_receive) and flag_online:
unit.parse(rx_data)
else:
if sock.get_available_packet_count():
last_update_time = 0.0
else:
$BROADCAST.modulate = Color(0.5, 0.5, 0.5, 1)
var line_yau07_control = node_select.get_node2(0, 0)
line_yau07_control.text = ' НЕТ СВЯЗИ С ЯУ-07Б'
line_yau07_control.modulate = Constants.RED
return false
func _process(delta):
if flag_online:
if flag_interval == false:
poll_receive(soc_brodcast, unit, address, port)
var fl_done = unit.cmd_state == unit.CmdState.DONE
if state == 1 and fl_done: ## Чтение из ИСА
unit.send_isa(unit.CmdCode.READ_ISA, [port_select])
node_select.set_node_text(3, 1, ' ПРОЧИТАНО ИЗ %x' % port_select)
state = 2
elif state == 2 and fl_done: ## Запись в ИСА
unit.send_isa(unit.CmdCode.WRITE_ISA, [port_select, ports_wr[port_select]])
if unit.isa_ports.has(port_select):
node_select.set_node_text(4, 1, ' %x' % unit.isa_ports[port_select])
var isa: Array = []
for i in unit.isa_ports:
isa.append('%x: %x' % [i, unit.isa_ports[i]])
node_select.set_node_text(1, 1, ' ЗАПИСАТЬ В %x' % port_select)
$ISA.text = 'ISA: ' + str(isa)
state = 1
func _process(delta) -> void:
last_update_time += delta
poll_receive(soc_brodcast)
poll_receive(soc_unicast)
if flag_online and not flag_interval:
state_machine()
var port_txt = node_select.get_node2(0, 1)
if port_select != node_select.get_node2(0, 2).get_text().hex_to_int():
port_txt.text = ' 1 ПОРТ ЯЧЕЙКИ (hex)*'
port_txt.modulate = Color.GREEN
else:
port_txt.text = ' 1 ПОРТ ЯЧЕЙКИ (hex)'
port_txt.modulate = Color.WHITE
if flag_two_ports:
var port_txt_2 = node_select.get_node2(0, 3)
if port_select_2 != node_select.get_node2(0, 4).get_text().hex_to_int():
port_txt_2.text = ' 2 ПОРТ ЯЧЕЙКИ (hex)*'
port_txt_2.modulate = Color.GREEN
else:
port_txt_2.text = ' 2 ПОРТ ЯЧЕЙКИ (hex)'
port_txt_2.modulate = Color.WHITE
match unit.process(delta):
Error.OK: soc_unicast.send_to(address, port, unit.tx_data.slice(0, unit.tx_len))
Error.FAILED: print('Ошибка отправки данных')
dt = delta
func on_timer() -> void:
if flag_interval == true:
if flag_online:
flag_read_isa = true
state_machine()
var rc = unit.process(delta)
if rc == Error.OK:
soc_unicast.send_to(address, port, unit.tx_data.slice(0, unit.tx_len))
dt = delta
func on_timer():
if flag_online:
if flag_interval == true:
poll_receive(soc_brodcast, unit, address, port)
var fl_done = unit.cmd_state == unit.CmdState.DONE
if state == 1 and fl_done: ## Чтение из ИСА
unit.send_isa(unit.CmdCode.READ_ISA, [port_select])
node_select.set_node_text(3, 1, ' ПРОЧИТАНО ИЗ %x' % port_select)
state = 2
elif state == 2 and fl_done: ## Запись в ИСА
unit.send_isa(unit.CmdCode.WRITE_ISA, [port_select, ports_wr[port_select]])
if unit.isa_ports.has(port_select):
node_select.set_node_text(4, 1, '%x' % unit.isa_ports[port_select])
var isa: Array = []
for i in unit.isa_ports:
isa.append('%x: %x' % [i, unit.isa_ports[i]])
node_select.set_node_text(1, 1, ' ЗАПИСАТЬ В %x' % port_select)
$ISA.text = 'ISA: ' + str(isa)
state = 1
var rc = unit.process(dt)
if rc == Error.OK:
soc_unicast.send_to(address, port, unit.tx_data.slice(0, unit.tx_len))
func on_line_changed(_unit):
print_debug()
func on_line_changed(_unit) -> void:
if unit.online:
var line_yau07_control = node_select.get_node2(0, 0)
line_yau07_control.modulate = Constants.GREEN
else:
var line_yau07_control = node_select.get_node2(0, 0)
line_yau07_control.modulate = Constants.RED
var light_interval = node_select.get_node2(1, 2)
light_interval.modulate = Color(0.5, 0.5, 0.5, 1)
var line_board_control = node_select.get_node2(0, 1)
line_board_control.modulate = Constants.RED
$Turn_on.button_pressed = false
flag_online = false
flag_interval = false
## Ессли отсутствует подключение к ячейке ЯУ-07
func on_command_fail(_unit):
var line_yau07_control = node_select.get_node2(0, 0)
line_yau07_control.text = ' НЕТ СВЯЗИ С ЯУ-07'
line_yau07_control.modulate = Color(1, 0, 0, 1)
flag_online = false
soc_unicast = Socket.new()
func on_command_fail(_unit) -> void:
$Turn_on.button_pressed = false
unit.cmd_state = unit.CmdState.UNCK
## Индикация чтения портов
func on_command_done(_unit):
if flag_online:
var line_yau07_control = node_select.get_node2(0, 0)
line_yau07_control.text = ' ЯУ-07 НА СВЯЗИ'
line_yau07_control.modulate = Color(0, 1, 0, 1)
func on_command_done(_unit) -> void:
var isa: Array = []
ports_wr[port_select] = unit.isa_ports[port_select]
if (unit.isa_ports[port_select] == ports_wr[port_select]) and flag_online:
for i in unit.isa_ports:
isa.append('%x: %x' % [i, unit.isa_ports[i]])
$ISA.text = 'ISA: ' + str(isa)
$ISA.modulate = Color(1, 1, 1, 1)
else:
$ISA.modulate = Constants.RED
func state_machine() -> void:
var fl_done = (unit.cmd_state == unit.CmdState.DONE)
if state == Constants.STATE.WAIT and fl_done:
if flag_two_ports:
$write_ISA2.disabled = false
$read_ISA2.disabled = false
node_select.set_node_text(3, 3, ' ПРОЧИТАНО ИЗ %x' % port_select_2)
node_select.set_node_text(1, 3, ' ЗАПИСАТЬ В %x' % port_select_2)
var line_board_control_2 = node_select.get_node2(0, 3)
var nubre_from_port_2 = 'ffff'
if unit.isa_ports.has(port_select_2):
nubre_from_port_2 = '%x' % unit.isa_ports[port_select_2]
line_board_control_2.modulate = Constants.RED if nubre_from_port_2 == 'ffff' else Constants.GREEN
node_select.set_node_text(4, 3, nubre_from_port_2)
$write_ISA.disabled = false
$read_ISA.disabled = false
node_select.set_node_text(3, 1, ' ПРОЧИТАНО ИЗ %x' % port_select)
node_select.set_node_text(1, 1, ' ЗАПИСАТЬ В %x' % port_select)
var line_board_control = node_select.get_node2(0, 1)
var nubre_from_port = 'ffff'
if unit.isa_ports.has(port_select):
nubre_from_port = '%x' % unit.isa_ports[port_select]
line_board_control.modulate = Constants.RED if nubre_from_port == 'ffff' else Constants.GREEN
node_select.set_node_text(4, 1, nubre_from_port)
if flag_write_isa:
flag_write_isa = false
state = Constants.STATE.WRITE
elif flag_read_isa:
flag_read_isa = false
state = Constants.STATE.READ
else:
state = Constants.STATE.WAIT
elif state == Constants.STATE.READ and fl_done: ## Чтение из ИСА
if flag_two_ports:
unit.send_isa(unit.CmdCode.READ_ISA, [port_select, port_select_2])
else:
unit.send_isa(unit.CmdCode.READ_ISA, [port_select])
state = Constants.STATE.WAIT
elif state == Constants.STATE.WRITE and fl_done: ## Запись в ИСА
if flag_two_ports:
unit.send_isa(unit.CmdCode.WRITE_ISA, [port_select, ports_wr[port_select], port_select_2, ports_wr_2[port_select_2]])
else:
unit.send_isa(unit.CmdCode.WRITE_ISA, [port_select, ports_wr[port_select]])
state = Constants.STATE.WAIT
## Выставить адресс для записи
func _on_written_addres(write_addres):
func _on_written_addres(write_addres) -> void:
port_select = write_addres.hex_to_int()
ports_wr[port_select] = 0
if ports_wr.has(port_select) != true:
ports_wr[port_select] = 0
node_select.set_node_text(0, 2, '%x' % port_select)
## Выставить адресс для записи №2
func _on_written_addres_2(write_addres_2) -> void:
flag_two_ports = true
port_select_2 = write_addres_2.hex_to_int()
if ports_wr_2.has(port_select_2) != true:
ports_wr_2[port_select_2] = 0
node_select.set_node_text(0, 4, '%x' % port_select_2)
## Запись числа порт
func _on_written_text_submitted(write_addres_data):
func _on_written_port(write_addres_data) -> void:
var is_hex = true
for chr in write_addres_data:
if chr.to_upper() < '0' or chr.to_upper() > 'F':
is_hex = false
break
break
ports_wr[port_select] = write_addres_data.hex_to_int() if is_hex else 0xffff
state = 2 # Запись
flag_read_isa = true
flag_write_isa = true # Запись
func _on_written_interval(write_interval):
## Запись числа порт №2
func _on_written_port_2(write_addres_data_2):
var is_hex = true
for chr in write_addres_data_2:
if chr.to_upper() < '0' or chr.to_upper() > 'F':
is_hex = false
break
ports_wr_2[port_select_2] = write_addres_data_2.hex_to_int() if is_hex else 0xffff
flag_read_isa = true
flag_write_isa = true # Запись
func _on_written_interval(write_interval) -> void:
timer.start(float(write_interval))
flag_interval = true
var light_interval = node_select.get_node2(1, 2)
light_interval.modulate = Color(0, 1, 0, 1)
light_interval.modulate = Constants.GREEN
## Подключение
func _on_button_pressed(turn_on):
func _on_button_pressed(turn_on) -> void:
if turn_on:
address = node_select.get_node2(2,0).text
port = int(node_select.get_node2(4,0).text)
var rc = soc_unicast.bind(Constants.UNICAST_PORT, Constants.UNICAST_ADDRESS)
if rc != OK:
print('Ошибка: неудачная привязка адреса: ', address)
soc_unicast = Socket.new()
flag_online = false
else:
state = 1 # Чтение
flag_online = true
flag_read_isa = false # Чтение
flag_online = true
save_settings()
else:
var line_yau07_control = node_select.get_node2(0, 0)
line_yau07_control.text = ' НЕТ СВЯЗИ С ЯУ-07'
line_yau07_control.modulate = Color(1, 0, 0, 1)
var light_interval = node_select.get_node2(1, 2)
light_interval.modulate = Color(0.5, 0.5, 0.5, 1)
soc_unicast = Socket.new()
flag_online = false
flag_interval = false
var light_interval = node_select.get_node2(1, 2)
light_interval.modulate = Color(1,1,1,1)
func _on_button_read() -> void:
port_select = node_select.get_node2(0, 2).text.hex_to_int()
flag_read_isa = true
func _on_button_read_2() -> void:
port_select_2 = node_select.get_node2(0, 4).text.hex_to_int()
flag_read_isa = true
func _on_button_write() -> void:
port_select = node_select.get_node2(0, 2).text.hex_to_int()
_on_written_port(node_select.get_node2(2, 1).text)
flag_write_isa = true
func _on_button_write_2() -> void:
port_select_2 = node_select.get_node2(0, 4).text.hex_to_int()
_on_written_port_2(node_select.get_node2(2, 3).text)
flag_write_isa = true
func save_settings():
var file = FileAccess.open("user://constants.txt", FileAccess.WRITE)
if file:
file.store_line(address) # Сохранить IP-адрес
file.store_line(str(port)) # Сохранить порт
file.store_line(str(port_select)) # Сохранить базовый адрес
file.close()

92
Pla56EE.tmp Normal file
View File

@@ -0,0 +1,92 @@
[gd_scene load_steps=5 format=3 uid="uid://ccp4ypftnrbwq"]
[ext_resource type="Script" path="res://Main.gd" id="1_8v2wa"]
[ext_resource type="Script" path="res://table/table.gd" id="2_ri1qb"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jbuuq"]
bg_color = Color(0.0901961, 0.52549, 0.0588235, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_so1no"]
bg_color = Color(0, 0, 0, 1)
[node name="Node2D" type="Node2D"]
script = ExtResource("1_8v2wa")
[node name="Background" type="ColorRect" parent="."]
offset_right = 2916.0
offset_bottom = 1542.0
color = Color(0.313726, 0.227451, 0.290196, 1)
metadata/_edit_lock_ = true
[node name="scroll1" type="ScrollContainer" parent="."]
offset_left = 42.0
offset_top = 72.0
offset_right = 1135.0
offset_bottom = 265.0
metadata/_edit_lock_ = true
[node name="table1" type="GridContainer" parent="scroll1"]
layout_mode = 2
script = ExtResource("2_ri1qb")
metadata/_edit_lock_ = true
[node name="scroll2" type="ScrollContainer" parent="."]
offset_left = 40.0
offset_top = 169.0
offset_right = 1133.0
offset_bottom = 261.0
metadata/_edit_lock_ = true
[node name="table2" type="GridContainer" parent="scroll2"]
layout_mode = 2
script = ExtResource("2_ri1qb")
[node name="Turn_on" type="Button" parent="."]
offset_left = 963.0
offset_top = 72.0
offset_right = 1098.0
offset_bottom = 96.0
theme_override_font_sizes/font_size = 17
theme_override_styles/pressed = SubResource("StyleBoxFlat_jbuuq")
theme_override_styles/normal = SubResource("StyleBoxFlat_so1no")
toggle_mode = true
text = "ПОДКЛЮЧИТЬ"
metadata/_edit_lock_ = true
[node name="read_ISA" type="Button" parent="."]
offset_left = 963.0
offset_top = 100.0
offset_right = 1098.0
offset_bottom = 124.0
theme_override_styles/pressed = SubResource("StyleBoxFlat_jbuuq")
theme_override_styles/normal = SubResource("StyleBoxFlat_so1no")
text = "ПРОЧИТАТЬ"
metadata/_edit_lock_ = true
[node name="write_ISA" type="Button" parent="."]
offset_left = 963.0
offset_top = 129.0
offset_right = 1098.0
offset_bottom = 153.0
theme_override_styles/pressed = SubResource("StyleBoxFlat_jbuuq")
theme_override_styles/normal = SubResource("StyleBoxFlat_so1no")
text = "ЗАПИСАТЬ"
metadata/_edit_lock_ = true
[node name="BROADCAST" type="Label" parent="."]
offset_left = 45.0
offset_top = 274.0
offset_right = 998.0
offset_bottom = 297.0
metadata/_edit_lock_ = true
[node name="ISA" type="Label" parent="."]
offset_left = 45.0
offset_top = 243.0
offset_right = 998.0
offset_bottom = 266.0
metadata/_edit_lock_ = true
[connection signal="toggled" from="Turn_on" to="." method="_on_button_pressed"]
[connection signal="pressed" from="read_ISA" to="." method="_on_button_read"]
[connection signal="pressed" from="write_ISA" to="." method="_on_button_write"]

92
Pla63AD.tmp Normal file
View File

@@ -0,0 +1,92 @@
[gd_scene load_steps=5 format=3 uid="uid://ccp4ypftnrbwq"]
[ext_resource type="Script" path="res://Main.gd" id="1_8v2wa"]
[ext_resource type="Script" path="res://table/table.gd" id="2_ri1qb"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jbuuq"]
bg_color = Color(0.0901961, 0.52549, 0.0588235, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_so1no"]
bg_color = Color(0, 0, 0, 1)
[node name="Node2D" type="Node2D"]
script = ExtResource("1_8v2wa")
[node name="Background" type="ColorRect" parent="."]
offset_right = 2916.0
offset_bottom = 1542.0
color = Color(0.313726, 0.227451, 0.290196, 1)
metadata/_edit_lock_ = true
[node name="scroll1" type="ScrollContainer" parent="."]
offset_left = 42.0
offset_top = 72.0
offset_right = 1135.0
offset_bottom = 265.0
metadata/_edit_lock_ = true
[node name="table1" type="GridContainer" parent="scroll1"]
layout_mode = 2
script = ExtResource("2_ri1qb")
metadata/_edit_lock_ = true
[node name="scroll2" type="ScrollContainer" parent="."]
offset_left = 40.0
offset_top = 169.0
offset_right = 1133.0
offset_bottom = 261.0
metadata/_edit_lock_ = true
[node name="table2" type="GridContainer" parent="scroll2"]
layout_mode = 2
script = ExtResource("2_ri1qb")
[node name="Turn_on" type="Button" parent="."]
offset_left = 963.0
offset_top = 72.0
offset_right = 1098.0
offset_bottom = 96.0
theme_override_font_sizes/font_size = 17
theme_override_styles/pressed = SubResource("StyleBoxFlat_jbuuq")
theme_override_styles/normal = SubResource("StyleBoxFlat_so1no")
toggle_mode = true
text = "ПОДКЛЮЧИТЬ"
metadata/_edit_lock_ = true
[node name="read_ISA" type="Button" parent="."]
offset_left = 963.0
offset_top = 100.0
offset_right = 1098.0
offset_bottom = 124.0
theme_override_styles/pressed = SubResource("StyleBoxFlat_jbuuq")
theme_override_styles/normal = SubResource("StyleBoxFlat_so1no")
text = "ПРОЧИТАТЬ"
metadata/_edit_lock_ = true
[node name="write_ISA" type="Button" parent="."]
offset_left = 963.0
offset_top = 129.0
offset_right = 1098.0
offset_bottom = 153.0
theme_override_styles/pressed = SubResource("StyleBoxFlat_jbuuq")
theme_override_styles/normal = SubResource("StyleBoxFlat_so1no")
text = "ЗАПИСАТЬ"
metadata/_edit_lock_ = true
[node name="BROADCAST" type="Label" parent="."]
offset_left = 45.0
offset_top = 274.0
offset_right = 998.0
offset_bottom = 297.0
metadata/_edit_lock_ = true
[node name="ISA" type="Label" parent="."]
offset_left = 45.0
offset_top = 243.0
offset_right = 998.0
offset_bottom = 266.0
metadata/_edit_lock_ = true
[connection signal="toggled" from="Turn_on" to="." method="_on_button_pressed"]
[connection signal="pressed" from="read_ISA" to="." method="_on_button_read"]
[connection signal="pressed" from="write_ISA" to="." method="_on_button_write"]

62
Pla7AC5.tmp Normal file
View File

@@ -0,0 +1,62 @@
[gd_scene load_steps=5 format=3 uid="uid://ccp4ypftnrbwq"]
[ext_resource type="Script" path="res://Main.gd" id="1_8v2wa"]
[ext_resource type="Script" path="res://table/table.gd" id="2_ri1qb"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_so1no"]
bg_color = Color(0, 0, 0, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jbuuq"]
bg_color = Color(0.0901961, 0.52549, 0.0588235, 1)
[node name="Node2D" type="Node2D"]
script = ExtResource("1_8v2wa")
[node name="Background" type="ColorRect" parent="."]
offset_right = 1158.0
offset_bottom = 655.0
color = Color(0.313726, 0.227451, 0.290196, 1)
metadata/_edit_lock_ = true
[node name="scroll1" type="ScrollContainer" parent="."]
offset_left = 42.0
offset_top = 72.0
offset_right = 1135.0
offset_bottom = 265.0
metadata/_edit_lock_ = true
[node name="table1" type="GridContainer" parent="scroll1"]
layout_mode = 2
script = ExtResource("2_ri1qb")
metadata/_edit_lock_ = true
[node name="Turn_on" type="Button" parent="."]
offset_left = 963.0
offset_top = 72.0
offset_right = 1088.0
offset_bottom = 96.0
theme_override_font_sizes/font_size = 17
theme_override_styles/normal = SubResource("StyleBoxFlat_so1no")
theme_override_styles/pressed = SubResource("StyleBoxFlat_jbuuq")
toggle_mode = true
text = "Подключить"
metadata/_edit_lock_ = true
[node name="read_ISA" type="Button" parent="."]
offset_left = 963.0
offset_top = 100.0
offset_right = 1088.0
offset_bottom = 124.0
theme_override_styles/normal = SubResource("StyleBoxFlat_so1no")
theme_override_styles/pressed = SubResource("StyleBoxFlat_jbuuq")
text = "ПРОЧИТАТЬ"
metadata/_edit_lock_ = true
[node name="ISA" type="Label" parent="."]
offset_left = 46.0
offset_top = 179.0
offset_right = 999.0
offset_bottom = 202.0
metadata/_edit_lock_ = true
[connection signal="pressed" from="read_ISA" to="." method="_on_button_read"]

View File

@@ -3,18 +3,18 @@
[ext_resource type="Script" path="res://Main.gd" id="1_8v2wa"]
[ext_resource type="Script" path="res://table/table.gd" id="2_ri1qb"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_so1no"]
bg_color = Color(0, 0, 0, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jbuuq"]
bg_color = Color(0.0901961, 0.52549, 0.0588235, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_so1no"]
bg_color = Color(0, 0, 0, 1)
[node name="Node2D" type="Node2D"]
script = ExtResource("1_8v2wa")
[node name="Background" type="ColorRect" parent="."]
offset_right = 1158.0
offset_bottom = 655.0
offset_right = 2916.0
offset_bottom = 1542.0
color = Color(0.313726, 0.227451, 0.290196, 1)
metadata/_edit_lock_ = true
@@ -30,21 +30,86 @@ layout_mode = 2
script = ExtResource("2_ri1qb")
metadata/_edit_lock_ = true
[node name="scroll2" type="ScrollContainer" parent="."]
offset_left = 40.0
offset_top = 225.0
offset_right = 1133.0
offset_bottom = 317.0
metadata/_edit_lock_ = true
[node name="table2" type="GridContainer" parent="scroll2"]
layout_mode = 2
script = ExtResource("2_ri1qb")
[node name="Turn_on" type="Button" parent="."]
offset_left = 963.0
offset_top = 72.0
offset_right = 1088.0
offset_right = 1098.0
offset_bottom = 96.0
theme_override_font_sizes/font_size = 17
theme_override_styles/normal = SubResource("StyleBoxFlat_so1no")
theme_override_styles/pressed = SubResource("StyleBoxFlat_jbuuq")
theme_override_styles/normal = SubResource("StyleBoxFlat_so1no")
toggle_mode = true
text = "Подключить"
text = "ПОДКЛЮЧИТЬ"
metadata/_edit_lock_ = true
[node name="read_ISA" type="Button" parent="."]
offset_left = 963.0
offset_top = 99.0
offset_right = 1098.0
offset_bottom = 123.0
theme_override_styles/pressed = SubResource("StyleBoxFlat_jbuuq")
theme_override_styles/normal = SubResource("StyleBoxFlat_so1no")
text = "ПРОЧИТАТЬ"
metadata/_edit_lock_ = true
[node name="write_ISA" type="Button" parent="."]
offset_left = 963.0
offset_top = 128.0
offset_right = 1098.0
offset_bottom = 152.0
theme_override_styles/pressed = SubResource("StyleBoxFlat_jbuuq")
theme_override_styles/normal = SubResource("StyleBoxFlat_so1no")
text = "ЗАПИСАТЬ"
metadata/_edit_lock_ = true
[node name="read_ISA2" type="Button" parent="."]
offset_left = 963.0
offset_top = 155.0
offset_right = 1098.0
offset_bottom = 179.0
theme_override_styles/pressed = SubResource("StyleBoxFlat_jbuuq")
theme_override_styles/normal = SubResource("StyleBoxFlat_so1no")
text = "ПРОЧИТАТЬ 2"
metadata/_edit_lock_ = true
[node name="write_ISA2" type="Button" parent="."]
offset_left = 963.0
offset_top = 184.0
offset_right = 1098.0
offset_bottom = 208.0
theme_override_styles/pressed = SubResource("StyleBoxFlat_jbuuq")
theme_override_styles/normal = SubResource("StyleBoxFlat_so1no")
text = "ЗАПИСАТЬ 2"
metadata/_edit_lock_ = true
[node name="BROADCAST" type="Label" parent="."]
offset_left = 45.0
offset_top = 290.0
offset_right = 998.0
offset_bottom = 313.0
autowrap_mode = 2
metadata/_edit_lock_ = true
[node name="ISA" type="Label" parent="."]
offset_left = 46.0
offset_top = 179.0
offset_right = 999.0
offset_bottom = 202.0
offset_left = 45.0
offset_top = 259.0
offset_right = 998.0
offset_bottom = 282.0
metadata/_edit_lock_ = true
[connection signal="toggled" from="Turn_on" to="." method="_on_button_pressed"]
[connection signal="pressed" from="read_ISA" to="." method="_on_button_read"]
[connection signal="pressed" from="write_ISA" to="." method="_on_button_write"]
[connection signal="pressed" from="read_ISA2" to="." method="_on_button_read_2"]
[connection signal="pressed" from="write_ISA2" to="." method="_on_button_write_2"]

View File

@@ -1,6 +1,24 @@
extends Node
const UNICAST_PORT: int = 50080
const UNICAST_ADDRESS: String = '10.1.1.14'
const TableNode = preload("res://table/node.tscn")
var file = FileAccess.open("user://constants.txt", FileAccess.READ)
const UNICAST_PORT: int = 50003
const UNICAST_ADDRESS: String = '10.1.1.3'
const BROADCAST_PORT: int = 50000
const BASE_ADDR = 0x100
const RED = Color(1, 0, 0, 1)
const GREEN = Color(0, 1, 0, 1)
var DEFAULT_ADDRESS: String = file.get_line() if file else '10.1.1.70'
var DEFAULT_PORT: String = file.get_line() if file else '50070'
var BASE_ADDR: int = int(file.get_line()) if file else 0x100
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],
[TableNode, TableNode, TableNode, TableNode, TableNode]]
const ROWS_BLOCK_DATA: Array = [
[TableNode, TableNode, TableNode, TableNode, TableNode]]
enum STATE {
WAIT, # Режим ожидания команды
READ, # Чтение из ИСА
WRITE, # ЗАпись в ИСА
}

View File

@@ -12,7 +12,7 @@ config_version=5
config/name="Plata-check.exe"
run/main_scene="res://Plata-check.tscn"
config/features=PackedStringArray("4.2", "GL Compatibility")
config/features=PackedStringArray("4.3", "GL Compatibility")
config/icon="res://icon.svg"
[autoload]
@@ -20,6 +20,10 @@ config/icon="res://icon.svg"
yau07="*res://yau07.gd"
Constants="*res://constants.gd"
[display]
window/size/viewport_height=448
[rendering]
renderer/rendering_method="gl_compatibility"

View File

@@ -13,10 +13,15 @@ class YaU07:
## Коды выполняемых команд
enum CmdCode {
READ_ISA = 0, ## Код команды "читать порт ISA" ячейки ЯУ-07
WRITE_ISA = 1, ## Код команды "записать порт ISA" ячейки ЯУ-07
READ_ISA = 0, ## Код команды "читать порт ISA" ячейки ЯУ-07
WRITE_ISA = 1, ## Код команды "записать порт ISA" ячейки ЯУ-07
ERASE_FLASH = 49, ## Код команды "стереть данные из FLASH" ячейки ЯУ-07
WRITE_FLASH = 50, ## Код команды "записать данные в FLASH" ячейки ЯУ-07
READ_FLASH = 51, ## Код команды "прочитать данные из FLASH" ячейки ЯУ-07
LOAD_FLASH = 52, ## Код команды "записать данные из FLASH в КЭМС" ячейки ЯУ-07
WRITE_FLASH_B = 55, ## Код команды "записать данные в FLASH" ячейки ЯУ-07Б
WRITE_BLOCK = 60, ## Код команды "записать блок данных ISA" внешней шины ячейки ЯУ-07
READ_BLOCK = 61, ## Код команды "читать блок данных ISA" внешней шины ячейки ЯУ-07
READ_BLOCK = 61, ## Код команды "читать блок данных ISA" внешней шины ячейки ЯУ-07
}
## Состояние автомата выполнения команды
@@ -40,6 +45,7 @@ class YaU07:
var cmd_result: = 1 ## Результат выполнения команды. Устанавливается в ЯУ-07
var cmd_data: = PackedByteArray() ## Данные команды. Устанавливается в ЯУ-07
var cmd_retry = 0 ## Счётчик оставшихся попыток выполнить команду
var cmd_code_rx = 0 ## Код последней выполненой команды
var tick = 0.0 ## Текущее тик-время в мс
var cmd_tick_tx = 0.0 ## Время последней отправки команды
var cmd_tick_rx = 0.0 ## Время последнего приёма команды
@@ -48,18 +54,18 @@ class YaU07:
var tx_len = 0 ## Длина последнего отправленного пакета
var isa_ports = {} ## Результат выполнения команды "читать порт"
var isa_block = {} ## Результат выполнения команды "читать массив из порта"
var flash_data: = PackedByteArray() ## Данные прочитанные из Flash
var flash_len: = 0 ## Длинна данных прочитанных из Flash
var online = false ## Состояние связи с ячейкой
func _to_string() -> String: return String('яу07: %s %s' % [self.name, ['отключен', 'на связи'][int(online)]])
func _init(nm):
self.name = nm
tx_data.resize(BUFFER_SIZE)
tx_data.fill(0)
tick = 0.0
func process(delta: float):
tick += delta
if online and ((tick - cmd_tick_rx) > ONLINE_TIMEOUT):
@@ -84,6 +90,40 @@ class YaU07:
rc = Error.FAILED
return rc
func send_flash(cmd_code: int, fl_data: Array, num_byte_rd: int) -> bool:
if (cmd_state == CmdState.WAIT) \
or (cmd_state == CmdState.SEND) \
or (cmd_state == CmdState.UNCK):
return false
if not ((cmd_code == CmdCode.ERASE_FLASH) or (cmd_code == CmdCode.WRITE_FLASH) \
or (cmd_code == CmdCode.READ_FLASH) or (cmd_code == CmdCode.LOAD_FLASH) or \
(cmd_code == CmdCode.WRITE_FLASH_B)):
return false
cmd_num_tx = (cmd_num_rx + 1) % 0xffff
tx_data.encode_u16(0, cmd_retry)
tx_data.encode_u16(2, cmd_num_tx)
tx_data.encode_u8(6, cmd_code)
if cmd_code == CmdCode.ERASE_FLASH:
tx_len = 7
elif cmd_code == CmdCode.WRITE_FLASH:
tx_data.encode_u8(7, 1)
tx_data.encode_u16(8, 0)
tx_data.encode_u16(10, len(fl_data))
tx_len = 11 + len(fl_data) * 2
for i in range(len(fl_data)):
tx_data.encode_u16(12 + i * 2, fl_data[i])
elif cmd_code == CmdCode.WRITE_FLASH_B:
tx_data.encode_u16(7, 0)
tx_data.encode_u16(9, len(fl_data))
tx_len = 11 + len(fl_data)
for i in range(len(fl_data)):
tx_data.encode_u8(11 + i, fl_data[i])
elif cmd_code == CmdCode.READ_FLASH:
tx_len = 11
tx_data.encode_u16(7, 0)
tx_data.encode_u16(9, num_byte_rd)
cmd_state = CmdState.SEND
return true
func send_isa(cmd_code: int, ports_data: Array) -> bool:
if (cmd_state == CmdState.WAIT) \
@@ -92,9 +132,7 @@ class YaU07:
return false
if not ((cmd_code == CmdCode.READ_ISA) or (cmd_code == CmdCode.WRITE_ISA)):
return false
cmd_num_tx = (cmd_num_rx + 1) % 0xffff
var ports_count = ports_data.size()
tx_len = ports_count * 2 + 8
tx_data.encode_u16(0, cmd_retry)
@@ -111,7 +149,7 @@ class YaU07:
i += 2
cmd_state = CmdState.SEND
return true
func send_block(cmd_code: int, block_len: int, port: Array) -> bool:
if (cmd_state == CmdState.WAIT) \
or (cmd_state == CmdState.SEND) \
@@ -129,11 +167,12 @@ class YaU07:
if cmd_code == CmdCode.WRITE_BLOCK:
block_len /= 2
tx_data[6] = cmd_code
tx_data.encode_u16(7, block_len)
tx_data.encode_u16(7, block_len)
tx_data.encode_u16(9, int(port[0]))
cmd_state = CmdState.SEND
return true
## Возвращает код команды ЯУ-07
## rx_data - Принятые данные
## Возвращает - Код команды не найден, 0...255 - код команды
@@ -150,7 +189,6 @@ class YaU07:
return null
return rx_data[cmd_code_pos] # "код команды"
func parse_isa(rx_data: PackedByteArray, status_len) -> bool:
var ports_count_pos = status_len + 10 # Положение в приёмном буфере количества портов
if rx_data.size() < ports_count_pos:
@@ -175,8 +213,6 @@ class YaU07:
var ports_count_pos = status_len + 7 # Положение в приёмном буфере количества портов
if rx_data.size() < ports_count_pos:
return false
var block_len = rx_data.decode_u16(ports_count_pos + 3)
var block_adr = rx_data.decode_u16(ports_count_pos + 5)
var block_data = []
@@ -185,7 +221,12 @@ class YaU07:
block_data.append(rx_data.decode_u16(ports_count_pos + 7 + shift))
isa_block[block_adr] = block_data
return true
func parse_flash(rx_data: PackedByteArray, status_len, cmd_code) -> bool:
if cmd_code == CmdCode.READ_FLASH:
flash_len = rx_data.decode_u16(status_len + 12)
flash_data = rx_data.slice(status_len + 14)
return true
## Заполняет состояние прибора данными прочитанными из портов ЯУ-07
## для команд "читать порты" или "записать порты"[br]
@@ -193,7 +234,7 @@ class YaU07:
## Возвращает [b]true[/b] - Данные обработаны успешно[br]
## Возвращает [b]false[/b] - Данные не обработаны из за ошибки[br]
func parse(rx_data: PackedByteArray) -> bool:
cmd_tick_rx = tick
if not online:
@@ -238,13 +279,18 @@ class YaU07:
var rc = true
if (cmd_code == CmdCode.READ_ISA) or (cmd_code == CmdCode.WRITE_ISA):
rc = parse_isa(rx_data, status_len)
elif (cmd_code == CmdCode.READ_BLOCK) or (cmd_code == CmdCode.WRITE_BLOCK):
rc = parse_block(rx_data, status_len)
elif (cmd_code == CmdCode.ERASE_FLASH) or (cmd_code == CmdCode.WRITE_FLASH) \
or (cmd_code == CmdCode.READ_FLASH) or (cmd_code == CmdCode.LOAD_FLASH):
rc = parse_flash(rx_data, status_len, cmd_code)
if rc:
if (cmd_state == CmdState.WAIT) and (cmd_num_rx == cmd_num_tx):
cmd_state = CmdState.DONE
cmd_code_rx = cmd_code
emit_signal('command_done', self)
else:
emit_signal('parse_failed', self)