Skip to content

Commit

Permalink
Merge pull request #126 from danielhrisca/master
Browse files Browse the repository at this point in the history
slight optimization for the USB transport
  • Loading branch information
christoph2 committed Jan 2, 2023
2 parents f1703d9 + fe17f9f commit 44c2e7c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
3 changes: 0 additions & 3 deletions pyxcp/transport/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,12 @@ def processResponse(self, response, length, counter, recv_timestamp=None):
)
)
if pid >= 0xFE:
# self.resQueue.put(response)
self.resQueue.append(response)
self.recv_timestamp = recv_timestamp
elif pid == 0xFD:
# self.evQueue.put(response)
self.process_event_packet(response)
self.evQueue.append(response)
elif pid == 0xFC:
# self.servQueue.put(response)
self.servQueue.append(response)
else:
if self._debug:
Expand Down
1 change: 0 additions & 1 deletion pyxcp/transport/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ def listen(self):
break
else:
if current_size >= length:
# response = memoryview(data[current_position : current_position + length])
response = data[current_position : current_position + length]
processResponse(response, length, counter, timestamp)

Expand Down
9 changes: 5 additions & 4 deletions pyxcp/transport/usb_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def _packet_listen(self):
read = self.reply_endpoint.read

buffer = array("B", bytes(RECV_SIZE))
buffer_view = memoryview(buffer)

while True:
try:
Expand All @@ -115,7 +116,7 @@ def _packet_listen(self):
recv_timestamp = timestamp_origin + perf_counter() - perf_counter_origin
read_count = read(buffer, 100) # 100ms timeout
if read_count != RECV_SIZE:
_packets.append((buffer.tobytes()[:read_count], recv_timestamp))
_packets.append((buffer_view[:read_count].tobytes(), recv_timestamp))
else:
_packets.append((buffer.tobytes(), recv_timestamp))
except BaseException:
Expand Down Expand Up @@ -176,7 +177,7 @@ def listen(self):
break
else:
if current_size >= length:
response = memoryview(data[current_position : current_position + length])
response = data[current_position : current_position + length]
processResponse(response, length, counter, timestamp)

current_size -= length
Expand All @@ -198,7 +199,7 @@ def send(self, frame):
# sometimes usb.core.USBError: [Errno 5] Input/Output Error is raised
# even though the command is send and a reply is received from the device.
# Ignore this here since a Timeout error will be raised anyway if
# the device does not responde
# the device does not respond
pass
self.post_send_timestamp = time()
else:
Expand All @@ -209,7 +210,7 @@ def send(self, frame):
# sometimes usb.core.USBError: [Errno 5] Input/Output Error is raised
# even though the command is send and a reply is received from the device.
# Ignore this here since a Timeout error will be raised anyway if
# the device does not responde
# the device does not respond
pass
post_send_timestamp = perf_counter()
self.pre_send_timestamp = self.timestamp_origin + pre_send_timestamp - self.perf_counter_origin
Expand Down

0 comments on commit 44c2e7c

Please sign in to comment.