Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3823816

Browse files
committedNov 6, 2023
Minor fixes and DSC functionality addition to dump_dids
1 parent 6ac7cdd commit 3823816

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed
 

‎caringcaribou/modules/uds.py

+21-11
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,7 @@ def send_key(arb_id_request, arb_id_response, level, key, timeout):
900900

901901
def __dump_dids_wrapper(args):
902902
"""Wrapper used to initiate data identifier dump"""
903+
diagnostic = args.dsc
903904
arb_id_request = args.src
904905
arb_id_response = args.dst
905906
timeout = args.timeout
@@ -920,7 +921,7 @@ def __dump_dids_wrapper(args):
920921

921922
padding_set(padding, no_padding)
922923

923-
dump_dids(arb_id_request, arb_id_response, timeout, reporting, min_did, max_did,
924+
dump_dids(arb_id_request, arb_id_response, timeout, reporting, diagnostic, min_did, max_did,
924925
print_results)
925926

926927
def report_print(text):
@@ -1236,7 +1237,7 @@ def __auto_wrapper(args):
12361237
report_print("\nDiscovery failed: {0}".format(e))
12371238

12381239

1239-
def dump_dids(arb_id_request, arb_id_response, timeout, reporting,
1240+
def dump_dids(arb_id_request, arb_id_response, timeout, reporting, diagnostic,
12401241
min_did=DUMP_DID_MIN, max_did=DUMP_DID_MAX, print_results=True):
12411242
"""
12421243
Sends read data by identifier (DID) messages to 'arb_id_request'.
@@ -1275,6 +1276,10 @@ def dump_dids(arb_id_request, arb_id_response, timeout, reporting,
12751276
global REPORT
12761277
REPORT = 1
12771278

1279+
response_diag = extended_session(arb_id_request, arb_id_response, diagnostic)
1280+
if not Iso14229_1.is_positive_response(response_diag):
1281+
raise ValueError("Supplied Diagnostic Session Control subservice results in Negative Response")
1282+
12781283
responses = []
12791284
with IsoTp(arb_id_request=arb_id_request,
12801285
arb_id_response=arb_id_response) as tp:
@@ -1561,7 +1566,7 @@ def __routine_control_dump_wrapper(args):
15611566
"""Wrapper used to initiate routine dump"""
15621567
arb_id_request = args.src
15631568
arb_id_response = args.dst
1564-
dsc = args.dsc
1569+
diagnostic = args.dsc
15651570
subfunction = args.subfunction
15661571
timeout = args.timeout
15671572
min_routine = args.min_routine
@@ -1571,14 +1576,14 @@ def __routine_control_dump_wrapper(args):
15711576

15721577
padding_set(padding, no_padding)
15731578

1574-
found_routines = routine_control_dump(arb_id_request, arb_id_response, timeout, dsc, subfunction, min_routine, max_routine)
1579+
found_routines = routine_control_dump(arb_id_request, arb_id_response, timeout, diagnostic, subfunction, min_routine, max_routine)
15751580

15761581
print("\nDiscovered Routines:")
15771582
# Print results
15781583
for routine_id in found_routines:
15791584
print(routine_id)
15801585

1581-
def routine_control_dump(arb_id_request, arb_id_response, timeout, dsc, subfunction,
1586+
def routine_control_dump(arb_id_request, arb_id_response, timeout, diagnostic, subfunction,
15821587
min_routine=DUMP_ROUTINE_MIN, max_routine=DUMP_ROUTINE_MAX):
15831588
"""
15841589
Sends start routine messages to 'arb_id_request'.
@@ -1630,12 +1635,14 @@ def routine_control_dump(arb_id_request, arb_id_response, timeout, dsc, subfunct
16301635

16311636
print('Enumerating Routines with attributes:')
16321637

1633-
print('Diagnostic Session Control: 0x{0:02x}'.format(dsc))
1638+
print('Diagnostic Session Control: 0x{0:02x}'.format(diagnostic))
16341639
print('Routine Control Sub Function: 0x{0:02x}'.format(subfunction))
16351640
print('Minimum Routine: 0x{:04x}'.format(min_routine))
16361641
print('Maximum Routine: 0x{:04x}'.format(max_routine))
16371642

1638-
raw_send(arb_id_request, arb_id_response, ServiceID.DIAGNOSTIC_SESSION_CONTROL, dsc)
1643+
response_diag = extended_session(arb_id_request, arb_id_response, diagnostic)
1644+
if not Iso14229_1.is_positive_response(response_diag):
1645+
raise ValueError("Supplied Diagnostic Session Control subservice results in Negative Response")
16391646

16401647
for routine in range(min_routine, max_routine + 1):
16411648
response = uds.routine_control(subfunction, routine=[routine])
@@ -1645,7 +1652,7 @@ def routine_control_dump(arb_id_request, arb_id_response, timeout, dsc, subfunct
16451652
if len(response) >= 2:
16461653
if Iso14229_1.is_positive_response(response):
16471654
found_routines.append('0x{:04x}'.format(routine))
1648-
if len(response) < 2:
1655+
if response is None or len(response) == 0:
16491656
continue
16501657

16511658
print("\033[K", file=stderr)
@@ -1875,6 +1882,9 @@ def __parse_args(args):
18751882
default=DUMP_DID_TIMEOUT,
18761883
help="wait T seconds for response before "
18771884
"timeout")
1885+
parser_did.add_argument("--dsc", metavar="dtype",
1886+
type=parse_int_dec_or_hex, default="0x01",
1887+
help="Diagnostic Session Control Subsession Byte")
18781888
parser_did.add_argument("--min_did",
18791889
type=parse_int_dec_or_hex,
18801890
default=DUMP_DID_MIN,
@@ -1995,15 +2005,15 @@ def __parse_args(args):
19952005

19962006
# Parser for write_did
19972007
parser_wdid = subparsers.add_parser("write_dids")
1998-
parser_wdid.add_argument("dsc", metavar="dtype",
1999-
type=parse_int_dec_or_hex, default="0x03",
2000-
help="Diagnostic Session Control Subsession Byte")
20012008
parser_wdid.add_argument("src",
20022009
type=parse_int_dec_or_hex,
20032010
help="arbitration ID to transmit to")
20042011
parser_wdid.add_argument("dst",
20052012
type=parse_int_dec_or_hex,
20062013
help="arbitration ID to listen to")
2014+
parser_wdid.add_argument("--dsc", metavar="dtype",
2015+
type=parse_int_dec_or_hex, default="0x03",
2016+
help="Diagnostic Session Control Subsession Byte")
20072017
parser_wdid.add_argument("-t", "--timeout",
20082018
type=float, metavar="T",
20092019
default=DUMP_DID_TIMEOUT,

0 commit comments

Comments
 (0)
Please sign in to comment.