Доработка. Проверка данных СПТ-25

This commit is contained in:
sasha80
2025-03-26 13:58:41 +03:00
parent e023fa9960
commit e9aa5408b0

View File

@@ -5,6 +5,12 @@ const REQUEST_PERIOD: int = 3000 ## Переиод запроса, мс
class SPT25 extends unit.Unit:
enum CmdCode {
START = 0,
STOP = 2,
INFO = 4,
}
func _to_string() -> String: return String('СПТ-25 %s %s' % [self.name, ['отключен', 'на связи'][int(online)]])
func _init(nm) -> void:
@@ -22,12 +28,18 @@ class SPT25 extends unit.Unit:
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
if rx_data[0] != 0x7e:
emit_signal('parse_failed', self)
return
if not (rx_data[2] in [CmdCode.START, CmdCode.STOP, CmdCode.INFO]):
emit_signal('parse_failed', self)
return
if not online:
online = true
emit_signal('line_changed', self)
emit_signal('data_received', rx_data)