From 2a0dcbea1c138154f8557de58dc04ffcdbc1b7af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Wed, 13 Sep 2017 14:11:06 +0100 Subject: otverio2015: add debug logging to help track Issue #22. --- glucometerutils/drivers/otverio2015.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/glucometerutils/drivers/otverio2015.py b/glucometerutils/drivers/otverio2015.py index 7a4bac8..deeac4b 100644 --- a/glucometerutils/drivers/otverio2015.py +++ b/glucometerutils/drivers/otverio2015.py @@ -24,7 +24,9 @@ __email__ = 'flameeyes@flameeyes.eu' __copyright__ = 'Copyright © 2016-2017, Diego Elio Pettenò' __license__ = 'MIT' +import binascii import datetime +import logging import struct from pyscsi.pyscsi.scsi import SCSI @@ -94,6 +96,8 @@ def _extract_message(register): raise exceptions.InvalidChecksum(encoded_checksum, calculated_checksum) response = register[_STRUCT_PREAMBLE.size:coda_offset] + + logging.debug('Read packet: %s' % binascii.hexlify(response)) return response def _encode_message(cmd): @@ -102,10 +106,12 @@ def _encode_message(cmd): preamble = _STRUCT_PREAMBLE.pack(_STX, length) message = preamble + cmd + bytes((_ETX,)) checksum = _STRUCT_CHECKSUM.pack(lifescan.crc_ccitt(message)) + message += checksum + + logging.debug('Sending packet: %s' % binascii.hexlify(message)) # Pad the message to match the size of the register. - return message + checksum + bytes( - _REGISTER_SIZE - 2 - len(message)) + return message + bytes(_REGISTER_SIZE - len(message)) def _convert_timestamp(timestamp): return datetime.datetime.utcfromtimestamp(timestamp + _EPOCH_BASE) -- cgit v1.2.3