Ejemplo n.º 1
0
int MavlinkShell::shell_start_thread(int argc, char *argv[])
{
	dup2(1, 2); //redirect stderror to stdout

#ifdef __PX4_NUTTX
	nsh_consolemain(0, NULL);
#endif /* __PX4_NUTTX */

	return 0;
}
Ejemplo n.º 2
0
static int nxterm_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("nxterm_task: Unregister the NX console device\n");
  (void)nxterm_unregister(g_nxterm_vars.hdrvr);

  printf("nxterm_task: Close the window\n");
  (void)nxtk_closewindow(g_nxterm_vars.hwnd);

  /* Disconnect from the server */

  printf("nxterm_task: Disconnect from the server\n");
  nx_disconnect(g_nxterm_vars.hnx);

  return EXIT_SUCCESS;
}
Ejemplo n.º 3
0
int
nshterm_main(int argc, char *argv[])
{
    if (argc < 2) {
        printf("Usage: nshterm <device>\n");
        exit(1);
    }
    unsigned retries = 0;
    int fd = -1;
    int armed_fd = orb_subscribe(ORB_ID(actuator_armed));
    struct actuator_armed_s armed;
    /* we assume the system does not provide arming status feedback */
    bool armed_updated = false;

    /* try the first 30 seconds or if arming system is ready */
    while ((retries < 300) || armed_updated) {

        /* abort if an arming topic is published and system is armed */
        bool updated = false;
        if (orb_check(armed_fd, &updated)) {
            /* the system is now providing arming status feedback.
             * instead of timing out, we resort to abort bringing
             * up the terminal.
             */
            armed_updated = true;
            orb_copy(ORB_ID(actuator_armed), armed_fd, &armed);

            if (armed.armed) {
                /* this is not an error, but we are done */
                exit(0);
            }
        }

        /* the retries are to cope with the behaviour of /dev/ttyACM0 */
        /* which may not be ready immediately. */
        fd = open(argv[1], O_RDWR);
        if (fd != -1) {
            break;
        }
        usleep(100000);
        retries++;
    }
    if (fd == -1) {
        perror(argv[1]);
        exit(1);
    }

    /* set up the serial port with output processing */
    
    /* Try to set baud rate */
    struct termios uart_config;
    int termios_state;

    /* Back up the original uart configuration to restore it after exit */
    if ((termios_state = tcgetattr(fd, &uart_config)) < 0) {
        warnx("ERR get config %s: %d\n", argv[1], termios_state);
        close(fd);
        return -1;
    }

    /* Set ONLCR flag (which appends a CR for every LF) */
    uart_config.c_oflag |= (ONLCR | OPOST/* | OCRNL*/);

    if ((termios_state = tcsetattr(fd, TCSANOW, &uart_config)) < 0) {
        warnx("ERR set config %s\n", argv[1]);
        close(fd);
        return -1;
    }

    /* setup standard file descriptors */
    close(0);
    close(1);
    close(2);
    dup2(fd, 0);
    dup2(fd, 1);
    dup2(fd, 2);

    nsh_consolemain(0, NULL);

    close(fd);

    return OK;
}
Ejemplo n.º 4
0
int nsh_main(int argc, char *argv[])
{
  int exitval = 0;
  int ret;

  /* Call all C++ static constructors */

#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE)
  up_cxxinitialize();
#endif

  /* Make sure that we are using our symbol take */

#if defined(CONFIG_LIBC_EXECFUNCS) && defined(CONFIG_EXECFUNCS_SYMTAB)
  exec_setsymtab(CONFIG_EXECFUNCS_SYMTAB, 0);
#endif

  /* Register the BINFS file system */

#if defined(CONFIG_FS_BINFS) && (CONFIG_BUILTIN)
  ret = builtin_initialize();
  if (ret < 0)
    {
     fprintf(stderr, "ERROR: builtin_initialize failed: %d\n", ret);
     exitval = 1;
   }
#endif

  /* Initialize the NSH library */

  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);
     exitval = 1;
   }
#endif

  /* If the serial console front end is selected, then run it on this thread */

#ifdef CONFIG_NSH_CONSOLE
  ret = nsh_consolemain(0, NULL);

  /* nsh_consolemain() should not return.  So if we get here, something
   * is wrong.
   */

  fprintf(stderr, "ERROR: nsh_consolemain() returned: %d\n", ret);
  exitval = 1;
#endif

  return exitval;
}