Skip to content

Commit

Permalink
snoop: correctly detect response types and streamline terminal output
Browse files Browse the repository at this point in the history
Once upon a time, the `response_type` property of `Response` objects
used to be a string. In modern times it has become an enum in order to
make it play nicely with type checking.

Besides this, the output of the snoop tool is slightly decluttered,
i.e., it does not prefix everything which is send by the tester by
`tester:` and everything send by the ECU by `ECU:`. (this is IMO quite
clear from the context.)

Signed-off-by: Andreas Lauser <[email protected]>
Signed-off-by: Gerrit Ecke <[email protected]>
  • Loading branch information
andlaus committed Feb 6, 2024
1 parent 5fd1a00 commit 57e8394
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions odxtools/cli/snoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import odxtools.uds as uds
from odxtools.exceptions import DecodeError
from odxtools.isotp_state_machine import IsoTpStateMachine
from odxtools.response import Response, ResponseType

from . import _parser_utils

Expand All @@ -31,7 +32,7 @@ def handle_telegram(telegram_id: int, payload: bytes) -> None:

if telegram_id == ecu_tx_id:
if uds.is_response_pending(payload):
print(f" -> ECU: ... (response pending)")
print(f" ... (response pending)")
return

decoded_message = None
Expand All @@ -48,21 +49,29 @@ def handle_telegram(telegram_id: int, payload: bytes) -> None:
if len(decoded_message) > 1:
dec_str = f" (decoding {i+1})"

response_type = getattr(resp.coding_object, "response_type", None)
rt_str = "unknown"
if response_type == "POS-RESPONSE":
rt_str = "positive"
elif response_type == "NEG-RESPONSE":
rt_str = "negative"

print(f" -> {rt_str} ECU response{dec_str}: \"{resp.coding_object.short_name}\"")
if isinstance(resp.coding_object, Response):
if resp.coding_object.response_type == ResponseType.POSITIVE:
rt_str = "positive"
elif resp.coding_object.response_type in (ResponseType.NEGATIVE,
ResponseType.GLOBAL_NEGATIVE):
rt_str = "negative"

settable_params = []
for param_name, param_val in resp.param_dict.items():
param = [x for x in params if x.short_name == param_name][0]
if not param.is_settable:
continue
print(f" {param_name} = {repr(param_val)}")
settable_params.append((param_name, param_val))

if settable_params:
print(f" {rt_str} response{dec_str} {resp.coding_object.short_name}:")
for param_name, param_val in settable_params:
print(f" {param_name} = {repr(param_val)}")
else:
print(f" {rt_str} response{dec_str} {resp.coding_object.short_name}")
else:
print(f" -> ECU response: unrecognized response of {len(payload)} bytes length: "
print(f" unrecognized response of {len(payload)} bytes length: "
f"0x{payload.hex()}")

return
Expand All @@ -76,7 +85,7 @@ def handle_telegram(telegram_id: int, payload: bytes) -> None:
last_request = None

if decoded_message is not None:
print(f"tester request: \"{decoded_message.coding_object.short_name}\"")
print(f"request {decoded_message.coding_object.short_name}:")
params = decoded_message.coding_object.parameters
for param_name, param_val in decoded_message.param_dict.items():
param = [x for x in params if x.short_name == param_name][0]
Expand Down

0 comments on commit 57e8394

Please sign in to comment.