rptun cmd: add broadcast rptun cmd

Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd 2022-02-11 21:05:08 +08:00 committed by Xiang Xiao
parent e0e5652de4
commit 622784be89
2 changed files with 49 additions and 13 deletions

View File

@ -470,8 +470,8 @@ static const struct cmdmap_s g_cmdmap[] =
#endif #endif
#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN) #if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN)
{ "rptun", cmd_rptun, 3, 4, { "rptun", cmd_rptun, 2, 4,
"start|stop|reset|panic|dump <dev-path> [value]" }, "start|stop|reset|panic|dump [dev-path] [value]" },
#endif #endif
#ifndef CONFIG_NSH_DISABLE_SET #ifndef CONFIG_NSH_DISABLE_SET

View File

@ -28,6 +28,7 @@
#include <sys/boardctl.h> #include <sys/boardctl.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/utsname.h> #include <sys/utsname.h>
#include <dirent.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -344,17 +345,12 @@ int cmd_reset_cause(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN) #if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN)
int cmd_rptun(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) static int cmd_rptun_once(FAR struct nsh_vtbl_s *vtbl, char *path,
int argc, char **argv)
{ {
unsigned long val = 0; unsigned long val = 0;
int fd;
int cmd; int cmd;
int fd;
if (argc < 3)
{
nsh_output(vtbl, g_fmtargrequired, argv[0]);
return ERROR;
}
if (strcmp(argv[1], "start") == 0) if (strcmp(argv[1], "start") == 0)
{ {
@ -387,17 +383,57 @@ int cmd_rptun(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
return ERROR; return ERROR;
} }
fd = open(argv[2], 0); fd = open(path, 0);
if (fd < 0) if (fd < 0)
{ {
nsh_output(vtbl, g_fmtarginvalid, argv[2]); nsh_output(vtbl, g_fmtarginvalid, argv[2]);
return ERROR; return ERROR;
} }
ioctl(fd, cmd, val); cmd = ioctl(fd, cmd, val);
close(fd); close(fd);
return 0;
return cmd;
}
static int cmd_rptun_recursive(FAR struct nsh_vtbl_s *vtbl,
const char *dirpath,
struct dirent *entryp, void *pvarg)
{
char *path;
int ret = 0;
if (DIRENT_ISDIRECTORY(entryp->d_type))
{
return 0;
}
path = nsh_getdirpath(vtbl, dirpath, entryp->d_name);
if (path)
{
ret = cmd_rptun_once(vtbl, path, 2, pvarg);
free(path);
}
return ret;
}
int cmd_rptun(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
if (argc < 2)
{
nsh_output(vtbl, g_fmtargrequired, argv[0]);
return ERROR;
}
if (argc == 2)
{
return nsh_foreach_direntry(vtbl, "rptun", "/dev/rptun",
cmd_rptun_recursive, argv);
}
return cmd_rptun_once(vtbl, argv[2], argc, argv);
} }
#endif #endif