diff options
author | Ben <b-schaefer@posteo.de> | 2020-02-21 10:45:40 +0100 |
---|---|---|
committer | Diego Elio Pettenò <flameeyes@flameeyes.com> | 2020-03-08 00:36:39 +0100 |
commit | e72b02d84e7f67cdf6107862ad580e951a5bbda1 (patch) | |
tree | 0887513d2478f55b27abccfeb307f313231bd994 /glucometerutils/drivers/otverioiq.py | |
parent | pre-commit guide in README (diff) | |
download | glucometerutils-e72b02d84e7f67cdf6107862ad580e951a5bbda1.tar glucometerutils-e72b02d84e7f67cdf6107862ad580e951a5bbda1.tar.gz glucometerutils-e72b02d84e7f67cdf6107862ad580e951a5bbda1.tar.bz2 glucometerutils-e72b02d84e7f67cdf6107862ad580e951a5bbda1.tar.lz glucometerutils-e72b02d84e7f67cdf6107862ad580e951a5bbda1.tar.xz glucometerutils-e72b02d84e7f67cdf6107862ad580e951a5bbda1.tar.zst glucometerutils-e72b02d84e7f67cdf6107862ad580e951a5bbda1.zip |
Diffstat (limited to 'glucometerutils/drivers/otverioiq.py')
-rw-r--r-- | glucometerutils/drivers/otverioiq.py | 104 |
1 files changed, 49 insertions, 55 deletions
diff --git a/glucometerutils/drivers/otverioiq.py b/glucometerutils/drivers/otverioiq.py index 69bdac9..24327ef 100644 --- a/glucometerutils/drivers/otverioiq.py +++ b/glucometerutils/drivers/otverioiq.py @@ -21,63 +21,63 @@ import logging import construct from glucometerutils import common -from glucometerutils.support import driver_base, lifescan, lifescan_binary_protocol, serial +from glucometerutils.support import ( + driver_base, + lifescan, + lifescan_binary_protocol, + serial, +) _PACKET = lifescan_binary_protocol.LifeScanPacket(False) -_COMMAND_SUCCESS = construct.Const(b'\x03\x06') +_COMMAND_SUCCESS = construct.Const(b"\x03\x06") -_VERSION_REQUEST = construct.Const(b'\x03\x0d\x01') +_VERSION_REQUEST = construct.Const(b"\x03\x0d\x01") _VERSION_RESPONSE = construct.Struct( _COMMAND_SUCCESS, - 'version' / construct.PascalString(construct.Byte, encoding='ascii'), + "version" / construct.PascalString(construct.Byte, encoding="ascii"), # NULL-termination is not included in string length. - construct.Const(b'\x00'), + construct.Const(b"\x00"), ) -_SERIAL_NUMBER_REQUEST = construct.Const( - b'\x03\x0b\x01\x02') +_SERIAL_NUMBER_REQUEST = construct.Const(b"\x03\x0b\x01\x02") _SERIAL_NUMBER_RESPONSE = construct.Struct( - _COMMAND_SUCCESS, - 'serial_number' / construct.CString(encoding='ascii'), + _COMMAND_SUCCESS, "serial_number" / construct.CString(encoding="ascii"), ) -_READ_RTC_REQUEST = construct.Const(b'\x03\x20\x02') +_READ_RTC_REQUEST = construct.Const(b"\x03\x20\x02") _READ_RTC_RESPONSE = construct.Struct( _COMMAND_SUCCESS, - 'timestamp' / lifescan_binary_protocol.VERIO_TIMESTAMP, # type: ignore + "timestamp" / lifescan_binary_protocol.VERIO_TIMESTAMP, # type: ignore ) _WRITE_RTC_REQUEST = construct.Struct( - construct.Const(b'\x03\x20\x01'), - 'timestamp' / lifescan_binary_protocol.VERIO_TIMESTAMP, # type: ignore + construct.Const(b"\x03\x20\x01"), + "timestamp" / lifescan_binary_protocol.VERIO_TIMESTAMP, # type: ignore ) -_GLUCOSE_UNIT_REQUEST = construct.Const( - b'\x03\x09\x02\x02') +_GLUCOSE_UNIT_REQUEST = construct.Const(b"\x03\x09\x02\x02") _GLUCOSE_UNIT_RESPONSE = construct.Struct( _COMMAND_SUCCESS, - 'unit' / lifescan_binary_protocol.GLUCOSE_UNIT, + "unit" / lifescan_binary_protocol.GLUCOSE_UNIT, construct.Padding(3), ) -_MEMORY_ERASE_REQUEST = construct.Const(b'\x03\x1a') +_MEMORY_ERASE_REQUEST = construct.Const(b"\x03\x1a") -_READ_RECORD_COUNT_REQUEST = construct.Const(b'\x03\x27\x00') +_READ_RECORD_COUNT_REQUEST = construct.Const(b"\x03\x27\x00") _READ_RECORD_COUNT_RESPONSE = construct.Struct( - _COMMAND_SUCCESS, - 'count' / construct.Int16ul, + _COMMAND_SUCCESS, "count" / construct.Int16ul, ) _READ_RECORD_REQUEST = construct.Struct( - construct.Const(b'\x03\x21'), - 'record_id' / construct.Int16ul, + construct.Const(b"\x03\x21"), "record_id" / construct.Int16ul, ) _MEAL_FLAG = { @@ -88,18 +88,17 @@ _MEAL_FLAG = { _READING_RESPONSE = construct.Struct( _COMMAND_SUCCESS, - 'timestamp' / lifescan_binary_protocol.VERIO_TIMESTAMP, # type: ignore - 'value' / construct.Int16ul, - 'control_test' / construct.Flag, - 'meal' / construct.Mapping( - construct.Byte, _MEAL_FLAG), + "timestamp" / lifescan_binary_protocol.VERIO_TIMESTAMP, # type: ignore + "value" / construct.Int16ul, + "control_test" / construct.Flag, + "meal" / construct.Mapping(construct.Byte, _MEAL_FLAG), construct.Padding(2), # unknown ) class Device(serial.SerialDevice, driver_base.GlucometerDriver): BAUDRATE = 38400 - DEFAULT_CABLE_ID = '10c4:85a7' # Specific ID for embedded cp210x + DEFAULT_CABLE_ID = "10c4:85a7" # Specific ID for embedded cp210x TIMEOUT = 0.5 def __init__(self, device): @@ -107,18 +106,15 @@ class Device(serial.SerialDevice, driver_base.GlucometerDriver): self.buffered_reader_ = construct.Rebuffered(_PACKET, tailcutoff=1024) def _send_packet(self, message): - pkt = _PACKET.build( - {'data': {'value': { - 'message': message, - }}}) - logging.debug('sending packet: %s', binascii.hexlify(pkt)) + pkt = _PACKET.build({"data": {"value": {"message": message,}}}) + logging.debug("sending packet: %s", binascii.hexlify(pkt)) self.serial_.write(pkt) self.serial_.flush() def _read_packet(self): raw_pkt = self.buffered_reader_.parse_stream(self.serial_).data - logging.debug('received packet: %r', raw_pkt) + logging.debug("received packet: %r", raw_pkt) # discard the checksum and copy pkt = raw_pkt.value @@ -138,66 +134,64 @@ class Device(serial.SerialDevice, driver_base.GlucometerDriver): def get_meter_info(self): return common.MeterInfo( - 'OneTouch Verio IQ glucometer', + "OneTouch Verio IQ glucometer", serial_number=self.get_serial_number(), - version_info=( - 'Software version: ' + self.get_version(),), - native_unit=self.get_glucose_unit()) + version_info=("Software version: " + self.get_version(),), + native_unit=self.get_glucose_unit(), + ) def get_version(self): - response = self._send_request( - _VERSION_REQUEST, None, _VERSION_RESPONSE) + response = self._send_request(_VERSION_REQUEST, None, _VERSION_RESPONSE) return response.version def get_serial_number(self): response = self._send_request( - _SERIAL_NUMBER_REQUEST, None, _SERIAL_NUMBER_RESPONSE) + _SERIAL_NUMBER_REQUEST, None, _SERIAL_NUMBER_RESPONSE + ) return response.serial_number def get_datetime(self): - response = self._send_request( - _READ_RTC_REQUEST, None, _READ_RTC_RESPONSE) + response = self._send_request(_READ_RTC_REQUEST, None, _READ_RTC_RESPONSE) return response.timestamp def _set_device_datetime(self, date): - self._send_request( - _WRITE_RTC_REQUEST, { - 'timestamp': date, - }, _COMMAND_SUCCESS) + self._send_request(_WRITE_RTC_REQUEST, {"timestamp": date,}, _COMMAND_SUCCESS) # The device does not return the new datetime, so confirm by calling # READ RTC again. return self.get_datetime() def zero_log(self): - self._send_request( - _MEMORY_ERASE_REQUEST, None, - _COMMAND_SUCCESS) + self._send_request(_MEMORY_ERASE_REQUEST, None, _COMMAND_SUCCESS) def get_glucose_unit(self): response = self._send_request( - _GLUCOSE_UNIT_REQUEST, None, _GLUCOSE_UNIT_RESPONSE) + _GLUCOSE_UNIT_REQUEST, None, _GLUCOSE_UNIT_RESPONSE + ) return response.unit def _get_reading_count(self): response = self._send_request( - _READ_RECORD_COUNT_REQUEST, None, _READ_RECORD_COUNT_RESPONSE) + _READ_RECORD_COUNT_REQUEST, None, _READ_RECORD_COUNT_RESPONSE + ) return response.count def _get_reading(self, record_id): response = self._send_request( - _READ_RECORD_REQUEST, {'record_id': record_id}, _READING_RESPONSE) + _READ_RECORD_REQUEST, {"record_id": record_id}, _READING_RESPONSE + ) if response.control_test: - logging.debug('control solution test, ignoring.') + logging.debug("control solution test, ignoring.") return None return common.GlucoseReading( - response.timestamp, float(response.value), meal=response.meal) + response.timestamp, float(response.value), meal=response.meal + ) def get_readings(self): record_count = self._get_reading_count() |