Search code examples
caplcanoe

Assign Signal names dynamically from a String in CAPL


I have a string that stores a signal name extracted from an excel file. 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.

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?


Solution

  • You are mixing the variable formats like this. The only object on which you can use $ is dbSignal type. What you would need is a function like getSignal(dbSignal name);, but with char[] parameter. 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).

    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.