controller.c

Simple demonstration controller application.

Summary
controller.cSimple demonstration controller application.
Controller descriptionThis demo controller is a very basic terminal program in which can discover devices, parse their DDL and access the properties exposed.
Variables
Discovery strings (see EPI19)
DMP structures
Functions
rx_sbsacceptCallback function which receives subscribe-accept messages.
showpropsCallback function which sisplay the properties received in a get property reply or event message.
cd_sdtevCallback function to handle out of band events from the SDT layer.
wordmatchMatch a command word.
readU32Read a uint32_t value from the command line.
readremoteRead a remote component specifier from the command line.
readpropRead a property specifier from the command line and check it against the property map for the device.
ddltreePrint the property tree of the specified device.
dodiscoverInitiate SLP discovery.
dmpconnectOpen a DMP connection to the specified device.
setintpropSend a set property command for an integer property.
setstringpropSend a set property command for a string property.
setpropRead the command line property and value specification then call setintprop or setstringprop to set the value.
getpropConstruct and send a get-property message.
dosubscribeConstruct and send a subscribe message.
term_eventInput has arrived from the terminal.
run_controllerInitialize ACN and SLP and run the event loop.
Command line optionsThese are parsed by library function getopt_long()
mainParse command line options and start controller.

Controller description

This demo controller is a very basic terminal program in which can discover devices, parse their DDL and access the properties exposed.

Each command is input on a text line and these have been developed piecemeal.  Commands are words but the matching function (wordmatch) will usually accept the first few letters.  See term_event for details.

Variables

Discovery strings (see EPI19)

fctnFCTN. a constant string.
uacn_dfltUACN default.  Used if no user value has been set.

DMP structures

ctlcxttransmit context for control messages (see <dmptcxt_s>).
remlistarray of remote components (they are also stored in a uuid set for rapid lookup by CID).
nremotesthe count of components in remlist.
ctlmbrsarray holding SDT connections of members of the control group.
localComponent<Lcomponent_s> holding ACN data representing the single controller component (see CF_MULTI_COMPONENT).

Functions

rx_sbsaccept

static int rx_sbsaccept(struct dmprcxt_s *rcxt,
const uint8_t *bp)

Callback function which receives subscribe-accept messages.

showprops

static int showprops(struct dmprcxt_s *rcxt,
const uint8_t *bp)

Callback function which sisplay the properties received in a get property reply or event message.

cd_sdtev

static void cd_sdtev(int event,
void *object,
void *info)

Callback function to handle out of band events from the SDT layer.

wordmatch

static bool wordmatch(char **str,
const char *word,
int minlen)

Match a command word.  Returns true if the *str matches word for the entire length of *str, it need not be as long as word but cannot be longer and must be at least minlen characters.

readU32

static int readU32(char **bpp,
uint32_t *ip,
const char *delims)

Read a uint32_t value from the command line.

readremote

static int readremote(char **bpp)

Read a remote component specifier from the command line.  Currently components are specified by index only, but this could be extended to allow UUID or name specifiers.

readprop

static int readprop(char **bpp,
int rem,
const struct dmpprop_s **dpp,
struct adspec_s *ofp)

Read a property specifier from the command line and check it against the property map for the device.

ddltree

static void ddltree(char **bpp)

Print the property tree of the specified device.  If there is no property tree associated with the device, parse its DDL first to generate one.

dodiscover

static void dodiscover()

Initiate SLP discovery.  Most of the work is done in SLP callbacks.

dmpconnect

static void dmpconnect(char **bpp)

Open a DMP connection to the specified device.  The connection will be within the control channel. see ctlcxt.

setintprop

static void setintprop(struct member_s *mbr,
const struct dmpprop_s *dprop,
struct adspec_s *ofs,
uint32_t pval)

Send a set property command for an integer property.

setstringprop

static void setstringprop(struct member_s *mbr,
const struct dmpprop_s *dprop,
struct adspec_s *ofs,
char *str,
int len)

Send a set property command for a string property.

setprop

static void setprop(char **bpp)

Read the command line property and value specification then call setintprop or setstringprop to set the value.

getprop

static void getprop(char **bpp)

Construct and send a get-property message.

dosubscribe

static void dosubscribe(char **bpp,
bool subs)

Construct and send a subscribe message.

term_event

static void term_event(uint32_t evf,
void *evptr)

Input has arrived from the terminal.

Commands

discoverperform SLP discovery
describeparse DDL for a device (if necessary) and print its property tree.
connectconnect to a component
spset property
gpget property
subscribesubscribe to property events
unsubscribeunsubscribe from property events quit- quit the program

run_controller

static void run_controller(const char *uuidstr,
uint16_t port,
const char **interfaces)

Initialize ACN and SLP and run the event loop.

Command line options

These are parsed by library function getopt_long()

-c --cidCID to be used by the controller.
-p --portport to use for receiving ad hoc messages.
-i --interfaceadd interface (e.g.  “eth0”) to list of interfaces used when finding IP addresses to advertise with SLP.  If no interfaces are specified then all will be considered.

main

int main(int argc,
char *argv[])

Parse command line options and start controller.

static int rx_sbsaccept(struct dmprcxt_s *rcxt,
const uint8_t *bp)
Callback function which receives subscribe-accept messages.
static int showprops(struct dmprcxt_s *rcxt,
const uint8_t *bp)
Callback function which sisplay the properties received in a get property reply or event message.
static void cd_sdtev(int event,
void *object,
void *info)
Callback function to handle out of band events from the SDT layer.
static bool wordmatch(char **str,
const char *word,
int minlen)
Match a command word.
static int readU32(char **bpp,
uint32_t *ip,
const char *delims)
Read a uint32_t value from the command line.
static int readremote(char **bpp)
Read a remote component specifier from the command line.
static int readprop(char **bpp,
int rem,
const struct dmpprop_s **dpp,
struct adspec_s *ofp)
Read a property specifier from the command line and check it against the property map for the device.
static void ddltree(char **bpp)
Print the property tree of the specified device.
static void dodiscover()
Initiate SLP discovery.
static void dmpconnect(char **bpp)
Open a DMP connection to the specified device.
static void setintprop(struct member_s *mbr,
const struct dmpprop_s *dprop,
struct adspec_s *ofs,
uint32_t pval)
Send a set property command for an integer property.
static void setstringprop(struct member_s *mbr,
const struct dmpprop_s *dprop,
struct adspec_s *ofs,
char *str,
int len)
Send a set property command for a string property.
static void setprop(char **bpp)
Read the command line property and value specification then call setintprop or setstringprop to set the value.
static void getprop(char **bpp)
Construct and send a get-property message.
static void dosubscribe(char **bpp,
bool subs)
Construct and send a subscribe message.
static void term_event(uint32_t evf,
void *evptr)
Input has arrived from the terminal.
static void run_controller(const char *uuidstr,
uint16_t port,
const char **interfaces)
Initialize ACN and SLP and run the event loop.
int main(int argc,
char *argv[])
Parse command line options and start controller.
One or many components?
transmit context for control messages (see dmptcxt_s).
Close