summaryrefslogtreecommitdiffstats
path: root/glucometerutils
diff options
context:
space:
mode:
authorDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-01-17 01:28:54 +0100
committerDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-01-17 01:28:54 +0100
commit154239e52766217ce1c49417102fef51d46b27ba (patch)
treeb32789615f17994a18127d6e855686a9c773560b /glucometerutils
parentfsprecisionneo: move the version and serial number information to the common support class. (diff)
downloadglucometerutils-154239e52766217ce1c49417102fef51d46b27ba.tar
glucometerutils-154239e52766217ce1c49417102fef51d46b27ba.tar.gz
glucometerutils-154239e52766217ce1c49417102fef51d46b27ba.tar.bz2
glucometerutils-154239e52766217ce1c49417102fef51d46b27ba.tar.lz
glucometerutils-154239e52766217ce1c49417102fef51d46b27ba.tar.xz
glucometerutils-154239e52766217ce1c49417102fef51d46b27ba.tar.zst
glucometerutils-154239e52766217ce1c49417102fef51d46b27ba.zip
Diffstat (limited to 'glucometerutils')
-rw-r--r--glucometerutils/drivers/fsinsulinx.py66
1 files changed, 66 insertions, 0 deletions
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)