You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/04/01 09:37:03 UTC
[incubator-nuttx-apps] 06/06: rptun: update rptun cmd usage
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 470174260c363ea636640a85e2a2c412de5ea1dc
Author: ligd <li...@xiaomi.com>
AuthorDate: Thu Mar 31 20:11:09 2022 +0800
rptun: update rptun cmd usage
Signed-off-by: ligd <li...@xiaomi.com>
---
nshlib/nsh_command.c | 5 +++--
nshlib/nsh_syscmds.c | 23 +++++++++--------------
2 files changed, 12 insertions(+), 16 deletions(-)
diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c
index 19740c8..46a59a5 100644
--- a/nshlib/nsh_command.c
+++ b/nshlib/nsh_command.c
@@ -470,8 +470,9 @@ static const struct cmdmap_s g_cmdmap[] =
#endif
#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN)
- { "rptun", cmd_rptun, 2, 6,
- "start|stop|reset|panic|dump|ping [dev-path] [value|times length ack]" },
+ { "rptun", cmd_rptun, 3, 6,
+ "<start|stop|reset|panic|dump|ping> <path|all> "
+ "[value|times length ack]" },
#endif
#ifndef CONFIG_NSH_DISABLE_SET
diff --git a/nshlib/nsh_syscmds.c b/nshlib/nsh_syscmds.c
index cba1ad0..3e987cf 100644
--- a/nshlib/nsh_syscmds.c
+++ b/nshlib/nsh_syscmds.c
@@ -345,8 +345,8 @@ int cmd_reset_cause(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
****************************************************************************/
#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN)
-static int cmd_rptun_once(FAR struct nsh_vtbl_s *vtbl, char *path,
- int argc, char **argv)
+static int cmd_rptun_once(FAR struct nsh_vtbl_s *vtbl,
+ FAR const char *path, char **argv)
{
struct rptun_ping_s ping;
unsigned long val = 0;
@@ -363,11 +363,7 @@ static int cmd_rptun_once(FAR struct nsh_vtbl_s *vtbl, char *path,
}
else if (strcmp(argv[1], "reset") == 0)
{
- if (argc > 3)
- {
- val = atoi(argv[3]);
- }
-
+ val = atoi(argv[3]);
cmd = RPTUNIOC_RESET;
}
else if (strcmp(argv[1], "panic") == 0)
@@ -380,9 +376,8 @@ static int cmd_rptun_once(FAR struct nsh_vtbl_s *vtbl, char *path,
}
else if (strcmp(argv[1], "ping") == 0)
{
- if (argc != 6)
+ if (argv[3] == 0 || argv[4] == 0 || argv[5] == 0)
{
- nsh_output(vtbl, g_fmtarginvalid, path);
return ERROR;
}
@@ -418,7 +413,7 @@ static int cmd_rptun_recursive(FAR struct nsh_vtbl_s *vtbl,
struct dirent *entryp, void *pvarg)
{
char *path;
- int ret = 0;
+ int ret = ERROR;
if (DIRENT_ISDIRECTORY(entryp->d_type))
{
@@ -428,7 +423,7 @@ static int cmd_rptun_recursive(FAR struct nsh_vtbl_s *vtbl,
path = nsh_getdirpath(vtbl, dirpath, entryp->d_name);
if (path)
{
- ret = cmd_rptun_once(vtbl, path, 2, pvarg);
+ ret = cmd_rptun_once(vtbl, path, pvarg);
free(path);
}
@@ -437,19 +432,19 @@ static int cmd_rptun_recursive(FAR struct nsh_vtbl_s *vtbl,
int cmd_rptun(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
- if (argc < 2)
+ if (argc < 3)
{
nsh_output(vtbl, g_fmtargrequired, argv[0]);
return ERROR;
}
- if (argc == 2)
+ if (strcmp(argv[2], "all") == 0)
{
return nsh_foreach_direntry(vtbl, "rptun", "/dev/rptun",
cmd_rptun_recursive, argv);
}
- return cmd_rptun_once(vtbl, argv[2], argc, argv);
+ return cmd_rptun_once(vtbl, argv[2], argv);
}
#endif