Fix TA decoding for shorter sequences

Этот коммит содержится в:
Alexander UR6LKW
2025-06-01 01:02:12 +03:00
родитель 07aa4efb2d
Коммит fa6399b0e6
2 изменённых файлов: 22 добавлений и 11 удалений
+2
Просмотреть файл
@@ -178,6 +178,8 @@ class LCTalkerAlias(LCBase):
return bytes(self._data[2:9]) return bytes(self._data[2:9])
def __str__(self) -> str: def __str__(self) -> str:
if self.flco != 0x04:
return (f"LC TA {self.flco} data:{self.ta_data.hex()}")
return (f"LC TA {self.flco} fmt:{self.format.name} " return (f"LC TA {self.flco} fmt:{self.format.name} "
f"len:{self.len} data:{self.ta_data.hex()}") f"len:{self.len} data:{self.ta_data.hex()}")
+20 -11
Просмотреть файл
@@ -116,29 +116,38 @@ class CallLCDecoder:
@property @property
def ta(self) -> str|None: def ta(self) -> str|None:
# check if all parts are collected and are instances of LCTalkerAlias return self.get_ta()
if any((flco not in self.lcs or
type(self.lcs[flco]) is not LCTalkerAlias) def get_ta(self, partial: bool = False) -> str|None:
for flco in LCTalkerAlias.FLCOS): # check if first part of TA part collected
if LCTalkerAlias.FLCOS[0] not in self.lcs:
return None return None
lcta0: LCTalkerAlias = self.lcs[LCTalkerAlias.FLCOS[0]] # type: ignore[assignment] lcta0 = self.lcs[LCTalkerAlias.FLCOS[0]]
if type(lcta0) is not LCTalkerAlias:
return None
# collect all datas
ta_data: bytes = b"" ta_data: bytes = b""
for flco in LCTalkerAlias.FLCOS: for flco in LCTalkerAlias.FLCOS:
if type(lc := self.lcs[flco]) is LCTalkerAlias: if flco in self.lcs and type(lc := self.lcs[flco]) is LCTalkerAlias:
ta_data += lc.ta_data ta_data += lc.ta_data
ta_len = lcta0.len ta_len = lcta0.len
encoding = "utf-8"
match lcta0.format: match lcta0.format:
case LCTalkerAlias.Format._7BIT: case LCTalkerAlias.Format._7BIT:
return "" # Not supported; !!TODO: decode 7-bit return None # Not supported; !!TODO: decode 7-bit
case LCTalkerAlias.Format.ISO8: case LCTalkerAlias.Format.ISO8:
return ta_data.decode("iso-8859-1", errors='replace')[:ta_len] encoding = "iso-8859-1"
case LCTalkerAlias.Format.UTF8: case LCTalkerAlias.Format.UTF8:
return ta_data.decode("utf-8", errors='replace')[:ta_len] encoding = "utf-8"
case LCTalkerAlias.Format.UTF16BE: case LCTalkerAlias.Format.UTF16BE:
return ta_data.decode("utf-16-be", errors='replace')[:ta_len] encoding = "utf-16-be"
return None ta_str = ta_data.decode(encoding=encoding, errors='replace')
if len(ta_str) < ta_len: # not collected all TA LCs yet
return ta_str if partial else None
return ta_str[:ta_len]