diff options
author | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2018-01-06 21:47:13 +0100 |
---|---|---|
committer | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2018-01-06 21:47:13 +0100 |
commit | 3999c3eb3c82abc20af618df81631a114504a7b0 (patch) | |
tree | 1a560a81324270cee508b0ad27e83236ef1d1ee8 /glucometerutils/support | |
parent | tests: improve code quality by passing the linter. (diff) | |
download | glucometerutils-3999c3eb3c82abc20af618df81631a114504a7b0.tar glucometerutils-3999c3eb3c82abc20af618df81631a114504a7b0.tar.gz glucometerutils-3999c3eb3c82abc20af618df81631a114504a7b0.tar.bz2 glucometerutils-3999c3eb3c82abc20af618df81631a114504a7b0.tar.lz glucometerutils-3999c3eb3c82abc20af618df81631a114504a7b0.tar.xz glucometerutils-3999c3eb3c82abc20af618df81631a114504a7b0.tar.zst glucometerutils-3999c3eb3c82abc20af618df81631a114504a7b0.zip |
Diffstat (limited to 'glucometerutils/support')
-rw-r--r-- | glucometerutils/support/lifescan_binary_protocol.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/glucometerutils/support/lifescan_binary_protocol.py b/glucometerutils/support/lifescan_binary_protocol.py new file mode 100644 index 0000000..68b030d --- /dev/null +++ b/glucometerutils/support/lifescan_binary_protocol.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +"""Support module for the LifeScan binary protocol. + +A number of LifeScan devices use a semi-compatible binary protocol to talk host +and device, which is (vastly) compatible. + +This module implements an interface to send and receive these messages. +""" + +__author__ = 'Diego Elio Pettenò' +__email__ = 'flameeyes@flameeyes.eu' +__copyright__ = 'Copyright © 2014-2018, Diego Elio Pettenò' +__license__ = 'MIT' + +import construct + +from glucometerutils.support import construct_extras +from glucometerutils.support import lifescan + + +PACKET = construct.Struct( + construct.RawCopy( + construct.Embedded( + construct.Struct( + construct.Const(b'\x02'), # stx + 'length' / construct.Rebuild( + construct.Byte, lambda ctx: len(ctx.message) + 6), + # The following structure is only used by some of the devices. + 'link_control' / construct.BitStruct( + construct.Padding(3), + 'more' / construct.Default( + construct.Flag, False), + 'disconnect' / construct.Default( + construct.Flag, False), + 'acknowledge' / construct.Default( + construct.Flag, False), + 'expect_receive' / construct.Default( + construct.Flag, False), + 'sequence_number' / construct.Default( + construct.Flag, False), + ), + 'message' / construct.Bytes(length=lambda ctx: ctx.length - 6), + construct.Const(b'\x03'), # etx + ), + ), + ), + 'checksum' / construct.Checksum( + construct.Int16ul, lifescan.crc_ccitt, construct.this.data), +) + +VERIO_TIMESTAMP = construct_extras.Timestamp( + construct.Int32ul, epoch=946684800) # 2010-01-01 00:00 |