diff options
author | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2018-11-16 00:31:22 +0100 |
---|---|---|
committer | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2018-11-16 00:31:22 +0100 |
commit | b0f52759910837f35bfceedc2cbc23bcd0d9f18b (patch) | |
tree | cc1875142ecf0aaf78d51803c868797bf77aa471 | |
parent | Don't fold the command prefix into the LifeScanPacket. (diff) | |
download | glucometerutils-b0f52759910837f35bfceedc2cbc23bcd0d9f18b.tar glucometerutils-b0f52759910837f35bfceedc2cbc23bcd0d9f18b.tar.gz glucometerutils-b0f52759910837f35bfceedc2cbc23bcd0d9f18b.tar.bz2 glucometerutils-b0f52759910837f35bfceedc2cbc23bcd0d9f18b.tar.lz glucometerutils-b0f52759910837f35bfceedc2cbc23bcd0d9f18b.tar.xz glucometerutils-b0f52759910837f35bfceedc2cbc23bcd0d9f18b.tar.zst glucometerutils-b0f52759910837f35bfceedc2cbc23bcd0d9f18b.zip |
-rw-r--r-- | glucometerutils/drivers/otultraeasy.py | 29 | ||||
-rw-r--r-- | test/test_otultraeasy.py | 30 |
2 files changed, 49 insertions, 10 deletions
diff --git a/glucometerutils/drivers/otultraeasy.py b/glucometerutils/drivers/otultraeasy.py index 323ebd7..3c0098a 100644 --- a/glucometerutils/drivers/otultraeasy.py +++ b/glucometerutils/drivers/otultraeasy.py @@ -92,6 +92,19 @@ _READING_RESPONSE = construct.Struct( 'value' / construct.Int32ul, ) +def _make_packet( + message, sequence_number, expect_receive, acknowledge, disconnect): + return _PACKET.build( + {'data': {'value': { + 'message': message, + 'link_control': { + 'sequence_number': sequence_number, + 'expect_receive': expect_receive, + 'acknowledge': acknowledge, + 'disconnect': disconnect, + }, + }}}) + class Device(serial.SerialDevice): BAUDRATE = 9600 DEFAULT_CABLE_ID = '067b:2303' # Generic PL2303 cable. @@ -116,16 +129,12 @@ class Device(serial.SerialDevice): self.connect() def _send_packet(self, message, acknowledge=False, disconnect=False): - pkt = _PACKET.build( - {'data': {'value': { - 'message': message, - 'link_control': { - 'sequence_number': self.sent_counter_, - 'expect_receive': self.expect_receive_, - 'acknowledge': acknowledge, - 'disconnect': disconnect, - }, - }}}) + pkt = _make_packet( + message, + self.sent_counter_, + self.expect_receive_, + acknowledge, + disconnect) logging.debug('sending packet: %s', binascii.hexlify(pkt)) self.serial_.write(pkt) diff --git a/test/test_otultraeasy.py b/test/test_otultraeasy.py new file mode 100644 index 0000000..6d802db --- /dev/null +++ b/test/test_otultraeasy.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +"""Tests for the LifeScan OneTouch Ultra Easy driver.""" + +__author__ = 'Diego Elio Pettenò' +__email__ = 'flameeyes@flameeyes.eu' +__copyright__ = 'Copyright © 2018, Diego Elio Pettenò' +__license__ = 'MIT' + +# pylint: disable=protected-access,missing-docstring + +from absl.testing import absltest + +from glucometerutils.drivers import otultraeasy + + +class ConstructTest(absltest.TestCase): + + def test_make_packet_ack(self): + self.assertEqual( + b'\x02\x06\x08\x03\xc2\x62', + otultraeasy._make_packet(b'', False, False, False, True)) + + def test_make_packet_version_request(self): + self.assertEqual( + b'\x02\x09\x03\x05\x0d\x02\x03\x08\x9f', + otultraeasy._make_packet( + b'\x05\x0d\x02', True, True, False, False)) + +if __name__ == '__main__': + absltest.main() |