summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-03-29 22:20:47 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-03-29 22:20:47 +0000
commit67ea31797d0a81295664484a61aebd54607f3c86 (patch)
treeffdeb3afd707f0c9bd41edbf3a2e48756fbc8065 /apps
parent3e62f2be816d0a212b52fd609121004b16d80a8a (diff)
downloadnuttx-67ea31797d0a81295664484a61aebd54607f3c86.tar.gz
nuttx-67ea31797d0a81295664484a61aebd54607f3c86.tar.bz2
nuttx-67ea31797d0a81295664484a61aebd54607f3c86.zip
Can now run an NSH session within an NX window
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4539 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps')
-rwxr-xr-xapps/ChangeLog.txt2
-rw-r--r--apps/examples/Makefile2
-rw-r--r--apps/examples/README.txt15
-rw-r--r--apps/examples/nxconsole/Makefile14
-rw-r--r--apps/examples/nxconsole/nxcon_internal.h29
-rw-r--r--apps/examples/nxconsole/nxcon_main.c231
-rw-r--r--apps/examples/nxconsole/nxcon_wndo.c9
7 files changed, 156 insertions, 146 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt
index feb80dcb4..89379f99f 100755
--- a/apps/ChangeLog.txt
+++ b/apps/ChangeLog.txt
@@ -213,3 +213,5 @@
* vsn/hello: Removed. The modified apps/examples/hello is enough "Hello,
World!"
* apps/examples/nxconsole: Add a test of the NX console device.
+ * apps/examples/nxconsole: The NX console example now supports running
+ the NuttShell (NSH) within an NX window.
diff --git a/apps/examples/Makefile b/apps/examples/Makefile
index c1da00628..838b70699 100644
--- a/apps/examples/Makefile
+++ b/apps/examples/Makefile
@@ -56,7 +56,7 @@ SUBDIRS = adc buttons can cdcacm composite dhcpd ftpc ftpd hello helloxx \
CNTXTDIRS = pwm
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
-CNTXTDIRS += adc can cdcacm composite ftpd dhcpd nettest nxconsole qencoder telnetd
+CNTXTDIRS += adc can cdcacm composite ftpd dhcpd nettest qencoder telnetd
endif
ifeq ($(CONFIG_EXAMPLES_HELLO_BUILTIN),y)
diff --git a/apps/examples/README.txt b/apps/examples/README.txt
index 6cd1051bc..ec636cd6d 100644
--- a/apps/examples/README.txt
+++ b/apps/examples/README.txt
@@ -617,9 +617,11 @@ examples/nx
examples/nxconsole
^^^^^^^^^^^^^^^^^^
- This directory contains a simple test of the NX console device defined in
- include/nuttx/nx/nxconsole.h. Prerequisite configuration settings for this
- test include:
+ This directory contains yet another version of the NuttShell (NSH). This
+ version uses the NX console device defined in include/nuttx/nx/nxconsole.h
+ for output. the result is that the NSH input still come from the standard
+ console input (probably a serial console). But the text output will go to
+ an NX winbdow. Prerequisite configuration settings for this test include:
CONFIG_NX=y -- NX graphics must be enabled
CONFIG_NXCONSOLE=y -- The NX console driver must be built
@@ -628,12 +630,11 @@ examples/nxconsole
CONFIG_DISABLE_SIGNALS=n -- Signals are needed
CONFIG_DISABLE_PTHREAD=n -- pthreads are needed
CONFIG_NX_BLOCKING=y -- pthread APIs must be blocking
+ CONFIG_NSH_CONSOLE=y -- NSH must be configured to use a console.
The following configuration options can be selected to customize the
test:
- CONFIG_NSH_BUILTIN_APPS -- Build the NX example as a "built-in"
- that can be executed from the NSH command line
CONFIG_EXAMPLES_NXCON_VPLANE -- The plane to select from the frame-
buffer driver for use in the test. Default: 0
CONFIG_EXAMPLES_NXCON_DEVNO - The LCD device to select from the LCD
@@ -669,6 +670,10 @@ examples/nxconsole
CONFIG_EXAMPLES_NXCON_DEVNAME -- The quoated, full path to the
NX console device corresponding to CONFIG_EXAMPLES_NXCON_MINOR.
Default: "/dev/nxcon0"
+ CONFIG_EXAMPLES_NXCONSOLE_PRIO - Priority of the NxConsole task.
+ Default: SCHED_PRIORITY_DEFAULT
+ CONFIG_EXAMPLES_NXCONSOLE_STACKSIZE - Stack size allocated for the
+ NxConsole task. Default: 2048
The following configuration settings determine how to set up the NX
server (CONFIG_NX_MULTIUSER):
diff --git a/apps/examples/nxconsole/Makefile b/apps/examples/nxconsole/Makefile
index 2a04f982e..cfd7329a5 100644
--- a/apps/examples/nxconsole/Makefile
+++ b/apps/examples/nxconsole/Makefile
@@ -56,12 +56,6 @@ endif
ROOTDEPPATH = --dep-path .
-# NxConsole built-in application info
-
-APPNAME = nxcon
-PRIORITY = SCHED_PRIORITY_DEFAULT
-STACKSIZE = 2048
-
# Common build
VPATH =
@@ -81,13 +75,7 @@ $(COBJS): %$(OBJEXT): %.c
done ; )
@touch .built
-.context:
-ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
- $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
- @touch $@
-endif
-
-context: .context
+context:
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
diff --git a/apps/examples/nxconsole/nxcon_internal.h b/apps/examples/nxconsole/nxcon_internal.h
index 96ea8f781..199bbd052 100644
--- a/apps/examples/nxconsole/nxcon_internal.h
+++ b/apps/examples/nxconsole/nxcon_internal.h
@@ -56,21 +56,37 @@
/****************************************************************************
* Definitions
****************************************************************************/
-
/* Configuration ************************************************************/
+/* Need NX graphics support */
#ifndef CONFIG_NX
# error "NX is not enabled (CONFIG_NX=y)"
#endif
+/* Can't do the NxConsole example if the NxConsole driver is not built */
+
#ifndef CONFIG_NXCONSOLE
# error "NxConsole is not enabled (CONFIG_NXCONSOLE=y)"
#endif
+/* NxConsole requires NX Multi-user mode */
+
#ifndef CONFIG_NX_MULTIUSER
# error "Multi-user NX support is required (CONFIG_NX_MULTIUSER=y)"
#endif
+/* If there is no NSH console, then why are we running this example? */
+
+#ifndef CONFIG_NSH_CONSOLE
+# warning "Expected CONFIG_NSH_CONSOLE=y"
+#endif
+
+/* The NSH telnet console requires networking support (and TCP/IP) */
+
+#ifndef CONFIG_NET
+# undef CONFIG_NSH_TELNET
+#endif
+
/* If not specified, assume that the hardware supports one video plane */
#if CONFIG_NX_NPLANES != 1
@@ -209,6 +225,16 @@
# define CONFIG_EXAMPLES_NXCON_DEVNAME "/dev/nxcon0"
#endif
+/* NxConsole task */
+
+#ifndef CONFIG_EXAMPLES_NXCONSOLE_PRIO
+# define CONFIG_EXAMPLES_NXCONSOLE_PRIO SCHED_PRIORITY_DEFAULT
+#endif
+
+#ifndef CONFIG_EXAMPLES_NXCONSOLE_STACKSIZE
+# define CONFIG_EXAMPLES_NXCONSOLE_STACKSIZE 2048
+#endif
+
/* Debug ********************************************************************/
#ifdef CONFIG_CPP_HAVE_VARARGS
@@ -242,6 +268,7 @@ struct nxcon_state_s
volatile bool haveres; /* True: Have screen resolution */
volatile bool connected; /* True: Connected to server */
sem_t eventsem; /* Control waiting for display events */
+ pid_t pid; /* Console task ID */
NXHANDLE hnx; /* The connection handler */
NXTKWINDOW hwnd; /* The window */
NXCONSOLE hdrvr; /* The console driver */
diff --git a/apps/examples/nxconsole/nxcon_main.c b/apps/examples/nxconsole/nxcon_main.c
index 8713be493..5a9d20307 100644
--- a/apps/examples/nxconsole/nxcon_main.c
+++ b/apps/examples/nxconsole/nxcon_main.c
@@ -63,14 +63,14 @@
#include <nuttx/nx/nxfonts.h>
#include <nuttx/nx/nxconsole.h>
+#include <apps/nsh.h>
+
#include "nxcon_internal.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
-#define NCON_MSG_NLINES 24
-
/****************************************************************************
* Private Types
****************************************************************************/
@@ -83,37 +83,6 @@
* Private Data
****************************************************************************/
-#ifdef CONFIG_NX_KBD
-static const uint8_t g_pumsg[] = "Pop-Up!";
-static const char *g_nxcon_msg[NCON_MSG_NLINES] =
-{
- "\nJULIET\n", /* Line 1 */
- "Wilt thou be gone?\n", /* Line 2 */
- " It is not yet near day:\n", /* Line 3 */
- "It was the nightingale,\n", /* Line 4 */
- " and not the lark,\n", /* Line 5 */
- "That pierced the fearful hollow\n", /* Line 6 */
- " of thine ear;\n", /* Line 7 */
- "Nightly she sings\n", /* Line 8 */
- " on yon pomegranate-tree:\n", /* Line 9 */
- "Believe me, love,\n", /* Line 10 */
- " it was the nightingale.\n", /* Line 11 */
- "\nROMEO\n", /* Line 12 */
- "It was the lark,\n", /* Line 13 */
- " the herald of the morn,\n", /* Line 14 */
- "No nightingale:\n", /* Line 15 */
- " look, love, what envious streaks\n", /* Line 16 */
- "Do lace the severing clouds\n", /* Line 17 */
- " in yonder east:\n", /* Line 18 */
- "Night's candles are burnt out,\n", /* Line 19 */
- " and jocund day\n", /* Line 20 */
- "Stands tiptoe\n", /* Line 21 */
- " on the misty mountain tops.\n", /* Line 22 */
- "I must be gone and live,\n", /* Line 23 */
- " or stay and die.\n" /* Line 24 */
-};
-#endif
-
/****************************************************************************
* Public Data
****************************************************************************/
@@ -208,70 +177,112 @@ static int nxcon_initialize(void)
}
/****************************************************************************
- * Public Functions
+ * Name: nxcon_task
****************************************************************************/
+static int nxcon_task(int argc, char **argv)
+{
+ /* If the console front end is selected, then run it on this thread */
+
+#ifdef CONFIG_NSH_CONSOLE
+ (void)nsh_consolemain(0, NULL);
+#endif
+
+ printf("nxcon_task: Unregister the NX console device\n");
+ (void)nxcon_unregister(g_nxcon_vars.hdrvr);
+
+ printf("nxcon_task: Close the window\n");
+ (void)nxtk_closewindow(g_nxcon_vars.hwnd);
+
+ /* Disconnect from the server */
+
+ printf("nxcon_task: Disconnect from the server\n");
+ nx_disconnect(g_nxcon_vars.hnx);
+
+ return EXIT_SUCCESS;
+}
+
/****************************************************************************
- * Name: user_start/nxcon_main
+ * Public Functions
****************************************************************************/
-#ifdef CONFIG_NSH_BUILTIN_APPS
-# define MAIN_NAME nxcon_main
-# define MAIN_NAME_STRING "nxcon_main"
-#else
-# define MAIN_NAME user_start
-# define MAIN_NAME_STRING "user_start"
-#endif
+/****************************************************************************
+ * Name: user_start
+ ****************************************************************************/
-int MAIN_NAME(int argc, char **argv)
+int user_start(int argc, char **argv)
{
- int exitcode = EXIT_FAILURE;
-#if 0 /* Don't re-direct... too hard to debug */
- int fd;
-#else
- FILE *outstream;
-#endif
nxgl_mxpixel_t color;
- int ndx;
+ int fd;
int ret;
+ /* General Initialization *************************************************/
/* Reset all global data */
+ message("user_start: Started\n");
memset(&g_nxcon_vars, 0, sizeof(struct nxcon_state_s));
+ /* Call all C++ static constructors */
+
+#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE)
+ up_cxxinitialize();
+#endif
+
+ /* NSH Initialization *****************************************************/
+ /* Initialize the NSH library */
+
+ message("user_start: Initialize NSH\n");
+ nsh_initialize();
+
+ /* If the Telnet console is selected as a front-end, then start the
+ * Telnet daemon.
+ */
+
+#ifdef CONFIG_NSH_TELNET
+ ret = nsh_telnetstart();
+ if (ret < 0)
+ {
+ /* The daemon is NOT running. Report the the error then fail...
+ * either with the serial console up or just exiting.
+ */
+
+ fprintf(stderr, "ERROR: Failed to start TELNET daemon: %d\n", ret);
+ }
+#endif
/* NX Initialization ******************************************************/
/* Initialize NX */
+ message("user_start: Initialize NX\n");
ret = nxcon_initialize();
- message(MAIN_NAME_STRING ": NX handle=%p\n", g_nxcon_vars.hnx);
+ message("user_start: NX handle=%p\n", g_nxcon_vars.hnx);
if (!g_nxcon_vars.hnx || ret < 0)
{
- message(MAIN_NAME_STRING ": Failed to get NX handle: %d\n", errno);
+ message("user_start: Failed to get NX handle: %d\n", errno);
goto errout;
}
/* Set the background to the configured background color */
- message(MAIN_NAME_STRING ": Set background color=%d\n", CONFIG_EXAMPLES_NXCON_BGCOLOR);
+ message("user_start: Set background color=%d\n", CONFIG_EXAMPLES_NXCON_BGCOLOR);
color = CONFIG_EXAMPLES_NXCON_BGCOLOR;
ret = nx_setbgcolor(g_nxcon_vars.hnx, &color);
if (ret < 0)
{
- message(MAIN_NAME_STRING ": nx_setbgcolor failed: %d\n", errno);
+ message("user_start: nx_setbgcolor failed: %d\n", errno);
goto errout_with_nx;
}
/* Window Configuration ***************************************************/
/* Create a window */
- message(MAIN_NAME_STRING ": Create window\n");
+ message("user_start: Create window\n");
g_nxcon_vars.hwnd = nxtk_openwindow(g_nxcon_vars.hnx, &g_nxconcb, NULL);
if (!g_nxcon_vars.hwnd)
{
- message(MAIN_NAME_STRING ": nxtk_openwindow failed: %d\n", errno);
+ message("user_start: nxtk_openwindow failed: %d\n", errno);
goto errout_with_nx;
}
- message(MAIN_NAME_STRING ": hwnd=%p\n", g_nxcon_vars.hwnd);
+ message("user_start: hwnd=%p\n", g_nxcon_vars.hwnd);
/* Wait until we have the screen resolution. We'll have this immediately
* unless we are dealing with the NX server.
@@ -281,7 +292,7 @@ int MAIN_NAME(int argc, char **argv)
{
(void)sem_wait(&g_nxcon_vars.eventsem);
}
- message(MAIN_NAME_STRING ": Screen resolution (%d,%d)\n", g_nxcon_vars.xres, g_nxcon_vars.yres);
+ message("user_start: Screen resolution (%d,%d)\n", g_nxcon_vars.xres, g_nxcon_vars.yres);
/* Determine the size and position of the window */
@@ -293,38 +304,42 @@ int MAIN_NAME(int argc, char **argv)
/* Set the window position */
- message(MAIN_NAME_STRING ": Set window position to (%d,%d)\n",
+ message("user_start: Set window position to (%d,%d)\n",
g_nxcon_vars.wpos.x, g_nxcon_vars.wpos.y);
ret = nxtk_setposition(g_nxcon_vars.hwnd, &g_nxcon_vars.wpos);
if (ret < 0)
{
- message(MAIN_NAME_STRING ": nxtk_setposition failed: %d\n", errno);
+ message("user_start: nxtk_setposition failed: %d\n", errno);
goto errout_with_hwnd;
}
/* Set the window size */
- message(MAIN_NAME_STRING ": Set window size to (%d,%d)\n",
+ message("user_start: Set window size to (%d,%d)\n",
g_nxcon_vars.wndo.wsize.w, g_nxcon_vars.wndo.wsize.h);
ret = nxtk_setsize(g_nxcon_vars.hwnd, &g_nxcon_vars.wndo.wsize);
if (ret < 0)
{
- message(MAIN_NAME_STRING ": nxtk_setsize failed: %d\n", errno);
+ message("user_start: nxtk_setsize failed: %d\n", errno);
goto errout_with_hwnd;
}
/* Open the toolbar */
- message(MAIN_NAME_STRING ": Add toolbar to window\n");
+ message("user_start: Add toolbar to window\n");
ret = nxtk_opentoolbar(g_nxcon_vars.hwnd, CONFIG_EXAMPLES_NXCON_TOOLBAR_HEIGHT, &g_nxtoolcb, NULL);
if (ret < 0)
{
- message(MAIN_NAME_STRING ": nxtk_opentoolbar failed: %d\n", errno);
+ message("user_start: nxtk_opentoolbar failed: %d\n", errno);
goto errout_with_hwnd;
}
+ /* Sleep a little bit to allow the server to catch up */
+
+ sleep(2);
+
/* NxConsole Configuration ************************************************/
/* Use the window to create an NX console */
@@ -335,99 +350,63 @@ int MAIN_NAME(int argc, char **argv)
g_nxcon_vars.hdrvr = nxtk_register(g_nxcon_vars.hwnd, &g_nxcon_vars.wndo, CONFIG_EXAMPLES_NXCON_MINOR);
if (!g_nxcon_vars.hdrvr)
{
- message(MAIN_NAME_STRING ": nxtk_register failed: %d\n", errno);
+ message("user_start: nxtk_register failed: %d\n", errno);
goto errout_with_hwnd;
}
- /* Open the driver */
+ /* Open the NxConsole driver */
-#if 0 /* Don't re-direct... too hard to debug */
fd = open(CONFIG_EXAMPLES_NXCON_DEVNAME, O_WRONLY);
if (fd < 0)
{
- message(MAIN_NAME_STRING ": open %s read-only failed: %d\n",
+ message("user_start: open %s read-only failed: %d\n",
CONFIG_EXAMPLES_NXCON_DEVNAME, errno);
goto errout_with_driver;
}
+ /* Start Console Task *****************************************************/
/* Now re-direct stdout and stderr so that they use the NX console driver.
- * If debug is enabled, then perform the test using only stderr so that we
- * can still get debug output on stdout.
+ * Note that stdin is retained (file descriptor 0, probably the the serial console).
*/
- (void)dup2(fd, 1);
- (void)dup2(fd, 2);
-
- /* And we can close our original driver fd */
-
- close(fd);
-#else
- /* Open the Console driver as a write-only stream */
-
- outstream = fopen(CONFIG_EXAMPLES_NXCON_DEVNAME, "w");
- if (!outstream)
- {
- message(MAIN_NAME_STRING ": fopen %s read-only failed: %d\n",
- CONFIG_EXAMPLES_NXCON_DEVNAME, errno);
- goto errout_with_driver;
- }
-#endif
-
- /* Test Loop **************************************************************/
- /* Now loop, adding text to the NX console */
+ message("user_start: Starting the console task\n");
+ msgflush();
- ndx = 0;
- for (;;)
- {
- /* Sleep for one second */
+ (void)fflush(stdout);
+ (void)fflush(stderr);
- sleep(1);
+ (void)fclose(stdout);
+ (void)fclose(stderr);
- /* Give another line of text to the NX console.*/
+ (void)dup2(fd, 1);
+ (void)dup2(fd, 2);
-#if 0 /* Don't re-direct... too hard to debug */
- printf(g_nxcon_msg[ndx]);
- fflush(stdout);
-#else
- fprintf(outstream, g_nxcon_msg[ndx]);
- fflush(outstream);
-#endif
- if (++ndx >= NCON_MSG_NLINES)
- {
-#ifdef CONFIG_NSH_BUILTIN_APPS
- /* If this is an NSH built-in app, then just return after all
- * of the lines have been presented.
- */
-
- break;
-#else
- /* Otherwise, just reset the index to the first line and continue */
+ /* And we can close our original driver file descriptor */
- ndx = 0;
-#endif
- }
- }
- exitcode = EXIT_SUCCESS;
+ close(fd);
- /* Clean-up and Error Exits ***********************************************/
+ /* And start the console task. It will inherit stdin, stdout, and stderr
+ * from this task.
+ */
+
+ g_nxcon_vars.pid = TASK_CREATE("NxConsole", CONFIG_EXAMPLES_NXCONSOLE_PRIO,
+ CONFIG_EXAMPLES_NXCONSOLE_STACKSIZE,
+ nxcon_task, NULL);
+ ASSERT(g_nxcon_vars.pid > 0);
+ return EXIT_SUCCESS;
-#if 1 /* Don't re-direct... too hard to debug */
- fclose(outstream);
-#endif
+ /* Error Exits ************************************************************/
errout_with_driver:
- message(MAIN_NAME_STRING ": Unregister the NX console device\n");
(void)nxcon_unregister(g_nxcon_vars.hdrvr);
errout_with_hwnd:
- message(MAIN_NAME_STRING ": Close the window\n");
(void)nxtk_closewindow(g_nxcon_vars.hwnd);
errout_with_nx:
/* Disconnect from the server */
- message(MAIN_NAME_STRING ": Disconnect from the server\n");
nx_disconnect(g_nxcon_vars.hnx);
errout:
- return exitcode;
+ return EXIT_FAILURE;
}
diff --git a/apps/examples/nxconsole/nxcon_wndo.c b/apps/examples/nxconsole/nxcon_wndo.c
index 6fadda866..083da739d 100644
--- a/apps/examples/nxconsole/nxcon_wndo.c
+++ b/apps/examples/nxconsole/nxcon_wndo.c
@@ -115,6 +115,8 @@ const struct nx_callback_s g_nxconcb =
static void nxwndo_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
bool more, FAR void *arg)
{
+ nxgl_mxpixel_t wcolor[CONFIG_NX_NPLANES];
+
gvdbg("hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n",
hwnd, rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
more ? "true" : "false");
@@ -127,6 +129,13 @@ static void nxwndo_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
nxcon_redraw(g_nxcon_vars.hdrvr, rect, more);
}
+ else
+ {
+ /* If the driver has not been opened, then just redraw the window color */
+
+ wcolor[0] = CONFIG_EXAMPLES_NXCON_WCOLOR;
+ (void)nxtk_fillwindow(hwnd, rect, wcolor);
+ }
}
/****************************************************************************