Shop OBEX P1 Docs P2 Docs Learn Events
Child object writing to 50+ VAR used by Parent object? — Parallax Forums

Child object writing to 50+ VAR used by Parent object?

tonyp12tonyp12 Posts: 1,951
edited 2015-02-17 12:52 in Propeller 1
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.

Comments

  • JonnyMacJonnyMac Posts: 9,105
    edited 2015-02-17 11:46
    I have several objects that accept a pointer to a block of variables that are declared in the parent -- this just makes things easier. In most cases, I allow the user to on using the child vars or external vars.
    pub start(param, param, p_vars)
    
      if (p_vars < 0)
        varpntr := @localvars
      else
        varpntr := p_var
    


    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.
  • tonyp12tonyp12 Posts: 1,951
    edited 2015-02-17 12:01
    > returns the hub address of child object variables

    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.
    .
  • kwinnkwinn Posts: 8,697
    edited 2015-02-17 12:13
    Pass 3 pointers to 3 arrays, long, word, and byte arrays?
  • tonyp12tonyp12 Posts: 1,951
    edited 2015-02-17 12:20
    >Pass 3 pointers to 3 arrays, long, word, and byte arrays?
    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2015-02-17 12:52
    "How do you externally load a VAR definition in Spin" ... you can't.

    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".
Sign In or Register to comment.