How to specify transmit CAN-ID?

A free API for the communication with control devices according to UDS (ISO 14229-1)
Post Reply
spoekles
Posts: 9
Joined: Tue 14. Mar 2023, 09:36

How to specify transmit CAN-ID?

Post by spoekles » Mon 20. Mar 2023, 15:01

I'm trying to send a UDS request with a specific ID, but I am unable to figure out how I should achieve this.

The ECU I am trying to communicate with can have an address from 1 through 9.

So I set up the UDS mapping for these IDs. In the current situation I know the ECU will have address 4, so I have that ID hardcoded in the config.

Code: Select all

    
    config_physical.can_id = 0x0CDA04F1UL;
    config_physical.can_msgtype = PCANTP_CAN_MSGTYPE_EXTENDED;
    config_physical.can_tx_dlc = 8U;
    config_physical.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_29B_NORMAL;
    config_physical.nai.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL;
    config_physical.type = PUDS_MSGTYPE_USDT;
    
    for (uint8_t i = 1; i <= 9; i++)
    {
        source_mapping.can_id = 0x0CDA00F1UL | (i << 8);			// Client ID
        source_mapping.can_id_flow_ctrl = 0x0CDAF100UL | i;		// Server ID
        source_mapping.can_msgtype = config_physical.can_msgtype;
        source_mapping.can_tx_dlc = config_physical.can_tx_dlc;
        source_mapping.nai = config_physical.nai;
        UdsStatus = UDS_AddMapping_2013(client_handle, &source_mapping);
        (void)UDS_GetErrorText_2013(UdsStatus, 0, err_msg_buff, 4095);
        qCritical() << QString(err_msg_buff);

        response_mapping = source_mapping;
        response_mapping.can_id = source_mapping.can_id_flow_ctrl;
        response_mapping.can_id_flow_ctrl = source_mapping.can_id;
        response_mapping.nai.source_addr = source_mapping.nai.target_addr;
        response_mapping.nai.target_addr = source_mapping.nai.source_addr;
        UdsStatus = UDS_AddMapping_2013(client_handle, &response_mapping);
        (void)UDS_GetErrorText_2013(UdsStatus, 0, err_msg_buff, 4095);
        qCritical() << QString(err_msg_buff);
    }
With CAN-TP Write I can specify which map to use, but for UDS I don't see a similar function.

When I request tester present

Code: Select all

UdsStatus = UDS_SvcTesterPresent_2013(client_handle, config_physical, &msg_request, PUDS_SVC_PARAM_DSC_DS);
I do pass the config, but the ID that is being used to send the request is not the ID in the config. Instead it uses the ID of the latest added UDS map, in this case it's using the last added response map their CAN-ID (0x0CDAF109), however I want it to be 0x0CDA04F1. It is quite possible that I misunderstand the concept of maps :D

Can I specify which CAN-ID the client should use?

spoekles
Posts: 9
Joined: Tue 14. Mar 2023, 09:36

Re: How to specify transmit CAN-ID?

Post by spoekles » Mon 20. Mar 2023, 16:50

I noticed that with UDS_MsgAlloc_2013 the can_id in the uds_msg is set according to the ID from the config. But when used with UDS_Write_2013 it gets swapped to the the wrong ID from the last map.

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

Re: How to specify transmit CAN-ID?

Post by F.Vergnaud » Mon 20. Mar 2023, 17:29

Hello,

Based on the CAN IDs you are trying to use, I'd say your ECU communicates with 29bit FIXED NORMAL addressing.
You should check PCAN-UDS documentation §4.3 UDS and ISO-TP Network Addressing Information p.772.
If that is the case, you don't need configure any mapping, taht type of communication is handled automatically by the API.

UDS uses ISO-TP network addressing information to identify the CAN ID to use. There must be a unique association between a CAN ID and the content of the structure "xxx_mapping.nai".
In your loop you don't update the values of that structure, so the application will surely not work as expected.

You must use source_addr and target_address to identify your node and the ECU. To communicate with ECU #4, your request should have:
- source_addr: 0xF1
- target_address: 0x04.

Here is a configuration sample with 29b FIXED NORMAL addressing:

Code: Select all

	// Initialize a physical configuration (29b fixed_normal, between 0xF1 and 0x04)
	config_physical.can_id = (uint32_t)-1;
	config_physical.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD;
	config_physical.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_29B_FIXED_NORMAL;
	config_physical.nai.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL;
	config_physical.type = PUDS_MSGTYPE_USDT;
	config_physical.nai.source_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
	config_physical.nai.target_addr = PUDS_ISO_15765_4_ADDR_ECU_4;
	config_physical.nai.extension_addr = 0;
Best regards,
Fabrice

spoekles
Posts: 9
Joined: Tue 14. Mar 2023, 09:36

Re: How to specify transmit CAN-ID?

Post by spoekles » Tue 21. Mar 2023, 09:01

Thank you! After setting PUDS_PARAMETER_J1939_PRIORITY it works as intended!

Much easier than working with the mapping ;)

Post Reply