Skip to content

Commit

Permalink
finalize SET_MTA command response properly
Browse files Browse the repository at this point in the history
  • Loading branch information
lmbsog0 committed Dec 13, 2022
1 parent 46bbca4 commit 1879789
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions source/Xcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2670,6 +2670,9 @@ static uint8 Xcp_DTOCmdStdSetMta(PduIdType rxPduId, const PduInfoType *pPduInfo)
Xcp_Internal.memory_transfer.extension = pPduInfo->SduDataPtr[0x03u];
Xcp_CopyToU32WithOrder(&pPduInfo->SduDataPtr[0x04u], (uint32 *)&Xcp_Internal.memory_transfer.address, Xcp_Ptr->general->byteOrder);

Xcp_Internal.cto_response.pdu_info.SduDataPtr[0x00u] = XCP_PID_RESPONSE;
Xcp_FinalizeResPacket(0x01u, &Xcp_Internal.cto_response.pdu_info);

return E_OK;
}

Expand Down
18 changes: 18 additions & 0 deletions test/set_mta_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from .parameter import *
from .conftest import XcpTest


@pytest.mark.parametrize('trailing_value', trailing_values)
@pytest.mark.parametrize('max_cto', max_ctos)
def test_set_mta_sets_all_remaining_bytes_to_trailing_value(trailing_value, max_cto):
handle = XcpTest(DefaultConfig(channel_rx_pdu_ref=0x0001, max_cto=max_cto, trailing_value=trailing_value))
handle.lib.Xcp_CanIfRxIndication(0x0001, handle.get_pdu_info((0xFF, 0x00)))
handle.lib.Xcp_MainFunction()
handle.lib.Xcp_CanIfTxConfirmation(0x0001, handle.define('E_OK'))
handle.lib.Xcp_CanIfRxIndication(0x0001, handle.get_pdu_info((0xF6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)))
handle.lib.Xcp_MainFunction()
remaining_zeros = tuple(trailing_value for _ in range(max_cto - 0x08))
assert tuple(handle.can_if_transmit.call_args[0][1].SduDataPtr[0x08:max_cto]) == remaining_zeros
13 changes: 13 additions & 0 deletions test/set_request_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,16 @@ def store_calibration_data_to_non_volatile_memory(p_success):
ANY,
handle.define('XCP_MAIN_FUNCTION_API_ID'),
handle.define('XCP_E_EVENT_QUEUE_FULL'))


@pytest.mark.parametrize('trailing_value', trailing_values)
@pytest.mark.parametrize('max_cto', max_ctos)
def test_set_request_sets_all_remaining_bytes_to_trailing_value(trailing_value, max_cto):
handle = XcpTest(DefaultConfig(channel_rx_pdu_ref=0x0001, max_cto=max_cto, trailing_value=trailing_value))
handle.lib.Xcp_CanIfRxIndication(0x0001, handle.get_pdu_info((0xFF, 0x00)))
handle.lib.Xcp_MainFunction()
handle.lib.Xcp_CanIfTxConfirmation(0x0001, handle.define('E_OK'))
handle.lib.Xcp_CanIfRxIndication(0x0001, handle.get_pdu_info((0xF9, 0x01, 0x00, 0x00)))
handle.lib.Xcp_MainFunction()
remaining_zeros = tuple(trailing_value for _ in range(max_cto - 0x08))
assert tuple(handle.can_if_transmit.call_args[0][1].SduDataPtr[0x08:max_cto]) == remaining_zeros

0 comments on commit 1879789

Please sign in to comment.