summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README31
-rw-r--r--glucometerutils/support/freestyle.py19
-rw-r--r--setup.py6
3 files changed, 30 insertions, 26 deletions
diff --git a/README b/README
index a070a05..1f42487 100644
--- a/README
+++ b/README
@@ -32,21 +32,21 @@ $ . glucometerutils-venv/bin/activate
Please see the following table for the driver for each device that is known and
supported.
-| Manufacturer | Model Name | Driver | Dependencies |
-| --- | --- | --- | --- |
-| LifeScan | OneTouch Ultra 2 | `otultra2` | [pyserial] |
-| LifeScan | OneTouch Ultra Easy | `otultraeasy` | [pyserial] |
-| LifeScan | OneTouch Ultra Mini | `otultraeasy` | [pyserial] |
-| LifeScan | OneTouch Verio (USB) | `otverio2015` | [python-scsi] |
-| LifeScan | OneTouch Select Plus | `otverio2015` | [python-scsi] |
-| Abbott | FreeStyle InsuLinx† | `fsinsulinx` | [hidapi]‡ |
-| Abbott | FreeStyle Libre | `fslibre` | [hidapi]‡ |
-| Abbott | FreeStyle Optium | `fsoptium` | [pyserial] |
-| Abbott | FreeStyle Precision Neo | `fsprecisionneo` | [hidapi]‡ |
-| Abbott | FreeStyle Optium Neo | `fsprecisionneo` | [hidapi]‡ |
-| Abbott | FreeStyle Optium Neo H | `fsprecisionneo` | [hidapi]‡ |
-| Roche | Accu-Chek Mobile | `accuchek_reports` | |
-| SD Biosensor | SD CodeFree | `sdcodefree` | [pyserial] |
+| Manufacturer | Model Name | Driver | Dependencies |
+| --- | --- | --- | --- |
+| LifeScan | OneTouch Ultra 2 | `otultra2` | [pyserial] |
+| LifeScan | OneTouch Ultra Easy | `otultraeasy` | [pyserial] |
+| LifeScan | OneTouch Ultra Mini | `otultraeasy` | [pyserial] |
+| LifeScan | OneTouch Verio (USB) | `otverio2015` | [python-scsi] |
+| LifeScan | OneTouch Select Plus | `otverio2015` | [python-scsi] |
+| Abbott | FreeStyle InsuLinx† | `fsinsulinx` | [construct] [hidapi]‡ |
+| Abbott | FreeStyle Libre | `fslibre` | [construct] [hidapi]‡ |
+| Abbott | FreeStyle Optium | `fsoptium` | [pyserial] |
+| Abbott | FreeStyle Precision Neo | `fsprecisionneo` | [construct] [hidapi]‡ |
+| Abbott | FreeStyle Optium Neo | `fsprecisionneo` | [construct] [hidapi]‡ |
+| Abbott | FreeStyle Optium Neo H | `fsprecisionneo` | [construct] [hidapi]‡ |
+| Roche | Accu-Chek Mobile | `accuchek_reports` | |
+| SD Biosensor | SD CodeFree | `sdcodefree` | [pyserial] |
† Untested.
‡ Optional dependency on Linux; required on other operating systems.
@@ -60,6 +60,7 @@ If you have knowledge of a protocol of a glucometer you would have supported,
please provide a reference, possibly by writing a specification and contribute
it to https://github.com/Flameeyes/glucometer-protocols/.
+[construct]: https://construct.readthedocs.io/en/latest/
[pyserial]: https://pythonhosted.org/pyserial/
[python-scsi]: https://github.com/rosjat/python-scsi
[hidapi]: https://pypi.python.org/pypi/hidapi
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)
diff --git a/setup.py b/setup.py
index 5da8086..5e65e1e 100644
--- a/setup.py
+++ b/setup.py
@@ -34,10 +34,10 @@ setup(
'otultra2': ['pyserial'],
'otultraeasy': ['pyserial'],
'otverio2015': ['python-scsi'],
- 'fsinsulinx': ['hidapi'],
- 'fslibre': ['hidapi'],
+ 'fsinsulinx': ['construct', 'hidapi'],
+ 'fslibre': ['construct', 'hidapi'],
'fsoptium': ['pyserial'],
- 'fsprecisionneo': ['hidapi'],
+ 'fsprecisionneo': ['construct', 'hidapi'],
'accucheck_reports': [],
'sdcodefree': ['pyserial'],
},