Skip to content

Commit

Permalink
filter extraneous dids, update testing infra to respond properly to dids
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdetrano committed Jan 23, 2024
1 parent f314698 commit 19c612e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 19 deletions.
30 changes: 21 additions & 9 deletions caringcaribou/modules/uds.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,18 +1074,30 @@ def dump_dids(arb_id_request, arb_id_response, timeout,
print('Identified DIDs:')
print('DID Value (hex)')
for identifier in range(min_did, max_did + 1):
print(f'0x{identifier:04x}', end='\r', file=stderr)
if print_results:
print(f'0x{identifier:04x}', end='\r', file=stderr)
response = uds.read_data_by_identifier(identifier=[identifier])

# Only keep positive responses
if response and Iso14229_1.is_positive_response(response):
responses.append((identifier, response))
# only display the data record portion of the payload
# response[0] = response SID (0x62)
# response[1:3] = Data Identifier (DID)
# response[3:] = data
if print_results and len(response) > 3:
print('0x{:04x}'.format(identifier), list_to_hex_str(response[3:]))
if not response:
continue
if not Iso14229_1.is_positive_response(response):
continue
# should be 4 byte minimum for 1 byte response
# [response_code, DID_upper, DID_lower, data_0]
if len(response) < 4:
continue

if identifier != int(list_to_hex_str(response[1:3]), 16):
continue

responses.append((identifier, response))
# only display the data record portion of the payload
# response[0] = response SID (0x62)
# response[1:3] = Data Identifier (DID)
# response[3:] = data
if print_results:
print('0x{:04x}'.format(identifier), list_to_hex_str(response[3:]))
if print_results:
print("\033[K", file=stderr) # clear line
print("Done!")
Expand Down
4 changes: 3 additions & 1 deletion caringcaribou/tests/mock/mock_ecu_uds.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,14 @@ def handle_read_data_by_identifier(self, data):
:return: Response to be sent
"""
service_id = data[0]
data_id = data[1:3]
request = data[2]

if request == self.IDENTIFIER_REQUEST_POSITIVE:
# Request for positive response
# TODO Actually read a parameter from memory
payload = [self.IDENTIFIER_REQUEST_POSITIVE_RESPONSE]
payload = data_id
payload.append(self.IDENTIFIER_REQUEST_POSITIVE_RESPONSE)
response_data = self.create_positive_response(service_id, payload)
elif request == self.IDENTIFIER_REQUEST_NEGATIVE:
# Request for negative response - use Conditions Not Correct
Expand Down
9 changes: 8 additions & 1 deletion caringcaribou/tests/test_iso_14229_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,15 @@ def test_create_iso_14229_1(self):
def test_read_data_by_identifier_success(self):
service_id = iso14229_1.ServiceID.READ_DATA_BY_IDENTIFIER
identifier = [MockEcuIso14229.IDENTIFIER_REQUEST_POSITIVE]
expected_response = [MockEcuIso14229.IDENTIFIER_REQUEST_POSITIVE_RESPONSE]
expected_response = [0x00,
MockEcuIso14229.IDENTIFIER_REQUEST_POSITIVE,
MockEcuIso14229.IDENTIFIER_REQUEST_POSITIVE_RESPONSE]
result = self.diagnostics.read_data_by_identifier(identifier=identifier)

# result looks like [0x62, DID_ADDR_UPPER, DID_ADDR_LOWER, RESULT]
#rsp_pos = result[0]
#rx_identifier = result[1:3]
print(result)
self.verify_positive_response(service_id, result, expected_response)

def test_read_data_by_identifier_failure(self):
Expand Down
21 changes: 13 additions & 8 deletions caringcaribou/tests/test_module_uds.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,16 @@ def test_security_access_request_seed_invalid_level(self):
timeout=timeout)

def test_dump_dids(self):
# mock ECU responds to DIDs 0x0001, 0x0101, 0x0201...0xff01
# response data is always 6272
# scanning 0x0000...0x0101 should yield 2 positive responses out of 258 requests
# and each response will contain 6272
# mock ECU responds to DIDs 0x0001, 0x0101, 0x0201...
# response data is always 62, 00, 01, 72
# scanning 0x0000...0x0101 should yield 1 positive responses out of 258 requests
#
timeout = None
min_did = 0x0000
max_did = 0x0101
max_did = 0x0100
print_results = False
expected_response_cnt = 2
expected_response = [0x62, 0x72]
expected_response_cnt = 1
expected_responses = [[0x62, 0x00, 0x01, 0x72]]
responses = uds.dump_dids(arb_id_request=self.ARB_ID_REQUEST,
arb_id_response=self.ARB_ID_RESPONSE,
timeout=timeout,
Expand All @@ -199,4 +198,10 @@ def test_dump_dids(self):

# next check the responses contain the proper data
for response in responses:
self.assertListEqual(expected_response, response[1])
# response is a tuple (data_identifier, response)
identifier = response[0]
full_response = response[1:][0] # data comes out
if full_response[0:2] == [0, 1]:
self.assertListEqual(expected_responses[0], full_response)
elif full_response[0:2] == [1,1]:
self.assertListEqual(expected_responses[1], full_response)

0 comments on commit 19c612e

Please sign in to comment.