From 35f5e4527b77ed29d0fcd2353b0d700bab7a3a30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Sat, 21 May 2016 17:32:18 +0100 Subject: otverio2015: implement proper glucose unit identification. I managed to get my hands on an US-edition of the device, and I can confirm this behaves in a similar way to the otultraeasy. --- glucometerutils/drivers/otverio2015.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/glucometerutils/drivers/otverio2015.py b/glucometerutils/drivers/otverio2015.py index 080e3df..4093727 100644 --- a/glucometerutils/drivers/otverio2015.py +++ b/glucometerutils/drivers/otverio2015.py @@ -45,6 +45,9 @@ _QUERY_KEY_SERIAL = b'\x00' _QUERY_KEY_MODEL = b'\x01' _QUERY_KEY_SOFTWARE = b'\x02' +_READ_PARAMETER_REQUEST = b'\x04' +_PARAMETER_KEY_UNIT = b'\x04' + _READ_RTC_REQUEST = b'\x04\x20\x02' _WRITE_RTC_REQUEST = b'\x04\x20\x01' # All timestamp reported by this device are seconds since this date. @@ -134,11 +137,12 @@ class Device(object): 'Serial number: %s\n' 'Software version: %s\n' 'Time: %s\n' - 'Default unit: unknown\n' % ( + 'Default unit: %s\n' % ( self._query_string(_QUERY_KEY_MODEL), self.get_serial_number(), self.get_version(), - self.get_datetime())) + self.get_datetime(), + self.get_glucose_unit())) def _query_string(self, query_key): response = self._send_message(_QUERY_REQUEST + query_key, 3) @@ -151,6 +155,15 @@ class Device(object): # null-terminated, so the last character should be dropped. return response[2:].decode('utf-16-le')[:-1] + def _read_parameter(self, parameter_key): + response = self._send_message( + _READ_PARAMETER_REQUEST + parameter_key, 4) + if response[0:2] != b'\x03\x06': + raise lifescan_common.MalformedCommand( + 'invalid response, expected 03 06, received %02x %02x' % ( + response[0], response[1])) + return response[2:] + def get_serial_number(self): return self._query_string(_QUERY_KEY_SERIAL) @@ -201,7 +214,13 @@ class Device(object): return record_count def get_glucose_unit(self): - return common.UNIT_MGDL + unit_value = self._read_parameter(_PARAMETER_KEY_UNIT) + if unit_value == b'\x00\x00\x00\x00': + return common.UNIT_MGDL + elif unit_value == b'\x01\x00\x00\x00': + return common.UNIT_MMOLL + else: + raise exceptions.InvalidGlucoseUnit('%r' % unit_value) def _get_reading(self, record_number): request = (_READ_RECORD_REQUEST_PREFIX + -- cgit v1.2.3