From 9d3e0ee1fb2dd2db8d838723316c8329d049b51d Mon Sep 17 00:00:00 2001 From: Arkadiusz Bulski Date: Fri, 16 Feb 2018 08:51:39 +0100 Subject: construct code fixed improper embedding --- glucometerutils/drivers/otultraeasy.py | 6 +++--- glucometerutils/drivers/otverio2015.py | 10 +++++----- glucometerutils/drivers/otverioiq.py | 6 +++--- glucometerutils/support/lifescan_binary_protocol.py | 6 ++---- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/glucometerutils/drivers/otultraeasy.py b/glucometerutils/drivers/otultraeasy.py index 8e794ca..f0e16a7 100644 --- a/glucometerutils/drivers/otultraeasy.py +++ b/glucometerutils/drivers/otultraeasy.py @@ -116,7 +116,7 @@ class Device(serial.SerialDevice): def _send_packet(self, message, acknowledge=False, disconnect=False): pkt = _PACKET.build( - {'value': { + {'data': {'value': { 'message': message, 'link_control': { 'sequence_number': self.sent_counter_, @@ -124,14 +124,14 @@ class Device(serial.SerialDevice): 'acknowledge': acknowledge, 'disconnect': disconnect, }, - }}) + }}}) 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_) + raw_pkt = self.buffered_reader_.parse_stream(self.serial_).data logging.debug('received packet: %r', raw_pkt) # discard the checksum and copy diff --git a/glucometerutils/drivers/otverio2015.py b/glucometerutils/drivers/otverio2015.py index 2589a97..833ad43 100644 --- a/glucometerutils/drivers/otverio2015.py +++ b/glucometerutils/drivers/otverio2015.py @@ -42,8 +42,8 @@ from glucometerutils.support import lifescan_binary_protocol _REGISTER_SIZE = 512 _PACKET = construct.Padded( - _REGISTER_SIZE, construct.Embedded( - lifescan_binary_protocol.LifeScanPacket(0x03, False))) + _REGISTER_SIZE, + lifescan_binary_protocol.LifeScanPacket(0x03, False)) _QUERY_REQUEST = construct.Struct( construct.Const(b'\xe6\x02'), @@ -157,9 +157,9 @@ class Device(object): """ try: request = request_format.build(request_obj) - request_raw = _PACKET.build({'value': { + request_raw = _PACKET.build({'data': {'value': { 'message': request, - }}) + }}}) logging.debug( 'Request sent: %s', binascii.hexlify(request_raw)) self.scsi_.write10(lba, 1, request_raw) @@ -167,7 +167,7 @@ class Device(object): response_raw = self.scsi_.read10(lba, 1) logging.debug( 'Response received: %s', binascii.hexlify(response_raw.datain)) - response_pkt = _PACKET.parse(response_raw.datain) + response_pkt = _PACKET.parse(response_raw.datain).data logging.debug('Response packet: %r', response_pkt) response = response_format.parse(response_pkt.value.message) diff --git a/glucometerutils/drivers/otverioiq.py b/glucometerutils/drivers/otverioiq.py index 669900e..cecac4e 100644 --- a/glucometerutils/drivers/otverioiq.py +++ b/glucometerutils/drivers/otverioiq.py @@ -120,16 +120,16 @@ class Device(serial.SerialDevice): def _send_packet(self, message): pkt = _PACKET.build( - {'value': { + {'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_) + raw_pkt = self.buffered_reader_.parse_stream(self.serial_).data logging.debug('received packet: %r', raw_pkt) # discard the checksum and copy diff --git a/glucometerutils/support/lifescan_binary_protocol.py b/glucometerutils/support/lifescan_binary_protocol.py index 6579ab0..22e96d9 100644 --- a/glucometerutils/support/lifescan_binary_protocol.py +++ b/glucometerutils/support/lifescan_binary_protocol.py @@ -36,8 +36,7 @@ def LifeScanPacket(command_prefix, include_link_control): command_prefix_construct = construct.Const(command_prefix, construct.Byte) return construct.Struct( - construct.RawCopy( - construct.Embedded( + 'data' / construct.RawCopy( construct.Struct( construct.Const(b'\x02'), # stx 'length' / construct.Rebuild( @@ -48,10 +47,9 @@ def LifeScanPacket(command_prefix, include_link_control): length=lambda ctx: ctx.length - 7), construct.Const(b'\x03'), # etx ), - ), ), 'checksum' / construct.Checksum( - construct.Int16ul, lifescan.crc_ccitt, construct.this.data), + construct.Int16ul, lifescan.crc_ccitt, construct.this.data.data), ) COMMAND_SUCCESS = construct.Const(b'\x06') -- cgit v1.2.3