From 090b66a2da55f45b0bd56f4264f14b61655a9044 Mon Sep 17 00:00:00 2001 From: gwillgues Date: Sat, 4 May 2024 14:42:38 -0500 Subject: [PATCH 1/5] Fix truncation of last character of VIN number by modifying decode_encoded_string function to use .replace() instead of .strip() --- obd/decoders.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/obd/decoders.py b/obd/decoders.py index fffca50a..4a7c5e3b 100644 --- a/obd/decoders.py +++ b/obd/decoders.py @@ -505,7 +505,8 @@ def decode_encoded_string(messages, length): # Encoded strings come in bundles of messages with leading null values to # pad out the string to the next full message size. We strip off the # leading null characters here and return the resulting string. - return d.strip().strip(b'\x00' b'\x01' b'\x02' b'\\x00' b'\\x01' b'\\x02') + decoded_string = d.strip().replace(b'\x00', b'').replace(b'\x01', b'').replace(b'\x02', b'').replace(b'\\x00', b'').replace(b'\\x01', b'').replace(b'\\x02', b'') + return decoded_string def cvn(messages): From 05514fc96c3ea92196078928fb91d94b02ede3f3 Mon Sep 17 00:00:00 2001 From: gwillgues Date: Sat, 4 May 2024 15:27:58 -0500 Subject: [PATCH 2/5] Add environment variable logging verbosity support via DEBUG env var --- obd/__init__.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/obd/__init__.py b/obd/__init__.py index 5002708b..67a56e60 100644 --- a/obd/__init__.py +++ b/obd/__init__.py @@ -46,11 +46,20 @@ from .protocols import ECU from .utils import scan_serial, OBDStatus from .UnitsAndScaling import Unit - +import os import logging +def getenv(key:str, default=0): return type(default)(os.getenv(key, default)) + logger = logging.getLogger(__name__) -logger.setLevel(logging.WARNING) +DEBUG = getenv("DEBUG", 0) +if DEBUG == 1: + logger.setLevel(logging.INFO) +elif DEBUG == 2: + logger.setLevel(logging.DEBUG) +else: + logger.setLevel(logging.WARNING) + console_handler = logging.StreamHandler() # sends output to stderr console_handler.setFormatter(logging.Formatter("[%(name)s] %(message)s")) From a10a12c2cb318640beeb352a9b5db661cad9f602 Mon Sep 17 00:00:00 2001 From: gwillgues Date: Sat, 4 May 2024 17:17:10 -0500 Subject: [PATCH 3/5] Revert "Fix truncation of last character of VIN number by modifying decode_encoded_string function to use .replace() instead of .strip()" This reverts commit 090b66a2da55f45b0bd56f4264f14b61655a9044. --- obd/decoders.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/obd/decoders.py b/obd/decoders.py index 4a7c5e3b..fffca50a 100644 --- a/obd/decoders.py +++ b/obd/decoders.py @@ -505,8 +505,7 @@ def decode_encoded_string(messages, length): # Encoded strings come in bundles of messages with leading null values to # pad out the string to the next full message size. We strip off the # leading null characters here and return the resulting string. - decoded_string = d.strip().replace(b'\x00', b'').replace(b'\x01', b'').replace(b'\x02', b'').replace(b'\\x00', b'').replace(b'\\x01', b'').replace(b'\\x02', b'') - return decoded_string + return d.strip().strip(b'\x00' b'\x01' b'\x02' b'\\x00' b'\\x01' b'\\x02') def cvn(messages): From c67bbf4f85b913be9f1847d66bee5cbd0111ee84 Mon Sep 17 00:00:00 2001 From: gwillgues Date: Sat, 4 May 2024 17:22:28 -0500 Subject: [PATCH 4/5] Revert "Revert "Fix truncation of last character of VIN number by modifying decode_encoded_string function to use .replace() instead of .strip()"" This reverts commit a10a12c2cb318640beeb352a9b5db661cad9f602. --- obd/decoders.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/obd/decoders.py b/obd/decoders.py index fffca50a..4a7c5e3b 100644 --- a/obd/decoders.py +++ b/obd/decoders.py @@ -505,7 +505,8 @@ def decode_encoded_string(messages, length): # Encoded strings come in bundles of messages with leading null values to # pad out the string to the next full message size. We strip off the # leading null characters here and return the resulting string. - return d.strip().strip(b'\x00' b'\x01' b'\x02' b'\\x00' b'\\x01' b'\\x02') + decoded_string = d.strip().replace(b'\x00', b'').replace(b'\x01', b'').replace(b'\x02', b'').replace(b'\\x00', b'').replace(b'\\x01', b'').replace(b'\\x02', b'') + return decoded_string def cvn(messages): From efe417a98ef3f135177f1577574e15ad4c6d3fd0 Mon Sep 17 00:00:00 2001 From: gwillgues Date: Sat, 4 May 2024 17:23:16 -0500 Subject: [PATCH 5/5] Revert "Add environment variable logging verbosity support via DEBUG env var" This reverts commit 05514fc96c3ea92196078928fb91d94b02ede3f3. --- obd/__init__.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/obd/__init__.py b/obd/__init__.py index 67a56e60..5002708b 100644 --- a/obd/__init__.py +++ b/obd/__init__.py @@ -46,20 +46,11 @@ from .protocols import ECU from .utils import scan_serial, OBDStatus from .UnitsAndScaling import Unit -import os -import logging -def getenv(key:str, default=0): return type(default)(os.getenv(key, default)) +import logging logger = logging.getLogger(__name__) -DEBUG = getenv("DEBUG", 0) -if DEBUG == 1: - logger.setLevel(logging.INFO) -elif DEBUG == 2: - logger.setLevel(logging.DEBUG) -else: - logger.setLevel(logging.WARNING) - +logger.setLevel(logging.WARNING) console_handler = logging.StreamHandler() # sends output to stderr console_handler.setFormatter(logging.Formatter("[%(name)s] %(message)s"))