diff options
-rw-r--r-- | README.md | 10 | ||||
-rw-r--r-- | glucometerutils/drivers/td42xx.py (renamed from glucometerutils/drivers/td4277.py) | 24 | ||||
-rw-r--r-- | glucometerutils/drivers/tests/test_td4277.py | 28 |
3 files changed, 22 insertions, 40 deletions
@@ -61,10 +61,12 @@ supported. | Abbott | FreeStyle Optium Neo H | `fsprecisionneo` | [freestyle-hid] [hidapi]‡ | | Roche | Accu-Chek Mobile | `accuchek_reports` | | | SD Biosensor | SD CodeFree | `sdcodefree` | [construct] [pyserial] | -| TaiDoc | TD-4277 | `td4277` | [construct] [pyserial]² [hidapi] | -| GlucoRx | Nexus | `td4277` | [construct] [pyserial]² [hidapi] | -| Menarini | GlucoMen Nexus | `td4277` | [construct] [pyserial]² [hidapi] | -| Aktivmed | GlucoCheck XL | `td4277` | [construct] [pyserial]² [hidapi] | +| TaiDoc | TD-4277 | `td42xx` | [construct] [pyserial]² [hidapi] | +| TaiDoc | TD-4235B | `td42xx` | [construct] [pyserial]² [hidapi] | +| GlucoRx | Nexus | `td42xx` | [construct] [pyserial]² [hidapi] | +| GlucoRx | NexusQ | `td42xx` | [construct] [pyserial]² [hidapi] | +| Menarini | GlucoMen Nexus | `td42xx` | [construct] [pyserial]² [hidapi] | +| Aktivmed | GlucoCheck XL | `td42xx` | [construct] [pyserial]² [hidapi] | | Ascensia | ContourUSB | `contourusb` | [construct] [hidapi]‡ | † Untested. diff --git a/glucometerutils/drivers/td4277.py b/glucometerutils/drivers/td42xx.py index ecbd2ed..0487029 100644 --- a/glucometerutils/drivers/td4277.py +++ b/glucometerutils/drivers/td42xx.py @@ -2,7 +2,7 @@ # # SPDX-FileCopyrightText: © 2019 The glucometerutils Authors # SPDX-License-Identifier: MIT -"""Driver for TaiDoc TD-4277 devices. +"""Driver for TaiDoc TD-42xx devices. Supported features: - get readings, including pre-/post-meal notes; @@ -69,7 +69,7 @@ _GET_READING_VALUE = 0x26 _CLEAR_MEMORY = 0x52 _MODEL_STRUCT = construct.Struct( - const=construct.Const(b"\x77\x42"), + model=construct.Int16ul, unknown_1=construct.Byte, unknown_2=construct.Byte, ) @@ -104,7 +104,7 @@ _MEAL_FLAG = { _READING_VALUE_STRUCT = construct.Struct( value=construct.Int16ul, - const=construct.Const(b"\x06"), + unknown_1=construct.Byte, meal=construct.Mapping(construct.Byte, _MEAL_FLAG), ) @@ -176,19 +176,27 @@ class Device(serial.SerialDevice, driver.GlucometerDevice): f"Invalid response received: {response_command:02x} {message!r}" ) + self._get_model() + + def _get_model(self) -> str: _, model_message = self._send_command(_GET_MODEL) try: - _MODEL_STRUCT.parse(model_message) - except construct.ConstructError: + result = _MODEL_STRUCT.parse(model_message) + except construct.ConstructError as e: raise exceptions.ConnectionFailed( - f"Invalid model identified: {model_message!r}" - ) + f"Invalid model response: {model_message!r}" + ) from e + + # The model number is presented as BCD (Binary Coded Decimal). + model_number = hex(result.model)[2:] + + return f"TD-{model_number}" def disconnect(self) -> None: pass def get_meter_info(self) -> common.MeterInfo: - return common.MeterInfo("TaiDoc TD-4277 glucometer") + return common.MeterInfo(f"TaiDoc {self._get_model()} glucometer") def get_version(self) -> NoReturn: # pylint: disable=no-self-use raise NotImplementedError diff --git a/glucometerutils/drivers/tests/test_td4277.py b/glucometerutils/drivers/tests/test_td4277.py deleted file mode 100644 index 031381f..0000000 --- a/glucometerutils/drivers/tests/test_td4277.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- -# -# SPDX-FileCopyrightText: © 2019 The glucometerutils Authors -# SPDX-License-Identifier: MIT -"""Tests for the TD-4277 driver.""" - -# pylint: disable=protected-access,missing-docstring - -import datetime - -from absl.testing import parameterized - -from glucometerutils.drivers import td4277 - - -class TestTD4277Nexus(parameterized.TestCase): - @parameterized.parameters( - (b"\x21\x24\x0e\x15", datetime.datetime(2018, 1, 1, 21, 14)), - (b"\x21\x26\x0e\x15", datetime.datetime(2019, 1, 1, 21, 14)), - (b"\x04\x27\x25\x0d", datetime.datetime(2019, 8, 4, 13, 37)), - ) - def test_parse_datetime(self, message, date): - self.assertEqual(td4277._parse_datetime(message), date) - - def test_making_message(self): - self.assertEqual( - td4277._make_packet(0x22, 0), b"\x51\x22\x00\x00\x00\x00\xa3\x16" - ) |