mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-05 14:17:20 +08:00
Use realine instead of fgets in several other places
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4357 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
@@ -244,9 +244,20 @@ examples/ftpc
|
|||||||
where xx.xx.xx.xx is the IP address of the FTP server and pp is an
|
where xx.xx.xx.xx is the IP address of the FTP server and pp is an
|
||||||
optional port number.
|
optional port number.
|
||||||
|
|
||||||
NOTE: The ftpc task uses the system console for input/output. It will
|
NOTE: By default, FTPC uses readline to get data from stdin. So your
|
||||||
not work from NSH over a telnet NSH connection (Well, it will work you
|
appconfig file must have the following build path:
|
||||||
just won't be able to access the command line).
|
|
||||||
|
CONFIGURED_APPS += system/readline
|
||||||
|
|
||||||
|
NOTE: If you use the ftpc task over a telnet NSH connection, then you
|
||||||
|
should set the following configuration item:
|
||||||
|
|
||||||
|
CONFIG_EXAMPLES_FTPC_FGETS=y
|
||||||
|
|
||||||
|
By default, the FTPC client will use readline() to get characters from
|
||||||
|
the console. Readline includes and command-line editor and echos
|
||||||
|
characters received in stdin back through stdout. Neither of these
|
||||||
|
behaviors are desire-able if Telnet is used.
|
||||||
|
|
||||||
You may also want to define the following in your configuration file.
|
You may also want to define the following in your configuration file.
|
||||||
Otherwise, you will have not feeback about what is going on:
|
Otherwise, you will have not feeback about what is going on:
|
||||||
@@ -393,6 +404,11 @@ examples/nsh
|
|||||||
|
|
||||||
CONFIGURED_APPS += nshlib
|
CONFIGURED_APPS += nshlib
|
||||||
|
|
||||||
|
NOTE: If the NSH serial console is used, then following is also
|
||||||
|
required to build the readline() library:
|
||||||
|
|
||||||
|
CONFIGURED_APPS += system/readline
|
||||||
|
|
||||||
And if networking is included:
|
And if networking is included:
|
||||||
|
|
||||||
CONFIGURED_APPS += uiplib
|
CONFIGURED_APPS += uiplib
|
||||||
@@ -1257,6 +1273,21 @@ examples/usbterm
|
|||||||
CONFIG_EXAMPLES_USBTERM_TRACEINTERRUPTS
|
CONFIG_EXAMPLES_USBTERM_TRACEINTERRUPTS
|
||||||
Show interrupt-related events.
|
Show interrupt-related events.
|
||||||
|
|
||||||
|
NOTE: By default, USBterm uses readline to get data from stdin. So your
|
||||||
|
appconfig file must have the following build path:
|
||||||
|
|
||||||
|
CONFIGURED_APPS += system/readline
|
||||||
|
|
||||||
|
NOTE: If you use the USBterm task over a telnet NSH connection, then you
|
||||||
|
should set the following configuration item:
|
||||||
|
|
||||||
|
CONFIG_EXAMPLES_USBTERM_FGETS=y
|
||||||
|
|
||||||
|
By default, the USBterm client will use readline() to get characters from
|
||||||
|
the console. Readline includes and command-line editor and echos
|
||||||
|
characters received in stdin back through stdout. Neither of these
|
||||||
|
behaviors are desire-able if Telnet is used.
|
||||||
|
|
||||||
Error results are always shown in the trace output
|
Error results are always shown in the trace output
|
||||||
|
|
||||||
Other relevant configuration options: CONFIG_CDCACM selected by the
|
Other relevant configuration options: CONFIG_CDCACM selected by the
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* examples/ftpc/ftpc_main.c
|
* examples/ftpc/ftpc_main.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -41,10 +41,13 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <apps/ftpc.h>
|
#include <apps/ftpc.h>
|
||||||
|
|
||||||
|
#include <apps/readline.h>
|
||||||
|
|
||||||
#include "ftpc.h"
|
#include "ftpc.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -357,6 +360,9 @@ int ftpc_main(int argc, char **argv, char **envp)
|
|||||||
struct ftpc_connect_s connect = {{0}, 0};
|
struct ftpc_connect_s connect = {{0}, 0};
|
||||||
SESSION handle;
|
SESSION handle;
|
||||||
FAR char *ptr;
|
FAR char *ptr;
|
||||||
|
#ifndef CONFIG_EXAMPLES_FTPC_FGETS
|
||||||
|
int ret;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
{
|
{
|
||||||
@@ -413,9 +419,32 @@ int ftpc_main(int argc, char **argv, char **envp)
|
|||||||
|
|
||||||
/* Get the next line of input */
|
/* Get the next line of input */
|
||||||
|
|
||||||
if (fgets(g_line, CONFIG_FTPC_LINELEN, stdin))
|
#ifdef CONFIG_EXAMPLES_FTPC_FGETS
|
||||||
|
/* fgets returns NULL on end-of-file or any I/O error */
|
||||||
|
|
||||||
|
if (fgets(g_line, CONFIG_FTPC_LINELEN, stdin) == NULL)
|
||||||
{
|
{
|
||||||
/* Parse process the command */
|
printf("ERROR: fgets failed: %d\n", errno);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
ret = readline(g_line, CONFIG_FTPC_LINELEN, stdin, stdout);
|
||||||
|
|
||||||
|
/* Readline normally returns the number of characters read,
|
||||||
|
* but will return 0 on end of file or a negative value
|
||||||
|
* if an error occurs. Either will cause the session to
|
||||||
|
* terminate.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (ret <= 0)
|
||||||
|
{
|
||||||
|
printf("ERROR: readline failed: %d\n", ret);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Parse and process the command */
|
||||||
|
|
||||||
(void)ftpc_parse(handle, g_line);
|
(void)ftpc_parse(handle, g_line);
|
||||||
FFLUSH();
|
FFLUSH();
|
||||||
|
|||||||
@@ -50,6 +50,8 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <apps/readline.h>
|
||||||
|
|
||||||
#include <nuttx/usb/usbdev.h>
|
#include <nuttx/usb/usbdev.h>
|
||||||
#include <nuttx/usb/usbdev_trace.h>
|
#include <nuttx/usb/usbdev_trace.h>
|
||||||
|
|
||||||
@@ -297,9 +299,32 @@ int MAIN_NAME(int argc, char *argv[])
|
|||||||
fputs("usbterm> ", stdout);
|
fputs("usbterm> ", stdout);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
/* Get the next line of input from stdin */
|
/* Get the next line of input */
|
||||||
|
|
||||||
if (fgets(g_usbterm.outbuffer, CONFIG_EXAMPLES_USBTERM_BUFLEN, stdin))
|
#ifdef CONFIG_EXAMPLES_USBTERM_FGETS
|
||||||
|
/* fgets returns NULL on end-of-file or any I/O error */
|
||||||
|
|
||||||
|
if (fgets(g_usbterm.outbuffer, CONFIG_EXAMPLES_USBTERM_BUFLEN, stdin) == NULL)
|
||||||
|
{
|
||||||
|
printf("ERROR: fgets failed: %d\n", errno);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
ret = readline(g_usbterm.outbuffer, CONFIG_EXAMPLES_USBTERM_BUFLEN, stdin, stdout);
|
||||||
|
|
||||||
|
/* Readline normally returns the number of characters read,
|
||||||
|
* but will return 0 on end of file or a negative value
|
||||||
|
* if an error occurs. Either will cause the session to
|
||||||
|
* terminate.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (ret <= 0)
|
||||||
|
{
|
||||||
|
printf("ERROR: readline failed: %d\n", ret);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
else
|
||||||
{
|
{
|
||||||
/* Send the line of input via USB */
|
/* Send the line of input via USB */
|
||||||
|
|
||||||
|
|||||||
@@ -1047,3 +1047,11 @@ Common Problems
|
|||||||
Make sure that the polled console is disabled in the OS configuration
|
Make sure that the polled console is disabled in the OS configuration
|
||||||
file, .config. That file should have CONFIG_DEV_LOWCONSOLE=n for
|
file, .config. That file should have CONFIG_DEV_LOWCONSOLE=n for
|
||||||
NSH over serial.
|
NSH over serial.
|
||||||
|
|
||||||
|
Problem:
|
||||||
|
The function 'readline' is undefined.
|
||||||
|
Usual Cause:
|
||||||
|
The following is missing from your appconfig file:
|
||||||
|
|
||||||
|
CONFIGURED_APPS += system/readline
|
||||||
|
|
||||||
|
|||||||
@@ -525,7 +525,7 @@ int nsh_consolemain(int argc, char *argv[])
|
|||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(pstate->ss_outstream, g_fmtcmdfailed, "readline", NSH_ERRNO);
|
fprintf(pstate->ss_outstream, g_fmtcmdfailed, "readline", NSH_ERRNO_OF(-ret));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user