fs is connect
This commit is contained in:
@@ -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