简体   繁体   English

从CAPL中的字符串动态分配信号名称

[英]Assign Signal names dynamically from a String in CAPL

I have a string that stores a signal name extracted from an excel file. 我有一个字符串,用于存储从excel文件中提取的信号名称。 I want to dynamically assign the name of the signal using the string, if I have many such signals. 如果我有很多这样的信号,我想使用字符串动态分配信号的名称。

For example, if I have a signal called 'speed' in my dbc file, and I have a string that stores 'speed', I need to set the value of signal 'speed' as 100. 例如,如果我在dbc文件中有一个名为“ speed”的信号,并且有一个存储“ speed”的字符串,则需要将信号“ speed”的值设置为100。

variable
{
    message BCM BCM;
    char signal[100]= "speed";
}

on message * 
{
    $signal= 100;
}

The error I get is: 我得到的错误是:
Error: Identifier 'signal' does not have a signal type. 错误:标识符“信号”没有信号类型。

Is there a workaround to this problem, such that I can convert the string into a signal name by some means? 是否有解决此问题的方法,以便可以通过某种方式将字符串转换为信号名称?

You are mixing the variable formats like this. 您正在混合这样的变量格式。 The only object on which you can use $ is dbSignal type. 可以使用$的唯一对象是dbSignal类型。 What you would need is a function like getSignal ( dbSignal name );, but with char[] parameter. 您需要的是一个类似getSignaldbSignal name );的函数,但是带有char []参数。 Sadly, Vector did not implement such workaround, leaving you the only option to pass your signal strings by testcase parameters (if you are using XML Test nodes). 遗憾的是,Vector没有实现这种解决方法,使您成为通过测试用例参数传递信号字符串的唯一选择(如果使用XML测试节点)。

Since, I presume you have too many, I suggest you write a script in another scripting language constructing the text of the .can file itself, filling the place of dbsignals with the strings from the excel, then use the .can file for testing/simulation. 既然,我想您太多了,建议您用另一种脚本语言编写一个脚本,以构造.can文件本身的文本,用excel中的字符串填充dbsignals的位置,然后使用.can文件进行测试/模拟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM