From 1c17ec96aaf2feec74d57b6dbf7577b73c84243e Mon Sep 17 00:00:00 2001 From: Rainer Staude Date: Thu, 29 Dec 2022 18:39:41 +0100 Subject: [PATCH] extend debug output --- pybecker/becker_helper.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pybecker/becker_helper.py b/pybecker/becker_helper.py index 6dee924..90e4be4 100644 --- a/pybecker/becker_helper.py +++ b/pybecker/becker_helper.py @@ -1,3 +1,4 @@ +"""Helper for Becker centronic USB Stick.""" import logging import re import time @@ -28,26 +29,29 @@ + rb'[0-9A-F]{6,6}' + rb'(?P[0-9A-F]{1,1})' + rb'00' - + rb'(?P[124]{1,1})' # HALT, UP, DOWN + + rb'(?P[0-9A-F]{1,1})' + rb'(?P[0-9A-F]{1,1})' + rb'[0-9A-F]{2,2}' + ETX, re.I ) -COMMANDS = {b'1': 'HALT', b'2': 'UP', b'4': 'DOWN'} +COMMANDS = {b'0': 'RELEASE', b'1': 'HALT', b'2': 'UP', b'4': 'DOWN', b'8': 'TRAIN'} _LOGGER = logging.getLogger(__name__) def hex2(n): + """Return word""" return '%02X' % (n & 0xFF) def hex4(n): + """Return dword""" return '%04X' % (n & 0xFFFF) def checksum(code): + """Calculate checksum""" code_length = len(code) if code_length != 40: _LOGGER.error("The code must be 40 characters long (without , and checksum)") @@ -62,6 +66,7 @@ def checksum(code): def generate_code(channel, unit, cmd_code, with_checksum=True): + """Generate code""" unit_id = unit[0] # contains the unit code in hex (5 chars) unit_inc = unit[1] # contains the next increment (required to convert into hex4) @@ -75,10 +80,12 @@ def generate_code(channel, unit, cmd_code, with_checksum=True): return checksum(code) if with_checksum else code def finalize_code(code): + """Add frame""" return b"".join([STX, code.encode(), ETX]) class BeckerConnectionError(Exception): + """Error class for Becker centronic USB Stick.""" pass