Child object writing to 50+ VAR used by Parent object?
tonyp12
Posts: 1,951
A Parent object can read a child object's CONs ,by using #
But it can not read a Childs VARs
Solution is that child object has a method that returns the value
PUB getmacid
result := @macid 'returns the address in hub ram that stores the 6 byte macid
PUB getxvalue
result:= xvalue 'directly returns the value of the VAR xvalue
But doing this for 50+ VARs don't seem to be elegant
The VARs are not used by the child object, as they are from parsing data from a rx buffer it is in control of.
Should the Parent create a VAR structure (and can you load it the same way you declare child object?)
And when you start the child object you pass on the base address.
But the child objects should use "names" for these VAR and not baseaddres+2,
byte[baseaddress+macid][0], I guess is OK
So it needs a set of CON names of all these same VARs in the same order as the Parent has them.
And with a mix of bytes, words and longs complicates it a little.
But it can not read a Childs VARs
Solution is that child object has a method that returns the value
PUB getmacid
result := @macid 'returns the address in hub ram that stores the 6 byte macid
PUB getxvalue
result:= xvalue 'directly returns the value of the VAR xvalue
But doing this for 50+ VARs don't seem to be elegant
The VARs are not used by the child object, as they are from parsing data from a rx buffer it is in control of.
Should the Parent create a VAR structure (and can you load it the same way you declare child object?)
And when you start the child object you pass on the base address.
But the child objects should use "names" for these VAR and not baseaddres+2,
byte[baseaddress+macid][0], I guess is OK
So it needs a set of CON names of all these same VARs in the same order as the Parent has them.
And with a mix of bytes, words and longs complicates it a little.
Comments
And nearly every object I write, espeically if it has some sort of buffer, has a method that returns the hub address of child object variables that I want easy access to.
That would make the Parent having to use: byte[childbase+macid][0]
Something I'm trying to avoid as the Parent is just a demo and the end user will create their own program with a list of known variables.
And would have to know if the var is a word or long etc and makes everything look messy.
.
Yes I think that will be the best solution.
The driver(child object) will use for example: word[parentwordbase][varname] ' writes to the 3rd word from the start
And you set up childs objects CON's #0 + all the names for each type, as they will be correct if you use type[base] [number] and not by mistake type[base+number]
How do you externally load a VAR definition in Spin
Though if users always start out with copy of "demo", it will be there and seeing the list of available VARs does help.
The best you can is to have named offsets for all the child variables you want to access and have a method that returns a pointer to the base of the variables.
I've done this before when working on an OS for the Propeller. One of the FemtoBasic versions in the ObEx has a definitions object that contains all the shared variable offsets that happen to be kept in the high end of memory. You need to have at least one method or variable in the object since the Propeller Tool won't allow an object to have only CON definitions in it.
Look at BB_definitions.spin in DongleBasic for one example. There the CONs are the actual memory addresses of the variables and are referenced with <type>[ def#<name> ]. where the object is declared as "def".