Доработка. Контрольная сумма для СПТ-25

This commit is contained in:
sasha80
2025-08-29 10:10:53 +03:00
parent 5fee396387
commit 6b24cd713c

View File

@@ -21,6 +21,31 @@ class Spt25Serial extends SerialPort:
func _to_string() -> String: return 'последовательный порт \"%s\" @ %d (%s)' % [self.port, self.baudrate, 'открыт' if is_open() else 'закрыт']
func get_check_sum(src: PackedByteArray) -> int:
var P_DIV: = 0xF0B8
var FCS = ~((src[2]<<8) + src[1])
for i in range(3, src.size()):
var C = src[i]
for j in 8:
if C & 1:
if FCS & 1:
FCS = ((FCS >> 1) | 0x8000) ^ P_DIV
else:
FCS = ((FCS >> 1) | 0x8000)
else:
if FCS & 1:
FCS = (FCS >> 1) ^ P_DIV
else:
FCS = FCS >> 1
C >>= 1
for j in 16:
if FCS & 1:
FCS = (FCS >> 1) ^ P_DIV
else:
FCS = FCS >> 1
return ~FCS
func try_open(parsing_proc: Callable):
if is_open():
return Error.OK