在CAPL中使用消息和信号之前将其声明为变量



我创建了一个CAPL程序来计算每次接收特定帧时的消耗。问题是,如果帧是不同的,帧的名称和它的信号必须在整个代码中改变。

是否有可能将消息和信号声明为整个代码中使用的变量?

我想在程序开始时声明消息和它的信号,这将允许只改变这一个,而不是整个代码。

在下面的例子中,帧被称为TOTAL_DISTANCE_VhSpeed_565,它的信号是st_con_ev_565,但这些可能会根据日志而改变。

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);
}

提前感谢您的反馈。

是,使用语法消息,然后您可以从此消息有效负载设置任何变量。例:

variable
{
message PDU_Name1 msg_A:
message PDU_Name2 msg_B:
int currentvaluelast;
}
on message PDU_Name1
{
currentvaluelast = msg_A.Byte(0);
}
on message PDU_Name2
{
currentvaluelast = msg_B.Byte(0);
// when different frame layout: currentvaluelast = msg_B.Byte(1); 
}

也可以直接从PDU中提取数据。如果有dbc,请发出信号。

currentvaluelast = PDU_Name1.signal3;
currentvaluelast = PDU_Name2.signal1;

最新更新