Files
uarep-ctl/scripts/yemstg.gd

39 lines
1.4 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

extends Node
class YeMSTG extends unit.Unit:
static var json_conv: = JSON.new()
var online_timeout: float = 5000 ## Должен быть равен наибольшему времени дотоверности из всех кластеров
var info: = Dictionary() ## Доклад о состоянии
var cmd: = Dictionary() ## Команда
var cnt: int = 0 ## Счётчик отправленных пакетов
func _init(unit_name) -> void:
super._init(unit_name)
cmd_state = CmdState.DONE
func parse(data: PackedByteArray, now_tick: int):
self.rx_tick = now_tick
if not online:
online = true
emit_signal('line_changed', self)
var utf8_data: = data.get_string_from_utf8()
if Error.OK == json_conv.parse(utf8_data):
info.merge(json_conv.get_data(), true)
emit_signal('data_received', info)
else:
var msg: = json_conv.get_error_message()
emit_signal('parse_error', self, msg)
func process(now_tick: int):
if online and ((now_tick - rx_tick) > online_timeout):
online = false
emit_signal('line_changed', self)
var rc = Error.ERR_BUSY
if cmd_state == CmdState.SEND:
tx_data = JSON.stringify(cmd).to_utf8_buffer()
tx_len = tx_data.size()
cmd_state = CmdState.DONE
rc = Error.OK
return rc