I am getting stuck on building basic functionality with PCAN-UDS library, hopefully we will solve this quickly.
I am using Windows 10 with mingw, IDE is Codeblocks.
Basically I am calling functions:
Code: Select all
UDS_Initialize();
UDS_removeMappings();
UDS_AddMapping)();
UDS_RemovePadding();
UDS_WaitForServiceWithReadDID(&uds);
Code: Select all
uds_status UDS_Initialize(UDS_t *this, cantp_handle channel)
{
uds_status retval;
this->channel = channel;
this->sett->dongle = channel;
retval = UDS_Initialize_2013(this->channel, this->baudrate, this->hw_type, this->io_port, this->interrupt);
return retval;
}
Code: Select all
uds_status UDS_removeMappings(UDS_t* this)
{
uds_mapping mappings[256];
uint16_t count;
uds_status status;
uint16_t i;
status = UDS_GetMappings_2013(this->channel, mappings, 256, &count);
if(!UDS_StatusIsOk_2013(status, PUDS_STATUS_OK, 0))
{
return status;
}
for (i = 0; i < count; i++)
{
status = UDS_GetMappings_2013(this->channel, mappings, 256, &count);
if(!UDS_StatusIsOk_2013(status, PUDS_STATUS_OK, 0))
{
return status;
}
status = UDS_RemoveMapping_2013(this->channel, mappings[0]);
}
return status;
}
Code: Select all
uds_status UDS_AddMapping(UDS_t *this)
{
uds_status status;
uds_mapping mapping = {};
uds_mapping mapping2 = {};
// Add mapping for physical request from external equipment to ECU_1
mapping.can_id = this->sett->uds_start.canid_req; //0x30B;
mapping.can_id_flow_ctrl = this->sett->uds_start.canid_resp; //0x28B;
mapping.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD;
mapping.can_tx_dlc = 8;
mapping.nai.extension_addr = 0;
mapping.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL;
mapping.nai.source_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
mapping.nai.target_addr = PUDS_ISO_15765_4_ADDR_ECU_1;
mapping.nai.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL;
status = UDS_AddMapping_2013(this->channel, &mapping);
if (!UDS_StatusIsOk_2013(status, PUDS_STATUS_OK, 0))
{
return status;
}
// Add mapping for physical response from ECU_1 to external equipment
mapping2.can_id = this->sett->uds_start.canid_resp; //0x28B;
mapping2.can_id_flow_ctrl = this->sett->uds_start.canid_req; //0x30B;
mapping2.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD;
mapping2.can_tx_dlc = 8;
mapping2.nai.extension_addr = 0;
mapping2.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL;
mapping2.nai.source_addr = PUDS_ISO_15765_4_ADDR_ECU_1;
mapping2.nai.target_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
mapping2.nai.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL;
status = UDS_AddMapping_2013(this->channel, &mapping2);
if (!UDS_StatusIsOk_2013(status, PUDS_STATUS_OK, 0))
{
return status;
}
return status;
}
Code: Select all
uds_status UDS_RemovePadding(UDS_t* this)
{
uint8_t buffer = PUDS_CAN_DATA_PADDING_NONE;
return UDS_SetValue_2013(this->channel, PUDS_PARAMETER_CAN_DATA_PADDING, &buffer, 1);
}
Code: Select all
uds_status UDS_WaitForServiceWithReadDID(UDS_t *this)
{
uds_status result;
uds_msg request = {};
uds_msg request_confirmation = {};
uds_msg response = {};
uds_msgconfig config = {};
config.can_id = PUDS_ISO_15765_4_CAN_ID_PHYSICAL_REQUEST_1;
config.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD;
config.nai.extension_addr = 0x0;
config.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL;
config.nai.source_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
config.nai.target_addr = PUDS_ISO_15765_4_ADDR_ECU_1;
config.nai.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL;
config.type = PUDS_MSGTYPE_USDT;
// Sends a physical ReadDataByIdentifier message
uint16_t buffer[1] = {0xF195};
result = UDS_SvcReadDataByIdentifier_2013(this->channel, config, &request, buffer, 1);
if (UDS_StatusIsOk_2013(result, PUDS_STATUS_OK, 0))
{
result = UDS_WaitForService_2013(this->channel, &request, &response, &request_confirmation);
if (UDS_StatusIsOk_2013(result, PUDS_STATUS_OK, 0))
{
printf("Response was received: ");
uint8_t *data2 = response.msg.msgdata.can->data;
printf("%02X %02X %02X %02X %02X %02X %02X %02X", data2[0], data2[1], data2[2], data2[3],data2[4], data2[5], data2[6],data2[7]);
printf("\n");
UDS_MsgFree_2013(&response);
UDS_MsgFree_2013(&request_confirmation);
}
else
{
char str_msg[256] = "";
result = UDS_GetErrorText_2013(result, 0x0, str_msg, 256);
printf("An error occurred: %s\n", str_msg);
}
UDS_MsgFree_2013(&request);
}
else
{
char str_msg[256] = "";
result = UDS_GetErrorText_2013(result, 0x0, str_msg, 256);
printf("An error occurred while sending the request: %s\n", str_msg);
}
return result;
}
