LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with LIN communication software – inverted frame IDs in log file

Hello everyone,

I’m currently working on a software project that manages LIN communication between a master and a slave. The software loads a file that contains the frames to be sent on the LIN bus. Then, I receive the frames from the bus and store them in a logfile.

However, I’ve noticed an issue: sometimes the IDs of the frames in the logfile appear inverted or corrupted (see the screenshot below).

said123_0-1755765475587.png

( the frame of ID 25 has take the data of ID 21)

Here is the code snippet of the function that handles reception and writes the frames to the logfile

Has anyone encountered a similar problem before?
Could this be caused by uninitialized structures, memory handling issues, or how I copy the received frame into my logging function?

Any hints or suggestions on how to fix this would be greatly appreciated!

Thanks in advance.

 

code :

int CVICALLBACK AsyncReceive (void *iPanel)
{
int iIncrement = 0, iIndexPanel = *(int*)iPanel, iNumberErrorFrame = 0, iBoolMessagePopup = 0, iFind = 0, iIncrementData = 0, iIncrementTimeStamp = 0;
tBfrStatus iError = SUCCESS;
tBfrLinMsg  structLinMessage ; 
unsigned int uiTempsDebutError = 0, uiTempsFinError = 0;
STRING strTime, strError = {0, "\0"};
 
 
if 
CmtScheduleThreadPoolFunctionAdv (DEFAULT_THREAD_POOL_HANDLE, AsyncReceiveLin, iPanel, THREAD_PRIORITY_HIGHEST, 0, EVENT_TP_THREAD_FUNCTION_END, 0, CmtGetCurrentThreadID(), 0);
 
while (iAsyncReceiveStop[iIndexPanel] == 1) 
{
iError = SUCCESS;
 
while (iAsyncHandle[iIndexPanel] == 0 && iAsyncReceiveStop[iIndexPanel] == 1)
ProcessSystemEvents ();
 
iAsyncHandle[iIndexPanel] = 0;
if (structTabChannel[iIndexPanel].structConnectionTypeChannel == LIN)
 
{
 
memset(&structLinMessage, 0, sizeof(structLinMessage)); 
 
//Set to null structure structLinMessage and try to receive data
/*********************************************************************************************/
 
for (iIncrementData = 0; iIncrementData < structTabReceiveTrameLIN[iIndexPanel].dlc; iIncrementData++)
{
structLinMessage.data[iIncrementData] = structTabReceiveTrameLIN[iIndexPanel].data[iIncrementData];
}
structLinMessage.dlc = structTabReceiveTrameLIN[iIndexPanel].dlc;
structLinMessage.id = structTabReceiveTrameLIN[iIndexPanel].id;
structLinMessage.period = structTabReceiveTrameLIN[iIndexPanel].period;
structLinMessage.service = structTabReceiveTrameLIN[iIndexPanel].service;
structLinMessage.timeStamp = structTabReceiveTrameLIN[iIndexPanel].timeStamp;
 
memset(&structTabReceiveTrameLIN[iIndexPanel], 0, sizeof(structTabReceiveTrameLIN[iIndexPanel])); 
/****************************************************************************************/
 
if (structLinMessage.id == 0)
iError = ERR_MSG_EMPTY;
 
if ((iError != SUCCESS  && iError != 0) && iError != ERR_MSG_EMPTY)
gestionErreur(iIndexPanel, iError); //Display message if an error occurs
else if (iError == ERR_MSG_EMPTY) //If error is an empty message
{
//Recover current time error
uiTempsFinError = time(&uiTempsFinError);
 
//If first error, initialize start time error
if (uiTempsFinError == 0 || iNumberErrorFrame == 0)
uiTempsDebutError = uiTempsFinError;
 
iNumberErrorFrame = 1;
 
//If there are only errors for 2 seconds
if (uiTempsFinError > (uiTempsDebutError + 1))
{   
//Reset start time error
uiTempsDebutError = uiTempsFinError;
 
//Display empty message into log file and user interface
/********************************************************************/
Rapport("Error : No message present", &structTabChannel[iIndexPanel].uiValueChannel);
DisplayInformation(iPanelTravail[iIndexPanel], ERROR_DISPLAY, "No message present");
/********************************************************************/
}
}
else
 
{
//if not error frame
if (structLinMessage.service != ERROR_FRAME)
{
iNumberErrorFrame = 0;
iAsyncError[iIndexPanel] = 0;
}
 
switch(structLinMessage.service)
{
case TRANSMIT_DATA: FillDataLog(iIndexPanel, structLinMessage.id, structLinMessage.data, structLinMessage.dlc, "Transmit"); break;
case RECEIVE_DATA: FillDataLog(iIndexPanel, structLinMessage.id, structLinMessage.data, structLinMessage.dlc, "Receive"); break;
case LIN_REQUEST_IFR: FillDataLog(iIndexPanel, structLinMessage.id, structLinMessage.data, structLinMessage.dlc, "Request"); break;
case LIN_UPDATE_IFR: FillDataLog(iIndexPanel, structLinMessage.id, structLinMessage.data, structLinMessage.dlc, "Update"); break;
case LIN_WAKE_UP: FillDataLog(iIndexPanel, 0, 0, 0, "Wake Up"); break;
 
 
}
 
 
}
 
}
 
}
 
return NO_ERROR; 
}

 

0 Kudos
Message 1 of 1
(158 Views)