diff options
author | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2017-12-28 21:16:22 +0100 |
---|---|---|
committer | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2017-12-28 22:45:50 +0100 |
commit | 09a5fe1f8d34ee9a9f8263624a9b92a2bcd96f79 (patch) | |
tree | c430a625f38deb93c7b6b472debad1f0f32bc6ef | |
parent | deps: correct dependency for fsoptium. (diff) | |
download | glucometerutils-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 |
-rw-r--r-- | README | 31 | ||||
-rw-r--r-- | glucometerutils/support/freestyle.py | 19 | ||||
-rw-r--r-- | setup.py | 6 |
3 files changed, 30 insertions, 26 deletions
@@ -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) @@ -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'], }, |