summaryrefslogtreecommitdiff
path: root/apps/system/usbmonitor
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-01-28 21:55:16 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-01-28 21:55:16 +0000
commitae5e2d8004affd8a0519de97a3c1ad700fa2b720 (patch)
treed6bc886b1d8c6772e245e715bb2676d95b8a9b78 /apps/system/usbmonitor
parent489c78d7b6b14ca5b8eb7e2011c77599166a7894 (diff)
downloadnuttx-ae5e2d8004affd8a0519de97a3c1ad700fa2b720.tar.gz
nuttx-ae5e2d8004affd8a0519de97a3c1ad700fa2b720.tar.bz2
nuttx-ae5e2d8004affd8a0519de97a3c1ad700fa2b720.zip
Add syslog.h; rename lib_rawprintf() to syslog()
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5578 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/system/usbmonitor')
-rw-r--r--apps/system/usbmonitor/Makefile4
-rw-r--r--apps/system/usbmonitor/usbmonitor.c68
2 files changed, 36 insertions, 36 deletions
diff --git a/apps/system/usbmonitor/Makefile b/apps/system/usbmonitor/Makefile
index 04fcaf0ac..b4c323eb7 100644
--- a/apps/system/usbmonitor/Makefile
+++ b/apps/system/usbmonitor/Makefile
@@ -44,7 +44,6 @@ endif
# Hello Application
# TODO: appname can be automatically extracted from the directory name
-APPNAME = usbmon
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 768
@@ -90,7 +89,8 @@ $(COBJS): %$(OBJEXT): %.c
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
- $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
+ $(call REGISTER,"usbmon_start",$(PRIORITY),$(STACKSIZE),usbmonitor_start)
+ $(call REGISTER,"usbmon_stop",$(PRIORITY),$(STACKSIZE),usbmonintor_stop)
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
else
diff --git a/apps/system/usbmonitor/usbmonitor.c b/apps/system/usbmonitor/usbmonitor.c
index b101b128c..b615b99f9 100644
--- a/apps/system/usbmonitor/usbmonitor.c
+++ b/apps/system/usbmonitor/usbmonitor.c
@@ -40,20 +40,29 @@
#include <nuttx/config.h>
#include <nuttx/progmem.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <sys/types.h>
+#include <stdbool.h>
+#include <debug.h>
+
+#include <nuttx/usb/usbdev_trace.h"
+
+#ifdef CONFIG_SYSTEM_USBMONITOR
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define USBMON_PREFIX "USB Monitor: "
/****************************************************************************
- * Private Typs
+ * Private Types
****************************************************************************/
struct usbmon_state_s
{
-#ifdef CONFIG_NSH_BUILTIN_APPS
volatile bool started;
volatile bool stop;
pid_t pid;
-#endif
};
/****************************************************************************
@@ -66,34 +75,29 @@ static struct usbmon_state_s g_usbmonitor;
* Private Functions
****************************************************************************/
+static int usbmonitor_tracecallback(struct usbtrace_s *trace, void *arg)
+{
+ usbtrace_trprintf((trprintf_t)syslog, trace->event, trace->value);
+ return 0;
+}
+
static int usbmonitor_daemon(int argc, char **argv)
{
-#ifdef CONFIG_NSH_BUILTIN_APPS
- print("USB Monitor running: %d\n", g_usbmonitor.pid);
-#endif
+ syslog(USBMON_PREFIX "Running: %d\n", g_usbmonitor.pid);
-#ifdef CONFIG_NSH_BUILTIN_APPS
- /* If we are running as an NSH command, then loop until we detect that
- * there is a request to stop.
- */
+ /* Loop until we detect that there is a request to stop. */
while (!g_usbmonitor.stop)
-#else
- /* If we are running as a standalone program, then loop forever */
-
- for (;;)
-#endif
{
-#warning "Missing logic"
+ (void)usbmonitor_enumerate(nsh_tracecallback, NULL);
}
/* Stopped */
-#ifdef CONFIG_NSH_BUILTIN_APPS
g_usbmonitor.stop = false;
g_usbmonitor.started = false;
- print("USB Monitor stopped: %d\n", g_usbmonitor.pid);
-#endif
+ syslog(USBMON_PREFIX "Stopped: %d\n", g_usbmonitor.pid);
+
return 0;
}
@@ -101,9 +105,8 @@ static int usbmonitor_daemon(int argc, char **argv)
* Public Functions
****************************************************************************/
-int usbmonitor_main(int argc, char **argv)
+int usbmonitor_start(int argc, char **argv)
{
-#ifdef CONFIG_NSH_BUILTIN_APPS
/* Has the monitor already started? */
sched_lock();
@@ -122,13 +125,14 @@ int usbmonitor_main(int argc, char **argv)
if (ret < 0)
{
int errcode = errno;
- fprintf(stderr, "ERROR: Failed to start the USB monitor: %d\n",
- errcode);
+ syslog(USBMON_PREFIX
+ "ERROR: Failed to start the USB monitor: %d\n",
+ errcode);
}
else
{
g_usbmonitor.pid = ret;
- print("USB Monitor started: %d\n", g_usbmonitor.pid);
+ syslog(USBMON_PREFIX "Started: %d\n", g_usbmonitor.pid);
}
sched_unlock();
@@ -136,27 +140,23 @@ int usbmonitor_main(int argc, char **argv)
}
sched_unlock();
- print("USB Monitor running: %d\n", g_usbmonitor.pid);
+ syslog(USBMON_PREFIX "Running: %d\n", g_usbmonitor.pid);
return 0;
-#else
- return usbmonitor_daemon(argc, argv);
-#endif
}
-#ifdef CONFIG_NSH_BUILTIN_APPS
int usbmonitor_stop(int argc, char **argv)
{
/* Has the monitor already started? */
if (g_usbmonitor.started)
{
- print("USB Monitor stopping: %d\n", g_usbmonitor.pid);
+ syslog(USBMON_PREFIX "Stopping: %d\n", g_usbmonitor.pid);
g_usbmonitor.stop = true;
return 0;
}
- print("USB Monitor stopped: %d\n", g_usbmonitor.pid);
+ syslog(USBMON_PREFIX "Stopped: %d\n", g_usbmonitor.pid);
return 0;
}
-#endif
+#endif /* CONFIG_SYSTEM_USBMONITOR */