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.