Allow NSH date command with no RTC. This command is useful without an RTC too. Also, this permits testing on the simulator which never has an RTC

This commit is contained in:
Gregory Nutt 2015-04-11 12:13:18 -06:00
parent c341e06e84
commit 23075e0b30
8 changed files with 25 additions and 21 deletions

View File

@ -179,8 +179,8 @@ config NSH_DISABLE_CMP
config NSH_DISABLE_DATE config NSH_DISABLE_DATE
bool "Disable date" bool "Disable date"
default n default n if RTC
depends on RTC default y if !RTC
config NSH_DISABLE_DD config NSH_DISABLE_DD
bool "Disable dd" bool "Disable dd"

View File

@ -42,7 +42,7 @@ include $(APPDIR)/Make.defs
ASRCS = ASRCS =
CSRCS = nsh_init.c nsh_parse.c nsh_console.c nsh_script.c CSRCS = nsh_init.c nsh_parse.c nsh_console.c nsh_script.c
CSRCS += nsh_command.c nsh_fscmds.c nsh_ddcmd.c nsh_proccmds.c nsh_mmcmds.c CSRCS += nsh_command.c nsh_fscmds.c nsh_ddcmd.c nsh_proccmds.c nsh_mmcmds.c
CSRCS += nsh_envcmds.c nsh_dbgcmds.c CSRCS += nsh_timcmds.c nsh_envcmds.c nsh_dbgcmds.c
ifeq ($(CONFIG_NFILE_STREAMS),0) ifeq ($(CONFIG_NFILE_STREAMS),0)
CSRCS += nsh_stdsession.c CSRCS += nsh_stdsession.c
@ -69,10 +69,6 @@ CSRCS += nsh_routecmds.c
endif endif
endif endif
ifeq ($(CONFIG_RTC),y)
CSRCS += nsh_timcmds.c
endif
ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y) ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y)
CSRCS += nsh_mntcmds.c CSRCS += nsh_mntcmds.c
endif endif

View File

@ -343,8 +343,7 @@ o cp <source-path> <dest-path>
o date [-s "MMM DD HH:MM:SS YYYY"] o date [-s "MMM DD HH:MM:SS YYYY"]
Show or set the current date and time. This command is only supported Show or set the current date and time.
if the platform supported RTC hardware (CONFIG_RTC=y).
Only one format is used both on display and when setting the date/time: Only one format is used both on display and when setting the date/time:
MMM DD HH:MM:SS YYYY. For example, MMM DD HH:MM:SS YYYY. For example,

View File

@ -848,7 +848,7 @@ void nsh_usbtrace(void);
int cmd_lbracket(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); int cmd_lbracket(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
#endif #endif
#if defined (CONFIG_RTC) && !defined(CONFIG_NSH_DISABLE_DATE) #ifndef CONFIG_NSH_DISABLE_DATE
int cmd_date(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); int cmd_date(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
#endif #endif

View File

@ -140,7 +140,7 @@ static const struct cmdmap_s g_cmdmap[] =
# endif # endif
#endif #endif
#if defined (CONFIG_RTC) && !defined(CONFIG_NSH_DISABLE_DATE) #ifndef CONFIG_NSH_DISABLE_DATE
{ "date", cmd_date, 1, 3, "[-s \"MMM DD HH:MM:SS YYYY\"]" }, { "date", cmd_date, 1, 3, "[-s \"MMM DD HH:MM:SS YYYY\"]" },
#endif #endif

View File

@ -240,7 +240,7 @@ static inline int ls_specialdir(const char *dir)
static int ls_handler(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath, static int ls_handler(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath,
FAR struct dirent *entryp, FAR void *pvarg) FAR struct dirent *entryp, FAR void *pvarg)
{ {
unsigned int lsflags = (unsigned int)pvarg; unsigned int lsflags = (unsigned int)((uintptr_t)pvarg);
int ret; int ret;
/* Check if any options will require that we stat the file */ /* Check if any options will require that we stat the file */
@ -995,19 +995,22 @@ int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
* file * file
*/ */
ret = ls_handler(vtbl, fullpath, NULL, (void*)lsflags); ret = ls_handler(vtbl, fullpath, NULL, (FAR void *)((uintptr_t)lsflags));
} }
else else
{ {
/* List the directory contents */ /* List the directory contents */
nsh_output(vtbl, "%s:\n", fullpath); nsh_output(vtbl, "%s:\n", fullpath);
ret = foreach_direntry(vtbl, "ls", fullpath, ls_handler, (void*)lsflags);
ret = foreach_direntry(vtbl, "ls", fullpath, ls_handler,
(FAR void*)((uintptr_t)lsflags));
if (ret == OK && (lsflags & LSFLAGS_RECURSIVE) != 0) if (ret == OK && (lsflags & LSFLAGS_RECURSIVE) != 0)
{ {
/* Then recurse to list each directory within the directory */ /* Then recurse to list each directory within the directory */
ret = foreach_direntry(vtbl, "ls", fullpath, ls_recursive, (void*)lsflags); ret = foreach_direntry(vtbl, "ls", fullpath, ls_recursive,
(FAR void *)((uintptr_t)lsflags));
} }
} }

View File

@ -365,7 +365,7 @@ static pthread_addr_t nsh_child(pthread_addr_t arg)
dbg("BG %s complete\n", carg->argv[0]); dbg("BG %s complete\n", carg->argv[0]);
nsh_releaseargs(carg); nsh_releaseargs(carg);
return (void*)ret; return (pthread_addr_t)((uintptr_t)ret);
} }
#endif #endif

View File

@ -65,7 +65,7 @@
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
#if defined (CONFIG_RTC) && !defined(CONFIG_NSH_DISABLE_DATE) #ifndef CONFIG_NSH_DISABLE_DATE
static FAR const char * const g_datemontab[] = static FAR const char * const g_datemontab[] =
{ {
"jan", "feb", "mar", "apr", "may", "jun", "jan", "feb", "mar", "apr", "may", "jun",
@ -85,7 +85,7 @@ static FAR const char * const g_datemontab[] =
* Name: date_month * Name: date_month
****************************************************************************/ ****************************************************************************/
#if defined (CONFIG_RTC) && !defined(CONFIG_NSH_DISABLE_DATE) #ifndef CONFIG_NSH_DISABLE_DATE
static inline int date_month(FAR const char *abbrev) static inline int date_month(FAR const char *abbrev)
{ {
int i; int i;
@ -105,7 +105,7 @@ static inline int date_month(FAR const char *abbrev)
* Name: date_gettime * Name: date_gettime
****************************************************************************/ ****************************************************************************/
#if defined (CONFIG_RTC) && !defined(CONFIG_NSH_DISABLE_DATE) #ifndef CONFIG_NSH_DISABLE_DATE
static inline int date_showtime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name) static inline int date_showtime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name)
{ {
static const char format[] = "%b %d %H:%M:%S %Y"; static const char format[] = "%b %d %H:%M:%S %Y";
@ -139,7 +139,7 @@ static inline int date_showtime(FAR struct nsh_vtbl_s *vtbl, FAR const char *nam
* Name: date_settime * Name: date_settime
****************************************************************************/ ****************************************************************************/
#if defined (CONFIG_RTC) && !defined(CONFIG_NSH_DISABLE_DATE) #ifndef CONFIG_NSH_DISABLE_DATE
static inline int date_settime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name, static inline int date_settime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name,
FAR char *newtime) FAR char *newtime)
{ {
@ -178,6 +178,7 @@ static inline int date_settime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name
{ {
goto errout_bad_parm; goto errout_bad_parm;
} }
tm.tm_mday = (int)result; tm.tm_mday = (int)result;
/* Get the hours */ /* Get the hours */
@ -193,6 +194,7 @@ static inline int date_settime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name
{ {
goto errout_bad_parm; goto errout_bad_parm;
} }
tm.tm_hour = (int)result; tm.tm_hour = (int)result;
/* Get the minutes */ /* Get the minutes */
@ -208,6 +210,7 @@ static inline int date_settime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name
{ {
goto errout_bad_parm; goto errout_bad_parm;
} }
tm.tm_min = (int)result; tm.tm_min = (int)result;
/* Get the seconds */ /* Get the seconds */
@ -223,6 +226,7 @@ static inline int date_settime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name
{ {
goto errout_bad_parm; goto errout_bad_parm;
} }
tm.tm_sec = (int)result; tm.tm_sec = (int)result;
/* And finally the year */ /* And finally the year */
@ -238,6 +242,7 @@ static inline int date_settime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name
{ {
goto errout_bad_parm; goto errout_bad_parm;
} }
tm.tm_year = (int)result - 1900; tm.tm_year = (int)result - 1900;
/* Convert this to the right form, then set the timer */ /* Convert this to the right form, then set the timer */
@ -251,6 +256,7 @@ static inline int date_settime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name
nsh_output(vtbl, g_fmtcmdfailed, name, "clock_settime", NSH_ERRNO); nsh_output(vtbl, g_fmtcmdfailed, name, "clock_settime", NSH_ERRNO);
return ERROR; return ERROR;
} }
return OK; return OK;
errout_bad_parm: errout_bad_parm:
@ -267,7 +273,7 @@ errout_bad_parm:
* Name: cmd_date * Name: cmd_date
****************************************************************************/ ****************************************************************************/
#if defined (CONFIG_RTC) && !defined(CONFIG_NSH_DISABLE_DATE) #ifndef CONFIG_NSH_DISABLE_DATE
int cmd_date(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) int cmd_date(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{ {
FAR char *newtime = NULL; FAR char *newtime = NULL;