UDS Api Mapping

A free API for the communication with control devices according to UDS (ISO 14229-1)
Post Reply
mdanski
Posts: 17
Joined: Tue 28. Aug 2018, 13:57

UDS Api Mapping

Post by mdanski » Mon 26. Nov 2018, 11:29

Hi,
I am trying to write an application to set data on ECU via UDS Api. However device has custom CAN ID request and response. After setting up connection I get ERROR_NO_MESSAGE on WaitForService() after sending request. In PCAN-View I can see that frame is send on correct CAN ID and there is response which application don't see.

ECU is listening to requests on 0x780 and response on 0x781, baud rate is 500 kBit/s

Code used to configurate device:

Code: Select all

// Set basic address info
AddressInfo = new TPUDSNetAddrInfo
{
	SA = (byte)TPUDSAddress.PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT,
	TA = (byte)TPUDSAddress.PUDS_ISO_15765_4_ADDR_ECU_1,
	TA_TYPE = TPUDSAddressingType.PUDS_ADDRESSING_PHYSICAL,
	RA = 0x00,
	PROTOCOL = TPUDSProtocol.PUDS_PROTOCOL_ISO_15765_2_11B
};

// Initialize connection
status = UDSApi.Initialize(Channel, (TPUDSBaudrate)BaudRate.Id);
if (IsError(status))
{
	Trace.TraceError("Initialization failed");
	return false;
}

// Set this device address
uint buffer = AddressInfo.TA;
status = UDSApi.SetValue(Channel, TPUDSParameter.PUDS_PARAM_SERVER_ADDRESS, ref buffer, 1);
if (IsError(status))
{
	Trace.TraceError("Can't set buffer");
	return false;
}

TPCANTPStatus s;
// Define ISO-TP communication from ECU to Client (physical responses)
s = CanTpApi.AddMapping(Channel, 0x780, 0x7E0,
		   TPCANTPIdType.PCANTP_ID_CAN_11BIT,
		   TPCANTPFormatType.PCANTP_FORMAT_NORMAL,
		   TPCANTPMessageType.PCANTP_MESSAGE_DIAGNOSTIC,
		   AddressInfo.SA, AddressInfo.TA,
		   TPCANTPAddressingType.PCANTP_ADDRESSING_PHYSICAL,
		   0x00);

// Define ISO-TP communication from Client to ECU (physical requests)
s = CanTpApi.AddMapping(Channel, 0x7E8, 0x781,
		TPCANTPIdType.PCANTP_ID_CAN_11BIT,
		TPCANTPFormatType.PCANTP_FORMAT_NORMAL,
		TPCANTPMessageType.PCANTP_MESSAGE_DIAGNOSTIC,
		AddressInfo.TA, AddressInfo.SA,
		TPCANTPAddressingType.PCANTP_ADDRESSING_PHYSICAL, 0x00);
and code used to send request and wait for service:

Code: Select all

TPUDSStatus status;
TPUDSMsg message = new TPUDSMsg
{
	NETADDRINFO = connection.AddressInfo
};
TPUDSMsg messageResponse = new TPUDSMsg();
TPUDSMsg messageBuffer = new TPUDSMsg();

status = UDSApi.SvcDiagnosticSessionControl(connection.Channel, ref message, UDSApi.TPUDSSvcParamDSC.PUDS_SVC_PARAM_DSC_DS);
if (status == TPUDSStatus.PUDS_ERROR_OK)
	status = UDSApi.WaitForService(connection.Channel, out messageResponse, ref message, out messageBuffer);
connection.Error = status.ToString();
I send PCAN-View trace which confirms that ECU responds.

What can cause the problem that application do not receive message?
Attachments
PCAN View
PCAN View
img.jpg (74.24 KiB) Viewed 4091 times

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

Re: UDS Api Mapping

Post by K.Wagner » Mon 26. Nov 2018, 12:45

Hello,

as far as I see you need to define mapping in your client too. The client doesn't know the IDs 0x780 and 0x781.
Best regards,
Keneth

mdanski
Posts: 17
Joined: Tue 28. Aug 2018, 13:57

Re: UDS Api Mapping

Post by mdanski » Tue 27. Nov 2018, 08:05

Yes and I am trying to achieve it. Client has configuration given in previous post. For now my client (App) can send reqest to ECU using frames with ID 0x780 and ECU responds with ID 0x781, but mapping if frame that has ID 0x781 do not work in App. I can't change ECU CAN ID frames.

I also tried to modify Yours example PCUClicent included in UDS Api archive file. Here I am totally out of lack, beacuse both mappings gives me ALREADY_INITIALIAZED error.

Code: Select all

// Set the PCAN-Channel to use (PCAN-USB Channel 1)
Channel = PUDS_USBBUS2;
// Initializing of the UDS Communication session 
Status = UDS_Initialize(Channel, PUDS_BAUD_500K, 0, 0, 0);
printf("Initialize UDS: %i\n", (int)Status);

// Define Address
iBuffer = PUDS_SERVER_ADDR_TEST_EQUIPMENT;
Status = UDS_SetValue(Channel, PUDS_PARAM_SERVER_ADDRESS, &iBuffer, 1);
printf("  Set ServerAddress: %i (0x%02x)\n", (int)Status, iBuffer);

TPCANTPStatus result;

// Define Network Address Information used for all the tests
N_AI.SA = PUDS_SERVER_ADDR_TEST_EQUIPMENT;
N_AI.TA = PUDS_ISO_15765_4_ADDR_ECU_1;
N_AI.TA_TYPE = PUDS_ADDRESSING_PHYSICAL;
N_AI.RA = 0x00;
N_AI.PROTOCOL = PUDS_PROTOCOL_ISO_15765_2_11B;

// Defines a first mapping to allow communication from App to ECU
result = CANTP_AddMapping(Channel, 0x7E0, 0x780, PCANTP_ID_CAN_11BIT,
	PCANTP_FORMAT_NORMAL, PCANTP_MESSAGE_DIAGNOSTIC, N_AI.SA, N_AI.TA,
	PCANTP_ADDRESSING_PHYSICAL, N_AI.RA);
printf("  set S -> D mapping: %i", (int)result);

// Defines a second mapping to allow communication from ECU to App
result = CANTP_AddMapping(Channel, 0x7E8, 0x781, PCANTP_ID_CAN_11BIT,
	PCANTP_FORMAT_NORMAL, PCANTP_MESSAGE_DIAGNOSTIC, N_AI.TA, N_AI.SA,
	PCANTP_ADDRESSING_PHYSICAL, N_AI.RA);
printf("  set D -> S mapping: %i", (int)result);
I would appreciate if you can provide me any clue how mappings should be set.

I am also curious is there any software that can show in real time or log all frames received by UDS Api or on ISO-TP level so it possible to see content, ServerAdress and TargetAdress ?

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

Re: UDS Api Mapping

Post by K.Wagner » Tue 27. Nov 2018, 09:32

Hello,

Mappings involving physically addressed communication are most usually defined in pairs: the first mapping
defines outgoing communication (i.e. request messages from node A to node B) and the second to match
incoming communication (i.e. responses from node B to node A).

If your ECU is hearing to the ID 0x780 and responding using ID 0x781 then you need to match this in two mapping:
0x780, 0x781, 0xF1, 1 (sending from Client to ECU)
0x781, 0x780, 1, 0xF1 (receiving from ECU)

Code: Select all

TPCANTPStatus s;
// Sending from Client to ECU (ECU is listening to 0x780)
s = CanTpApi.AddMapping(Channel, 0x780, 0x781,
         TPCANTPIdType.PCANTP_ID_CAN_11BIT,
         TPCANTPFormatType.PCANTP_FORMAT_NORMAL,
         TPCANTPMessageType.PCANTP_MESSAGE_DIAGNOSTIC,
         AddressInfo.SA, AddressInfo.TA,
         TPCANTPAddressingType.PCANTP_ADDRESSING_PHYSICAL,
         0x00);

// Receiving from ECU (ECU is sending using 0x781)
s = CanTpApi.AddMapping(Channel, 0x781, 0x780,
      TPCANTPIdType.PCANTP_ID_CAN_11BIT,
      TPCANTPFormatType.PCANTP_FORMAT_NORMAL,
      TPCANTPMessageType.PCANTP_MESSAGE_DIAGNOSTIC,
      AddressInfo.TA, AddressInfo.SA,
      TPCANTPAddressingType.PCANTP_ADDRESSING_PHYSICAL, 0x00);
With these mappings your application should be able to to communicate well with your ECU:
UDS: Sending 12 bytes
UDS: Sending 12 bytes
UDSComm.PNG (18.76 KiB) Viewed 4083 times
mdanski wrote:I am also curious is there any software that can show in real time or log all frames received by UDS Api or on ISO-TP level so it possible to see content, ServerAdress and TargetAdress ?
Not really. We don't have monitor software for those protocols.
Best regards,
Keneth

Post Reply