Click here to Skip to main content
15,868,149 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have log file data as shown below

2.1345 2  CFF190Bx        Rx   d 8 FF FF FF FF FF FF FF FF
3.2904 9  CF00400x        Rx   d 8 FF 7D 7D 00 00 FF FF AB
2.1365 1  C000003x        Rx   d 8 EC FF FF FF FF FF FF FF
2.1366 2  18FFFB21x       Rx   d 8 57 C1 C4 7E 00 FF FF FF
2.1368 1  C010305x        Rx   d 8 FF FF FF FF FF FF FF 3F
2.1368 3  CFE6CEEx        Rx   d 8 FF FF FF FF 00 00 00 00
2.1371 1  CF00203x        Rx   d 8 C0 FF FF FF FF FF FF FF
2.1372 2  CFE6CEEx        Rx   d 8 FF FF FF FF 00 00 00 00
2.1374 1  CFF8027x        Rx   d 8 0C 00 01 FC FD F0 0F 00
2.1376 1  18FE4A03x       Rx   d 8 FF FF FF FF FF FF FF FF
2.1379 1  18FF8227x       Rx   d 8 FF 00 FB FF FF FF FF FF
2.1382 1  CF00C03x        Rx   d 8 FF FF FF FF FF FF FF FF
2.1385 1  18F00503x       Rx   d 8 7D 00 00 7D FF FF 20 4E
3.2942 9  CFE6CEEx        Rx   d 8 FF FF FF FF 00 00 00 00
2.1388 1  18F00010x       Rx   d 8 FF 7D 7D FF FE FF FF 7D
2.5140 5  CF00400x        Rx   d 8 FF 7D 7D 00 00 FF FF AB
2.5146 5  CFE6CEEx        Rx   d 8 FF FF FF FF 00 00 00 00
2.1427 1  18F0090Bx       Rx   d 8 FF FF 7F FF FF FF FF FF
2.1430 1  8FE6E0Bx        Rx   d 8 00 FE 00 FE 00 FE 00 FE
2.1433 2  CF00300x        Rx   d 8 F1 00 00 FF FF FF FF FF
2.1433 3  CF00300x        Rx   d 8 F1 00 00 FF FF FF FF FF
2.1433 1  18FFFB21x       Rx   d 8 57 C1 C4 7E 00 FF FF FF
2.1437 1  CF00400x        Rx   d 8 FF 7D 7D 00 00 FF FF AE
2.1468 1  CF00203x        Rx   d 8 C0 FF FF FF FF FF FF FF

I am using the following code to find messages with same MsgId and different buses.

C#
for (int m = 0; m < CANMsgIdList.Count; m++)
{
   if (CANMsgIdList[m].Bus == ConsoleApplication13.Buses.CANBusRed)
   {
      reds.Add(index);
   }
   index++;
}

List<double> times = new List<double>();
           
foreach (var i in reds)
{
   for (int j = 1; j < (CANMsgIdList.Count) ; j++)
   {
      if ((CANMsgIdList[j].Bus).Equals(ConsoleApplication13.Buses.CANBusYellow) && (CANMsgIdList[i].MsgId == CANMsgIdList[j].MsgId) && (CANMsgIdList[i].TimeStamp > CANMsgIdList[j].TimeStamp))
      {
         times.Add(CANMsgIdList[j].TimeStamp- CANMsgIdList[i].TimeStamp);
      }
   }
}


But I need to find the average of difference between timestamps of messages with same MsgId and different buses and may not be immediate (like may be after 10 messages)
In the code I used something like below
(CANMsgIdList[i].MsgId == CANMsgIdList[i + 1].MsgId)
But this code checks immediate messages

Can anyone help me in solving this???


Thanks
John
Posted
Updated 29-Dec-13 10:43am
v7
Comments
Not clear. What exactly is the problem with the code?
Member 10408451 29-Dec-13 10:58am    
Hi,

The exact problem is, there are lot of MsgIds on YellowBus which matches with same MsgId on RedBus and timeStamp value greater than timeStamp value of RedBus

But I need to choose the message on YellowBus with same MsgId and the nearest one regarding timeStamp value (For example if 2 or 3 MsgIds matches with the MsgIds of RedBus then I need to choose the message with timestamp greater than timestamp value of RedBus and small among other timeStamp values)

I am able to give condition to choose same MsgId on YellowBus and timeStamp value greater than RedBus timeStamp value with the following code


if ((CANMsgIdList[j].Bus).Equals(ConsoleApplication13.Buses.CANBusYellow) && (CANMsgIdList[i].MsgId == CANMsgIdList[j].MsgId) && (CANMsgIdList[i].TimeStamp > CANMsgIdList[j].TimeStamp))

But I am not able to choose nearest one among timeStamps to RedBus timeStamp values



This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900