(Just holding some notes now)
How do I add node variables to a node's XML? And how do I access them?
For example, a node that implements two turnouts might have:
Consumed events
Turnout0
SetNormal
SetReversed
Lock
Unlock
Turnout1
SetNormal
SetReversed
Lock
Unlock
Produced events
Turnout0
Normal
Reversed
Locked
Unlocked
Turnout1
Normal
Reversed
Locked
Unlocked
Node variables
SpeedOfChange 0..255, 0 slowest
Answer:
Start at the inside and work out.
For each event, put in an <eventid> element, with an optional name:
<eventid>
<name>setNormal</name>
</eventid>
Then you can put those into group elements as desired, with optional names and descriptions:
<group>
<name>Turnout 0</name>
<description>Something</description>
<eventid>
<name>setNormal</name>
</eventid>
<eventid>
<name>setReversed</name>
</eventid>
</group>
Those can then be grouped if desired:
<group>
<name>Consumed Events</name>
<group>
<name>Turnout 0</name>
<description>Something</description>
<eventid>
<name>setNormal</name>
</eventid>
<eventid>
<name>setReversed</name>
</eventid>
</group>
<group>
<name>Turnout 1</name>
<description>Something</description>
<eventid>
<name>setNormal</name>
</eventid>
<eventid>
<name>setReversed</name>
</eventid>
</group>
</group>
All variables are the same as far as the entire system is concerned; there's no such thing as "node variables", there's just information. The code itself has to know whether something applies to the entire node, a group of channels, or something else. So I don't find it useful to think in terms of "node variables" vs events vs anything else. Variables that do live outside any groups, e.g. your example SpeedOfChange, you just put that where you want it. See the stuff at top and bottom in the OlcbBasicNode/cdi.xml
Also note that the order & grouping isn't forced; you can do it any way you want. Instead of "all consumers" then "all producers", you could also do it as "P & C for TO 1", then "P & C for TO 2", etc.
Finally, you have to put it in a segment element to tell it where in memory to write:
<segment space="253">
<group>
<name>Consumed Events</name>
<group>
<name>Turnout 0</name>
<description>Something</description>
<eventid>
<name>setNormal</name>
</eventid>
</group>
<group>
<name>Turnout 1</name>
<description>Something</description>
<eventid>
<name>setNormal</name>
</eventid>
</group>
</group>
<integer size="1" max="255">
<name>SpeedOfChange</name>
<description>0 slowest</description>
</integer>
</segment>
Once you have that the way you want it, then you have to match it to what the node program expects to find in memory. They have to agree. You can adjust where the CDI & configuration process puts stuff using the offset="" attribute (and origin="" on the segment element that encloses the entire thing, see the OlcbBasicNode). Or you can let the CDI write all the stuff linearly in memory, and have the node's code sort that out.
In the most recent OlcbBasicNode, you'll see that in action. The event IDs are sequential at the base of memory, with the description strings way above them. That's for historical reasons as the node code expects the event IDs there and I didn't want to change that when adding the description strings. So I used the offset attributes to jump the strings to upper memory.
This is SVN $Revision: 2291 $