2012-03-27 18:59:15 +02:00
|
|
|
/****************************************************************************
|
2021-06-16 09:22:16 +02:00
|
|
|
* apps/examples/nxterm/nxterm_main.c
|
2012-03-27 18:59:15 +02:00
|
|
|
*
|
2020-09-22 17:57:05 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2012-03-27 18:59:15 +02:00
|
|
|
*
|
2020-09-22 17:57:05 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-03-27 18:59:15 +02:00
|
|
|
*
|
2020-09-22 17:57:05 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2012-03-27 18:59:15 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2016-12-01 23:33:45 +01:00
|
|
|
#include <sys/boardctl.h>
|
2012-03-27 18:59:15 +02:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
2021-06-01 06:37:18 +02:00
|
|
|
#include <assert.h>
|
2012-03-27 18:59:15 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#ifdef CONFIG_NX_LCDDRIVER
|
|
|
|
# include <nuttx/lcd/lcd.h>
|
|
|
|
#else
|
2013-12-10 16:23:54 +01:00
|
|
|
# include <nuttx/video/fb.h>
|
2012-03-27 18:59:15 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <nuttx/nx/nx.h>
|
|
|
|
#include <nuttx/nx/nxglib.h>
|
|
|
|
#include <nuttx/nx/nxfonts.h>
|
2014-09-20 22:51:48 +02:00
|
|
|
#include <nuttx/nx/nxterm.h>
|
2012-03-27 18:59:15 +02:00
|
|
|
|
2016-07-11 18:11:18 +02:00
|
|
|
#include "nshlib/nshlib.h"
|
2012-03-30 00:20:47 +02:00
|
|
|
|
2014-09-20 22:51:48 +02:00
|
|
|
#include "nxterm_internal.h"
|
2012-03-27 18:59:15 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* All example global variables are retained in a structure to minimize
|
|
|
|
* the chance of name collisions.
|
|
|
|
*/
|
|
|
|
|
2014-09-20 22:51:48 +02:00
|
|
|
struct nxterm_state_s g_nxterm_vars;
|
2012-03-27 18:59:15 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-09-20 22:51:48 +02:00
|
|
|
* Name: nxterm_initialize
|
2012-03-27 18:59:15 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-20 22:51:48 +02:00
|
|
|
static int nxterm_initialize(void)
|
2012-03-27 18:59:15 +02:00
|
|
|
{
|
|
|
|
struct sched_param param;
|
|
|
|
pthread_t thread;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Set the client task priority */
|
|
|
|
|
2015-09-08 17:20:49 +02:00
|
|
|
param.sched_priority = CONFIG_EXAMPLES_NXTERM_CLIENTPRIO;
|
2012-03-27 18:59:15 +02:00
|
|
|
ret = sched_setparam(0, ¶m);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxterm_initialize: sched_setparam failed: %d\n" , ret);
|
2012-03-27 18:59:15 +02:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2016-12-01 23:33:45 +01:00
|
|
|
/* Start the NX server kernel thread */
|
2012-03-27 18:59:15 +02:00
|
|
|
|
2016-12-01 23:33:45 +01:00
|
|
|
ret = boardctl(BOARDIOC_NX_START, 0);
|
|
|
|
if (ret < 0)
|
2012-03-27 18:59:15 +02:00
|
|
|
{
|
2020-06-30 14:57:45 +02:00
|
|
|
printf("nxterm_initialize: Failed to start the NX server: %d\n",
|
|
|
|
errno);
|
2012-03-27 18:59:15 +02:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Connect to the server */
|
|
|
|
|
2014-09-20 22:51:48 +02:00
|
|
|
g_nxterm_vars.hnx = nx_connect();
|
|
|
|
if (g_nxterm_vars.hnx)
|
2012-03-27 18:59:15 +02:00
|
|
|
{
|
|
|
|
pthread_attr_t attr;
|
|
|
|
|
2016-04-22 21:38:06 +02:00
|
|
|
#ifdef CONFIG_VNCSERVER
|
2019-04-02 15:06:06 +02:00
|
|
|
/* Setup the VNC server to support keyboard/mouse inputs */
|
|
|
|
|
2020-02-03 14:35:37 +01:00
|
|
|
struct boardioc_vncstart_s vnc =
|
|
|
|
{
|
|
|
|
0, g_nxterm_vars.hnx
|
|
|
|
};
|
|
|
|
|
|
|
|
ret = boardctl(BOARDIOC_VNC_START, (uintptr_t)&vnc);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
printf("boardctl(BOARDIOC_VNC_START) failed: %d\n", ret);
|
|
|
|
nx_disconnect(g_nxterm_vars.hnx);
|
|
|
|
return ERROR;
|
|
|
|
}
|
2016-04-22 21:38:06 +02:00
|
|
|
#endif
|
2019-04-02 15:06:06 +02:00
|
|
|
|
2020-06-30 14:57:45 +02:00
|
|
|
/* Start a separate thread to listen for server events. This is
|
|
|
|
* probably the least efficient way to do this, but it makes this
|
|
|
|
* example flow more smoothly.
|
2020-02-03 14:35:37 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
pthread_attr_init(&attr);
|
|
|
|
param.sched_priority = CONFIG_EXAMPLES_NXTERM_LISTENERPRIO;
|
|
|
|
pthread_attr_setschedparam(&attr, ¶m);
|
|
|
|
pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_NXTERM_STACKSIZE);
|
|
|
|
|
|
|
|
ret = pthread_create(&thread, &attr, nxterm_listener, NULL);
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
printf("nxterm_initialize: pthread_create failed: %d\n", ret);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't return until we are connected to the server */
|
|
|
|
|
|
|
|
while (!g_nxterm_vars.connected)
|
|
|
|
{
|
|
|
|
/* Wait for the listener thread to wake us up when we really
|
|
|
|
* are connected.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sem_wait(&g_nxterm_vars.eventsem);
|
|
|
|
}
|
2012-03-27 18:59:15 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxterm_initialize: nx_connect failed: %d\n", errno);
|
2012-03-27 18:59:15 +02:00
|
|
|
return ERROR;
|
|
|
|
}
|
2020-02-03 14:35:37 +01:00
|
|
|
|
2012-03-27 18:59:15 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-09-20 22:51:48 +02:00
|
|
|
* Name: nxterm_task
|
2012-03-27 18:59:15 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-20 22:51:48 +02:00
|
|
|
static int nxterm_task(int argc, char **argv)
|
2012-03-30 00:20:47 +02:00
|
|
|
{
|
|
|
|
/* If the console front end is selected, then run it on this thread */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NSH_CONSOLE
|
2020-08-17 12:28:50 +02:00
|
|
|
nsh_consolemain(argc, argv);
|
2012-03-30 00:20:47 +02:00
|
|
|
#endif
|
|
|
|
|
2019-03-06 17:53:13 +01:00
|
|
|
printf("nxterm_task: Unlinking the NX console device\n");
|
2020-01-02 13:09:50 +01:00
|
|
|
unlink(CONFIG_EXAMPLES_NXTERM_DEVNAME);
|
2012-03-30 00:20:47 +02:00
|
|
|
|
2014-09-20 22:51:48 +02:00
|
|
|
printf("nxterm_task: Close the window\n");
|
2020-01-02 13:09:50 +01:00
|
|
|
nxtk_closewindow(g_nxterm_vars.hwnd);
|
2012-03-30 00:20:47 +02:00
|
|
|
|
|
|
|
/* Disconnect from the server */
|
|
|
|
|
2014-09-20 22:51:48 +02:00
|
|
|
printf("nxterm_task: Disconnect from the server\n");
|
|
|
|
nx_disconnect(g_nxterm_vars.hnx);
|
2012-03-30 00:20:47 +02:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-03-27 18:59:15 +02:00
|
|
|
/****************************************************************************
|
2012-03-30 00:20:47 +02:00
|
|
|
* Public Functions
|
2012-03-27 18:59:15 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2012-03-30 00:20:47 +02:00
|
|
|
/****************************************************************************
|
2014-09-20 22:51:48 +02:00
|
|
|
* Name: nxterm_main
|
2012-03-30 00:20:47 +02:00
|
|
|
****************************************************************************/
|
2012-03-27 18:59:15 +02:00
|
|
|
|
2014-09-06 17:23:23 +02:00
|
|
|
int main(int argc, FAR char *argv[])
|
2012-03-27 18:59:15 +02:00
|
|
|
{
|
2019-03-06 17:53:13 +01:00
|
|
|
struct boardioc_nxterm_create_s nxcreate;
|
2012-03-27 18:59:15 +02:00
|
|
|
nxgl_mxpixel_t color;
|
2012-03-30 00:20:47 +02:00
|
|
|
int fd;
|
2012-03-27 18:59:15 +02:00
|
|
|
int ret;
|
|
|
|
|
2012-03-30 00:20:47 +02:00
|
|
|
/* General Initialization *************************************************/
|
2020-02-03 14:35:37 +01:00
|
|
|
|
2012-03-27 18:59:15 +02:00
|
|
|
/* Reset all global data */
|
|
|
|
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxterm_main: Started\n");
|
2014-09-20 22:51:48 +02:00
|
|
|
memset(&g_nxterm_vars, 0, sizeof(struct nxterm_state_s));
|
2012-03-27 18:59:15 +02:00
|
|
|
|
2012-03-30 00:20:47 +02:00
|
|
|
/* NSH Initialization *****************************************************/
|
2020-02-03 14:35:37 +01:00
|
|
|
|
2012-03-30 00:20:47 +02:00
|
|
|
/* Initialize the NSH library */
|
|
|
|
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxterm_main: Initialize NSH\n");
|
2012-03-30 00:20:47 +02:00
|
|
|
nsh_initialize();
|
|
|
|
|
2012-03-27 18:59:15 +02:00
|
|
|
/* NX Initialization ******************************************************/
|
2020-02-03 14:35:37 +01:00
|
|
|
|
2012-03-27 18:59:15 +02:00
|
|
|
/* Initialize NX */
|
|
|
|
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxterm_main: Initialize NX\n");
|
2014-09-20 22:51:48 +02:00
|
|
|
ret = nxterm_initialize();
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxterm_main: NX handle=%p\n", g_nxterm_vars.hnx);
|
2014-09-20 22:51:48 +02:00
|
|
|
if (!g_nxterm_vars.hnx || ret < 0)
|
2012-03-27 18:59:15 +02:00
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxterm_main: Failed to get NX handle: %d\n", errno);
|
2012-03-27 18:59:15 +02:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the background to the configured background color */
|
|
|
|
|
2019-03-06 17:53:13 +01:00
|
|
|
printf("nxterm_main: Set background color=%d\n",
|
|
|
|
CONFIG_EXAMPLES_NXTERM_BGCOLOR);
|
|
|
|
|
2015-09-08 17:20:49 +02:00
|
|
|
color = CONFIG_EXAMPLES_NXTERM_BGCOLOR;
|
2014-09-20 22:51:48 +02:00
|
|
|
ret = nx_setbgcolor(g_nxterm_vars.hnx, &color);
|
2012-03-27 18:59:15 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxterm_main: nx_setbgcolor failed: %d\n", errno);
|
2012-03-27 18:59:15 +02:00
|
|
|
goto errout_with_nx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Window Configuration ***************************************************/
|
2020-02-03 14:35:37 +01:00
|
|
|
|
2012-03-27 18:59:15 +02:00
|
|
|
/* Create a window */
|
|
|
|
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxterm_main: Create window\n");
|
2019-03-13 19:32:54 +01:00
|
|
|
g_nxterm_vars.hwnd = nxtk_openwindow(g_nxterm_vars.hnx, 0, &g_nxtermcb,
|
2019-03-06 17:53:13 +01:00
|
|
|
NULL);
|
2014-09-20 22:51:48 +02:00
|
|
|
if (!g_nxterm_vars.hwnd)
|
2012-03-27 18:59:15 +02:00
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxterm_main: nxtk_openwindow failed: %d\n", errno);
|
2012-03-27 18:59:15 +02:00
|
|
|
goto errout_with_nx;
|
|
|
|
}
|
2019-03-06 17:53:13 +01:00
|
|
|
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxterm_main: hwnd=%p\n", g_nxterm_vars.hwnd);
|
2012-03-27 18:59:15 +02:00
|
|
|
|
2017-10-16 15:13:38 +02:00
|
|
|
/* Wait until we have the screen resolution. */
|
2012-03-27 18:59:15 +02:00
|
|
|
|
2014-09-20 22:51:48 +02:00
|
|
|
while (!g_nxterm_vars.haveres)
|
2012-03-27 18:59:15 +02:00
|
|
|
{
|
2020-01-02 13:09:50 +01:00
|
|
|
sem_wait(&g_nxterm_vars.eventsem);
|
2012-03-27 18:59:15 +02:00
|
|
|
}
|
2019-03-06 17:53:13 +01:00
|
|
|
|
|
|
|
printf("nxterm_main: Screen resolution (%d,%d)\n",
|
|
|
|
g_nxterm_vars.xres, g_nxterm_vars.yres);
|
2012-03-27 18:59:15 +02:00
|
|
|
|
|
|
|
/* Determine the size and position of the window */
|
|
|
|
|
2020-06-30 14:57:45 +02:00
|
|
|
g_nxterm_vars.wndo.wsize.w = g_nxterm_vars.xres / 2 +
|
|
|
|
g_nxterm_vars.xres / 4;
|
|
|
|
g_nxterm_vars.wndo.wsize.h = g_nxterm_vars.yres / 2 +
|
|
|
|
g_nxterm_vars.yres / 4;
|
2012-03-27 18:59:15 +02:00
|
|
|
|
2014-09-20 22:51:48 +02:00
|
|
|
g_nxterm_vars.wpos.x = g_nxterm_vars.xres / 8;
|
|
|
|
g_nxterm_vars.wpos.y = g_nxterm_vars.yres / 8;
|
2012-03-27 18:59:15 +02:00
|
|
|
|
|
|
|
/* Set the window position */
|
|
|
|
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxterm_main: Set window position to (%d,%d)\n",
|
|
|
|
g_nxterm_vars.wpos.x, g_nxterm_vars.wpos.y);
|
2012-03-27 18:59:15 +02:00
|
|
|
|
2014-09-20 22:51:48 +02:00
|
|
|
ret = nxtk_setposition(g_nxterm_vars.hwnd, &g_nxterm_vars.wpos);
|
2012-03-27 18:59:15 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxterm_main: nxtk_setposition failed: %d\n", errno);
|
2012-03-27 18:59:15 +02:00
|
|
|
goto errout_with_hwnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the window size */
|
|
|
|
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxterm_main: Set window size to (%d,%d)\n",
|
|
|
|
g_nxterm_vars.wndo.wsize.w, g_nxterm_vars.wndo.wsize.h);
|
2012-03-27 18:59:15 +02:00
|
|
|
|
2014-09-20 22:51:48 +02:00
|
|
|
ret = nxtk_setsize(g_nxterm_vars.hwnd, &g_nxterm_vars.wndo.wsize);
|
2012-03-27 18:59:15 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxterm_main: nxtk_setsize failed: %d\n", errno);
|
2012-03-27 18:59:15 +02:00
|
|
|
goto errout_with_hwnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open the toolbar */
|
|
|
|
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxterm_main: Add toolbar to window\n");
|
2019-03-06 17:53:13 +01:00
|
|
|
ret = nxtk_opentoolbar(g_nxterm_vars.hwnd,
|
|
|
|
CONFIG_EXAMPLES_NXTERM_TOOLBAR_HEIGHT,
|
|
|
|
&g_nxtoolcb, NULL);
|
2012-03-27 18:59:15 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxterm_main: nxtk_opentoolbar failed: %d\n", errno);
|
2012-03-27 18:59:15 +02:00
|
|
|
goto errout_with_hwnd;
|
|
|
|
}
|
|
|
|
|
2012-03-30 00:20:47 +02:00
|
|
|
/* Sleep a little bit to allow the server to catch up */
|
2014-04-14 00:24:28 +02:00
|
|
|
|
2012-03-30 00:20:47 +02:00
|
|
|
sleep(2);
|
|
|
|
|
2020-02-03 14:35:37 +01:00
|
|
|
/* NxTerm Configuration ***************************************************/
|
|
|
|
|
2012-03-27 18:59:15 +02:00
|
|
|
/* Use the window to create an NX console */
|
|
|
|
|
2015-09-08 17:20:49 +02:00
|
|
|
g_nxterm_vars.wndo.wcolor[0] = CONFIG_EXAMPLES_NXTERM_WCOLOR;
|
|
|
|
g_nxterm_vars.wndo.fcolor[0] = CONFIG_EXAMPLES_NXTERM_FONTCOLOR;
|
|
|
|
g_nxterm_vars.wndo.fontid = CONFIG_EXAMPLES_NXTERM_FONTID;
|
2012-03-27 18:59:15 +02:00
|
|
|
|
2019-03-06 17:53:13 +01:00
|
|
|
nxcreate.nxterm = NULL;
|
|
|
|
nxcreate.hwnd = g_nxterm_vars.hwnd;
|
|
|
|
nxcreate.wndo = g_nxterm_vars.wndo;
|
|
|
|
nxcreate.type = BOARDIOC_XTERM_FRAMED;
|
|
|
|
nxcreate.minor = CONFIG_EXAMPLES_NXTERM_MINOR;
|
|
|
|
|
2019-03-09 20:17:22 +01:00
|
|
|
/* BOARDIOC_NXTERM wants the size of the NxTK main sub-window */
|
|
|
|
|
|
|
|
nxcreate.wndo.wsize.w -= (2 * CONFIG_NXTK_BORDERWIDTH);
|
|
|
|
nxcreate.wndo.wsize.h -= (CONFIG_EXAMPLES_NXTERM_TOOLBAR_HEIGHT +
|
|
|
|
2 * CONFIG_NXTK_BORDERWIDTH);
|
|
|
|
|
2019-03-06 17:53:13 +01:00
|
|
|
ret = boardctl(BOARDIOC_NXTERM, (uintptr_t)&nxcreate);
|
|
|
|
if (ret < 0)
|
2012-03-27 18:59:15 +02:00
|
|
|
{
|
2019-03-06 17:53:13 +01:00
|
|
|
printf("nxterm_main: boardctl(BOARDIOC_NXTERM) failed: %d\n", errno);
|
2012-03-27 18:59:15 +02:00
|
|
|
goto errout_with_hwnd;
|
|
|
|
}
|
|
|
|
|
2019-03-06 17:53:13 +01:00
|
|
|
g_nxterm_vars.hdrvr = nxcreate.nxterm;
|
|
|
|
DEBUGASSERT(g_nxterm_vars.hdrvr != NULL);
|
|
|
|
|
2014-09-20 22:51:48 +02:00
|
|
|
/* Open the NxTerm driver */
|
2012-03-27 18:59:15 +02:00
|
|
|
|
2015-09-08 17:20:49 +02:00
|
|
|
fd = open(CONFIG_EXAMPLES_NXTERM_DEVNAME, O_WRONLY);
|
2012-03-27 18:59:15 +02:00
|
|
|
if (fd < 0)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxterm_main: open %s read-only failed: %d\n",
|
2015-09-08 17:20:49 +02:00
|
|
|
CONFIG_EXAMPLES_NXTERM_DEVNAME, errno);
|
2012-03-27 18:59:15 +02:00
|
|
|
goto errout_with_driver;
|
|
|
|
}
|
|
|
|
|
2012-03-30 00:20:47 +02:00
|
|
|
/* Start Console Task *****************************************************/
|
2020-02-03 14:35:37 +01:00
|
|
|
|
2012-03-28 02:10:43 +02:00
|
|
|
/* Now re-direct stdout and stderr so that they use the NX console driver.
|
2020-02-03 14:35:37 +01:00
|
|
|
* Note that stdin is retained (file descriptor 0, probably the serial
|
|
|
|
* console).
|
|
|
|
*/
|
2012-03-27 18:59:15 +02:00
|
|
|
|
2020-02-03 14:35:37 +01:00
|
|
|
printf("nxterm_main: Starting the console task\n");
|
2012-03-27 18:59:15 +02:00
|
|
|
|
2020-01-02 13:09:50 +01:00
|
|
|
fflush(stdout);
|
|
|
|
fflush(stderr);
|
2012-03-27 18:59:15 +02:00
|
|
|
|
2020-01-02 13:09:50 +01:00
|
|
|
dup2(fd, 1);
|
|
|
|
dup2(fd, 2);
|
2012-03-27 18:59:15 +02:00
|
|
|
|
2020-02-03 14:35:37 +01:00
|
|
|
/* And we can close our original driver file descriptor */
|
2012-03-27 18:59:15 +02:00
|
|
|
|
2020-02-03 14:35:37 +01:00
|
|
|
close(fd);
|
2012-03-27 18:59:15 +02:00
|
|
|
|
2020-02-03 14:35:37 +01:00
|
|
|
/* And start the console task. It will inherit stdin, stdout, and stderr
|
|
|
|
* from this task.
|
|
|
|
*/
|
2014-04-14 00:24:28 +02:00
|
|
|
|
2020-02-03 14:35:37 +01:00
|
|
|
g_nxterm_vars.pid = task_create("NxTerm", CONFIG_EXAMPLES_NXTERM_PRIO,
|
2014-09-20 22:25:51 +02:00
|
|
|
CONFIG_EXAMPLES_NXTERM_STACKSIZE,
|
2014-09-20 22:51:48 +02:00
|
|
|
nxterm_task, NULL);
|
2020-02-03 14:35:37 +01:00
|
|
|
DEBUGASSERT(g_nxterm_vars.pid > 0);
|
|
|
|
return EXIT_SUCCESS;
|
2012-03-27 18:59:15 +02:00
|
|
|
|
2012-03-30 00:20:47 +02:00
|
|
|
/* Error Exits ************************************************************/
|
2012-03-28 02:10:43 +02:00
|
|
|
|
2012-03-27 18:59:15 +02:00
|
|
|
errout_with_driver:
|
2020-01-02 13:09:50 +01:00
|
|
|
unlink(CONFIG_EXAMPLES_NXTERM_DEVNAME);
|
2012-03-27 18:59:15 +02:00
|
|
|
|
|
|
|
errout_with_hwnd:
|
2020-01-02 13:09:50 +01:00
|
|
|
nxtk_closewindow(g_nxterm_vars.hwnd);
|
2012-03-27 18:59:15 +02:00
|
|
|
|
|
|
|
errout_with_nx:
|
2020-02-03 14:35:37 +01:00
|
|
|
|
2012-03-27 18:59:15 +02:00
|
|
|
/* Disconnect from the server */
|
|
|
|
|
2014-09-20 22:51:48 +02:00
|
|
|
nx_disconnect(g_nxterm_vars.hnx);
|
2020-09-22 17:57:05 +02:00
|
|
|
|
2012-03-27 18:59:15 +02:00
|
|
|
errout:
|
2012-03-30 00:20:47 +02:00
|
|
|
return EXIT_FAILURE;
|
2012-03-27 18:59:15 +02:00
|
|
|
}
|