summaryrefslogtreecommitdiffstats
path: root/glucometerutils/support/lifescan.py
diff options
context:
space:
mode:
Diffstat (limited to 'glucometerutils/support/lifescan.py')
-rw-r--r--glucometerutils/support/lifescan.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/glucometerutils/support/lifescan.py b/glucometerutils/support/lifescan.py
index 19155d4..9340e49 100644
--- a/glucometerutils/support/lifescan.py
+++ b/glucometerutils/support/lifescan.py
@@ -8,22 +8,25 @@ from glucometerutils import exceptions
class MissingChecksum(exceptions.InvalidResponse):
"""The response misses the expected 4-digits checksum."""
+
def __init__(self, response):
super(MissingChecksum, self).__init__(
- 'Response is missing checksum: %s' % response)
+ "Response is missing checksum: %s" % response
+ )
class InvalidSerialNumber(exceptions.Error):
"""The serial number is not as expected."""
+
def __init__(self, serial_number):
super(InvalidSerialNumber, self).__init__(
- 'Serial number %s is invalid.' % serial_number)
+ "Serial number %s is invalid." % serial_number
+ )
class MalformedCommand(exceptions.InvalidResponse):
def __init__(self, message):
- super(MalformedCommand, self).__init__(
- 'Malformed command: %s' % message)
+ super(MalformedCommand, self).__init__("Malformed command: %s" % message)
def crc_ccitt(data):
@@ -39,13 +42,13 @@ def crc_ccitt(data):
This function uses the non-default 0xFFFF seed as used by multiple
LifeScan meters.
"""
- crc = 0xffff
+ crc = 0xFFFF
for byte in data:
- crc = (crc >> 8) & 0xffff | (crc << 8) & 0xffff
+ crc = (crc >> 8) & 0xFFFF | (crc << 8) & 0xFFFF
crc ^= byte
- crc ^= (crc & 0xff) >> 4
- crc ^= (((crc << 8) & 0xffff) << 4) & 0xffff
- crc ^= (crc & 0xff) << 5
+ crc ^= (crc & 0xFF) >> 4
+ crc ^= (((crc << 8) & 0xFFFF) << 4) & 0xFFFF
+ crc ^= (crc & 0xFF) << 5
- return crc & 0xffff
+ return crc & 0xFFFF