From 2d8d5dcd95cc594b45fe50db7190c1a527915a06 Mon Sep 17 00:00:00 2001 From: TedRio <100120740+TedRio@users.noreply.github.com> Date: Mon, 28 Aug 2023 15:49:37 +0200 Subject: [PATCH] Feat/add response timing (#15) * 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> --- CHANGELOG.md | 5 +++++ setup.py | 2 +- uds/uds_communications/Uds/Uds.py | 19 +++++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2872ce4..ea1b4df 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/setup.py b/setup.py index ba1c68a..624280c 100644 --- a/setup.py +++ b/setup.py @@ -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", diff --git a/uds/uds_communications/Uds/Uds.py b/uds/uds_communications/Uds/Uds.py index 4aaf15b..16699cb 100644 --- a/uds/uds_communications/Uds/Uds.py +++ b/uds/uds_communications/Uds/Uds.py @@ -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 @@ -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) @@ -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()