mapgen.c

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.

Summary
mapgen.cMapgen generates the address map and property tables for an ACN device from its DDL description.
Internals
Functions
src_outfOpen a file for source code output.
h_putheaderPrint the opening text of the generated .h file
c_putheaderPrint the opening text of the generated .c file
h_putfooterPrint the closing text of the generated .h file
c_putfooterPrint the closing text of the generated .c file.
dcid_litConvert a UUID (DCID) to a C literal which compiles to a binary array.
printpropsRecursively walk the property tree printing each property.
printtestsPrint the extra array of property pointers needed where multiple properties interleave in an address range.
printsrchmapPrint an addrmap structure in the generic search map format (srch_amap_s).
printindxmapPrint an addrmap structure in the direct index map format (indx_amap_s).
usagePrint a usage message and exit.
Main
Functions
mainMain mapgen program.
Address map type selectionAn index map is a single linear array with one entry per address.

Internals

Summary
Functions
src_outfOpen a file for source code output.
h_putheaderPrint the opening text of the generated .h file
c_putheaderPrint the opening text of the generated .c file
h_putfooterPrint the closing text of the generated .h file
c_putfooterPrint the closing text of the generated .c file.
dcid_litConvert a UUID (DCID) to a C literal which compiles to a binary array.
printpropsRecursively walk the property tree printing each property.
printtestsPrint the extra array of property pointers needed where multiple properties interleave in an address range.
printsrchmapPrint an addrmap structure in the generic search map format (srch_amap_s).
printindxmapPrint an addrmap structure in the direct index map format (indx_amap_s).
usagePrint a usage message and exit.

Functions

src_outf

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.

h_putheader

static void h_putheader(const char *dcidstr,
const char *hfilename)

Print the opening text of the generated .h file

c_putheader

static void c_putheader(const char *dcidstr,
const char **headers)

Print the opening text of the generated .c file

h_putfooter

static void h_putfooter(void)

Print the closing text of the generated .h file

c_putfooter

static inline void c_putfooter(void)

Print the closing text of the generated .c file.  This is included for completeness but currently does nothing.

dcid_lit

static char * dcid_lit(uint8_t *dcid,
char *buf)

Convert a UUID (DCID) to a C literal which compiles to a binary array.

printprops

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.

printtests

static void printtests(struct srch_amap_s *smap)

Print the extra array of property pointers needed where multiple properties interleave in an address range.

printsrchmap

static void printsrchmap(struct srch_amap_s *smap)

Print an addrmap structure in the generic search map format (srch_amap_s).

printindxmap

static void printindxmap(struct indx_amap_s *imap)

Print an addrmap structure in the direct index map format (indx_amap_s).

usage

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

Summary
Functions
mainMain mapgen program.
Address map type selectionAn index map is a single linear array with one entry per address.

Functions

main

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’.

static FILE * src_outf(const char *fname,
const char *dcidstr)
Open a file for source code output.
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.
static char * dcid_lit(uint8_t *dcid,
char *buf)
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.
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).
generic address map using binary search to find a region then possibly further tests as defined in Algorithm for address search.
static void printindxmap(struct indx_amap_s *imap)
Print an addrmap structure in the direct index map format (indx_amap_s).
linear vector address map for direct property lookup.
static void usage(bool fail)
Print a usage message and exit.
Close