Search code examples
can-buscaplcanoe

CAPL: How do I get the timestamp of the message containing a signal name?


I am sure this is much simpler than I'm making it out to be, but...

In CAPL, I'm trying to ouput the timestamp for signals that have a certain value:

on signal_update XXX
{ 
   if ($XXX == 42) {
      message * msg  = { DLC = 15 };
  
      getThisMessage(msg, 15);
  
      write("Time: %f", messageTimeNS(msg));
   }
}

So given a signal update, how do I get the containing message and its timestamp? (BTW, the 'DLC=15' is just the maximum value that the compiler let me include. I'm unsure of the correct value.)


Solution

  • You can always get the current simulation time by using

    timeNowNS();
    

    while you are in a on signal_update ... block, the time returned is the time which caused the event handler to be executed; in this case when a message was received which contained the signal of interest.

    The simulation time will not change during execution of the event handlers.