diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2013-05-21 12:47:07 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2013-05-21 12:47:07 -0600 |
commit | d1b1536d66431eeab17db17c6066c8da59410e1c (patch) | |
tree | 5c19708aff720b1035dda03a809eeca4a1939d66 /apps | |
parent | 63fbc0c2b3867e8919174c618a85a951f41b3682 (diff) | |
download | px4-nuttx-d1b1536d66431eeab17db17c6066c8da59410e1c.tar.gz px4-nuttx-d1b1536d66431eeab17db17c6066c8da59410e1c.tar.bz2 px4-nuttx-d1b1536d66431eeab17db17c6066c8da59410e1c.zip |
Add runtime configuration for UDP discovery utility. From Max Holtzberg
Diffstat (limited to 'apps')
-rw-r--r-- | apps/ChangeLog.txt | 3 | ||||
-rw-r--r-- | apps/examples/discover/discover_main.c | 2 | ||||
-rw-r--r-- | apps/include/netutils/discover.h | 14 | ||||
-rw-r--r-- | apps/netutils/discover/discover.c | 35 |
4 files changed, 39 insertions, 15 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt index a7f0fad8b..e6ceed475 100644 --- a/apps/ChangeLog.txt +++ b/apps/ChangeLog.txt @@ -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). + diff --git a/apps/examples/discover/discover_main.c b/apps/examples/discover/discover_main.c index 259a93d98..9c8f5f512 100644 --- a/apps/examples/discover/discover_main.c +++ b/apps/examples/discover/discover_main.c @@ -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; diff --git a/apps/include/netutils/discover.h b/apps/include/netutils/discover.h index c2226918d..df792b8ca 100644 --- a/apps/include/netutils/discover.h +++ b/apps/include/netutils/discover.h @@ -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 */ diff --git a/apps/netutils/discover/discover.c b/apps/netutils/discover/discover.c index 73b783209..dcd008a48 100644 --- a/apps/netutils/discover/discover.c +++ b/apps/netutils/discover/discover.c @@ -94,7 +94,7 @@ * Byte Description * 0 Protocol indentifier (0x99) * 1 Request command 0x01 - * 2 Destination device class (For querying subsets of available devices) + * 2 Destination device class (For querying subsets of available devices) * 0xff for all devices * 3 Checksum (Byte 0 - Byte 1 - Byte n) & 0xff */ @@ -103,7 +103,7 @@ * Byte Description * 0 Protocol indentifier (0x99) * 1 Reponse command (0x02) - * 2-33 Device description string with 0 bytes filled + * 2-33 Device description string with 0 bytes filled * 34 Checksum (Byte 0 - Byte 1 - Byte n) & 0xff */ @@ -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++) @@ -176,9 +180,9 @@ static int discover_daemon(int argc, char *argv[]) int sockfd = -1; int nbytes; int addrlen = sizeof(struct sockaddr_in); - struct sockaddr_in srcaddr; + 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"); @@ -198,7 +202,7 @@ static int discover_daemon(int argc, char *argv[]) } /* Read the next packet */ - + nbytes = recvfrom(sockfd, &g_state.request, sizeof(g_state.request), 0, (struct sockaddr*) &srcaddr, (socklen_t *) &addrlen); @@ -214,14 +218,14 @@ static int discover_daemon(int argc, char *argv[]) } continue; } - + if (discover_parse(g_state.request) != OK) { continue; } - + ndbg("Received discover from %08lx'\n", srcaddr.sin_addr.s_addr); - + discover_respond(&srcaddr.sin_addr.s_addr); } @@ -244,8 +248,8 @@ static inline int discover_parse(request_t packet) ndbg("Wrong command: %d\n", packet[1]); 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, |