summaryrefslogtreecommitdiffstats
path: root/glucometerutils
diff options
context:
space:
mode:
authorDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-12-28 21:16:22 +0100
committerDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-12-28 22:45:50 +0100
commit09a5fe1f8d34ee9a9f8263624a9b92a2bcd96f79 (patch)
treec430a625f38deb93c7b6b472debad1f0f32bc6ef /glucometerutils
parentdeps: correct dependency for fsoptium. (diff)
downloadglucometerutils-09a5fe1f8d34ee9a9f8263624a9b92a2bcd96f79.tar
glucometerutils-09a5fe1f8d34ee9a9f8263624a9b92a2bcd96f79.tar.gz
glucometerutils-09a5fe1f8d34ee9a9f8263624a9b92a2bcd96f79.tar.bz2
glucometerutils-09a5fe1f8d34ee9a9f8263624a9b92a2bcd96f79.tar.lz
glucometerutils-09a5fe1f8d34ee9a9f8263624a9b92a2bcd96f79.tar.xz
glucometerutils-09a5fe1f8d34ee9a9f8263624a9b92a2bcd96f79.tar.zst
glucometerutils-09a5fe1f8d34ee9a9f8263624a9b92a2bcd96f79.zip
Diffstat (limited to 'glucometerutils')
-rw-r--r--glucometerutils/support/freestyle.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/glucometerutils/support/freestyle.py b/glucometerutils/support/freestyle.py
index d722c35..7610729 100644
--- a/glucometerutils/support/freestyle.py
+++ b/glucometerutils/support/freestyle.py
@@ -15,7 +15,8 @@ import csv
import datetime
import logging
import re
-import struct
+
+import construct
from glucometerutils import exceptions
from glucometerutils.support import hiddevice
@@ -24,7 +25,13 @@ from glucometerutils.support import hiddevice
# protocol.
_INIT_SEQUENCE = (0x04, 0x05, 0x15, 0x01)
-_STRUCT_PREAMBLE = struct.Struct('<BB')
+_LIFESCAN_MESSAGE = construct.Struct(
+ 'hid_report' / construct.Const(construct.Byte, 0),
+ 'message_type' / construct.Byte,
+ 'command' / construct.Padded(
+ 63, # command can only be up to 62 bytes, but one is used for length.
+ construct.Prefixed(construct.Byte, construct.GreedyBytes)),
+)
_TEXT_COMPLETION_RE = re.compile('CMD (?:OK|Fail!)')
_TEXT_REPLY_FORMAT = re.compile(
@@ -93,12 +100,8 @@ class FreeStyleHidDevice(hiddevice.HidDevice):
message_type: (int) The first byte sent with the report to the device.
command: (bytes) The command to send out the device.
"""
- cmdlen = len(command)
- assert cmdlen <= 62
-
- # First byte in the written buffer is the report number.
- usb_packet = b'\x00' + _STRUCT_PREAMBLE.pack(
- message_type, cmdlen) + command + bytes(62 - cmdlen)
+ usb_packet = _LIFESCAN_MESSAGE.build(
+ {'message_type': message_type, 'command': command})
self._write(usb_packet)