hi,
i am trying to process ~800 CAN messages per second, the processing is just arranging the bytes into a different structure, how ever profiling it i can see it takes about 3 msec to decode each message, this seems wrong…
two things to mention
- i am using pulling inside a thread
- i used to DateTime to profile the timing
the code below, please advise…
public void Init()
{
int BRP = 12;
int T1 = 6;
int T2 = 5;
// create CAN object
m_CAN = new CAN(CAN.Channel.Channel_2, (uint)(((T2 - 1) << 20) | ((T1 - 1) << 16) | ((BRP - 1) << 0)));
// create worker thread
m_WorkerThread = new Thread(CANThread);
m_WorkerThread.Priority = ThreadPriority.Highest;
m_WorkerThread.Start();
}
private void CANThread()
{
// loop until thread is terminated
while (m_WorkerThread.ThreadState == ThreadState.Running)
{
int TempMsgsCount = m_CAN.GetMessages(m_MsgList, 0, m_CAN.ReceivedMessagesCount);
if (TempMsgsCount > 0)
{
//==========================================
for (int Index = 0; Index < TempMsgsCount; Index++)
{
CAN.Message TempMsg = m_MsgList[Index];
m_SW.Reset();
// decode regular message
if ((TempMsg.ArbID >= 0x1001) && (TempMsg.ArbID <= 0x1008))
{
// get Device index from message id
int DeviceIndex = (int)TempMsg.ArbID - 0x101;
DeviceData TempDevice = m_Device[DeviceIndex];
// set Device current mode
TempDevice.Mode = TempMsg.Data[0];
// set Device current event code
TempDevice.Event = TempMsg.Data[1];
// process Device data accoring to current mode
switch ((DeviceMode)TempMsg.Data[0])
{
// handle Device operational mode and its likes
case DeviceMode.Operational:
TempDevice.V1 = (UInt16)((TempMsg.Data[2] & 0x0F) << 8 + TempMsg.Data[3]);
TempDevice.V2 = (UInt16)((TempMsg.Data[2] & 0xF0) + (TempMsg.Data[3] & 0x0F));
TempDevice.V3 = (UInt16)((TempMsg.Data[4] << 8) + (TempMsg.Data[5]));
TempDevice.V4 = (UInt16)(((TempMsg.Data[6] & 0xF0) << 8) + (TempMsg.Data[7]));
break;
}
m_Device[DeviceIndex] = TempDevice;
}
double timepercycle = m_SW.ElapsedSec;
if (timepercycle > 0.1)
{
}
}
}
else
Thread.Sleep(50);
}
}