summaryrefslogtreecommitdiffstats
path: root/glucometerutils/support/lifescan_binary_protocol.py
diff options
context:
space:
mode:
authorBen <b-schaefer@posteo.de>2020-02-21 10:45:40 +0100
committerDiego Elio Pettenò <flameeyes@flameeyes.com>2020-03-08 00:36:39 +0100
commite72b02d84e7f67cdf6107862ad580e951a5bbda1 (patch)
tree0887513d2478f55b27abccfeb307f313231bd994 /glucometerutils/support/lifescan_binary_protocol.py
parentpre-commit guide in README (diff)
downloadglucometerutils-e72b02d84e7f67cdf6107862ad580e951a5bbda1.tar
glucometerutils-e72b02d84e7f67cdf6107862ad580e951a5bbda1.tar.gz
glucometerutils-e72b02d84e7f67cdf6107862ad580e951a5bbda1.tar.bz2
glucometerutils-e72b02d84e7f67cdf6107862ad580e951a5bbda1.tar.lz
glucometerutils-e72b02d84e7f67cdf6107862ad580e951a5bbda1.tar.xz
glucometerutils-e72b02d84e7f67cdf6107862ad580e951a5bbda1.tar.zst
glucometerutils-e72b02d84e7f67cdf6107862ad580e951a5bbda1.zip
Diffstat (limited to 'glucometerutils/support/lifescan_binary_protocol.py')
-rw-r--r--glucometerutils/support/lifescan_binary_protocol.py45
1 files changed, 24 insertions, 21 deletions
diff --git a/glucometerutils/support/lifescan_binary_protocol.py b/glucometerutils/support/lifescan_binary_protocol.py
index 288da83..441226e 100644
--- a/glucometerutils/support/lifescan_binary_protocol.py
+++ b/glucometerutils/support/lifescan_binary_protocol.py
@@ -12,48 +12,51 @@ This module implements an interface to send and receive these messages.
import construct
from glucometerutils import common
-from glucometerutils.support import construct_extras
-from glucometerutils.support import lifescan
+from glucometerutils.support import construct_extras, lifescan
_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),
+ "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),
)
+
def LifeScanPacket(include_link_control): # pylint: disable=invalid-name
# type: (bool) -> construct.Struct
if include_link_control:
link_control_construct = _LINK_CONTROL
else:
- link_control_construct = construct.Const(b'\x00')
+ link_control_construct = construct.Const(b"\x00")
return construct.Struct(
- 'data' / construct.RawCopy(
+ "data"
+ / construct.RawCopy(
construct.Struct(
- construct.Const(b'\x02'), # stx
- 'length' / construct.Rebuild(
- construct.Byte, lambda this: len(this.message) + 6),
- 'link_control' / link_control_construct,
- 'message' / construct.Bytes(
- lambda this: this.length - 6),
- construct.Const(b'\x03'), # etx
+ construct.Const(b"\x02"), # stx
+ "length"
+ / construct.Rebuild(construct.Byte, lambda this: len(this.message) + 6),
+ "link_control" / link_control_construct,
+ "message" / construct.Bytes(lambda this: this.length - 6),
+ construct.Const(b"\x03"), # etx
),
),
- 'checksum' / construct.Checksum(
- construct.Int16ul, lifescan.crc_ccitt, construct.this.data.data),
+ "checksum"
+ / construct.Checksum(
+ construct.Int16ul, lifescan.crc_ccitt, construct.this.data.data
+ ),
)
+
VERIO_TIMESTAMP = construct_extras.Timestamp(
- construct.Int32ul, epoch=946684800) # 2000-01-01 (not 2010)
+ construct.Int32ul, epoch=946684800
+) # 2000-01-01 (not 2010)
_GLUCOSE_UNIT_MAPPING_TABLE = {
common.Unit.MG_DL: 0x00,
common.Unit.MMOL_L: 0x01,
}
-GLUCOSE_UNIT = construct.Mapping(
- construct.Byte, _GLUCOSE_UNIT_MAPPING_TABLE)
+GLUCOSE_UNIT = construct.Mapping(construct.Byte, _GLUCOSE_UNIT_MAPPING_TABLE)