I created a CAPL program to calculate the consumption each time I receive a specific frame. The problem is that if the frame is different, the name of the frame and its signal must be changed throughout the code.
Is it possible to declare a message and a signal as a variable for use throughout the code?
I would like to declare the message and its signal at the beginning of the program, which would allow to change only this one and not the whole code.
In the example below, the frame is called TOTAL_DISTANCE_VhSpeed_565 and its signal is ST_CONS_EV_565 but these may change depending on the log.
on message TOTAL_DISTANCE_VhSpeed_565
{
// First loop for init
if (firstloop == 0) firstvalue = this.ST_CONS_EV_565.phys;
if (firstloop == 0) currentvaluehexlast = this.ST_CONS_EV_565;
if (firstloop == 0) currentvaluelast = this.ST_CONS_EV_565.phys;
if (firstloop == 0) firstloop = 1;
// Get the hex and phys value from consumption signal
currentvaluehex = this.ST_CONS_EV_565;
currentvalue = this.ST_CONS_EV_565.phys;
// If the current value is lower than the last one, that mean we do a full step
// Then, we take the last value from the maximum step and add it to the consumption calculation
if ((firststep == 0) & currentvaluehex < currentvaluehexlast) canaddition = canaddition + (currentvaluelast - firstvalue);
firststep = 1;
if ((firststep == 1) & currentvaluehex < currentvaluehexlast) canaddition = canaddition + currentvaluelast;
// the current value become the last one for the next loop
currentvaluehexlast = currentvaluehex;
currentvaluelast = currentvalue;
output(this);
}
Thank you in advance for your feedback.
yes, use syntax message and then you can set any variable from this message payload. ex:
alternatively, you can extract data directly from PDU.signal if you have dbc.