Files
uarep-ctl/scripts/spt25.gd

44 lines
1.7 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.

class_name spt25_unit extends Node
const ONLINE_TIMEOUT: int = 5000 ## Время ожидания данных
const REQUEST_PERIOD: int = 3000 ## Переиод запроса, мс
class SPT25 extends unit.Unit:
func _to_string() -> String: return String('СПТ-25 %s %s' % [self.name, ['отключен', 'на связи'][int(online)]])
func _init(nm) -> void:
self.name = nm
tx_data.resize(8)
tx_data[0] = 0x7e # Флаги синхронизации пакета
tx_data[1] = 0 # Адрес абонента, которому предназначен пакет
tx_data[2] = 4 # Тип пакета, КОД КОМАНДЫ - Получить информацию о состоянии преобразователя
tx_data[3] = 0 # Данные
tx_data[4] = 0 # Данные
tx_data[5] = 0 # Данные
tx_data[6] = 0 # Контрольная сумма
tx_data[7] = 0x7e # Флаги синхронизации пакета
func parse(rx_data: PackedByteArray, tick: int):
rx_tick = tick
if not online:
online = true
emit_signal('line_changed', self)
if rx_data.size() <= 6:
emit_signal('parse_failed', self)
return
emit_signal('data_received', rx_data)
func process(tick: int):
var rc: = Error.ERR_BUSY
if (tick - tx_tick) > REQUEST_PERIOD:
tx_tick = tick
rc = Error.OK
if online:
if (tick - rx_tick) > ONLINE_TIMEOUT:
online = false
emit_signal('line_changed', self)
return rc