From 154239e52766217ce1c49417102fef51d46b27ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Tue, 17 Jan 2017 00:28:54 +0000 Subject: fsinsulinx: add untested FreeStyle InsuLinx driver. This is based off the fsprecisionneo driver, as the two share an almost identical protocol. The readings format is different between them, but otherwise the commands are compatible. There are a number of higher-level commands that differ between them, though, so it might be necessary to specialize the drivers further in the future. --- README | 3 +- glucometerutils/drivers/fsinsulinx.py | 66 +++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 glucometerutils/drivers/fsinsulinx.py diff --git a/README b/README index e737508..c635bba 100644 --- a/README +++ b/README @@ -26,6 +26,7 @@ information on each of the devices. | LifeScan | OneTouch Ultra Mini | `otultraeasy` | | LifeScan | OneTouch Verio (USB) | `otverio2015` | | LifeScan | OneTouch Select Plus | `otverio2015` | +| Abbott | FreeStyle InsuLinx | `fsinsulinx` | | Abbott | FreeStyle Optium | `fsoptium` | | Abbott | FreeStyle Precision Neo | `fsprecisionneo` | | Roche | Accu-Chek Mobile | `accuchek_reports` | @@ -38,6 +39,7 @@ information on each of the devices. | `otultra2` | serialno, swver, unit | get and set | yes | yes | | `otultraeasy` | serialno, swver, unit | get and set | not supported by device | yes | | `otverio2015` | serialno, swver | get and set | no | yes | +| `fsinsulinx` | serialno, swver | get and set | no | not supported by device | | `fsoptium` | serialno, swver, unit | get and set | not supported by device | not supported by device | | `fsprecisionneo` | serialno, swver | get and set | not supported by device | not supported by device | | `accuchek_reports` | serialno, unit | no | yes | not supported by device | @@ -51,7 +53,6 @@ information on each of the devices. | `otultraeasy` | [pyserial] | | `otverio2015` | [python-scsi] | | `fsoptium` | [pyserial] | -| `fsprecisionneo` | | | `sdcodefree` | [pyserial] | [pyserial]: https://pythonhosted.org/pyserial/ diff --git a/glucometerutils/drivers/fsinsulinx.py b/glucometerutils/drivers/fsinsulinx.py new file mode 100644 index 0000000..376c862 --- /dev/null +++ b/glucometerutils/drivers/fsinsulinx.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +"""Driver for FreeStyle InsuLinx devices. + +WARNING: currently untested! Based off reverse engineering notes provided by +Xavier Claessens. + +""" + +__author__ = 'Diego Elio Pettenò' +__email__ = 'flameeyes@flameeyes.eu' +__copyright__ = 'Copyright © 2017, Diego Elio Pettenò' +__license__ = 'MIT' + +import collections +import datetime + +from glucometerutils import common +from glucometerutils.support import freestyle + + +# The type is a string because it precedes the parsing of the object. +_TYPE_GLUCOSE_READING = '0' + +_InsulinxReading = collections.namedtuple('_InsulinxReading', ( + 'type', # 0 = blood glucose + 'id', + 'month', 'day', 'year', # year is two-digits + 'hour', 'minute', + 'unknown1', 'unknown2', 'unknown3', + 'unknown4', 'unknown5', 'unknown6', + 'value', + 'unknown7', 'unknown8', +)) + + +class Device(freestyle.FreeStyleHidDevice): + """Glucometer driver for FreeStyle Precision Neo devices.""" + + def get_meter_info(self): + """Return the device information in structured form.""" + return common.MeterInfo( + 'FreeStyle InsuLinx', + serial_number=self.get_serial_number(), + version_info=( + 'Software version: ' + self._get_version(),), + native_unit=self.get_glucose_unit()) + + def get_glucose_unit(self): + """Returns the glucose unit of the device.""" + return common.UNIT_MGDL + + def get_readings(self): + """Iterate through the reading records in the device.""" + for record in self._get_multirecord(b'$result?'): + if not record or record[0] != _TYPE_GLUCOSE_READING: + continue + + # Build a reading object by parsing each of the entries in the CSV + # as integers. + raw_reading = _InsulinxReading._make([int(v) for v in record]) + + timestamp = datetime.datetime( + raw_reading.year + 2000, raw_reading.month, raw_reading.day, + raw_reading.hour, raw_reading.minute) + + yield common.Reading(timestamp, raw_reading.value) -- cgit v1.2.3