fs is connect
This commit is contained in:
@@ -505,9 +505,9 @@ metadata/_edit_lock_ = true
|
||||
|
||||
[node name="kasseta_fs_kd" parent="TabContainer/ControlPanel" instance=ExtResource("10_tdh2s")]
|
||||
layout_mode = 0
|
||||
offset_left = 206.0
|
||||
offset_left = 297.0
|
||||
offset_top = 311.0
|
||||
offset_right = 516.0
|
||||
offset_right = 515.0
|
||||
offset_bottom = 538.0
|
||||
script = null
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
[node name="kasseta_fs_kd" type="NinePatchRect"]
|
||||
offset_top = -32.0
|
||||
offset_right = 310.0
|
||||
offset_right = 218.0
|
||||
offset_bottom = 190.0
|
||||
texture = ExtResource("1_1jljp")
|
||||
patch_margin_left = 16
|
||||
@@ -21,61 +21,43 @@ self_modulate = Color(1, 1, 1, 0.62)
|
||||
layout_mode = 0
|
||||
offset_left = 5.0
|
||||
offset_top = 7.0
|
||||
offset_right = 303.0
|
||||
offset_right = 218.0
|
||||
offset_bottom = 33.0
|
||||
text = "Кассета"
|
||||
text = "Кассета ФС"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="ref_A2" parent="." instance=ExtResource("3_kqnvt")]
|
||||
offset_left = 5.0
|
||||
offset_top = 39.0
|
||||
offset_right = 55.0
|
||||
offset_bottom = 215.0
|
||||
self_size = Vector2i(50, 176)
|
||||
fname = "Модуль ФС"
|
||||
rname = "A1"
|
||||
|
||||
[node name="ref_A3" parent="." instance=ExtResource("3_kqnvt")]
|
||||
offset_left = 55.0
|
||||
offset_top = 39.0
|
||||
offset_right = 105.0
|
||||
offset_bottom = 215.0
|
||||
self_size = Vector2i(50, 176)
|
||||
fname = "Блок ФС-1"
|
||||
rname = "A4"
|
||||
|
||||
[node name="ref_A4" parent="." instance=ExtResource("3_kqnvt")]
|
||||
offset_left = 105.0
|
||||
offset_left = 9.0
|
||||
offset_top = 39.0
|
||||
offset_right = 155.0
|
||||
offset_right = 59.0
|
||||
offset_bottom = 215.0
|
||||
self_size = Vector2i(50, 176)
|
||||
fname = "Модуль ФС"
|
||||
rname = "A2"
|
||||
|
||||
[node name="ref_A6" parent="." instance=ExtResource("3_kqnvt")]
|
||||
offset_left = 155.0
|
||||
offset_left = 59.0
|
||||
offset_top = 39.0
|
||||
offset_right = 205.0
|
||||
offset_right = 109.0
|
||||
offset_bottom = 215.0
|
||||
self_size = Vector2i(50, 176)
|
||||
fname = "Блок ФС-6"
|
||||
rname = "A5"
|
||||
|
||||
[node name="ref_A5" parent="." instance=ExtResource("3_kqnvt")]
|
||||
offset_left = 205.0
|
||||
offset_left = 109.0
|
||||
offset_top = 39.0
|
||||
offset_right = 255.0
|
||||
offset_right = 159.0
|
||||
offset_bottom = 215.0
|
||||
self_size = Vector2i(50, 176)
|
||||
fname = "Модуль ФС"
|
||||
rname = "A3"
|
||||
|
||||
[node name="ref_A7" parent="." instance=ExtResource("3_kqnvt")]
|
||||
offset_left = 255.0
|
||||
offset_left = 159.0
|
||||
offset_top = 39.0
|
||||
offset_right = 305.0
|
||||
offset_right = 209.0
|
||||
offset_bottom = 215.0
|
||||
self_size = Vector2i(50, 176)
|
||||
fname = "Блок ФС-2"
|
||||
|
||||
@@ -37,7 +37,7 @@ class Socket extends PacketPeerUDP:
|
||||
self.put_packet(data)
|
||||
|
||||
|
||||
func poll_receive(sock: Socket) -> bool: ## Приёмник
|
||||
func poll_receive_yau07(sock: Socket) -> bool: ## Приёмник
|
||||
if timeout - last_update_time > 0:
|
||||
while sock.get_available_packet_count() > 0:
|
||||
broadcast_packet = sock.get_packet()
|
||||
@@ -55,17 +55,25 @@ func poll_receive(sock: Socket) -> bool: ## Приёмник
|
||||
return false
|
||||
|
||||
|
||||
func work_proc():
|
||||
client_fs_1.poll()
|
||||
func poll_receive_fs(client: StreamPeerTCP):
|
||||
client.poll()
|
||||
var peer = peerstream.get_stream_peer()
|
||||
# Проверяем, существует ли соединение
|
||||
if not peer:
|
||||
emit_signal("port_error", ip_fs_1)
|
||||
return
|
||||
var peer_len_data = peer.get_available_bytes()
|
||||
if peer_len_data > 0:
|
||||
emit_signal("port_opened", ip_fs_1) # Эмитируем сигнал об открытии порта
|
||||
get_data_fs(peer)
|
||||
else:
|
||||
pass
|
||||
# Проверяем состояние подключения
|
||||
if client.get_status() != StreamPeerTCP.STATUS_CONNECTED:
|
||||
emit_signal("port_closed", ip_fs_1)
|
||||
return
|
||||
|
||||
if peer.get_available_bytes() > 0:
|
||||
var rx_data: PackedByteArray
|
||||
rx_data.append_array(peer.get_data(peer.get_available_bytes())[1])
|
||||
emit_signal("data_received", rx_data)
|
||||
emit_signal("port_opened", ip_fs_1)
|
||||
if state_fs == Constants.STATE.SEND:
|
||||
state_fs = Constants.STATE.DONE
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -79,26 +87,24 @@ func _ready() -> void:
|
||||
rc = soc_unicast.bind(Constants.UNICAST_PORT, Constants.UNICAST_ADDRESS)
|
||||
if rc != OK:
|
||||
print_debug('Ошибка: неудачная привязка адреса: ', ip_address_yau)
|
||||
|
||||
|
||||
unit.connect('line_changed', Callable(self, 'on_line_changed'))
|
||||
unit.connect('command_fail', Callable(self, 'on_command_fail'))
|
||||
connect_fs()
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if client_fs_1:
|
||||
## State fs machine
|
||||
if (state_fs == Constants.STATE.IDLE) or (state_fs == Constants.STATE.DONE):
|
||||
if command_stack:
|
||||
var pack = command_stack.pop_front()
|
||||
send_data(pack)
|
||||
state_fs = Constants.STATE.SEND
|
||||
work_proc()
|
||||
|
||||
|
||||
last_update_time += delta
|
||||
poll_receive(soc_brodcast)
|
||||
poll_receive(soc_unicast)
|
||||
if client_fs_1:
|
||||
poll_receive_fs(client_fs_1)
|
||||
|
||||
poll_receive_yau07(soc_brodcast)
|
||||
poll_receive_yau07(soc_unicast)
|
||||
|
||||
state_machine_yau07()
|
||||
state_machine_fs()
|
||||
|
||||
match unit.process(delta):
|
||||
Error.OK: soc_unicast.send_to(ip_address_yau, ip_port_yau, unit.tx_data.slice(0, unit.tx_len))
|
||||
Error.FAILED: print_debug('Ошибка отправки данных')
|
||||
@@ -159,8 +165,21 @@ func on_command_change_device(meta_device):
|
||||
connect_fs()
|
||||
|
||||
|
||||
func state_machine_fs():
|
||||
if client_fs_1:
|
||||
## State fs machine
|
||||
if (state_fs == Constants.STATE.IDLE) or (state_fs == Constants.STATE.DONE):
|
||||
if command_stack:
|
||||
var pack = command_stack.pop_front()
|
||||
send_data(pack)
|
||||
state_fs = Constants.STATE.SEND
|
||||
|
||||
|
||||
# Подключится к модулю ФС
|
||||
func connect_fs():
|
||||
if client_fs_1:
|
||||
disconnect_fs(client_fs_1)
|
||||
|
||||
client_fs_1 = StreamPeerTCP.new()
|
||||
peerstream = PacketPeerStream.new()
|
||||
var rc = client_fs_1.connect_to_host(ip_fs_1, Constants.PORT_FS)
|
||||
@@ -170,17 +189,6 @@ func connect_fs():
|
||||
peerstream.set_stream_peer(client_fs_1)
|
||||
|
||||
|
||||
# Получить данные от ФС
|
||||
func get_data_fs(peer):
|
||||
var rx_data: PackedByteArray
|
||||
var len_data_in_buf = peer.get_available_bytes()
|
||||
if len_data_in_buf > 0:
|
||||
rx_data.append_array(peer.get_data(len_data_in_buf)[1])
|
||||
emit_signal("data_received", rx_data)
|
||||
if state_fs == Constants.STATE.SEND:
|
||||
state_fs = Constants.STATE.DONE
|
||||
|
||||
|
||||
# Отправить команду для ФС
|
||||
func send_data(data_to_sand):
|
||||
if client_fs_1.get_status() == 2:
|
||||
@@ -191,7 +199,8 @@ func send_data(data_to_sand):
|
||||
|
||||
|
||||
# Разорвать соединение с ФС
|
||||
#func disconnect_fs():
|
||||
#client_fs_1.disconnect_from_host()
|
||||
#state_fs = Constants.STATE.IDLE
|
||||
#peerstream = PacketPeerStream.new()
|
||||
func disconnect_fs(client_for_leave):
|
||||
client_for_leave.disconnect_from_host()
|
||||
state_fs = Constants.STATE.IDLE
|
||||
command_stack = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user