спт25 контрольная сумма

This commit is contained in:
Maxim
2025-09-01 13:22:05 +03:00
parent cd23da9a2d
commit 5dd4a684ce

View File

@@ -13,6 +13,32 @@ class SPT25 extends unit.Unit:
func _to_string() -> String: return String('СПТ-25 %s %s' % [self.name, ['отключен', 'на связи'][int(online)]])
##Вычисление контрольной суммы
func sciCalcFCS(src: PackedByteArray) -> int:
var P_DIV = 0
var ln = src[0]
var FCS = ~((src[2]<<8) + src[1])
for i in range(3, ln):
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 _init(nm) -> void:
self.name = nm
tx_data.resize(8)