apps/system/nxplayer and nxrecorder: apps/nxplayer&nxrecorder: Add nuttx shell support. Use system() function to support shell command in nxplayer and nxrecorder applications.

This commit is contained in:
qiaohaijiao 2019-11-20 07:41:05 -06:00 committed by Gregory Nutt
parent 1859f56380
commit c084cd820c
3 changed files with 206 additions and 132 deletions

View File

@ -8,7 +8,7 @@
*
* With ongoing support:
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2014, 2019 Gregory Nutt. All rights reserved.
* Author: Greory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -69,6 +69,7 @@
#include <netutils/netlib.h>
#include <nuttx/audio/audio.h>
#include "system/nxplayer.h"
/****************************************************************************
@ -121,7 +122,8 @@ int nxplayer_getmidisubformat(int fd);
****************************************************************************/
#ifdef CONFIG_NXPLAYER_FMT_FROM_EXT
static const struct nxplayer_ext_fmt_s g_known_ext[] = {
static const struct nxplayer_ext_fmt_s g_known_ext[] =
{
#ifdef CONFIG_AUDIO_FORMAT_AC3
{ "ac3", AUDIO_FMT_AC3, NULL },
#endif
@ -145,6 +147,7 @@ static const struct nxplayer_ext_fmt_s g_known_ext[] = {
{ "ogg", AUDIO_FMT_OGG_VORBIS, NULL }
#endif
};
static const int g_known_ext_count = sizeof(g_known_ext) /
sizeof(struct nxplayer_ext_fmt_s);
#endif /* CONFIG_NXPLAYER_FMT_FROM_EXT */
@ -377,7 +380,8 @@ static int nxplayer_opendevice(FAR struct nxplayer_s *pplayer, int format,
#ifdef CONFIG_AUDIO_DEV_ROOT
snprintf(path, sizeof(path), "/dev/%s", pDevice->d_name);
#else
snprintf(path, sizeof(path), CONFIG_AUDIO_DEV_PATH "/%s", pDevice->d_name);
snprintf(path, sizeof(path), CONFIG_AUDIO_DEV_PATH "/%s",
pDevice->d_name);
#endif /* CONFIG_AUDIO_DEV_ROOT */
#else
snprintf(path, sizeof(path), "/dev/audio/%s", pDevice->d_name);
@ -393,8 +397,8 @@ static int nxplayer_opendevice(FAR struct nxplayer_s *pplayer, int format,
caps.ac_type = AUDIO_TYPE_QUERY;
caps.ac_subtype = AUDIO_TYPE_QUERY;
if (ioctl(pplayer->devFd, AUDIOIOC_GETCAPS, (unsigned long) &caps)
== caps.ac_len)
if (ioctl(pplayer->devFd, AUDIOIOC_GETCAPS,
(unsigned long)&caps) == caps.ac_len)
{
/* Test if this device supports the format we want */
@ -432,8 +436,8 @@ static int nxplayer_opendevice(FAR struct nxplayer_s *pplayer, int format,
}
}
/* If we reached the end of the subformat list, then
* break out of the loop.
/* If we reached the end of the subformat list,
* then break out of the loop.
*/
if (x != sizeof(caps.ac_controls))
@ -513,6 +517,7 @@ int nxplayer_getmidisubformat(int fd)
ret = AUDIO_SUBFMT_MIDI_2;
break;
}
lseek(fd, 0, SEEK_SET);
return ret;
@ -547,7 +552,7 @@ static inline int nxplayer_fmtfromextension(FAR struct nxplayer_s *pplayer,
{
/* First '.' found. Now compare with known extensions */
pExt = &pFilename[x+1];
pExt = &pFilename[x + 1];
for (c = 0; c < g_known_ext_count; c++)
{
/* Test for extension match */
@ -710,7 +715,7 @@ static int nxplayer_readbuffer(FAR struct nxplayer_s *pplayer,
* called with a buffer of data to be enqueued in the audio stream.
*
* Be we may also receive an empty length buffer (with only the
* AUDIO_APB_FINAL set) in the event of certin read error occurs or in the
* AUDIO_APB_FINAL set) in the event of certain read error occurs or in the
* event that the file was an exact multiple of the nmaxbytes size of the
* audio buffer. In that latter case, we have an end of file with no bytes
* read.
@ -804,7 +809,8 @@ static void *nxplayer_playthread(pthread_addr_t pvarg)
/* Create array of pointers to buffers */
pbuffers = (FAR struct ap_buffer_s **) malloc(buf_info.nbuffers * sizeof(FAR void *));
pbuffers = (FAR struct ap_buffer_s **)
malloc(buf_info.nbuffers * sizeof(FAR void *));
if (pbuffers == NULL)
{
/* Error allocating memory for buffer storage! */
@ -901,8 +907,8 @@ static void *nxplayer_playthread(pthread_addr_t pvarg)
/* Failed to enqueue the buffer. The driver is not happy with
* the buffer. Perhaps a decoder has detected something that it
* does not like in the stream and has stopped streaming. This
* would happen normally if we send a file in the incorrect format
* to an audio decoder.
* would happen normally if we send a file in the incorrect
* format to an audio decoder.
*
* We must stop streaming as gracefully as possible. Close the
* file so that no further data is read.
@ -913,8 +919,9 @@ static void *nxplayer_playthread(pthread_addr_t pvarg)
/* We are no longer streaming data from the file. Be we will
* need to wait for any outstanding buffers to be recovered. We
* also still expect the audio driver to send a AUDIO_MSG_COMPLETE
* message after all queued buffers have been returned.
* also still expect the audio driver to send a
* AUDIO_MSG_COMPLETE message after all queued buffers have
* been returned.
*/
streaming = false;
@ -1023,6 +1030,7 @@ static void *nxplayer_playthread(pthread_addr_t pvarg)
/* An audio buffer is being dequeued by the driver */
case AUDIO_MSG_DEQUEUE:
#ifdef CONFIG_DEBUG_FEATURES
/* Make sure that we believe that the audio driver has at
* least one buffer.
@ -1092,6 +1100,7 @@ static void *nxplayer_playthread(pthread_addr_t pvarg)
/* Someone wants to stop the playback. */
case AUDIO_MSG_STOP:
/* Send a stop message to the device */
audinfo("Stopping! outstanding=%d\n", outstanding);
@ -1144,7 +1153,8 @@ err_out:
buf_desc.session = pplayer->session;
#endif
buf_desc.u.pBuffer = pbuffers[x];
ioctl(pplayer->devFd, AUDIOIOC_FREEBUFFER, (unsigned long) &buf_desc);
ioctl(pplayer->devFd, AUDIOIOC_FREEBUFFER,
(unsigned long)&buf_desc);
}
}
@ -1164,7 +1174,8 @@ err_out:
buf_desc.session = pplayer->session;
#endif
buf_desc.u.pBuffer = pbuffers[x];
ioctl(pplayer->devFd, AUDIOIOC_FREEBUFFER, (unsigned long) &buf_desc);
ioctl(pplayer->devFd, AUDIOIOC_FREEBUFFER,
(unsigned long)&buf_desc);
}
}
#endif
@ -1251,7 +1262,8 @@ int nxplayer_setvolume(FAR struct nxplayer_s *pplayer, uint16_t volume)
cap_desc.caps.ac_type = AUDIO_TYPE_FEATURE;
cap_desc.caps.ac_format.hw = AUDIO_FU_VOLUME;
cap_desc.caps.ac_controls.hw[0] = volume;
ret = ioctl(pplayer->devFd, AUDIOIOC_CONFIGURE, (unsigned long) &cap_desc);
ret = ioctl(pplayer->devFd, AUDIOIOC_CONFIGURE,
(unsigned long)&cap_desc);
if (ret < 0)
{
int errcode = errno;
@ -1516,7 +1528,7 @@ int nxplayer_resume(FAR struct nxplayer_s *pplayer)
* Name: nxplayer_fforward
*
* Selects to fast forward in the audio data stream. The fast forward
* operation can be cancelled by simply selected no sub-sampling with
* operation can be canceled by simply selected no sub-sampling with
* the AUDIO_SUBSAMPLE_NONE argument returning to normal 1x forward play.
* This function may be called multiple times to change fast forward rate.
*
@ -1684,7 +1696,8 @@ int nxplayer_cancel_motion(FAR struct nxplayer_s *pplayer, bool paused)
****************************************************************************/
#ifdef CONFIG_NXPLAYER_INCLUDE_PREFERRED_DEVICE
int nxplayer_setdevice(FAR struct nxplayer_s *pplayer, FAR const char *pDevice)
int nxplayer_setdevice(FAR struct nxplayer_s *pplayer,
FAR const char *pDevice)
{
int tempFd;
struct audio_caps_s caps;
@ -1848,7 +1861,8 @@ static int nxplayer_playinternal(FAR struct nxplayer_s *pplayer,
#ifdef CONFIG_NXPLAYER_MEDIA_SEARCH
/* File not found in the media dir. Do a search */
if (nxplayer_mediasearch(pplayer, pFilename, path, sizeof(path)) != OK)
if (nxplayer_mediasearch(pplayer, pFilename, path,
sizeof(path)) != OK)
{
auderr("ERROR: Could not find file\n");
return -ENOENT;
@ -1861,8 +1875,8 @@ static int nxplayer_playinternal(FAR struct nxplayer_s *pplayer,
#else /* CONFIG_NXPLAYER_INCLUDE_MEDIADIR */
auderr("ERROR: Could not open %s\n", pFilename);
return -ENOENT;
auderr("ERROR: Could not open %s\n", pFilename);
return -ENOENT;
#endif /* CONFIG_NXPLAYER_INCLUDE_MEDIADIR */
}
@ -1985,7 +1999,8 @@ static int nxplayer_playinternal(FAR struct nxplayer_s *pplayer,
pthread_attr_init(&tattr);
sparam.sched_priority = sched_get_priority_max(SCHED_FIFO) - 9;
(void)pthread_attr_setschedparam(&tattr, &sparam);
(void)pthread_attr_setstacksize(&tattr, CONFIG_NXPLAYER_PLAYTHREAD_STACKSIZE);
(void)pthread_attr_setstacksize(&tattr,
CONFIG_NXPLAYER_PLAYTHREAD_STACKSIZE);
/* Add a reference count to the player for the thread and start the
* thread. We increment for the thread to avoid thread start-up
@ -2358,9 +2373,10 @@ int nxplayer_systemreset(FAR struct nxplayer_s *pplayer)
#ifdef CONFIG_AUDIO_CUSTOM_DEV_PATH
#ifdef CONFIG_AUDIO_DEV_ROOT
snprintf(path, sizeof(path), "/dev/%s", pDevice->d_name);
snprintf(path, sizeof(path), "/dev/%s", pDevice->d_name);
#else
snprintf(path, sizeof(path), CONFIG_AUDIO_DEV_PATH "/%s", pDevice->d_name);
snprintf(path, sizeof(path), CONFIG_AUDIO_DEV_PATH "/%s",
pDevice->d_name);
#endif
#else
snprintf(path, sizeof(path), "/dev/audio/%s", pDevice->d_name);
@ -2377,7 +2393,6 @@ int nxplayer_systemreset(FAR struct nxplayer_s *pplayer)
close(pplayer->devFd);
}
}
pplayer->devFd = -1;

View File

@ -33,7 +33,6 @@
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
@ -56,7 +55,7 @@
* Pre-processor Definitions
****************************************************************************/
#define NXPLAYER_VER "1.05"
#define NXPLAYER_VER "1.05"
#ifdef CONFIG_NXPLAYER_INCLUDE_HELP
# define NXPLAYER_HELP_TEXT(x) #x
@ -168,8 +167,8 @@ static struct mp_cmd_s g_nxplayer_cmds[] =
{ "volume", "d%", nxplayer_cmd_volume, NXPLAYER_HELP_TEXT(Set volume to level specified) }
#endif
};
static const int g_nxplayer_cmd_count = sizeof(g_nxplayer_cmds) / sizeof(struct mp_cmd_s);
static const int g_nxplayer_cmd_count = sizeof(g_nxplayer_cmds) / sizeof(struct mp_cmd_s);
/****************************************************************************
* Private Functions
@ -594,16 +593,21 @@ static int nxplayer_cmd_quit(FAR struct nxplayer_s *pPlayer, char *parg)
#ifdef CONFIG_NXPLAYER_INCLUDE_HELP
static int nxplayer_cmd_help(FAR struct nxplayer_s *pPlayer, char *parg)
{
int x, len, maxlen = 0;
int len;
int maxlen = 0;
int x;
int c;
/* Calculate length of longest cmd + arghelp */
for (x = 0; x < g_nxplayer_cmd_count; x++)
{
len = strlen(g_nxplayer_cmds[x].cmd) + strlen(g_nxplayer_cmds[x].arghelp);
len = strlen(g_nxplayer_cmds[x].cmd) +
strlen(g_nxplayer_cmds[x].arghelp);
if (len > maxlen)
maxlen = len;
{
maxlen = len;
}
}
printf("NxPlayer commands\n================\n");
@ -615,9 +619,12 @@ static int nxplayer_cmd_help(FAR struct nxplayer_s *pPlayer, char *parg)
/* Calculate number of spaces to print before the help text */
len = maxlen - (strlen(g_nxplayer_cmds[x].cmd) + strlen(g_nxplayer_cmds[x].arghelp));
len = maxlen - (strlen(g_nxplayer_cmds[x].cmd) +
strlen(g_nxplayer_cmds[x].arghelp));
for (c = 0; c < len; c++)
printf(" ");
{
printf(" ");
}
printf(" : %s\n", g_nxplayer_cmds[x].help);
}
@ -634,10 +641,10 @@ static int nxplayer_cmd_help(FAR struct nxplayer_s *pPlayer, char *parg)
* Name: nxplayer
*
* nxplayer() reads in commands from the console using the readline
* system add-in and implemets a command-line based media player that
* system add-in and impalements a command-line based media player that
* uses the NuttX audio system to play media files read in from the
* file system. Commands are provided for setting volume, base and
* other audio features, as well as for pausing and stoping the
* other audio features, as well as for pausing and stopping the
* playback.
*
* Input Parameters:
@ -655,7 +662,7 @@ static int nxplayer_cmd_help(FAR struct nxplayer_s *pPlayer, char *parg)
int main(int argc, FAR char *argv[])
{
char buffer[64];
char buffer[CONFIG_NSH_LINELEN];
int len, x, running;
char *cmd, *arg;
FAR struct nxplayer_s *pPlayer;
@ -689,49 +696,71 @@ int main(int argc, FAR char *argv[])
buffer[len] = '\0';
if (len > 0)
{
if (buffer[len-1] == '\n')
buffer[len-1] = '\0';
/* Parse the command from the argument */
cmd = strtok_r(buffer, " \n", &arg);
if (cmd == NULL)
continue;
/* Remove leading spaces from arg */
while (*arg == ' ')
arg++;
/* Find the command in our cmd array */
for (x = 0; x < g_nxplayer_cmd_count; x++)
if (strncmp(buffer, "!", 1) != 0)
{
if (strcmp(cmd, g_nxplayer_cmds[x].cmd) == 0)
{
/* Command found. Call it's handler if not NULL */
/* nxplayer command */
if (g_nxplayer_cmds[x].pFunc != NULL)
g_nxplayer_cmds[x].pFunc(pPlayer, arg);
if (buffer[len - 1] == '\n')
{
buffer[len - 1] = '\0';
}
/* Test if it is a quit command */
/* Parse the command from the argument */
if (g_nxplayer_cmds[x].pFunc == nxplayer_cmd_quit)
running = FALSE;
break;
}
cmd = strtok_r(buffer, " \n", &arg);
if (cmd == NULL)
{
continue;
}
/* Remove leading spaces from arg */
while (*arg == ' ')
{
arg++;
}
/* Find the command in our cmd array */
for (x = 0; x < g_nxplayer_cmd_count; x++)
{
if (strcmp(cmd, g_nxplayer_cmds[x].cmd) == 0)
{
/* Command found. Call it's handler if not NULL */
if (g_nxplayer_cmds[x].pFunc != NULL)
{
g_nxplayer_cmds[x].pFunc(pPlayer, arg);
}
/* Test if it is a quit command */
if (g_nxplayer_cmds[x].pFunc == nxplayer_cmd_quit)
{
running = FALSE;
}
break;
}
}
}
else
{
#ifdef CONFIG_SYSTEM_SYSTEM
/* Transfer nuttx shell */
/* Test for Unknown command */
if (x == g_nxplayer_cmd_count)
printf("%s: unknown nxplayer command\n", buffer);
system(buffer + 1);
#else
printf("%s: unknown nxplayer command\n", buffer);
#endif
}
}
}
/* Release the NxPlayer context */
/* nxplayer_detach(pPlayer); */
nxplayer_release(pPlayer);
return OK;

View File

@ -79,21 +79,28 @@ struct mp_cmd_s
* Private Function Prototypes
****************************************************************************/
static int nxrecorder_cmd_quit(FAR struct nxrecorder_s *pRecorder, char *parg);
static int nxrecorder_cmd_recordraw(FAR struct nxrecorder_s *pRecorder, char *parg);
static int nxrecorder_cmd_device(FAR struct nxrecorder_s *pRecorder, char *parg);
static int nxrecorder_cmd_quit(FAR struct nxrecorder_s *pRecorder,
FAR char *parg);
static int nxrecorder_cmd_recordraw(FAR struct nxrecorder_s *pRecorder,
FAR char *parg);
static int nxrecorder_cmd_device(FAR struct nxrecorder_s *pRecorder,
FAR char *parg);
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
static int nxrecorder_cmd_pause(FAR struct nxrecorder_s *pRecorder, char *parg);
static int nxrecorder_cmd_resume(FAR struct nxrecorder_s *pRecorder, char *parg);
static int nxrecorder_cmd_pause(FAR struct nxrecorder_s *pRecorder,
FAR char *parg);
static int nxrecorder_cmd_resume(FAR struct nxrecorder_s *pRecorder,
FAR char *parg);
#endif
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
static int nxrecorder_cmd_stop(FAR struct nxrecorder_s *pRecorder, char *parg);
static int nxrecorder_cmd_stop(FAR struct nxrecorder_s *pRecorder,
FAR char *parg);
#endif
#ifdef CONFIG_NXRECORDER_INCLUDE_HELP
static int nxrecorder_cmd_help(FAR struct nxrecorder_s *pRecorder, char *parg);
static int nxrecorder_cmd_help(FAR struct nxrecorder_s *pRecorder,
FAR char *parg);
#endif
/****************************************************************************
@ -118,8 +125,8 @@ static const struct mp_cmd_s g_nxrecorder_cmds[] =
{ "q", "", nxrecorder_cmd_quit, NXRECORDER_HELP_TEXT(Exit NxRecorder) },
{ "quit", "", nxrecorder_cmd_quit, NXRECORDER_HELP_TEXT(Exit NxRecorder) },
};
static const int g_nxrecorder_cmd_count = sizeof(g_nxrecorder_cmds) / sizeof(struct mp_cmd_s);
static const int g_nxrecorder_cmd_count = sizeof(g_nxrecorder_cmds) / sizeof(struct mp_cmd_s);
/****************************************************************************
* Private Functions
@ -133,7 +140,8 @@ static const int g_nxrecorder_cmd_count = sizeof(g_nxrecorder_cmds) / sizeof(str
*
****************************************************************************/
static int nxrecorder_cmd_recordraw(FAR struct nxrecorder_s *pRecorder, char *parg)
static int nxrecorder_cmd_recordraw(FAR struct nxrecorder_s *pRecorder,
FAR char *parg)
{
int ret;
int channels = 0;
@ -194,7 +202,8 @@ static int nxrecorder_cmd_recordraw(FAR struct nxrecorder_s *pRecorder, char *pa
****************************************************************************/
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
static int nxrecorder_cmd_stop(FAR struct nxrecorder_s *pRecorder, char *parg)
static int nxrecorder_cmd_stop(FAR struct nxrecorder_s *pRecorder,
FAR char *parg)
{
/* Stop the record */
@ -213,7 +222,8 @@ static int nxrecorder_cmd_stop(FAR struct nxrecorder_s *pRecorder, char *parg)
****************************************************************************/
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
static int nxrecorder_cmd_pause(FAR struct nxrecorder_s *pRecorder, char *parg)
static int nxrecorder_cmd_pause(FAR struct nxrecorder_s *pRecorder,
FAR char *parg)
{
/* Pause the record */
@ -232,7 +242,8 @@ static int nxrecorder_cmd_pause(FAR struct nxrecorder_s *pRecorder, char *parg)
****************************************************************************/
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
static int nxrecorder_cmd_resume(FAR struct nxrecorder_s *pRecorder, char *parg)
static int nxrecorder_cmd_resume(FAR struct nxrecorder_s *pRecorder,
FAR char *parg)
{
/* Resume the record */
@ -249,7 +260,8 @@ static int nxrecorder_cmd_resume(FAR struct nxrecorder_s *pRecorder, char *parg)
*
****************************************************************************/
static int nxrecorder_cmd_device(FAR struct nxrecorder_s *pRecorder, char *parg)
static int nxrecorder_cmd_device(FAR struct nxrecorder_s *pRecorder,
FAR char *parg)
{
int ret;
char path[32];
@ -307,7 +319,8 @@ static int nxrecorder_cmd_device(FAR struct nxrecorder_s *pRecorder, char *parg)
* nxrecorder_cmd_quit() terminates the application
****************************************************************************/
static int nxrecorder_cmd_quit(FAR struct nxrecorder_s *pRecorder, char *parg)
static int nxrecorder_cmd_quit(FAR struct nxrecorder_s *pRecorder,
FAR char *parg)
{
/* Stop the record if any */
@ -326,16 +339,20 @@ static int nxrecorder_cmd_quit(FAR struct nxrecorder_s *pRecorder, char *parg)
****************************************************************************/
#ifdef CONFIG_NXRECORDER_INCLUDE_HELP
static int nxrecorder_cmd_help(FAR struct nxrecorder_s *pRecorder, char *parg)
static int nxrecorder_cmd_help(FAR struct nxrecorder_s *pRecorder,
FAR char *parg)
{
int x, len, maxlen = 0;
int len;
int maxlen = 0;
int x;
int c;
/* Calculate length of longest cmd + arghelp */
for (x = 0; x < g_nxrecorder_cmd_count; x++)
{
len = strlen(g_nxrecorder_cmds[x].cmd) + strlen(g_nxrecorder_cmds[x].arghelp);
len = strlen(g_nxrecorder_cmds[x].cmd) +
strlen(g_nxrecorder_cmds[x].arghelp);
if (len > maxlen)
{
maxlen = len;
@ -347,11 +364,13 @@ static int nxrecorder_cmd_help(FAR struct nxrecorder_s *pRecorder, char *parg)
{
/* Print the command and it's arguments */
printf(" %s %s", g_nxrecorder_cmds[x].cmd, g_nxrecorder_cmds[x].arghelp);
printf(" %s %s",
g_nxrecorder_cmds[x].cmd, g_nxrecorder_cmds[x].arghelp);
/* Calculate number of spaces to print before the help text */
len = maxlen - (strlen(g_nxrecorder_cmds[x].cmd) + strlen(g_nxrecorder_cmds[x].arghelp));
len = maxlen - (strlen(g_nxrecorder_cmds[x].cmd) +
strlen(g_nxrecorder_cmds[x].arghelp));
for (c = 0; c < len; c++)
{
printf(" ");
@ -374,8 +393,8 @@ static int nxrecorder_cmd_help(FAR struct nxrecorder_s *pRecorder, char *parg)
* nxrecorder() reads in commands from the console using the readline
* system add-in and implemets a command-line based pcm raw data recorder
* that uses the NuttX audio system to record pcm raw data files read in
* from the audio device. Commands are provided for setting volume, base and
* other audio features, as well as for pausing and stopping the
* from the audio device. Commands are provided for setting volume, base
* and other audio features, as well as for pausing and stopping the
* record.
*
* Input Parameters:
@ -393,9 +412,12 @@ static int nxrecorder_cmd_help(FAR struct nxrecorder_s *pRecorder, char *parg)
int main(int argc, FAR char *argv[])
{
char buffer[64];
int len, x, running;
char *cmd, *arg;
char buffer[CONFIG_NSH_LINELEN];
int len;
int x;
int running;
char *cmd;
char *arg;
FAR struct nxrecorder_s *pRecorder;
printf("NxRecorder version " NXRECORDER_VER "\n");
@ -427,55 +449,63 @@ int main(int argc, FAR char *argv[])
buffer[len] = '\0';
if (len > 0)
{
if (buffer[len-1] == '\n')
if (strncmp(buffer, "!", 1) != 0)
{
buffer[len-1] = '\0';
}
/* nxrecorder command */
/* Parse the command from the argument */
cmd = strtok_r(buffer, " \n", &arg);
if (cmd == NULL)
{
continue;
}
/* Remove leading spaces from arg */
while (*arg == ' ')
{
arg++;
}
/* Find the command in our cmd array */
for (x = 0; x < g_nxrecorder_cmd_count; x++)
{
if (strcmp(cmd, g_nxrecorder_cmds[x].cmd) == 0)
if (buffer[len - 1] == '\n')
{
/* Command found. Call it's handler if not NULL */
buffer[len - 1] = '\0';
}
if (g_nxrecorder_cmds[x].pFunc != NULL)
/* Parse the command from the argument */
cmd = strtok_r(buffer, " \n", &arg);
if (cmd == NULL)
{
continue;
}
/* Remove leading spaces from arg */
while (*arg == ' ')
{
arg++;
}
/* Find the command in our cmd array */
for (x = 0; x < g_nxrecorder_cmd_count; x++)
{
if (strcmp(cmd, g_nxrecorder_cmds[x].cmd) == 0)
{
g_nxrecorder_cmds[x].pFunc(pRecorder, arg);
/* Command found. Call it's handler if not NULL */
if (g_nxrecorder_cmds[x].pFunc != NULL)
{
g_nxrecorder_cmds[x].pFunc(pRecorder, arg);
}
/* Test if it is a quit command */
if (g_nxrecorder_cmds[x].pFunc == nxrecorder_cmd_quit)
{
running = FALSE;
}
break;
}
/* Test if it is a quit command */
if (g_nxrecorder_cmds[x].pFunc == nxrecorder_cmd_quit)
{
running = FALSE;
}
break;
}
}
/* Test for Unknown command */
if (x == g_nxrecorder_cmd_count)
else
{
printf("%s: unknown nxrecorder command\n", buffer);
#ifdef CONFIG_SYSTEM_SYSTEM
/* Transfer nuttx shell */
system(buffer + 1);
#else
printf("%s: unknown nxplayer command\n", buffer);
#endif
}
}
}