From 716737427b591986d054a2c68d5083b4dca216b6 Mon Sep 17 00:00:00 2001 From: semuadmin <28569967+semuadmin@users.noreply.github.com> Date: Tue, 4 Jun 2024 18:48:00 +0100 Subject: [PATCH] add ALN-ENUM --- examples/benchmark.py | 2 +- src/pyspartn/spartnreader.py | 14 ++------------ src/pyspartn/spartntables.py | 2 ++ 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/examples/benchmark.py b/examples/benchmark.py index 68e972f..61cbeb8 100644 --- a/examples/benchmark.py +++ b/examples/benchmark.py @@ -19,7 +19,7 @@ from time import process_time_ns from pyspartn import SPARTNReader -from pyspartn import _version as spartnver +from pyspartn import version as spartnver KEY = "930d847b779b126863c8b3b2766ae7cc" BASEDATE = datetime(2024, 4, 18, 20, 48, 29, 977255) diff --git a/src/pyspartn/spartnreader.py b/src/pyspartn/spartnreader.py index 07fa461..b99678c 100644 --- a/src/pyspartn/spartnreader.py +++ b/src/pyspartn/spartnreader.py @@ -57,6 +57,7 @@ from pyspartn.socket_stream import SocketStream from pyspartn.spartnhelpers import bitsval, naive2aware, timetag2date, valid_crc from pyspartn.spartnmessage import SPARTNMessage +from pyspartn.spartntables import ALN_ENUM from pyspartn.spartntypes_core import ERRLOG, ERRRAISE, SPARTN_PREB, VALCRC @@ -212,18 +213,7 @@ def _parse_spartn(self, preamble: bytes) -> tuple: payload = self._read_bytes(nData) embAuth = b"" if authInd > 1: - if embAuthLen == 0: - aln = 8 - elif embAuthLen == 1: - aln = 12 - elif embAuthLen == 2: - aln = 16 - elif embAuthLen == 3: - aln = 32 - elif embAuthLen == 4: - aln = 64 - else: - aln = 0 + aln = ALN_ENUM.get(embAuthLen, 0) embAuth = self._read_bytes(aln) crcb = self._read_bytes(crcType + 1) crc = int.from_bytes(crcb, "big") diff --git a/src/pyspartn/spartntables.py b/src/pyspartn/spartntables.py index 05b2b95..b5f4c98 100644 --- a/src/pyspartn/spartntables.py +++ b/src/pyspartn/spartntables.py @@ -156,6 +156,8 @@ ), } +ALN_ENUM = {0: 8, 1: 12, 2: 16, 3: 32, 4: 64} + SF015_ENUM = SF022_ENUM = { 0: "0 secs", 1: "1 secs",