I would like to set environment variables with a function. Is it even possible?
void SetEnvVariable(byte env_flag, byte ret_val)
{
putValue(env_flag, ret_val);
}
I get this error:
Error 1030 at (83,14): Environment variable expected. Database missing? test.cin
the CAPL function putValue require Environment variable name (on first parameter).
you cannot pass char name/value on first parameter by user defined function to this putValue.
what you can do is an workaround with hard bind the envar to if/switch case for example:
void SetEnvVariable(byte env_flag, byte ret_val)
{
if(env_flag==1)
{
putValue(Switch_K1, ret_val);
}
if(env_flag==2)
{
putValue(Switch_K2, ret_val);
}
}
where environment variable name Switch_K1 and Switch_K2 must be exist.
Note: The creation of environment variables is no longer supported. Instead, use system variables directly in CANoe. Currently CANoe still supports the use of environment variables. This support will not be available in future versions.
Related
Lets say you have a class Bird that has a const constructor:
class Bird {
const Bird();
void fly() {}
}
You need to use it in a place but you have two options:
1.
const bird = Bird();
void doIt() {
bird.fly();
}
void doIt2() {
const bird = Bird();
bird.fly();
}
Questions :)
Whats the of const constructors? it will avoid the creation of the objects in both examples?
Is there any difference between 1. and 2. related to const?
Im thinking that there are no difference in terms of performance but Im not really sure how to measure it
How can I measure that?
There is no difference in the value or the efficiency of accessing it.
The only difference is that in version 1, other code can refer to the bird variable, and in version 2, it's a local variable inside the function, and cannot be seen from the outside.
Just like any other variable, its scope is defined by where it's declared, not what its value is.
It doesn't matter, for that purpose, whether it's a const variable or not.
Because it is a const variable, it also means that the value is computed at compile-time, so accessing it takes no time at runtime.
There is nothing to measure, because accessing a constant variable at runtime, no matter where it is, just means loading a reference to the already existing value.
In the first example you have an instance variable. Instance variables are variables that are defined in the class, for which each instantiated object of that class has a separate copy or instance of the variables.
In the second example you have a local variable. After the calculate function executes, the local variables will no longer exist except of cases of closures.
By the way.
Use final for local variables that are not reassigned and var for those that are.
Use var for all local variables, even ones that aren’t reassigned. Never use final for locals. (Using final for fields and top-level variables is still encouraged, of course.)
https://dart.dev/guides/language/effective-dart/usage
From inside jShell script, is it possible to access or register variables that are defined in code that's also creating JShell?
Currently there seems to be no mechanism to either access or register a variable to Shell instance, or return none string types from inside JShell (like objects or lambda etc.)
ex:
import jdk.jshell.JShell;
import jdk.jshell.JShellException;
import jdk.jshell.SnippetEvent;
import java.util.List;
public class Main {
public static void main(String[] args) throws JShellException {
var localVar = 1;
JShell shell = JShell.create();
// How to register localVar variable with shell instance or access variables from scope
List events = shell.eval("var x = localVar;");
SnippetEvent event = events.get(0);
System.out.println("Kind: " + event.snippet().kind() + ", Value: " + event.value());
}
}
While you can't access local names like in your example, you can create a JShell instance that executes in the same JVM that created it. For this you would use the LocalExecutionControl. Using this execution control you could move localVar to a static field in your Main class and then access it from "inside" the JShell code with Main.localVar.
Unfortunately as the API is designed to support execution providers that could be in a different process or even a different machine, the return type is a string. If you are interested in a hack, the IJava jupyter kernel needed to an implementation of eval that returned an Object which ended up using an ExecutionControl implementation based on the DirectExecutionControl that stored the result of an eval call in a map and returned a unique id to reference that result. Then using the shell you would have to lookup the result from the id returned by eval (think of something like results.get(eval(sourceCode))). That implementation is on github in IJavaExecutionControl.java and IJavaExecutionControlProvider.java with a sample usage in CodeEvaluator.java#L72 if you are interested in taking any of it (MIT license).
I wanted to use a variable in 5 main CAN files. I have one include file common for all 5 CAN files. So I defined and declared the variable in this include file. But when I read the value of the variable from the main files I always get 0. Unfortunately Extern is not available in CAPL. So is there a way to do this.
Thanks.
If you use CAPL with CANoe you can create a database with the Vector CANdb++ Editor and declare an Environment-Variable in the database.
You Can access this variable in all your CAPL-files like this:
putValue(YourEnvironmentVariable,12); // Assigns the value 12 to the variable
Write("%d",getValue(YourEnvironmentVariable); //Prints 12
You can also declare an event that is thrown on change of the environment variable.
on envVar YourEnvironmentVariable{//do something...}
You can use System Variables for global access.
First you want to define a new namespace and a system variable in an include file global.cin:
/* global.cin */
on Start {
// define a namespace
sysDefineNamespace("myNamespace");
// define an integer system variable with starting, minimum and maximum value
sysDefineVariableInt("myNamespace", "mySysvar", 0, 0, 99);
}
By including global.cin in the main.can file you can then access the system variable using the corresponding CAPL functions:
/* main.can */
includes
{
#include "global.cin"
}
on Start {
// set system variable value
sysSetVariableInt("myNamespace", "mySysvar", 42));
// read system variable value
write("mySysvar: %d", sysGetVariableInt("myNamespace", "mySysvar"));
}
For data types other than integer there are corresponding CAPL functions in the naming-style of
sysDefineVariable<data-type>()
sysSetVariable<data-type>()
sysGetVariable<data-type>()
You can find additional information about accessing system variables via CAPL in the documentation of CANoe / CANalyzer under CAPL Functions -> System Variables CAPL Functions
I have a strange issue (which I can overcome however I would like to get a proper understanding of my error).
I have a small random number generator function which I use often:
func ranNum(low: Int, high:Int) -> UInt32 {
var result = arc4random_uniform(UInt32((high+1)-low)) + low
return result
}
When I use this in XCode playgrounds it works just fine if I pass in something like:
ranNum(1, 10)
However, in a regular Swift file it generates the error message : Missing argument label 'hi:' in call. Now I can overcome this by calling the function this way:
ranNum(1, hi:10)
Apart from it just being a little harder to read, it just isn't making sense why it works in Playgrounds but also why it requires only the 2nd argument label and not both. Any help as to what I am not understandinh would be greatly appreciated.
That's called external parameter name, and by default:
global functions: don't have implicit external names
class/struct methods: external names are automatically defined for all parameters after the first
initializers: external names are automatically defined for all parameters
If not explicitly specified, external names take the same name as the local parameter.
You can override that by prefixing a local parameter name with _. In your case:
func ranNum(low: Int, _ high:Int) -> UInt32 {
...
}
You mentioned that in playground calling the function works without any external parameter name - I may argue that:
in playground you have that function as a global function
in other tests, that function is a class/struct method
Am I right?
I wonder how to make a variable within IDA Pro bound to some function so the next time I double click the variable it will send me to the function.
v1 = this
*v2 = Known-Function
At Some Different location:
char __stdcall ClassA__KnownFunction(ClassA *ClassA, void a2) {
commands.....
}
I know you can set type to int, struct, dword etc. But I am looking for some method to point the variable to already known offset/function in IDA Pro.
Function pointer is merely a variable that holds the address of a function; you cannot treat a variable like a constant. You have two options:
Add the name of the function as a comment (just for the sake of documentation).
Get rid of the variable assignment, hard-code the function address by editing the hex, and then perform the analysis again.