Cannot receive Negative Response with custom mapping

A free API for the communication with control devices according to UDS (ISO 14229-1)
Post Reply
hieuht
Posts: 5
Joined: Wed 1. Jun 2022, 11:54

Cannot receive Negative Response with custom mapping

Post by hieuht » Wed 1. Jun 2022, 12:08

Hi everyone,

I have a problem with custom mapping when using PCAN-UDS API.

At first, I used the default Can ID (7E0/7E8) and it worked with my ECU. Now my specification changed and I need to change to a different ID, so I use UDS_AddMapping_2013, but now I cannot receive any negative response, and after the first negative response, my program cannot receive positive response too.

Here is my source code.

Code: Select all

   // Init mTpHandle with UDS_Initialize_2013
    uds_status status;
    map = {};
    map.can_id = sa;
    map.can_id_flow_ctrl = ra;
    map.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD;
    map.can_tx_dlc = 8;
    map.nai.extension_addr = 0;
    map.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL;
    map.nai.source_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
    map.nai.target_addr = PUDS_ISO_15765_4_ADDR_ECU_1;
    map.nai.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL;
    status = UDS_AddMapping_2013(mTpHandle, &map);
    if (!UDS_StatusIsOk_2013(status)) {
        std::cout << "Add mapping failed: " << std::hex << sa << " "
                  << int(status) << std::endl;
    }

    map = {};
    map.can_id = ra;
    map.can_id_flow_ctrl = sa;
    map.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD;
    map.can_tx_dlc = 8;
    map.nai.extension_addr = 0;
    map.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL;
    map.nai.source_addr = PUDS_ISO_15765_4_ADDR_ECU_1;
    map.nai.target_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
    map.nai.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL;
    UDS_AddMapping_2013(mTpHandle, &mGwMap);
    if (!UDS_StatusIsOk_2013(status)) {
        std::cout << "Add mapping failed: " << std::hex << sa << " "
                  << int(status) << std::endl;
    }

    map= {};
    map.can_id = fa;
    map.can_id_flow_ctrl = (uint32_t)-1;
    map.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD;
    map.can_tx_dlc = 8;
    map.nai.extension_addr = 0;
    map.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL;
    map.nai.source_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
    map.nai.target_addr = PUDS_ISO_15765_4_ADDR_OBD_FUNCTIONAL;
    map.nai.target_type = PCANTP_ISOTP_ADDRESSING_FUNCTIONAL;
    UDS_AddMapping_2013(mTpHandle, &mGwMap);
    if (!UDS_StatusIsOk_2013(status)) {
        std::cout << "Add mapping failed: " << std::hex << sa << " "
                  << int(status) << std::endl;
    }
    
    mConfigPhysical.can_id = sa;
    mConfigPhysical.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD;
    mConfigPhysical.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL;
    mConfigPhysical.nai.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL;
    mConfigPhysical.type = PUDS_MSGTYPE_USDT;
    mConfigPhysical.nai.source_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
    mConfigPhysical.nai.target_addr = PUDS_ISO_15765_4_ADDR_ECU_1;
    mConfigPhysical.nai.extension_addr = 0;
    mConfigPhysical.can_tx_dlc = 8;
Do you have any hint for this problem?
Thank you

K.Wagner
Software Development
Software Development
Posts: 1082
Joined: Wed 22. Sep 2010, 13:36

Re: Cannot receive Negative Response with custom mapping

Post by K.Wagner » Wed 1. Jun 2022, 12:20

Hello,

You are not posting which IDs you are using now. Please note that there are several IDs (not only 7E0/7E8) automatically registered by the API. You can see a list of them wihtin the documentation, chapter 4.3 (page 762). If the IDs you need are already registered, then you need to remove them first before doing your mappings.
Best regards,
Keneth

hieuht
Posts: 5
Joined: Wed 1. Jun 2022, 11:54

Re: Cannot receive Negative Response with custom mapping

Post by hieuht » Wed 1. Jun 2022, 12:30

Hi,

My sending address is 6BF and my receiving address is 6BF. They are not registered. Do I need to removes the default mapping first in order to use my mapping?

K.Wagner
Software Development
Software Development
Posts: 1082
Joined: Wed 22. Sep 2010, 13:36

Re: Cannot receive Negative Response with custom mapping

Post by K.Wagner » Wed 1. Jun 2022, 12:54

Hello,

you need to remove standard mappings, only when you need other configuration for the already defined, otherwise you just need to include the new mapping.
hieuht wrote:
Wed 1. Jun 2022, 12:30
My sending address is 6BF and my receiving address is 6BF
I think the problem is the use of the same ID for both, request and response. Please try using different CAN IDs.
Best regards,
Keneth

hieuht
Posts: 5
Joined: Wed 1. Jun 2022, 11:54

Re: Cannot receive Negative Response with custom mapping

Post by hieuht » Wed 1. Jun 2022, 13:28

Sorry, my mistake, it is not the same ID, it is 6BF and 63F. :D
K.Wagner wrote:
Wed 1. Jun 2022, 12:54
Hello,

you need to remove standard mappings, only when you need other configuration for the already defined, otherwise you just need to include the new mapping.
hieuht wrote:
Wed 1. Jun 2022, 12:30
My sending address is 6BF and my receiving address is 6BF
I think the problem is the use of the same ID for both, request and response. Please try using different CAN IDs.

F.Vergnaud
Software Development
Software Development
Posts: 305
Joined: Mon 9. Sep 2013, 12:21

Re: Cannot receive Negative Response with custom mapping

Post by F.Vergnaud » Wed 1. Jun 2022, 16:09

Hello hieuht,

In your code you are using the variable mGwMap, but you configured variable map. I think this is why your communication fails.

Code: Select all

    UDS_AddMapping_2013(mTpHandle, &mGwMap); // should be map
Note: it is not required to delete existing mappings but it is indeed cleaner as your mapping uses the same address as the standardized ECU#1.
Note: since your using a isotp format NORMAL, instead of PUDS_ISO_15765_4_ADDR_ECU_1 you could set a different address for your ECU.
Best regards,
Fabrice

hieuht
Posts: 5
Joined: Wed 1. Jun 2022, 11:54

Re: Cannot receive Negative Response with custom mapping

Post by hieuht » Thu 2. Jun 2022, 05:24

Hi Vergnaud,

I fixed the mistake you pointed out, but the result is the same.

I also tried to remove the default mapping with the following command before adding my map.

Code: Select all

	// Remove default mapping
    status = UDS_RemoveMappingByCanId_2013(
        PCANTP_HANDLE_USBBUS1, PUDS_ISO_15765_4_CAN_ID_PHYSICAL_REQUEST_1);
I added debug but nothing show

Code: Select all

    auto debugLevel = PUDS_DEBUG_LVL_TRACE;
	status = UDS_SetValue_2013(mTpHandle, PUDS_PARAMETER_DEBUG, &debugLevel, 1);
    if (!UDS_StatusIsOk_2013(status)) {
        std::cout << "Cannot enable debug" << std::endl;
    }
You also mention this, but I don't know what to do, can you please explain more?
Note: since your using a isotp format NORMAL, instead of PUDS_ISO_15765_4_ADDR_ECU_1 you could set a different address for your ECU.

F.Vergnaud
Software Development
Software Development
Posts: 305
Joined: Mon 9. Sep 2013, 12:21

Re: Cannot receive Negative Response with custom mapping

Post by F.Vergnaud » Thu 2. Jun 2022, 10:38

Hello,

Please check your code against this modified version of sample 02_client_request_ecu_reset_USDT.
ISOTP segmented communication is working with this mapping's configuration.

Code: Select all

#include "stdafx.h"

#include "lib/PCAN-UDS_2013.h"

#define OK_KO(test) (test)?"OK":"KO"
#define STATUS_OK_KO(test) OK_KO(UDS_StatusIsOk_2013(test, PUDS_STATUS_OK, false))

#define BUFFER_SIZE 256
#define MAPPING_BUFFER_SIZE 256

#define _PCAN_BITRATE_500K_2M			u8"f_clock=80000000, nom_brp=1,  nom_tseg1=127, nom_tseg2=32, nom_sjw=32, data_brp=1, data_tseg1=31, data_tseg2=8, data_sjw=8"

// Changes mapping setting
#define DO_MAPPING_WITH_FD 1
#if DO_MAPPING_WITH_FD
#define MAPPING_CAN_MSGTYPE (PCANTP_CAN_MSGTYPE_STANDARD | PCANTP_CAN_MSGTYPE_FD)
#else 
#define MAPPING_CAN_MSGTYPE (PCANTP_CAN_MSGTYPE_STANDARD)
#endif

// Changes UDS request/response msgtype
#define DO_COMMUNICATION_WITH_FD 1
#if DO_COMMUNICATION_WITH_FD
#define COMMUNICATION_CAN_MSGTYPE (PCANTP_CAN_MSGTYPE_STANDARD | PCANTP_CAN_MSGTYPE_FD)
#else 
#define COMMUNICATION_CAN_MSGTYPE (PCANTP_CAN_MSGTYPE_STANDARD)
#endif

using namespace std;
#include <iostream>

/// <summary>Entry point of the program, start a UDS channel, ask ECureset service and set new session info</summary>
int main()
{
	char buffer[BUFFER_SIZE];
	uds_status status;
	cantp_handle tp_handle;
	uds_msg msg_request;
	uds_msg request_confirmation;
	uds_msg response;
	uds_mapping map;
	uds_msgconfig mConfigPhysical;
	int sa = 0x6BF;
	int ra = 0x63F;
	int fa = 0x6FF;

	// Initialize variables
	tp_handle = PCANTP_HANDLE_USBBUS1; // TODO: modify the value according to your available PCAN devices.
	buffer[0] = '\0';
	memset(&mConfigPhysical, 0, sizeof(uds_msgconfig));
	memset(&msg_request, 0, sizeof(uds_msg));
	memset(&request_confirmation, 0, sizeof(uds_msg));
	memset(&response, 0, sizeof(uds_msg));

	// Print version informations
	status = UDS_GetValue_2013(PCANTP_HANDLE_NONEBUS, PUDS_PARAMETER_API_VERSION, buffer, BUFFER_SIZE);
	printf("PCAN-UDS API Version - %s: %s\n", buffer, STATUS_OK_KO(status));

	// Initialize client
	//status = UDS_Initialize_2013(tp_handle, PCANTP_BAUDRATE_500K, (cantp_hwtype)0, 0, 0);
	status = UDS_InitializeFD_2013(tp_handle, (const char*)_PCAN_BITRATE_500K_2M);
	printf("Initialize channel: %s\n", STATUS_OK_KO(status));

	//// Clear all predefined mappings
	//uds_mapping mappings[MAPPING_BUFFER_SIZE];
	//uint16_t mapping_count;
	//status = UDS_GetMappings_2013(tp_handle, mappings, MAPPING_BUFFER_SIZE, &mapping_count);
	//printf("Clearing predefined mappings: %s (#%u)\n", STATUS_OK_KO(status), mapping_count);
	//for (uint16_t i = 0; i < mapping_count; ++i) {
	//	status = UDS_RemoveMapping_2013(tp_handle, mappings[i]);
	//	printf("Clearing predefined mapping: %s\n", STATUS_OK_KO(status));
	//}


	map = {};
	map.can_id = sa;
	map.can_id_flow_ctrl = ra;
	map.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD;
	map.can_tx_dlc = 8;
	map.nai.extension_addr = 0;
	map.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL;
	map.nai.source_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
	map.nai.target_addr = PUDS_ISO_15765_4_ADDR_ECU_1;
	map.nai.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL;
	status = UDS_AddMapping_2013(tp_handle, &map);
	if (!UDS_StatusIsOk_2013(status)) {
		std::cout << "Add mapping failed: " << std::hex << sa << " "
			<< int(status) << std::endl;
	}

	map = {};
	map.can_id = ra;
	map.can_id_flow_ctrl = sa;
	map.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD;
	map.can_tx_dlc = 8;
	map.nai.extension_addr = 0;
	map.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL;
	map.nai.source_addr = PUDS_ISO_15765_4_ADDR_ECU_1;
	map.nai.target_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
	map.nai.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL;
	UDS_AddMapping_2013(tp_handle, &map);
	if (!UDS_StatusIsOk_2013(status)) {
		std::cout << "Add mapping failed: " << std::hex << sa << " "
			<< int(status) << std::endl;
	}

	map = {};
	map.can_id = fa;
	map.can_id_flow_ctrl = (uint32_t)-1;
	map.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD;
	map.can_tx_dlc = 8;
	map.nai.extension_addr = 0;
	map.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL;
	map.nai.source_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
	map.nai.target_addr = PUDS_ISO_15765_4_ADDR_OBD_FUNCTIONAL;
	map.nai.target_type = PCANTP_ISOTP_ADDRESSING_FUNCTIONAL;
	UDS_AddMapping_2013(tp_handle, &map);
	if (!UDS_StatusIsOk_2013(status)) {
		std::cout << "Add mapping failed: " << std::hex << sa << " "
			<< int(status) << std::endl;
	}

	mConfigPhysical.can_id = sa;
	mConfigPhysical.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD;
	mConfigPhysical.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL;
	mConfigPhysical.nai.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL;
	mConfigPhysical.type = PUDS_MSGTYPE_USDT;
	mConfigPhysical.nai.source_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
	mConfigPhysical.nai.target_addr = PUDS_ISO_15765_4_ADDR_ECU_1;
	mConfigPhysical.nai.extension_addr = 0;
	mConfigPhysical.can_tx_dlc = 8;

	// Execute customized ECUReset with extra data and wait response
	int size = 2 + 50;
	status = UDS_MsgAlloc_2013(&msg_request, mConfigPhysical, size); // CANTP Alloc + Init
	printf("UDS_MsgAlloc_2013: %s\n", STATUS_OK_KO(status));
	for (int i = 0; i < size; ++i) {
		msg_request.msg.msgdata.any->data[i] = (uint8_t)(0x10 + (i + 1));
	}
	*msg_request.links.service_id = PUDS_SI_ECUReset;
	msg_request.links.param[0] = PUDS_SVC_PARAM_ER_HR;
	status = UDS_Write_2013(tp_handle, &msg_request);
	printf("Execute ECUReset service: %s\n", STATUS_OK_KO(status));
	status = UDS_WaitForService_2013(tp_handle, &msg_request, &response, &request_confirmation);
	printf("Wait for service: %s\n", STATUS_OK_KO(status));

	// Free message structures
	status = UDS_MsgFree_2013(&msg_request);
	printf("Free request message: %s\n", STATUS_OK_KO(status));
	status = UDS_MsgFree_2013(&request_confirmation);
	printf("Free request confirmation: %s\n", STATUS_OK_KO(status));
	status = UDS_MsgFree_2013(&response);
	printf("Free response message: %s\n", STATUS_OK_KO(status));

	// Close client
	status = UDS_Uninitialize_2013(tp_handle);
	printf("Uninitialize channel: %s\n", STATUS_OK_KO(status));

	// Exit
	system("PAUSE");
	return EXIT_SUCCESS;
}

Note: since your using a isotp format NORMAL, instead of PUDS_ISO_15765_4_ADDR_ECU_1 you could set a different address for your ECU.
Please check the standard ISO_15765-2 for more information on ISOTP addressing formats (explaining ISOTP is outside our support scope).

You are using the message protocol PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL, hence source and target adresses are not physically transmitted on the CAN bus.
You can design your ISOTP network as you want: for instance you can identify your ECU with the custom mappings to have address 0xA1 instead of 0x01/PUDS_ISO_15765_4_ADDR_ECU_1.
This way you are telling the API that there can be multiple ECUs to communicate with: the standard ones and your customized one.
Best regards,
Fabrice

hieuht
Posts: 5
Joined: Wed 1. Jun 2022, 11:54

Re: Cannot receive Negative Response with custom mapping

Post by hieuht » Sat 4. Jun 2022, 06:24

Hello,

I checked my code against your example, but the problem still the same.

Here is my trace and my application output. The application still receive response normally, until the response "7F 27 78".
MicrosoftTeams-image (8).png
MicrosoftTeams-image (8).png (370.35 KiB) Viewed 5141 times

F.Vergnaud
Software Development
Software Development
Posts: 305
Joined: Mon 9. Sep 2013, 12:21

Re: Cannot receive Negative Response with custom mapping

Post by F.Vergnaud » Tue 7. Jun 2022, 12:26

Hello,

Your trace shows that the ECU is responding with a non-constant ISO-TP padding value (03 7F 27 78 XX XX XX XX).
This is a known issue:
- PCAN-ISO-TP API asserts that an ISO-TP frame is valid by expecting a contant padding value.
- This behaviour is too strict compared to the standard.
Note that your ECU sends ISOTP Flow Control frames with a constant padding value but not with Single Frames.

The fix is ready and will be included in the next release (for an estimation, we are currently in the validation process prior to release).
Best regards,
Fabrice

Post Reply