Request/Response Mapping with multiple Devices on CAN

A free API for the communication with control devices according to UDS (ISO 14229-1)
Locked
KEStarDev
Posts: 6
Joined: Thu 13. Jul 2023, 14:37

Request/Response Mapping with multiple Devices on CAN

Post by KEStarDev » Fri 18. Aug 2023, 11:33

Hey everybody,

I have the following situation:
I am writing a software in C# which uses the Peak UDS API to make some diagnostics of a can bus where 16 Devices are attached.

My current problem is, that I do not fully understand the Requese/Response mapping of the UDS API.
I have read the documentation and I do not understand the way, how the Function "AddMapping_2013" works. What is meant with nai.source and nai.target adress?

My CAN devices behave like the following:
Device 1: I send an UDS Request with CAN ID 0x280 and the device responses with a UDS response on CAN ID 0x2C0.
Device 2: I send an UDS Request with CAN ID 0x281 and the device responses with a UDS response on CAN ID 0x2C1.
Device 2: I send an UDS Request with CAN ID 0x282 and the device responses with a UDS response on CAN ID 0x2C2.

I have tried the following code and it works for Device 2 but I am still not sure if I use the API correctly.
I also do not understand, why it works with the source adress 0xF1 and Target adress 0xff. I just tried out some code snippets from the net.

Code: Select all

uds_mapping request_mapping = new uds_mapping();
request_mapping.can_id = 0x281;
request_mapping.can_id_flow_ctrl = 0x2C1;
request_mapping.can_msgtype = cantp_can_msgtype.PCANTP_CAN_MSGTYPE_STANDARD;
request_mapping.can_tx_dlc = 8;

request_mapping.nai.protocol = uds_msgprotocol.PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL;
request_mapping.nai.target_type = cantp_isotp_addressing.PCANTP_ISOTP_ADDRESSING_PHYSICAL;
request_mapping.nai.source_addr = (UInt16)uds_address.PUDS_ADDRESS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
request_mapping. = 0xFF;
request_mapping.nai.extension_addr = 0;

uds_mapping response_mapping;
response_mapping = request_mapping;
response_mapping.can_id = request_mapping.can_id_flow_ctrl;
response_mapping.can_id_flow_ctrl = request_mapping.can_id;
response_mapping.nai.source_addr = request_mapping.nai.target_addr;
response_mapping.nai.target_addr = request_mapping.nai.source_addr;

UDSApi.AddMapping_2013(cantp_handle.PCANTP_HANDLE_USBBUS1, ref request_mapping);
UDSApi.AddMapping_2013(cantp_handle.PCANTP_HANDLE_USBBUS1, ref response_mapping);
In addition, I do not know how to add the mappings for the other devices (1 to 16) because executing the API multiple times with different "request_mapping.can_id" does not work.
WaitForService_2013 returns a timeout, even when the devices are responding on the CAN bus.

Can anybody help me please and explain:
  • What is meant with nai.source_addr and nai.target_addr in general?
  • How I can add the mappings for all my 16 Devices so that the API informs me about their responses?
Thanks :)

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

Re: Request Mapping with multiple Devices on CAN

Post by F.Vergnaud » Fri 18. Aug 2023, 11:56

Source and Target address are identifier set at design time for your ECUs. For instance, the OBD standard define the following set of addresses: 0xF1 for the "Tester Equipment", and 0x01 to 0x08 for 8 standardized ECUs.
If you don't have more information from your ECU's specifications, you can set your own unique target address for each ECU.

To configure your mappings, simply initialize them in a loop:

Code: Select all

uds_status sts;
for (byte i = 1; i <= 16; i++)
{
    uds_mapping request_mapping = new uds_mapping();
    request_mapping.can_id = 0x280u + i;
    //request_mapping.uid = 0; // do not set uid, this is an internal field set by the API for later use.
    request_mapping.can_id_flow_ctrl = 0x2C0u + i;
    request_mapping.can_msgtype = cantp_can_msgtype.PCANTP_CAN_MSGTYPE_STANDARD;
    request_mapping.can_tx_dlc = 8;

    request_mapping.nai.protocol = uds_msgprotocol.PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL;
    request_mapping.nai.target_type = cantp_isotp_addressing.PCANTP_ISOTP_ADDRESSING_PHYSICAL;
    request_mapping.nai.source_addr = (UInt16)uds_address.PUDS_ADDRESS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
    request_mapping.nai.target_addr = 0x10 + i;
    request_mapping.nai.extension_addr = 0;

    uds_mapping response_mapping;
    response_mapping = request_mapping;
    //response_mapping.uid = 0; // // do not set uid, this is an internal field set by the API for later use.
    response_mapping.can_id = request_mapping.can_id_flow_ctrl;
    response_mapping.can_id_flow_ctrl = request_mapping.can_id;
    response_mapping.nai.source_addr = request_mapping.nai.target_addr;
    response_mapping.nai.target_addr = request_mapping.nai.source_addr;

    sts = UDSApi.AddMapping_2013(cantp_handle.PCANTP_HANDLE_USBBUS1, ref request_mapping);
    if (!UDSApi.StatusIsOk_2013(sts))
    {
        Console.WriteLine("Failed to set mapping {0}", i);
    }

    sts = UDSApi.AddMapping_2013(cantp_handle.PCANTP_HANDLE_USBBUS1, ref response_mapping);
    if (!UDSApi.StatusIsOk_2013(sts))
    {
        Console.WriteLine("Failed to set mapping {0}", i);
    }
}
Best regards,
Fabrice

KEStarDev
Posts: 6
Joined: Thu 13. Jul 2023, 14:37

Re: Request/Response Mapping with multiple Devices on CAN

Post by KEStarDev » Thu 24. Aug 2023, 07:30

Hello,

thanks for the quick response. This code snippet helps a lot. I tried something simmilar already but it did not work.
Now i got it running.

For those who have the same problem, the following might be helptful:
Even when I registered the correct response mappings, I did not change the "target_addr" field in the "uds_msgconfig" configuration when sending out UDS messages to different ECUs on the CAN bus. I just changed the CAN_ID in the config. This is not enough and was the problem why the response mappings did not work.

Creating a new Message config now for each individual ECU and using the request/response mapping from the code snippet from "F.Vergnaud" above works fine now.

BR,

Locked