Code: Select all
unsigned char Fiatframe[129] = {
0x87,0x99,0x00,0x00,0x08,0x00,0x00,0xD1,
0x87,0x99,0x00,0x00,0x08,0x00,0x01,0xCC,
0x87,0x99,0x00,0x00,0x08,0x00,0x02,0xEB,
0x87,0x99,0x00,0x00,0x08,0x00,0x03,0xF6,
0x87,0x99,0x00,0x00,0x08,0x00,0x04,0xA5,
0x87,0x99,0x00,0x00,0x08,0x00,0x05,0xB8,
0x87,0x99,0x00,0x00,0x08,0x00,0x06,0x9F,
0x87,0x99,0x00,0x00,0x08,0x00,0x07,0x82,
0x87,0x99,0x00,0x00,0x08,0x00,0x08,0x39,
0x87,0x99,0x00,0x00,0x08,0x00,0x09,0x24,
0x87,0x99,0x00,0x00,0x08,0x00,0x0A,0x03,
0x87,0x99,0x00,0x00,0x08,0x00,0x0B,0x1E,
0x87,0x99,0x00,0x00,0x08,0x00,0x0C,0x4D,
0x87,0x99,0x00,0x00,0x08,0x00,0x0D,0x50,
0x87,0x99,0x00,0x00,0x08,0x00,0x0E,0x77,
0x87,0x99,0x00,0x00,0x08,0x00,0x0F,0x6A };
int enable_ex8 = 0;
uds_status status;
cantp_handle channel = PCANTP_HANDLE_USBBUS1;
uds_msgconfig requestconfig;
uds_mapping mapping_tester_to_ecu, mapping_ecu_to_tester;
status = UDS_Initialize_2013(channel, PCANTP_BAUDRATE_500K);
if (!UDS_StatusIsOk_2013(status, PUDS_STATUS_OK, false)) {
return;
}
// add mapping to support communication from Tester to ECU
memset(&mapping_tester_to_ecu, 0, sizeof(mapping_tester_to_ecu));
mapping_tester_to_ecu.can_id = 0xE8;
mapping_tester_to_ecu.can_id_flow_ctrl = 0x725;
mapping_tester_to_ecu.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD;
mapping_tester_to_ecu.can_tx_dlc = 8;
mapping_tester_to_ecu.nai.extension_addr = 0;
mapping_tester_to_ecu.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL;
mapping_tester_to_ecu.nai.source_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
mapping_tester_to_ecu.nai.target_addr = 0x01;
mapping_tester_to_ecu.nai.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL;
status = UDS_AddMapping_2013(channel, &mapping_tester_to_ecu);
if (!UDS_StatusIsOk_2013(status, PUDS_STATUS_OK, false)) {
return;
}
// add mapping to support communication from ECU to Tester
mapping_ecu_to_tester = mapping_tester_to_ecu;
mapping_ecu_to_tester.can_id = mapping_tester_to_ecu.can_id_flow_ctrl;
mapping_ecu_to_tester.can_id_flow_ctrl = mapping_tester_to_ecu.can_id;
mapping_ecu_to_tester.nai.source_addr = mapping_tester_to_ecu.nai.target_addr;
mapping_ecu_to_tester.nai.target_addr = mapping_tester_to_ecu.nai.source_addr;
status = UDS_AddMapping_2013(channel, &mapping_ecu_to_tester);
if (!UDS_StatusIsOk_2013(status, PUDS_STATUS_OK, false)) {
return;
}
memset(&requestconfig, 0, sizeof(requestconfig));
requestconfig.can_id = -1;
requestconfig.can_msgtype = mapping_tester_to_ecu.can_msgtype;
requestconfig.nai = mapping_tester_to_ecu.nai;
requestconfig.type = PUDS_MSGTYPE_USDT;
for (int j = 0; j < 128; j += 8) {
uds_msg FIAT_msg;
memset(&FIAT_msg, 0, sizeof(uds_msg));
// Allocate TX message with previous configuration
status = UDS_MsgAlloc_2013(&FIAT_msg, requestconfig, 9);
if (UDS_StatusIsOk_2013(status, PUDS_STATUS_OK, false)) {
memcpy(FIAT_msg.msg.msgdata.any->data, &Fiatframe[j], 8);
status = UDS_Write_2013(channel, &FIAT_msg);
if (UDS_StatusIsOk_2013(status, PUDS_STATUS_OK, 0))
{
uds_msg request_confirmation;
uds_msg response;
memset(&request_confirmation, 0, sizeof(uds_msg));
memset(&response, 0, sizeof(uds_msg));
// either user a WaitForService or a WaitForMessage function
// since request has the flag no_response in the data (0x80)! the WaitForService status should return PUDS_STATUS_SERVICE_NO_MESSAGE.
//status = UDS_WaitForService_2013(channel, &FIAT_msg, &response, &request_confirmation);
// Wait for Tx confirmation only
status = UDS_WaitForSingleMessage_2013(channel, &FIAT_msg, true, 10, 10, &request_confirmation);
if (UDS_StatusIsOk_2013(status, PUDS_STATUS_OK, 0))
{
// handle what to do with a successfull transmission
}
UDS_MsgFree_2013(&request_confirmation);
UDS_MsgFree_2013(&response);
}
}
UDS_MsgFree_2013(&FIAT_msg);
}
status = UDS_Uninitialize_2013(channel);
// ...