Skip to content

Commit 5675d8e

Browse files
authored
fix: uds log less data when sending message (#565)
1 parent b8dd29c commit 5675d8e

3 files changed

Lines changed: 26 additions & 13 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pykiso"
3-
version = "1.6.2"
3+
version = "1.6.3"
44
description = "Embedded integration testing framework."
55
authors = ["Sebastian Fischer <sebastian.fischer@de.bosch.com>"]
66
license = "Eclipse Public License - v 2.0"

src/pykiso/lib/auxiliaries/udsaux/common/uds_response.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,28 @@ def __init__(
5353
self.resp_time = resp_time
5454
self.pending_resp_times = pending_resp_times
5555

56-
def __repr__(self):
57-
if self.data:
58-
if self.is_negative:
59-
return f"NegativeUdsResponse({bytes(self.data).hex(sep=' ')}, nrc={self.nrc.name})"
60-
return f"{self.__class__.__name__}({bytes(self.data).hex(sep=' ')})"
61-
else:
56+
def __repr__(self, truncate=False):
57+
"""Return a string representation of the UDS response.
58+
59+
:param truncate: If True, only show first 6 bytes of data
60+
:return: String representation of UdsResponse
61+
"""
62+
if not self.data:
6263
return f"{self.__class__.__name__} no data."
6364

65+
data_to_show = self.data[:6] if truncate else self.data
66+
67+
if self.is_negative:
68+
return f"NegativeUdsResponse({bytes(data_to_show).hex(sep=' ')}, nrc={self.nrc.name})"
69+
return f"{self.__class__.__name__}({bytes(data_to_show).hex(sep=' ')})"
70+
71+
def get_truncated_representation(self) -> str:
72+
"""Return a truncated string representation of the UDS response.
73+
74+
:return: Truncated string representation showing only first 6 bytes
75+
"""
76+
return self.__repr__(truncate=True)
77+
6478

6579
class NegativeResponseCode(IntEnum):
6680
"""NRC code response"""

src/pykiso/lib/auxiliaries/udsaux/uds_auxiliary.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def send_uds(
135135
if log.isEnabledFor(logging.getLogger().level):
136136
log.internal_info(
137137
"UDS request to send '%s'",
138-
["0x{:02X}".format(i) for i in msg_to_send],
138+
["0x{:02X}".format(i) for i in msg_to_send[:6]],
139139
)
140140
resp = self.uds_config.send(
141141
msg_to_send,
@@ -157,14 +157,12 @@ def send_uds(
157157
resp_time=self.uds_config.last_resp_time,
158158
pending_resp_times=self.uds_config.last_pending_resp_times,
159159
)
160-
log.internal_info("UDS response received %s", resp)
160+
if log.isEnabledFor(logging.getLogger().level):
161+
log.internal_info("UDS response received %s", resp.get_truncated_representation())
161162
return resp
162163

163164
def send_uds_raw(
164-
self,
165-
msg_to_send: Union[bytes, List[int], tuple],
166-
timeout_in_s: float = 6,
167-
response_required: bool = True,
165+
self, msg_to_send: Union[bytes, List[int], tuple], timeout_in_s: float = 6, response_required: bool = True
168166
) -> Union[UdsResponse, bool]:
169167
"""Send a UDS diagnostic request to the target ECU and check response.
170168
Deprecated alias of `send_uds` that returns `False` on error,
@@ -182,6 +180,7 @@ def send_uds_raw(
182180
not expected and the command is properly sent otherwise
183181
False
184182
"""
183+
185184
try:
186185
return True if (response := self.send_uds(msg_to_send, response_required)) is None else response
187186
except self.errors.ResponseNotReceivedError as exc:

0 commit comments

Comments
 (0)