I know it is a basic question but I didn't find anywhere an explication and I want to understand why sometimes the code are written using . or sometimes use ::.
For example:
Msg1::Signal
Msg1.Signal
When I read the code from my experienced colleagues I see these difference.
It's hard to explain, but in my experience it varies a bit depending on what type of object you are dealing with. Generally, I would say it has to do with scope. I'll try to explain with 2 examples.
Example 1:
Your dbc defines 2 messages (Msg1 and Msg2) which contain a signal named "Signal1". In CAPL, the "::" operator can be used to resolve the ambiguity of "Signal1".
This will not compile:
void foo() {
$Signal1 = 1; //notice the "$" in front
}
on signal Signal1 {
//do something
}
But this will:
void foo() {
$Msg1::Signal1 = 1; //notice the "$" in front
}
on signal Msg1::Signal1 {
//do something
}
So if you are accessing a message via its dbc definition, the "::" is used to resolve ambiguity. The signal is sort of treated a static member of the message and using the "$" operator will set/get the signal value on the bus via the IL (assuming the message is being broadcast).
Example 2:
The "." operator comes into play if you create a local message variable. In that case, you must use "." to access the signal (or other message properties), like this:
void bar() {
message Msg1 msg;
msg.Signal1 = 1; //notice there is no "$" symbol in front
output(msg);
}
In this case, the message seems to be treated more like a local (stack) variable. Example 2 does not use the IL and we must use the output function to send the message.
This might not be a definitive answer, but I hope it helps.