mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-01 20:29:00 +00:00
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
This commit is contained in:
parent
e26439df4d
commit
404bb36bbd
29 changed files with 201 additions and 105 deletions
|
|
@ -74,7 +74,7 @@
|
|||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_rawprintf(__VA_ARGS__)
|
||||
# define message(...) syslog(__VA_ARGS__)
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
|
|
@ -82,7 +82,7 @@
|
|||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_rawprintf
|
||||
# define message syslog
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message printf
|
||||
|
|
|
|||
|
|
@ -299,11 +299,11 @@ static void show_buttons(uint8_t oldset, uint8_t newset)
|
|||
state = "released";
|
||||
}
|
||||
|
||||
/* Use lib_lowprintf() because we make be executing from an
|
||||
/* Use lowsyslog() because we make be executing from an
|
||||
* interrupt handler.
|
||||
*/
|
||||
|
||||
lib_lowprintf(" %s %s\n", g_buttoninfo[BUTTON_INDEX(i)].name, state);
|
||||
lowsyslog(" %s %s\n", g_buttoninfo[BUTTON_INDEX(i)].name, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -313,8 +313,8 @@ static void button_handler(int id, int irq)
|
|||
{
|
||||
uint8_t newset = up_buttons();
|
||||
|
||||
lib_lowprintf("IRQ:%d Button %d:%s SET:%02x:\n",
|
||||
irq, id, g_buttoninfo[BUTTON_INDEX(id)].name, newset);
|
||||
lowsyslog("IRQ:%d Button %d:%s SET:%02x:\n",
|
||||
irq, id, g_buttoninfo[BUTTON_INDEX(id)].name, newset);
|
||||
show_buttons(g_oldset, newset);
|
||||
g_oldset = newset;
|
||||
}
|
||||
|
|
@ -409,7 +409,7 @@ int buttons_main(int argc, char *argv[])
|
|||
{
|
||||
maxbuttons = strtol(argv[1], NULL, 10);
|
||||
}
|
||||
lib_lowprintf("maxbuttons: %d\n", maxbuttons);
|
||||
lowsyslog("maxbuttons: %d\n", maxbuttons);
|
||||
#endif
|
||||
|
||||
/* Initialize the button GPIOs */
|
||||
|
|
@ -423,11 +423,11 @@ int buttons_main(int argc, char *argv[])
|
|||
{
|
||||
xcpt_t oldhandler = up_irqbutton(i, g_buttoninfo[BUTTON_INDEX(i)].handler);
|
||||
|
||||
/* Use lib_lowprintf() for compatibility with interrrupt handler output. */
|
||||
/* Use lowsyslog() for compatibility with interrrupt handler output. */
|
||||
|
||||
lib_lowprintf("Attached handler at %p to button %d [%s], oldhandler:%p\n",
|
||||
g_buttoninfo[BUTTON_INDEX(i)].handler, i,
|
||||
g_buttoninfo[BUTTON_INDEX(i)].name, oldhandler);
|
||||
lowsyslog("Attached handler at %p to button %d [%s], oldhandler:%p\n",
|
||||
g_buttoninfo[BUTTON_INDEX(i)].handler, i,
|
||||
g_buttoninfo[BUTTON_INDEX(i)].name, oldhandler);
|
||||
|
||||
/* Some hardware multiplexes different GPIO button sources to the same
|
||||
* physical interrupt. If we register multiple such multiplexed button
|
||||
|
|
@ -438,9 +438,9 @@ int buttons_main(int argc, char *argv[])
|
|||
|
||||
if (oldhandler != NULL)
|
||||
{
|
||||
lib_lowprintf("WARNING: oldhandler:%p is not NULL! "
|
||||
"Button events may be lost or aliased!\n",
|
||||
oldhandler);
|
||||
lowsyslog("WARNING: oldhandler:%p is not NULL! "
|
||||
"Button events may be lost or aliased!\n",
|
||||
oldhandler);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -468,11 +468,11 @@ int buttons_main(int argc, char *argv[])
|
|||
|
||||
flags = irqsave();
|
||||
|
||||
/* Use lib_lowprintf() for compatibility with interrrupt handler
|
||||
/* Use lowsyslog() for compatibility with interrrupt handler
|
||||
* output.
|
||||
*/
|
||||
|
||||
lib_lowprintf("POLL SET:%02x:\n", newset);
|
||||
lowsyslog("POLL SET:%02x:\n", newset);
|
||||
show_buttons(g_oldset, newset);
|
||||
g_oldset = newset;
|
||||
irqrestore(flags);
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@
|
|||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_rawprintf(__VA_ARGS__)
|
||||
# define message(...) syslog(__VA_ARGS__)
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
|
|
@ -97,7 +97,7 @@
|
|||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_rawprintf
|
||||
# define message syslog
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message printf
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@
|
|||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_lowprintf(__VA_ARGS__)
|
||||
# define message(...) lowsyslog(__VA_ARGS__)
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
|
|
@ -120,7 +120,7 @@
|
|||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_lowprintf
|
||||
# define message lowsyslog
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message printf
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@
|
|||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_lowprintf(__VA_ARGS__)
|
||||
# define message(...) lowsyslog(__VA_ARGS__)
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
|
|
@ -181,7 +181,7 @@
|
|||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_lowprintf
|
||||
# define message lowsyslog
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message printf
|
||||
|
|
|
|||
|
|
@ -46,12 +46,12 @@
|
|||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Used lib_rawprintf() so that there is no confusion from buffered IO */
|
||||
/* Used syslog() so that there is no confusion from buffered IO */
|
||||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# define message(...) lib_rawprintf(__VA_ARGS__)
|
||||
# define message(...) syslog(__VA_ARGS__)
|
||||
#else
|
||||
# define message lib_rawprintf
|
||||
# define message syslog
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
|||
|
|
@ -69,12 +69,12 @@
|
|||
|
||||
#else
|
||||
|
||||
/* Used lib_rawprintf() so that there is not confusion from buffered IO */
|
||||
/* Used syslog() so that there is not confusion from buffered IO */
|
||||
|
||||
# ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# define message(...) lib_rawprintf(__VA_ARGS__)
|
||||
# define message(...) syslog(__VA_ARGS__)
|
||||
# else
|
||||
# define message lib_rawprintf
|
||||
# define message syslog
|
||||
# endif
|
||||
|
||||
/* At present, uIP does only abortive disconnects */
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@
|
|||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_lowprintf(__VA_ARGS__)
|
||||
# define message(...) lowsyslog(__VA_ARGS__)
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
|
|
@ -176,7 +176,7 @@
|
|||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_lowprintf
|
||||
# define message lowsyslog
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message printf
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@
|
|||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_lowprintf(__VA_ARGS__)
|
||||
# define message(...) lowsyslog(__VA_ARGS__)
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
|
|
@ -247,7 +247,7 @@
|
|||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_lowprintf
|
||||
# define message lowsyslog
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message printf
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@
|
|||
#endif
|
||||
|
||||
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_FS)
|
||||
# define message lib_rawprintf
|
||||
# define message syslog
|
||||
# define msgflush()
|
||||
#else
|
||||
# define message printf
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@
|
|||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_lowprintf(__VA_ARGS__)
|
||||
# define message(...) lowsyslog(__VA_ARGS__)
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
|
|
@ -104,7 +104,7 @@
|
|||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_lowprintf
|
||||
# define message lowsyslog
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message printf
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@
|
|||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_lowprintf(__VA_ARGS__)
|
||||
# define message(...) lowsyslog(__VA_ARGS__)
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
|
|
@ -119,7 +119,7 @@
|
|||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_lowprintf
|
||||
# define message lowsyslog
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message printf
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@
|
|||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_lowprintf(__VA_ARGS__)
|
||||
# define message(...) lowsyslog(__VA_ARGS__)
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
|
|
@ -128,7 +128,7 @@
|
|||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_lowprintf
|
||||
# define message lowsyslog
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message printf
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@
|
|||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_lowprintf(__VA_ARGS__)
|
||||
# define message(...) lowsyslog(__VA_ARGS__)
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
|
|
@ -202,7 +202,7 @@
|
|||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_lowprintf
|
||||
# define message lowsyslog
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message printf
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@
|
|||
# undef HAVE_NETPOLL
|
||||
#endif
|
||||
|
||||
/* If debug is enabled, then use lib_rawprintf so that OS debug output and
|
||||
/* If debug is enabled, then use syslog so that OS debug output and
|
||||
* the test output are synchronized.
|
||||
*
|
||||
* These macros will differ depending upon if the toolchain supports
|
||||
|
|
@ -80,7 +80,7 @@
|
|||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_rawprintf(__VA_ARGS__)
|
||||
# define message(...) syslog(__VA_ARGS__)
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
|
|
@ -88,7 +88,7 @@
|
|||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_rawprintf
|
||||
# define message syslog
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message printf
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@
|
|||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_rawprintf(__VA_ARGS__)
|
||||
# define message(...) syslog(__VA_ARGS__)
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
|
|
@ -100,7 +100,7 @@
|
|||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_rawprintf
|
||||
# define message syslog
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message printf
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@
|
|||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_rawprintf(__VA_ARGS__)
|
||||
# define message(...) syslog(__VA_ARGS__)
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
|
|
@ -85,7 +85,7 @@
|
|||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_rawprintf
|
||||
# define message syslog
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message printf
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@
|
|||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_lowprintf(__VA_ARGS__)
|
||||
# define message(...) lowsyslog(__VA_ARGS__)
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
|
|
@ -133,7 +133,7 @@
|
|||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_lowprintf
|
||||
# define message lowsyslog
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message printf
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@
|
|||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_rawprintf(__VA_ARGS__)
|
||||
# define message(...) syslog(__VA_ARGS__)
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
|
|
@ -90,7 +90,7 @@
|
|||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_rawprintf
|
||||
# define message syslog
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message printf
|
||||
|
|
|
|||
|
|
@ -63,12 +63,12 @@
|
|||
|
||||
#else
|
||||
|
||||
/* If debug is enabled, use the synchronous lib_lowprintf so that the
|
||||
/* If debug is enabled, use the synchronous lowsyslog so that the
|
||||
* program output does not get disassociated in the debug output.
|
||||
*/
|
||||
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_lowprintf(__VA_ARGS__)
|
||||
# define message(...) lowsyslog(__VA_ARGS__)
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
# endif
|
||||
|
|
|
|||
|
|
@ -86,13 +86,13 @@
|
|||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_lowprintf(__VA_ARGS__)
|
||||
# define message(...) lowsyslog(__VA_ARGS__)
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_lowprintf
|
||||
# define message lowsyslog
|
||||
# else
|
||||
# define message (void)
|
||||
# endif
|
||||
|
|
|
|||
|
|
@ -109,16 +109,16 @@
|
|||
TRACE_TRANSFER_BITS|TRACE_CONTROLLER_BITS|TRACE_INTERRUPT_BITS)
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_lowprintf(__VA_ARGS__)
|
||||
# define trmessage lib_lowprintf
|
||||
# define message(...) lowsyslog(__VA_ARGS__)
|
||||
# define trmessage lowsyslog
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
# define trmessage printf
|
||||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_lowprintf
|
||||
# define trmessage lib_lowprintf
|
||||
# define message lowsyslog
|
||||
# define trmessage lowsyslog
|
||||
# else
|
||||
# define message printf
|
||||
# define trmessage printf
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@
|
|||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_lowprintf(__VA_ARGS__)
|
||||
# define message(...) lowsyslog(__VA_ARGS__)
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
|
|
@ -93,7 +93,7 @@
|
|||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_lowprintf
|
||||
# define message lowsyslog
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message printf
|
||||
|
|
|
|||
|
|
@ -101,16 +101,16 @@
|
|||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_rawprintf(__VA_ARGS__)
|
||||
# define trmessage lib_rawprintf
|
||||
# define message(...) syslog(__VA_ARGS__)
|
||||
# define trmessage syslog
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
# define trmessage printf
|
||||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_lowprintf
|
||||
# define trmessage lib_lowprintf
|
||||
# define message lowsyslog
|
||||
# define trmessage lowsyslog
|
||||
# else
|
||||
# define message printf
|
||||
# define trmessage printf
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@
|
|||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_rawprintf(__VA_ARGS__)
|
||||
# define message(...) syslog(__VA_ARGS__)
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
|
|
@ -97,7 +97,7 @@
|
|||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_rawprintf
|
||||
# define message syslog
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message printf
|
||||
|
|
|
|||
96
include/usbmonitor.h
Normal file
96
include/usbmonitor.h
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
/****************************************************************************
|
||||
* apps/include/usbmonitor.h
|
||||
*
|
||||
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_INCLUDE_USBMONITOR_H
|
||||
#define __APPS_INCLUDE_USBMONITOR_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#ifdef CONFIG_SYSTEM_USBMONITOR
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usbmon_start and usbmon_stop
|
||||
*
|
||||
* Start and top the USB monitor daemon. These are normally controlled
|
||||
* from the USB command line, but the ability to control these
|
||||
* programmatically is also helpful (for example, so that the daemon is
|
||||
* running before NSH starts).
|
||||
*
|
||||
* Input Parameters:
|
||||
* Standard task parameters. These can be called or spawned. Since the
|
||||
* return almost immediately, it is fine to just call the functions. The
|
||||
* parameters are not used so you can pass 0 and NULL, respectivley; this
|
||||
* is done this way so that these functions can be NSH builtin
|
||||
* applications.
|
||||
*
|
||||
* Returned values:
|
||||
* Standard task return values (zero meaning success).
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
int usbmonitor_start(int argc, char **argv);
|
||||
int usbmonitor_stop(int argc, char **argv);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_SYSTEM_USBMONITOR */
|
||||
#endif /* __APPS_INCLUDE_USBMONITOR_H */
|
||||
|
|
@ -63,7 +63,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_DEBUG) || defined(CONFIG_NSH_USBCONSOLE)
|
||||
# define trmessage lib_lowprintf
|
||||
# define trmessage lowsyslog
|
||||
#else
|
||||
# define trmessage printf
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
/****************************************************************************
|
||||
* Private Typs
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define USBMON_PREFIX "USB Monitor: "
|
||||
|
||||
/****************************************************************************
|
||||
* 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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue