I try to implement a custom service to transfert a custom data via UDS protocol.
My data takes 15 CAN frames to transfert (in consequence multiframe)
All works good during almost 4959 exchanges but in the number 4960 the software crashes.
And I don't understand why? What's wrong with my code.
I'm thinking a trouble inside the function: UDS_Read_2013()?
Or an internal variable not reinitialised.
I have updated this week with the latest:
- PCAN-BASIC.
- PCAN-UDS.
- PCAN-ISO-TP.
- PEAK CAN drivers
My code is:
Function
Code: Select all
bool uds::requestDatalog()
{
uds_status status;
uds_msg _msg_write;
uds_msg response;
uds_msg confirmation;
uds_msg loopback_msg;
bool _function_return = false;
QString var_debug="";
cantp_handle channel = s_tp_handle;
uds_msgconfig config = s_config_physical;
memset(&response, 0, sizeof(uds_msg));
memset(&confirmation, 0, sizeof(uds_msg));
memset(&_msg_write, 0, sizeof(uds_msg));
memset(&loopback_msg, 0, sizeof(loopback_msg));
//qDebug() << "\n*** UDS Service: requestDatalog ***\n";
memset(&config, 0, sizeof(uds_msgconfig));
config.can_msgtype = PCANTP_CAN_MSGTYPE_EXTENDED;
config.nai.protocol = PUDS_MSGPROTOCOL_NONE;//PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL;
config.nai.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL;
config.type = PUDS_MSGTYPE_UUDT;
status = UDS_MsgAlloc_2013(&_msg_write,config,8);
//qDebug() << "status alloc msgwrite = " << status;
status = UDS_MsgAlloc_2013(&response,config,8);
//qDebug() << "status alloc response = " << status;
//msg_request.msg.msgdata.any->flags = PCANTP_MSGFLAG_ISOTP_FRAME;
_msg_write.msg.can_info.can_id = (uint32_t)CAN_ID_UDS_REQUEST;
_msg_write.msg.type = PCANTP_MSGTYPE_CAN;
_msg_write.msg.msgdata.isotp->length = (uint32_t)8;
_msg_write.msg.msgdata.isotp->data[0] = (uint8_t)2;
_msg_write.msg.msgdata.isotp->data[1] = (uint8_t)0xBA;
_msg_write.msg.msgdata.isotp->data[2] = (uint8_t)0x02;
if(s_datalog_current_record_number >= 4959)
{
qDebug() << "BreakPoint !!! ";
}
_function_return = sentAloneUDSRequest(channel,&_msg_write,&response);
qDebug() << " position = " + QString::number(s_datalog_current_record_number) + "\n";
if(_function_return == true)
{
//qDebug() << "All is ok, start decode data";
printf(" Tout s'est bien passé, on peut décoder la trame. \n ");
fflush(stdout);
printf(" response.msg.msgdata.isotp length = %d \n ", response.msg.msgdata.isotp->length);
fflush(stdout);
printf(" response.msg.msgdata.isotp->data[0] = %d \n ", response.msg.msgdata.isotp->data[0]);
fflush(stdout);
printf(" response.msg.msgdata.isotp->data[1] = %d \n ", response.msg.msgdata.isotp->data[1]);
fflush(stdout);
_function_return = false;
if((response.msg.msgdata.isotp->data[0] == 0xFA) && (response.msg.msgdata.isotp->data[1] == 0x02))
{
s_datalog_current_record_number++;
// DATA PROCESS
//
}
else
{
var_debug = "\nERROR: Request a record has been failed: Service not iniialized or not data available.\n";
emit valueChanged(var_debug);
}
}
else
{
var_debug = "\nERROR: Request a record has been failed: No response.\n";
emit valueChanged(var_debug);
}
status = UDS_MsgFree_2013(&_msg_write);
//printf(" Free request message: %i\n", status);
status = UDS_MsgFree_2013(&response);
//printf(" Free response message: %i\n", status);
status = UDS_MsgFree_2013(&confirmation);
//printf(" Free confirmation message: %i\n", status);
status = UDS_MsgFree_2013(&loopback_msg);
// printf(" Free loopback_msg message: %i\n", status);
return _function_return;
}
Code: Select all
bool uds::sentAloneUDSRequest(cantp_handle channel, uds_msg *_msg_write, uds_msg *response)
{
bool _ret = false;
TPCANStatus _status_result = (TPCANStatus)PUDS_STATUS_OK;
uds_status status;
uint32_t _timeout_recep = 0;
uds_msg _uds_temp;
uint32_t test_id_frame = 0;
if(s_datalog_current_record_number >= 4959)
{
qDebug() << "BreakPoint !!! ";
}
memset(&_uds_temp, 0, sizeof(uds_msg));
_status_result = (TPCANStatus)UDS_Write_2013(channel,_msg_write);
status = (uds_status)_status_result;
//qDebug() << "UDS_Write_2013 1 = " << status << "\n";
_timeout_recep = 0;
while((test_id_frame != CAN_ID_UDS_ANSWER && (_timeout_recep < TIMEOUT_MAX_RECEPTION_FRAME)))
{
status = UDS_MsgFree_2013(&_uds_temp);
memset(&_uds_temp, 0, sizeof(uds_msg));
_status_result = UDS_Read_2013((cantp_handle)channel,&_uds_temp,NULL,NULL);
tempo_ms(TEMPO_BETWEEN_TEST_MS,qApp);
_timeout_recep++;
test_id_frame = _uds_temp.msg.can_info.can_id;
}
_uds_temp.msg.can_info.can_id = 0;
qDebug() << "Sortie while";
if(_timeout_recep < TIMEOUT_MAX_RECEPTION_FRAME) // Tout s'est bien passé, on peut continuer
{
if(_uds_temp.msg.msgdata.isotp->length > 7) // Multiframe
{
//qDebug() << "Trame sur du multiframe !!!";
printf("Trame sur du multiframe !!! \n ");
fflush(stdout);
_timeout_recep = 0;
while((_uds_temp.msg.can_info.can_id != CAN_ID_UDS_ANSWER && (_timeout_recep < TIMEOUT_MAX_RECEPTION_FRAME)))
{
status = UDS_MsgFree_2013(&_uds_temp);
memset(&_uds_temp, 0, sizeof(uds_msg));
_status_result = UDS_Read_2013((cantp_handle)channel,&_uds_temp,NULL,NULL);
//qDebug() << "Status result 1 = " << _status_result << " --- UDS_Read_2013 reponse ID 1 = " << response.msg.can_info.can_id;
tempo_ms(TEMPO_BETWEEN_TEST_MS,qApp);
_timeout_recep++;
}
}
else
{
printf("Single frame !!! \n ");
fflush(stdout);
printf("_uds_temp.msg.msgdata.isotp->length = %d \n ", _uds_temp.msg.msgdata.isotp->length);
fflush(stdout);
}
if(_timeout_recep < TIMEOUT_MAX_RECEPTION_FRAME)
{
response->msg.msgdata.isotp->length =_uds_temp.msg.msgdata.isotp->length;
response->msg.msgdata.isotp->data = _uds_temp.msg.msgdata.isotp->data;
_ret = true;
}
else
{
qDebug() << "Erreur alone function timeout ";
}
}
else
{
qDebug() << "Erreur alone function timeout ";
}
status = UDS_MsgFree_2013(&_uds_temp);
return _ret;
}