Assign Signal names dynamically from a String in CAPL - 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?

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.

Related

CAPL- Get value of string defined sysvar

i defined a sysvar as a string in CANalyzer to use it with a panel.
Then in a CAPL a would like to get the value of this variable and save the name,i tried as i usually do in CAPL with the numbers so:
write("%s",#namespace::name_of_variable)
But i got an error saying tha the '#' should be used only for integer or float variables. How can i get the value of this string and save it in a local variable to reused it in a CAPL?
Thanks in advice.
The CAPL function you are looking for is sysGetVariableString
Usage is as follows:
char value[100]; //has to be big enough to hold the value
sysGetVariableString(sysvar::namespace::name_of_variable, value, elcount(value));

h2o Steam Prediction Servlet not accepting character values from python script

I am using Steam to attempt to build a prediction service using a python preprocessing script. When python passes the cleaned data to the prediction service in the
variable:value var2:value2 var3:value3
format (as seen in the Spam Detection Example) I get a
ERROR PredictPythonServlet - Failed to parse
error from the service. When I look at the PredictPythonServlet.java file it seems to only use the strMapToRowData function which assumes every value in the input string is a number:
for (String p : pairs) {
String[] a = p.split(":");
String term = a[0];
double value = Float.parseFloat(a[1]);
row.put(term, value);
}
Are character values not allowed to be sent in this format? If so is there a way to get the PredictPythonServlet file to use the csvToRowData function that is defined but never used? I'd like to not have to use One-Hot encoding for my models so being able to pass the actual character string representation would be ideal.
Additionally, I passed the numeric representation found in the model pojo file for the categorical variables and received the error:
hex.genmodel.easy.exception.PredictUnknownTypeException: Unexpected object type java.lang.Double for categorical column home_team
So it looks like the service expects a character string but I can't figure out how to pass it along to the actual model. Any help would be greatly appreciated!
The prediction service is using EasyPredictModelWrapper and it can only use what the underlying model uses. Here it's not clear what model you use, but most use numerical float values. In the for loop code snippet you can see that the number has to be float.

Pascal I need to modify the program as the result to be write in text file maxim.out

I have a program which is counting the biggest number from 3 numbers. I need to modify the program as the result to be write in text file maxim.out (PASCAL)
You can write the value (assuming it is an integer and it has the name, say, yourValue) with:
var
maximFile: Text;
...
Assign(maximFile, 'maxim.out'); // link the name to the Text variable
Rewrite(maximFile); // open it for writing
Writeln(maximFile, yourValue); // write the value as a line of its own
Close(maximFile); // close the file
You can then read back the value later on with:
Assign(maximFile, 'maxim.out');
Reset(maximFile);
Readln(maximFile, yourValue);
Close(maximFile);
I did not add any error handling (e.g. if the file can't be found, or if it is readonly, or empty, or ...). Depending on settings, that is either done with exceptions or with IOResult values. Read the documentation on how to do that. There should be examples in the docs.
You should read about "file management in pascal". Anyway, declare a variable of type textfile:
var
outputfile : TextFile;
then assignfile() to it your name of choice (maxim.out), rewrite() the file, use writeln() to write into it, and finally closefile() it.
You can find a complete example program here: http://wiki.freepascal.org/File_Handling_In_Pascal

Problems opening files from a VHDL process into an entity instantiated twice: name conflicts

I have an entity in VHDL which has the following structure:
-- Imports...
entity myentity is
port (..specifying in and out signals..);
end myentity;
architecture beh_myentity of myentity is
begin
process(..sensitivity list..)
-- Some variables
file myfile : text open write_mode
is "myentlog.txt"; -- <== My problem is here!!!
begin
-- ..The process body..
end process;
end beh_myentity;
No problems in opening the file, everything works! I have a problem. When I create a testbench and run it I usually create one single instance of my entity. But in my case I now need to put two instances. My problem is that I will have conflicts with file name and one process will inevitably fail opening and writing the (same) log file.
I would like to solve this, so here the questions:
In my port I have signals, is it ok to append a signal value to the name of the file? I am afraid this is not the best thing to do (not even know if such a thing would work).
Is there a way to get a variable representing the instance name of the entity in the testbench?
is there a way to pass a string to the entity so that I can attach it at the end of the file name?
Thankyou
Either a signal of type string, containing the filename; or a generic (again, of type string).
The signal allows you to assign different filenames to the same entity at different times in your testbench - using VHDL-1993 or later, the architecture can call file_open() with the new filename.
The generic gives a fixed filename to each different entity.
Use whichever is simplest for your application.
Your specific questions :
1) Yes , if the signal is a string, you can either pass in the whole filename as a string or pass in a suffix. Because you are generating the string at runtime you need VHDL-93 (or later) syntax
process (...) is
file my_file;
begin
file_open(my_file, base_name & suffix & ".txt", read_mode);
...
file_close(my_file);
end process;
2) Best way is to generate the filename in the testbench and pass it in. However an out port from the entity would work! Naturally you can't synthesise this entity...
3) Of course...
entity myentity is
generic ( base_name : string := "testfile");
port (suffix : in string);
end myentity;
will pass in the strings you needed in (2).
If you must use VHDL-87 syntax, as in your example, pass the whole name in as a generic:
file myfile : text open write_mode is base_name;
Try passing the file name as a generic, instead of a port.
http://www.ics.uci.edu/~jmoorkan/vhdlref/generics.html

C++: What would be an appropriate solution to forming a collection of different data types?

I'm writing a command line interpreter and I'm trying to setup formats for individual commands. I have things like the name of the command, the maximum amount of parameters and the minimum amount of parameters. I want to have sort of collection, a sort of prototype of what kind of types the parameters are. My first thought was just to declare a vector without the generics, but then I realized this isn't Java.
Let's say I have a command such as "read test.dat 2"
I would want a structure showing that the typical read command has a string and then an integer.
Any ideas?
I'm not really clear about what you are asking so I may be getting this wrong.
From your description ,it sounds as if you have an abstract notion of commands, and that they have names and an expected structure in terms of parameters. From your description, it sounds like you would want a list of type identifiers and indications on whether they are optional.
Then, you could just instantiate a command object for each command you expect to work with, and add all of them to a collection of commands.
Alternatively, use a map collection to map from command names to the actual command objects.
Each command object can also hold a reference to a handler object to actually execute the command.
Heterogenous Container
If you want to have a container that can store a fixed set of types, you can use one of boost::variant:
typedef boost::variant<std::string, int> optval;
typedef std::vector<optval> options;
Now, you can push_back into the vector either strings or integers, and the variant will note what it contains:
options opts;
opts.push_back(10);
opts.push_back("hello");
You can read about it in its documentation at Boost variant, including how to get the right value out of the variant. You can of course also have a map from argument names to such variants, if you have already set up your command line parsing, and don't need libraries for that anymore:
std::map<std::string, optval> map;
map["--max-foo"] = 10;
map["--title"] = "something fun";
Command line parsing
If you want to parse the command line arguments of your program, you can look into the Boost.Program Options library, which will greatly assist you doing that.
Mostly, however, i end up using the posix getopt function, which can also parse the command line. I recommend you to look into boost program options first, and if you feel it's too heavy, you can look into getopt (see man 3 getopt)
Something like this, perhaps:
enum ParameterType
{
Int,
String
};
struct Command
{
string name;
vector<ParameterType> maxParameters;
int minParameters;
};

Resources