diff options
Diffstat (limited to 'glucometerutils')
-rw-r--r-- | glucometerutils/drivers/fsinsulinx.py | 7 | ||||
-rw-r--r-- | glucometerutils/drivers/fslibre.py | 6 | ||||
-rw-r--r-- | glucometerutils/drivers/fsprecisionneo.py | 5 | ||||
-rw-r--r-- | glucometerutils/support/freestyle.py | 35 |
4 files changed, 43 insertions, 10 deletions
diff --git a/glucometerutils/drivers/fsinsulinx.py b/glucometerutils/drivers/fsinsulinx.py index f0986ee..2d3cf2c 100644 --- a/glucometerutils/drivers/fsinsulinx.py +++ b/glucometerutils/drivers/fsinsulinx.py @@ -6,7 +6,8 @@ Supported features: - get and set date and time; - get serial number and software version. -Expected device path: /dev/hidraw9 or similar HID device. +Expected device path: /dev/hidraw9 or similar HID device. Optional when using +HIDAPI. WARNING: currently untested! Based off reverse engineering notes provided by Xavier Claessens. @@ -41,7 +42,9 @@ _InsulinxReading = collections.namedtuple('_InsulinxReading', ( class Device(freestyle.FreeStyleHidDevice): - """Glucometer driver for FreeStyle Precision Neo devices.""" + """Glucometer driver for FreeStyle InsuLinux devices.""" + + USB_PRODUCT_ID = 0x3460 def get_meter_info(self): """Return the device information in structured form.""" diff --git a/glucometerutils/drivers/fslibre.py b/glucometerutils/drivers/fslibre.py index b364cc2..4dda376 100644 --- a/glucometerutils/drivers/fslibre.py +++ b/glucometerutils/drivers/fslibre.py @@ -6,11 +6,13 @@ Supported features: - get and set date and time; - get serial number and software version. -Expected device path: /dev/hidraw9 or similar HID device. +Expected device path: /dev/hidraw9 or similar HID device. Optional when using +HIDAPI. Further information on the device protocol can be found at https://flameeyes.github.io/glucometer-protocols/abbott/freestyle-libre + """ __author__ = 'Diego Elio Pettenò' @@ -164,6 +166,8 @@ def _parse_arresult(record): class Device(freestyle.FreeStyleHidDevice): """Glucometer driver for FreeStyle Libre devices.""" + USB_PRODUCT_ID = 0x3650 + def get_meter_info(self): """Return the device information in structured form.""" return common.MeterInfo( diff --git a/glucometerutils/drivers/fsprecisionneo.py b/glucometerutils/drivers/fsprecisionneo.py index b77617c..42e652d 100644 --- a/glucometerutils/drivers/fsprecisionneo.py +++ b/glucometerutils/drivers/fsprecisionneo.py @@ -9,7 +9,8 @@ Supported features: - get and set date and time; - get serial number and software version. -Expected device path: /dev/hidraw9 or similar HID device. +Expected device path: /dev/hidraw9 or similar HID device. Optional when using +HIDAPI. Further information on the device protocol can be found at @@ -47,6 +48,8 @@ _NeoReading = collections.namedtuple('_NeoReading', ( class Device(freestyle.FreeStyleHidDevice): """Glucometer driver for FreeStyle Precision Neo devices.""" + USB_PRODUCT_ID = 0x3850 + def get_meter_info(self): """Return the device information in structured form.""" return common.MeterInfo( diff --git a/glucometerutils/support/freestyle.py b/glucometerutils/support/freestyle.py index bb891fd..737eda1 100644 --- a/glucometerutils/support/freestyle.py +++ b/glucometerutils/support/freestyle.py @@ -69,16 +69,39 @@ class FreeStyleHidDevice(object): TEXT_CMD = 0x60 TEXT_REPLY_CMD = 0x60 + USB_VENDOR_ID = 0x1a61 # Abbott Diabetes Care + USB_PRODUCT_ID = None + def __init__(self, device): - if not device: + # If we do not know for sure the device ID, rely on the user providing a + # device path. + if self.USB_PRODUCT_ID is None and not device: raise exceptions.CommandLineError( '--device parameter is required, should point to /dev/hidraw ' 'for the meter') - if not os.path.exists(device): + # If the user passed a device path that does not exist, raise an error. + if device and not os.path.exists(device): raise exceptions.ConnectionFailed( message='Path %s does not exist.' % device) - self.handle_ = open(device, 'w+b') + + # If the user passed a device, try opening it. Note that I have had no + # success on actually opening the /dev/hidraw path but that's a + # different problem. + try: + if device: + self.handle_ = open(device, 'w+b') + else: + try: + import hid + except ImportError: + raise exceptions.ConnectionFailed( + message='Missing requied "hidapi" module.') + self.handle_ = hid.device() + self.handle_.open(self.USB_VENDOR_ID, self.USB_PRODUCT_ID) + except OSError: + raise exceptions.ConnectionFailed( + message='Unable to connect to meter.') def connect(self): """Open connection to the device, starting the knocking sequence.""" @@ -103,8 +126,7 @@ class FreeStyleHidDevice(object): cmdlen = len(command) assert cmdlen <= 62 - # First byte in the written buffer is the report number, on Linux HID - # interface. + # First byte in the written buffer is the report number. usb_packet = b'\x00' + _STRUCT_PREAMBLE.pack( message_type, cmdlen) + command + bytes(62 - cmdlen) @@ -126,7 +148,8 @@ class FreeStyleHidDevice(object): if message_type == 0x22 and message_length == 1: return self._read_response() - return (message_type, message_content) + # hidapi module returns a list of bytes rather than a bytes object. + return (message_type, bytes(message_content)) def _send_text_command(self, command): """Send a command to the device that expects a text reply.""" |