Structures within structures

PatGPatG Junior MemberPosts: 25

Hi, can someone link me to a resource that can explain this? I can post more detail as to what's confusing me but if there's a good link I can just check that out to start.

Thanks

Answers

  • HARMAN_icraigieHARMAN_icraigie Technical Trainer II, Harman Professional University Posts: 442

    Maybe not the most useful but...

    structure _time
    {
        integer hours;
        integer minutes;
        integer seconds
    }
    
    structure _date
    {
        integer day;
        integer month;
        integer year;
    }
    
    structure _timeStamp
    {
        _time time;
       _date date;
    }
    
    volatile _timeStamp uTimeStamp;
    
    
    uTimeStamp.time.hours = time_to_hour(time);
    
  • PatGPatG Junior Member Posts: 25

    Cool thanks

  • viningvining X Member Posts: 4,341

    If you go too big and too deep nesting structures you might not enjoying watching them in debug. If you try to mimic deep jason or xml nests debug can really suck.

  • JasonSJasonS If I had known it was going to be that kind of party... Posts: 226
    Also you can't use Variable_To_XML on nested structures, it breaks and corrupts the XML.
  • fogled@mizzou[email protected] h4x354x0r Posts: 546

    I believe there is (or used to be) a hard limit on structure depth, like 5 deep or something like that? I've gone past it.

  • PatGPatG Junior Member Posts: 25

    I'm still lost. Any other links available?

  • JasonSJasonS If I had known it was going to be that kind of party... Posts: 226
    What is your application or what are you having dufficulty with so we can provide more relevant help.
  • fogled@mizzou[email protected] h4x354x0r Posts: 546
    edited February 12

    Since I ended up copying and pasting some code anyway, I'll post a simplified version of the structures I use to store room and device data...


    (***********************************************************)
    (* DATA TYPE DEFINITIONS GO BELOW *)
    (***********************************************************)


    structure deviceip {
    char name[32]
    char ipaddr[20]
    integer ipport
    integer iptype
    dev devid
    }


    structure displaysettings {
    char name[32]
    integer type
    dev devid
    dev vdvdevid
    integer commtype
    deviceip ipcomm[1] //THIS IS PUTTING THE STRUCTURE ABOVE INTO THIS STRUCTURE
    char sercomm[64]
    integer pwr
    integer vmute
    integer feed
    integer follows
    integer status
    integer swtid //VGA Switch ID
    char vport[16] //VGA Port Number
    integer chan
    integer amute
    integer vol
    integer volset
    integer tmp
    integer ipconnect
    integer ipdone
    integer init
    char text[32]
    char buffout[1024] //holds buffer of integer commands as string data for fifo operations
    char buffin[512]
    char lastacmd[512]
    integer lastcmd
    }


    structure audchans {
    char name[20]
    integer unit
    integer id
    integer chan
    integer val
    integer mute
    integer volset
    }


    structure audiodata {
    char name[32]
    integer type
    integer init
    char sernum[16]
    audchans ch[30] //THIS PUTS THE AUDIOCHANNELS ABOVE INTO THIS STRUCTURE
    }


    structure inputs {
    char name[32]
    integer swtid //VGA Switch ID
    char vport[16] //HDMI Switch Video Port (nornally Aud and Vid)
    char aport[16] //HDMI Switch Audio Port (Use separate Aud/Vid for oddball stuff)
    integer follows
    }


    //THIS IS THE MAIN, TOP-LEVEL STRUCTURE:
    structure room {
    char name[32]
    char dbid[12]
    integer status
    displaysettings d[21] //PUTS DISPLAY STRUCTURE (WITH IP SUB_STRUCTURE) IN THIS STRUCTURE
    audiodata audio[1] //PUTS AUDIO DATA STRUCTURE & SUB_STRUCTURES INTO THIS STRUCTURE
    inputs in[16] //PUTS INPUT DATA STRUCTURE INTO THIS STRUCTURE
    helpdata help[1]
    }

    ...then all I have to do to define the whole structure and sub-structure

    (***********************************************************)
    (* VARIABLE DEFINITIONS GO BELOW *)
    (***********************************************************)
    DEFINE_VARIABLE


    persistent room rm[2] //THIS DEFINES TWO ROOMS with all the data cells of the sub-structures underneath them

    Then to get to any cell in the structure:
    stored_volume = rm[this_rm].d[this_device].a[1].ch[this_ch].val

    ...hope that helps if you're still struggling with building and using structures.

  • mushmush I programme in the dark! Posts: 280

    @JasonS said:
    Also you can't use Variable_To_XML on nested structures, it breaks and corrupts the XML.

    This is not true, we write nested structures to XML all the time. In some cases up to 5 levels.

  • JasonSJasonS If I had known it was going to be that kind of party... Posts: 226
    edited May 9
    @mush Could you post an example of the code that writes the structure to disk? On an NX or NI processor?
  • viningvining X Member Posts: 4,341

    I use variable to string and string to variable to pass updated structures, a single level, from modules back to the main all the time and use variable to xml to store data on the flash that are 3 levels deep. I've never noticed corrupted data but to be honest I haven't looked for it either.

  • PatGPatG Junior Member Posts: 25

    Thanks everyone I figured it out.

Sign In or Register to comment.