How to Calculate Latency of CAN Gateway

Question:

How can I calculate the latency (time difference) between messages for CAN gateway applications with VN hardware?

Answer:

In the first instance of Tx in CAN1, EOF (timestamp) is considered.

And the SOF is considered for the first instance of Rx in CAN2.

Then the latency should be obtained by subtracting the EOF of tx from the SOF of rx.

Example:

From the screenshot we read

  • the EOF of tx = 34.996617707 s
  • the SOF of rx = 34.996633388 s

Result: Latency = 34.996633388 s - 34.996617707 s = 0.000015681 s = 15.681 ┬Ás.

Code Example:

variables
{
  message msgName msgObj_1;
  message can2.msgName msgObj_1;
  int64 endTimeTxFrame;
  int64 startTimeRxFrame;
}
on message *
{
  if(this.id==msgObj_1.id && this.can == 1) 
  {
    endTimeTxFrame = this.SOF + this.frameLen;
    write("CAN1 StartOfFrame= %I64d",this.SOF);
    write("CAN1 FrameLength= %ld",this.frameLen);
    write("CAN1 endTimeTxFrame is %I64d",endTimeTxFrame);
  }
  if(this.id==msgObj_2.id && this.can == 2 && endTimeTxFrame != 0) 
  {
    startTimeRxFrame = this.SOF;
    write("CAN2 startTimeRxFrame is %lld",startTimeRxFrame);
    write("Latency Time is %d microsconds", (startTimeRxFrame - endTimeTxFrame)/1000);
    endTimeTxFrame = 0;
  }
}



Article ID: 1603
Last updated: 2020-02-06
Revision: 4
CANalyzer/CANoe -> CAPL -> How to Calculate Latency of CAN Gateway
https://kb.vector.com/entry/1603/