Skip to content

Commit

Permalink
Feat/add response timing (#15)
Browse files Browse the repository at this point in the history
* feat: add response timing

* chore: fix typo in changelog

* feat: modify last pending resp times to be the interval between each pending response

* chore: fix typo

Co-authored-by: Sebastian Clerson <58192998+sebclrsn@users.noreply.github.com>

---------

Co-authored-by: Sebastian Clerson <58192998+sebclrsn@users.noreply.github.com>
  • Loading branch information
TedRio and sebclrsn committed Aug 28, 2023
1 parent 724ee2b commit 2d8d5dc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

## [3.1.0]

### Features
- ``Uds``: add response time and list of response pending times as attribute

## [3.0.3]

### Features
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -28,7 +28,7 @@
tests_require=["pytest", "pytest-mock"],
extras_require={"test": ["pytest", "pytest-mock"]},
# *strongly* suggested for sharing
version="3.0.3",
version="3.1.0",
# The license can be anything you like
license="MIT",
description="Please use python-uds instead, this is a refactored version with breaking changes, only for pykiso",
Expand Down
19 changes: 17 additions & 2 deletions uds/uds_communications/Uds/Uds.py
Expand Up @@ -39,6 +39,9 @@ def __init__(self, odx=None, ihexFile=None, **kwargs):
self.__transportProtocol, **kwargs
)

self.last_resp_time = None
self.last_pending_resp_times = []

# used as a semaphore for the tester present
self.__transmissionActive_flag = False

Expand Down Expand Up @@ -123,6 +126,7 @@ def send(self, msg, responseRequired=True, functionalReq=False, tpWaitTime=0.01)
# sets a current transmission in progress - tester present (if running) will not send if this flag is set to true
self.__transmissionActive_flag = True

before_send_time = time.perf_counter()
# We're moving to threaded operation, so putting a lock around the send operation.
with self.sendLock:
self.tp.send(msg, functionalReq, tpWaitTime)
Expand All @@ -132,13 +136,24 @@ def send(self, msg, responseRequired=True, functionalReq=False, tpWaitTime=0.01)

# Note: in automated mode (unlikely to be used any other way), there is no response from tester present, so threading is not an issue here.
response = None

previous_time = None
self.last_resp_time = None
self.last_pending_resp_times = []

if responseRequired:
while True:
response = self.tp.recv(self.__P2_CAN_Client)
current_time = time.perf_counter() - before_send_time
if response[2] == 0x78:
if previous_time is None:
self.last_pending_resp_times.append(current_time)
previous_time = current_time
else:
self.last_pending_resp_times.append(current_time - previous_time)
if not ((response[0] == 0x7F) and (response[2] == 0x78)):
self.last_resp_time = current_time
break

# If the diagnostic session control service is supported, record the sending time for possible use by the tester present functionality (again, if present) ...
if hasattr(self, "sessionSetLastSend"):
self.sessionSetLastSend()
Expand Down

0 comments on commit 2d8d5dc

Please sign in to comment.