Structures within structures
PatG
Posts: 42
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
0
Answers
Maybe not the most useful but...
Cool thanks
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.
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.
I'm still lost. Any other links available?
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.
This is not true, we write nested structures to XML all the time. In some cases up to 5 levels.
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.
Thanks everyone I figured it out.
@JasonS
Sorry for the tardy reply, do you still want code examples?
The NSX help file has a good example under XML_TO_VARIABLE.
If you want more let me know and I'll post some of our examples.
Have a look at this..
https://www.dropbox.com/s/h2qir6asa6ksqx9/XML Demo.AXW?dl=0
"JasonS
I am curious to see it work, I spent a good amount of time on it several years ago. A customer wanted a config file that was human readable and editable outside of the control code. I ended up going with a binary file because every time I tried to generate the XML file (using VariableToXML) with nested structures the XML output was corrupt."
This is a case where I might jut roll my own file reader. Pinning your hopes on the user getting a file format right every time is a pretty dicey prospect. This might be a good case for a good old fashioned CSV file which Excel et al can open easily enough and even if the format gets jacked up, you cam wrote sp,e cpde to deal with it and repair.
@ericmedley
We use XML editing programs to edit our config files. Using XML allows us to enforce the structure of the XML file as well as the data that is entered. e.g numerical or alpha can be enforced.
The example provided is for pre-configuring systems. Once the main code is loaded it looks for an existing XML, if one is found and the system is configured by that file. If there are errors in the file they are displayed on the touch panel and in debugging. If a file is not found a fresh one is written to the master.
This system is very handy when you have to roll out 200+ rooms at a university during summer break!
I've been using var to xml for my Viewstat scheduling code for a long time and haven't had any issues with corruption using a 3 deep nested structure.