Доработка машины состояния
This commit is contained in:
28
Main.gd
28
Main.gd
@@ -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):
|
||||
@@ -13,7 +11,7 @@ var timer = Timer.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 flag_wr_on_timer = false # Флаг для записи непрерывной
|
||||
@@ -23,10 +21,6 @@ var port_select: int = Constants.BASE_ADDR # Выбранный порд для
|
||||
var port: int
|
||||
var address: String
|
||||
var dt: float # Дельта
|
||||
var ROWS_REGS_DATA: Array = [
|
||||
[TableNode, TableNode, TableNode, TableNode, TableNode],
|
||||
[TableNode, TableNode, TableNode, TableNode, TableNode],
|
||||
[TableNode, TableNode, TableNode, TableNode, TableNode]]
|
||||
|
||||
|
||||
func _ready():
|
||||
@@ -34,7 +28,7 @@ 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-АДРЕС')
|
||||
@@ -59,7 +53,7 @@ func _ready():
|
||||
edit_node.connect('text_submitted', Callable(self, '_on_written_text_submitted'))
|
||||
|
||||
# Кнопка для включения
|
||||
$Turn_on.connect('toggled', Callable(self, '_on_button_pressed'))
|
||||
#$Turn_on.connect('toggled', Callable(self, '_on_button_pressed'))
|
||||
$read_ISA.disabled = true
|
||||
|
||||
# Поле для ввода (базовый порт)
|
||||
@@ -168,23 +162,23 @@ func on_command_done(_unit) -> void:
|
||||
|
||||
func state_machine() -> void:
|
||||
var fl_done = (unit.cmd_state == unit.CmdState.DONE) or (unit.cmd_state == unit.CmdState.FAIL)
|
||||
if state == 0 and fl_done:
|
||||
if state == Constants.STATE.WAIT and fl_done:
|
||||
node_select.set_node_text(3, 1, ' ПРОЧИТАНО ИЗ %x' % port_select)
|
||||
node_select.set_node_text(1, 1, ' ЗАПИСАТЬ В %x' % port_select)
|
||||
var nubre_from_port = '%x' % unit.isa_ports[port_select] if unit.isa_ports.has(port_select) else 'ffff'
|
||||
node_select.set_node_text(4, 1, nubre_from_port)
|
||||
$read_ISA.disabled = false
|
||||
state = 2 if flag_continuous else 0
|
||||
elif state == 1 and fl_done: ## Чтение из ИСА
|
||||
state = Constants.STATE.WRITE if flag_continuous else Constants.STATE.WAIT
|
||||
elif state == Constants.STATE.READ and fl_done: ## Чтение из ИСА
|
||||
unit.send_isa(unit.CmdCode.READ_ISA, [port_select])
|
||||
flag_continuous = false
|
||||
state = 2 if flag_wr_on_timer else 0
|
||||
elif state == 2 and fl_done: ## Запись в ИСА
|
||||
state = Constants.STATE.WRITE if flag_wr_on_timer else Constants.STATE.WAIT
|
||||
elif state == Constants.STATE.WRITE and fl_done: ## Запись в ИСА
|
||||
unit.send_isa(unit.CmdCode.WRITE_ISA, [port_select, ports_wr[port_select]])
|
||||
flag_wr_on_timer = false
|
||||
state = 1
|
||||
state = Constants.STATE.READ
|
||||
|
||||
|
||||
|
||||
## Выставить адресс для записи
|
||||
func _on_written_addres(write_addres) -> void:
|
||||
port_select = write_addres.hex_to_int()
|
||||
@@ -225,5 +219,5 @@ func _on_button_pressed(turn_on) -> void:
|
||||
|
||||
|
||||
func _on_button_read() -> void:
|
||||
state = 1
|
||||
state = Constants.STATE.READ
|
||||
|
||||
|
||||
62
Pla7AC5.tmp
Normal file
62
Pla7AC5.tmp
Normal 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"]
|
||||
@@ -33,19 +33,19 @@ metadata/_edit_lock_ = true
|
||||
[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")
|
||||
toggle_mode = true
|
||||
text = "Подключить"
|
||||
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_right = 1098.0
|
||||
offset_bottom = 124.0
|
||||
theme_override_styles/normal = SubResource("StyleBoxFlat_so1no")
|
||||
theme_override_styles/pressed = SubResource("StyleBoxFlat_jbuuq")
|
||||
@@ -59,4 +59,5 @@ offset_right = 999.0
|
||||
offset_bottom = 202.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"]
|
||||
|
||||
13
constants.gd
13
constants.gd
@@ -1,8 +1,17 @@
|
||||
extends Node
|
||||
|
||||
const TableNode = preload("res://table/node.tscn")
|
||||
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_PORT: String = '50052'
|
||||
const BASE_ADDR: int = 0x100
|
||||
const ROWS_REGS_DATA: Array = [
|
||||
[TableNode, TableNode, TableNode, TableNode, TableNode],
|
||||
[TableNode, TableNode, TableNode, TableNode, TableNode],
|
||||
[TableNode, TableNode, TableNode, TableNode, TableNode]]
|
||||
enum STATE {
|
||||
WAIT, # Режим ожидания команды
|
||||
READ, # Чтение из ИСА
|
||||
WRITE, # ЗАпись в ИСА
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user