demo_utils.c

Utilities common to multiple demo programs.

Summary
demo_utils.cUtilities common to multiple demo programs.
DMP address array conversionsConvert between DMP property address ranges and Arrays suitable for handling in C/C++
Functions
addr2ofsConvert a DMP address specifier to a property array offset.
ofs2addrConvert a property array offset to a DMP address specifier.
UACN managementThe UACN (User Assigned Component Name) is specified in EPI-19 (discovery).
Functions
uacn_initInitialize our UACN from a file.
uacn_changeChange the value of our UACN.
uacn_closeCall after a component is de-registered
gethomedirReturns a pointer to the current user’s home directory.

DMP address array conversions

Convert between DMP property address ranges and Arrays suitable for handling in C/C++

Because of the DMP addressing mechanism which allows arbitrary increments between property eddresses and the DDL array declaration method allowing nested arrays, the relationship between a DMP address and a particular element of an array property is not trivial.

Within these demonstrations any array property is treated as a C style array with the number of dimensions derived from its DDL declaration and with the DDL array declaration nearest the root as the outermost dimension of the array.  Thus a declaration like this:

<property array="12"...>
  ...
  <property array="1000"...>
  ...
  </property>
</property>

Is treated as a C array like this

array2D[12][1000].

Which may be “flattened” into a single dimensional array

array2D[column][row]  ==  array1D[column * 1000 + row]
Summary
Functions
addr2ofsConvert a DMP address specifier to a property array offset.
ofs2addrConvert a property array offset to a DMP address specifier.

Functions

addr2ofs

int addr2ofs(const struct dmpprop_s *dprop,
struct adspec_s *dmpads,
struct adspec_s *ofsads)

Convert a DMP address specifier to a property array offset.

arguments

dpropthe property within which the (first) address falls
dmpadsthe input DMP address specifier
ofsadsthe output offset address specifier (dmpads and ofsads may point to the same structure, in which case the conversion is made in situ).

returns

  • -1 on failure, ofsads is not modified
  • 0 on success in which case ofsads->addr is the offset into the C array of the first element, ofsads->inc is the increment in the C array equivalent to the DMP property space increment and ofsads->count is the number of properties for which this address specifier is valid (minimum 1, maximum dmpads->count)

ofs2addr

void ofs2addr(const struct dmpprop_s *dprop,
struct adspec_s *ofsads,
struct adspec_s *dmpads)

Convert a property array offset to a DMP address specifier.

arguments

dpropthe property within which the (first) address falls
ofsadsthe input offset address specifier
dmpadsthe output DMP address specifier (ofsads and dmpads may point to the same structure, in which case the conversion is made in situ).

UACN management

The UACN (User Assigned Component Name) is specified in EPI-19 (discovery).  It must be persistent and since it forms part of the component’s discovery attributes, the component must re-register with SLP if it changes.

Summary
Functions
uacn_initInitialize our UACN from a file.
uacn_changeChange the value of our UACN.
uacn_closeCall after a component is de-registered
gethomedirReturns a pointer to the current user’s home directory.

Functions

uacn_init

void uacn_init(const char *cidstr)

Initialize our UACN from a file.  If this fails assign the default value.

uacn_change

void uacn_change(const uint8_t *dp,
int size)

Change the value of our UACN.  The new value is stored to file, then the component must be re-advertised through SLP.

uacn_close

void uacn_close()

Call after a component is de-registered

gethomedir

char * gethomedir(void)

Returns a pointer to the current user’s home directory.  It first tries the environment variable HOME, then looks up in the system passwd file.

int addr2ofs(const struct dmpprop_s *dprop,
struct adspec_s *dmpads,
struct adspec_s *ofsads)
Convert a DMP address specifier to a property array offset.
void ofs2addr(const struct dmpprop_s *dprop,
struct adspec_s *ofsads,
struct adspec_s *dmpads)
Convert a property array offset to a DMP address specifier.
void uacn_init(const char *cidstr)
Initialize our UACN from a file.
void uacn_change(const uint8_t *dp,
int size)
Change the value of our UACN.
void uacn_close()
Call after a component is de-registered
char * gethomedir(void)
Returns a pointer to the current user’s home directory.
Close