Add runtime configuration for UDP discovery utility. From Max Holtzberg
This commit is contained in:
parent
dba4210e37
commit
ec32c5e636
@ -555,3 +555,6 @@
|
||||
Ken Pettit (2013-5-11).
|
||||
* apps/examples/helloxx: C++ name mangling was occurring when this
|
||||
example is built as an NSH built-in application. (2013-5-16).
|
||||
* apps/netutils/discover: Added a runtime configuration for the
|
||||
UDP discover utility. From Max Holtzberg (2013-5-21).
|
||||
|
||||
|
@ -177,7 +177,7 @@ int discover_main(int argc, char *argv[])
|
||||
#endif /* CONFIG_EXAMPLES_DISCOVER_DHCPC */
|
||||
#endif /* CONFIG_NSH_BUILTIN_APPS */
|
||||
|
||||
if (discover_start() < 0)
|
||||
if (discover_start(NULL) < 0)
|
||||
{
|
||||
ndbg("Could not start discover daemon.\n");
|
||||
return ERROR;
|
||||
|
@ -36,16 +36,28 @@
|
||||
#ifndef __APPS_INCLUDE_NETUTILS_DISCOVER_H
|
||||
#define __APPS_INCLUDE_NETUTILS_DISCOVER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
struct discover_info_s
|
||||
{
|
||||
uint8_t devclass; /* Device class, 0xff for all devices */
|
||||
const char *description;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Name: discover_start
|
||||
*
|
||||
* Description:
|
||||
* Start the discover daemon.
|
||||
*
|
||||
* Input Paramters:
|
||||
*
|
||||
* info Discover information, if NULL mconf defaults will be used.
|
||||
*
|
||||
* Return:
|
||||
* The process ID (pid) of the new discover daemon is returned on
|
||||
* success; A negated errno is returned if the daemon was not successfully
|
||||
@ -53,6 +65,6 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int discover_start(void);
|
||||
int discover_start(struct discover_info_s *info);
|
||||
|
||||
#endif /* __APPS_INCLUDE_NETUTILS_DISCOVER_H */
|
||||
|
@ -123,6 +123,7 @@ typedef uint8_t response_t[DISCOVER_RESPONSE_SIZE];
|
||||
|
||||
struct discover_state_s
|
||||
{
|
||||
struct discover_info_s info;
|
||||
in_addr_t serverip;
|
||||
request_t request;
|
||||
response_t response;
|
||||
@ -132,7 +133,10 @@ struct discover_state_s
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
struct discover_state_s g_state;
|
||||
struct discover_state_s g_state =
|
||||
{
|
||||
{CONFIG_DISCOVER_DEVICE_CLASS, CONFIG_DISCOVER_DESCR}
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
@ -158,7 +162,7 @@ static inline void discover_initresponse()
|
||||
g_state.response[0] = DISCOVER_PROTO_ID;
|
||||
g_state.response[1] = DISCOVER_RESPONSE;
|
||||
|
||||
strncpy((char*) &g_state.response[2], CONFIG_DISCOVER_DESCR,
|
||||
strncpy((char*) &g_state.response[2], g_state.info.description,
|
||||
DISCOVER_RESPONSE_SIZE-3);
|
||||
|
||||
for (i = 0; i < DISCOVER_RESPONSE_SIZE-1; i++)
|
||||
@ -178,7 +182,7 @@ static int discover_daemon(int argc, char *argv[])
|
||||
int addrlen = sizeof(struct sockaddr_in);
|
||||
struct sockaddr_in srcaddr;
|
||||
|
||||
memset(&g_state, 0, sizeof(struct discover_state_s));
|
||||
/* memset(&g_state, 0, sizeof(struct discover_state_s)); */
|
||||
discover_initresponse();
|
||||
|
||||
nvdbg("Started\n");
|
||||
@ -245,7 +249,7 @@ static inline int discover_parse(request_t packet)
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (packet[2] == 0xff || packet[2] == CONFIG_DISCOVER_DEVICE_CLASS)
|
||||
if (packet[2] == 0xff || packet[2] == g_state.info.devclass)
|
||||
{
|
||||
for (i = 0; i < DISCOVER_REQUEST_SIZE-1; i++)
|
||||
chk -= packet[i];
|
||||
@ -437,10 +441,15 @@ static inline int discover_openresponder(void)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int discover_start()
|
||||
int discover_start(struct discover_info_s *info)
|
||||
{
|
||||
pid_t pid;
|
||||
|
||||
if (info)
|
||||
{
|
||||
g_state.info = *info;
|
||||
}
|
||||
|
||||
/* Then start the new daemon */
|
||||
|
||||
pid = TASK_CREATE("Discover daemon", CONFIG_DISCOVER_PRIORITY,
|
||||
|
Loading…
Reference in New Issue
Block a user