diff options
author | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2014-01-29 23:45:05 +0100 |
---|---|---|
committer | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2014-01-29 23:45:05 +0100 |
commit | 6bfc12f901e938f95ea64bd0a80090333769e234 (patch) | |
tree | 0a2e9cf8df42efd1e93d0430431000a5cfb93dfa /glucometerutils/drivers/otultra2.py | |
parent | Initial support for OneTouch Ultra Easy glucometers. (diff) | |
download | glucometerutils-6bfc12f901e938f95ea64bd0a80090333769e234.tar glucometerutils-6bfc12f901e938f95ea64bd0a80090333769e234.tar.gz glucometerutils-6bfc12f901e938f95ea64bd0a80090333769e234.tar.bz2 glucometerutils-6bfc12f901e938f95ea64bd0a80090333769e234.tar.lz glucometerutils-6bfc12f901e938f95ea64bd0a80090333769e234.tar.xz glucometerutils-6bfc12f901e938f95ea64bd0a80090333769e234.tar.zst glucometerutils-6bfc12f901e938f95ea64bd0a80090333769e234.zip |
Diffstat (limited to 'glucometerutils/drivers/otultra2.py')
-rw-r--r-- | glucometerutils/drivers/otultra2.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/glucometerutils/drivers/otultra2.py b/glucometerutils/drivers/otultra2.py index 3af78fc..8f21ac2 100644 --- a/glucometerutils/drivers/otultra2.py +++ b/glucometerutils/drivers/otultra2.py @@ -46,6 +46,25 @@ _DUMP_LINE_RE = re.compile( _RESPONSE_MATCH = re.compile(r'^(.+) ([0-9A-F]{4})\r$') +def _calculate_checksum(bytestring): + """Calculate the checksum used by OneTouch Ultra and Ultra2 devices + + Args: + bytestring: the string of which the checksum has to be calculated. + + Returns: + A string with the hexdecimal representation of the checksum for the input. + + The checksum is a very stupid one: it just sums all the bytes, + modulo 16-bit, without any parity. + """ + checksum = 0 + + for byte in bytestring: + checksum = (checksum + byte) & 0xffff + + return checksum + def _validate_and_strip_checksum(line): """Verify the simple 16-bit checksum and remove it from the line. @@ -64,7 +83,7 @@ def _validate_and_strip_checksum(line): try: checksum_given = int(checksum_string, 16) - checksum_calculated = lifescan_common.calculate_checksum( + checksum_calculated = _calculate_checksum( bytes(response, 'ascii')) if checksum_given != checksum_calculated: |