Address map generator for devices
Mapgen generates the address map and property tables for an ACN device from its DDL description. These tables are output as C code which then gets compiled in to the device code along with other sources. Using the DDL to generate the device code both verifies the DDL and ensures that it really matches the device and so prevents errors and discrepancies when a controller later uses that same DDL.
Mapgen uses the same DDL parser that is used by controllers but it is run on the host system at build time. It parses DDL in exactly the same way to generate an address and property map. It then walks through these structures generating a C representation. For an example of its use see the Acacian device demonstration program.
|src_outf||Open a file for source code output.|
|h_putheader||Print the opening text of the generated .h file|
|c_putheader||Print the opening text of the generated .c file|
|h_putfooter||Print the closing text of the generated .h file|
|c_putfooter||Print the closing text of the generated .c file. |
|dcid_lit||Convert a UUID (DCID) to a C literal which compiles to a binary array.|
|printprops||Recursively walk the property tree printing each property.|
|printtests||Print the extra array of property pointers needed where multiple properties interleave in an address range.|
|printsrchmap||Print an addrmap structure in the generic search map format (srch_amap_s).|
|printindxmap||Print an addrmap structure in the direct index map format (indx_amap_s).|
|usage||Print a usage message and exit. |
|static FILE * src_outf(||const ||char ||*||fname,|
|const ||char ||*||dcidstr||)|
Open a file for source code output.
The named file is opened and a standard heading text is printed including the DCID of the device it represents. Used for both .c and .h outputs.
Returns a FILE pointer.
|static void h_putheader(||const ||char ||*||dcidstr,|
|const ||char ||*||hfilename||)|
Print the opening text of the generated .h file
|static void c_putheader(||const ||char ||*||dcidstr,|
|const ||char ||**||headers||)|
Print the opening text of the generated .c file
|static void h_putfooter(||void||)|
Print the closing text of the generated .h file
|static inline void c_putfooter(||void||)|
Print the closing text of the generated .c file. This is included for completeness but currently does nothing.
|static char * dcid_lit(||uint8_t ||*||dcid,|
Convert a UUID (DCID) to a C literal which compiles to a binary array.
|static void printprops(||struct ||ddlprop_s ||*||prop||)|
Recursively walk the property tree printing each property.
Network properties generate entries in the .c output for each DMP property together with external declarations in the .h output. Immediate properties (values) generate macros in the .h output.
If <Property Extensions> are enabled DMP properties also include function callbacks for handling get-property, set-property and subscription messages.
|static void printtests(||struct ||srch_amap_s ||*||smap||)|
Print the extra array of property pointers needed where multiple properties interleave in an address range.
|static void printsrchmap(||struct ||srch_amap_s ||*||smap||)|
Print an addrmap structure in the generic search map format (srch_amap_s).
|static void printindxmap(||struct ||indx_amap_s ||*||imap||)|
Print an addrmap structure in the direct index map format (indx_amap_s).
|static void usage(||bool ||fail||)|
Print a usage message and exit. If fail is false the message goes to stdout and the program returns a zero exit code. Otherwise the message goes to stderr and the exit code is EXIT_FAILURE.
Main mapgen program.
Usage: mapgen [ -h hfile ] [ -c cfile ] [-i hdr.h ] [-u] UUID
hfile is name of .h output, (default 'devicemap.h')
cfile is name of .c output, (default 'devicemap.c')
each -i option generates '#include \"hdr.h\"' in the .c file
- Parse command line arguments
- Parse the root DCID and its subdevices to generate a property tree and address map in default search format.
- Generate output from the property tree for each DMP property or immediate value.
- If the address map meets criteria for conversion, transform it into an index map for efficiency.
- Generate output for the address map in the chosen format, cross referenced to the property structures.
Address map type selection
An index map is a single linear array with one entry per address. The starting address and length of the map are stored in its header. This is very efficient since a single array reference goes straight from the address to the property structure. However it is only feasible where there are few properties and they are quite close together in the address space. Also, whereas a search-map usually has a single entry for an array property, however many elements in the array, an index map has an entry for each element. The code here calculates the size of the index array that would be needed and transforms the map to index format if the size is ‘reasonable’.