add isa write and read func to network.gd
This commit is contained in:
@@ -2,7 +2,6 @@ extends Node2D
|
||||
|
||||
signal read_ems_g_start()
|
||||
signal read_ems_g_finish()
|
||||
#var unit = Yau07.YaU07.new('ЯУ07')
|
||||
var flag_mode = Constants.ADDRESSES[0][3]
|
||||
var broadcast_packet: PackedByteArray
|
||||
var node_select1: Node
|
||||
@@ -56,9 +55,8 @@ func _on_yau_status(yau_status):
|
||||
else:
|
||||
$TabContainer/ControlPanel/sockets/ref_A26/light_ind.button_pressed = false
|
||||
$TabContainer/ControlPanel/sockets/ref_A26/light_ind.disabled = true
|
||||
for dev in (Constants.CONTROL_DEVICE.size() - 1):
|
||||
var node_board = $TabContainer/ControlPanel/control_tbl.get_node2(0, dev+1)
|
||||
node_board.modulate = Color.RED
|
||||
#for dev in (Constants.CONTROL_DEVICE.size() - 1):
|
||||
|
||||
flag_yau_control = false
|
||||
|
||||
|
||||
@@ -201,13 +199,10 @@ func fill_item(node, i_column: int, i_row: int, arr: Dictionary, select: int = 0
|
||||
|
||||
|
||||
func _on_zapret(toggled_on: bool, meta) -> void:
|
||||
var ports_wr: Dictionary = {0x122 : meta.get_meta('litera')} ## СИ2, СИ4, СИ6 = 0x30, СИ3, СИ5, СИ7 = 0x31, СИ1 = 0x2F
|
||||
Network.send_array.append(ports_wr)
|
||||
|
||||
ports_wr = {}
|
||||
ports_wr[0x128] = 0x4000 if toggled_on else 0x0
|
||||
Network.send_array.append(ports_wr)
|
||||
Network.write_port_isa(Constants.EMS_G_BASE_ADDR+2, meta.get_meta('litera'))
|
||||
var zapret_mode = 0x4000 if toggled_on else 0x0
|
||||
Network.write_port_isa(Constants.EMS_G_BASE_ADDR+8, zapret_mode)
|
||||
|
||||
|
||||
func _on_read_isa_pressed() -> void:
|
||||
Network.send_array.append(['rd', [0x122, 0x124, 0x128]])
|
||||
Network.read_port_isa([0x122, 0x124, 0x128])
|
||||
|
||||
@@ -14,7 +14,6 @@ const TableList = preload("res://table/node_list.tscn")
|
||||
const Switch = preload("res://table/switch.tscn")
|
||||
const SocketStatus = preload("res://table/socket_status.tscn")
|
||||
const SELECT_DEVICE: Array = [[TableNode, TableList]]
|
||||
const CONTROL_DEVICE: Array = ['ЯЧЕЙКА ЯУ-07Б', 'ФС', 'ЯЧЕЙКА ЭМС-Г', 'ЯЧЕЙКА УГ', 'ЯЧЕЙКА УКП №1', 'ЯЧЕЙКА УКП №2', 'ИП МАА №1', 'ИП МАА №2', 'ИП9-50 №1', 'ИП9-50 №2', 'ИП12-50 №1', '-', '-','ИП5-25', 'Х3:2(СЗИ2 от УФ)', 'Х3:19(СИ2 от ФС)', 'Х3:11(СИ2 в УФ)', 'Х3:14(Модуляция)', 'Х3:27(ФГОЗ)']
|
||||
const ROWS_REGS_DATA: Array = [
|
||||
[TableNode, TableNode],
|
||||
[TableNode, TableNode],
|
||||
@@ -48,12 +47,6 @@ const ADDRESSES: Array = [
|
||||
['ПРД-К2', '10.1.1.23', 50023, MODE.PRD_K],
|
||||
['ПРД-К3', '10.1.1.33', 50033, MODE.PRD_K],
|
||||
['ПРД-К4', '10.1.1.43', 50043, MODE.PRD_K]]
|
||||
const EMS_G_CONTROL_PANEL: Array = [
|
||||
['Нет Х3:2(СЗИ2 от УФ)', 'Есть Х3:2(СЗИ2 от УФ)'],
|
||||
['Нет Х3:19(СИ2 от ФС)', 'Есть Х3:19(СИ2 от ФС)'],
|
||||
['Нет Х3:11(СИ2 в УФ)', 'Есть Х3:11(СИ2 в УФ)'],
|
||||
['Нет Х3:14(Модуляция)', 'Есть Х3:14(Модуляция)'],
|
||||
['Нет Х3:27(ФГОЗ)', 'Есть Х3:27(ФГОЗ)']]
|
||||
const INPUT_EMS_G: Array = [
|
||||
'01 :34',
|
||||
'02 :35',
|
||||
|
||||
@@ -3,8 +3,8 @@ extends Node
|
||||
var unit = Yau07.YaU07.new('ЯУ07')
|
||||
var soc_unicast: Socket
|
||||
var soc_brodcast: Socket
|
||||
var address: String = Constants.ADDRESSES[0][1]
|
||||
var port: int = Constants.ADDRESSES[0][2]
|
||||
var ip_address: String = Constants.ADDRESSES[0][1]
|
||||
var ip_port: int = Constants.ADDRESSES[0][2]
|
||||
var timeout: float = Yau07.ONLINE_TIMEOUT
|
||||
var last_update_time: float = 0.0
|
||||
var broadcast_packet: PackedByteArray
|
||||
@@ -30,7 +30,7 @@ func poll_receive(sock: Socket) -> bool: ## Приёмник
|
||||
var addr_receive = sock.get_packet_ip()
|
||||
var port_receive = sock.get_packet_port()
|
||||
|
||||
if (address == addr_receive) and (port == port_receive):
|
||||
if (ip_address == addr_receive) and (ip_port == port_receive):
|
||||
last_update_time = 0.0
|
||||
unit.parse(broadcast_packet)
|
||||
var data_from_yau_07 = unit.status
|
||||
@@ -41,18 +41,17 @@ func poll_receive(sock: Socket) -> bool: ## Приёмник
|
||||
return false
|
||||
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
# Привязка для принятия широковещательного канала
|
||||
soc_brodcast = Socket.new()
|
||||
var rc = soc_brodcast.bind(Constants.BROADCAST_PORT, '*')
|
||||
if rc != OK:
|
||||
print('Ошибка: Неудачная привязка широковещательного адреса')
|
||||
print_debug('Ошибка: Неудачная привязка широковещательного адреса')
|
||||
|
||||
soc_unicast = Socket.new()
|
||||
rc = soc_unicast.bind(Constants.UNICAST_PORT, Constants.UNICAST_ADDRESS)
|
||||
if rc != OK:
|
||||
print('Ошибка: неудачная привязка адреса: ', address)
|
||||
print_debug('Ошибка: неудачная привязка адреса: ', ip_address)
|
||||
|
||||
unit.connect('line_changed', Callable(self, 'on_line_changed'))
|
||||
unit.connect('command_fail', Callable(self, 'on_command_fail'))
|
||||
@@ -64,32 +63,45 @@ func _process(delta: float) -> void:
|
||||
poll_receive(soc_unicast)
|
||||
state_machine()
|
||||
match unit.process(delta):
|
||||
Error.OK: soc_unicast.send_to(address, port, unit.tx_data.slice(0, unit.tx_len))
|
||||
Error.FAILED: print('Ошибка отправки данных')
|
||||
Error.OK: soc_unicast.send_to(ip_address, ip_port, unit.tx_data.slice(0, unit.tx_len))
|
||||
Error.FAILED: print_debug('Ошибка отправки данных')
|
||||
|
||||
|
||||
func state_machine():
|
||||
var fl_done = (unit.cmd_state == unit.CmdState.DONE)
|
||||
## Режим ожидания
|
||||
if state == Constants.STATE.WAIT and fl_done:
|
||||
if send_array.size():
|
||||
state = Constants.STATE.READ_ISA if send_array[0][0] == 'rd' else Constants.STATE.WRITE_ISA
|
||||
## Режим чтения из ИСА
|
||||
elif state == Constants.STATE.READ_ISA and fl_done:
|
||||
var ports_read = send_array.pop_front()
|
||||
unit.send_isa(unit.CmdCode.READ_ISA, ports_read[1])
|
||||
state = Constants.STATE.DONE
|
||||
## Режим записи в ИСА
|
||||
elif state == Constants.STATE.WRITE_ISA and fl_done:
|
||||
var ports_write = send_array.pop_front()
|
||||
var key = ports_write[1].keys()
|
||||
unit.send_isa(unit.CmdCode.WRITE_ISA, [key[0], ports_write[1][key[0]]])
|
||||
state = Constants.STATE.WAIT
|
||||
elif state == Constants.STATE.DONE and fl_done:
|
||||
emit_signal('yau_read_isa', unit.isa_ports)
|
||||
state = Constants.STATE.WAIT
|
||||
match state:
|
||||
Constants.STATE.WAIT:
|
||||
if fl_done and send_array.size():
|
||||
state = Constants.STATE.READ_ISA if send_array[0][0] == 'rd' else Constants.STATE.WRITE_ISA
|
||||
## Режим чтения из ИСА
|
||||
Constants.STATE.READ_ISA:
|
||||
if fl_done:
|
||||
var ports_read = send_array.pop_front()
|
||||
unit.send_isa(unit.CmdCode.READ_ISA, ports_read[1])
|
||||
state = Constants.STATE.DONE
|
||||
## Режим записи в ИСА
|
||||
Constants.STATE.WRITE_ISA:
|
||||
if fl_done:
|
||||
var ports_write = send_array.pop_front()
|
||||
var key = ports_write[1].keys()
|
||||
unit.send_isa(unit.CmdCode.WRITE_ISA, [key[0], ports_write[1][key[0]]])
|
||||
state = Constants.STATE.WAIT
|
||||
Constants.STATE.DONE:
|
||||
if fl_done:
|
||||
emit_signal('yau_read_isa', unit.isa_ports)
|
||||
state = Constants.STATE.WAIT
|
||||
|
||||
|
||||
func read_port_isa(read_ports: Array) -> void:
|
||||
send_array.append(['rd', read_ports])
|
||||
|
||||
|
||||
func write_port_isa(port_isa: int, data_isa: int) -> void:
|
||||
var write_data: Dictionary = {port_isa: data_isa}
|
||||
send_array.append(['wr', write_data])
|
||||
|
||||
|
||||
func on_line_changed(_unit) -> void:
|
||||
emit_signal('yau_status_line', unit.online)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user