diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2015-04-11 12:13:18 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2015-04-11 12:13:18 -0600 |
commit | 03a22b61713b49d36b355c2f286cdfd58739bec5 (patch) | |
tree | 9eb46bda1662f9d6a9f81e4eefdb45c0e369ed52 | |
parent | b80e8be652dfa52e97daa65aa3e550cf31cb2409 (diff) | |
download | px4-nuttx-03a22b61713b49d36b355c2f286cdfd58739bec5.tar.gz px4-nuttx-03a22b61713b49d36b355c2f286cdfd58739bec5.tar.bz2 px4-nuttx-03a22b61713b49d36b355c2f286cdfd58739bec5.zip |
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
-rw-r--r-- | apps/nshlib/Kconfig | 4 | ||||
-rw-r--r-- | apps/nshlib/Makefile | 6 | ||||
-rw-r--r-- | apps/nshlib/README.txt | 3 | ||||
-rw-r--r-- | apps/nshlib/nsh.h | 2 | ||||
-rw-r--r-- | apps/nshlib/nsh_command.c | 2 | ||||
-rw-r--r-- | apps/nshlib/nsh_fscmds.c | 11 | ||||
-rw-r--r-- | apps/nshlib/nsh_parse.c | 2 | ||||
-rw-r--r-- | apps/nshlib/nsh_timcmds.c | 16 | ||||
-rw-r--r-- | nuttx/Documentation/NuttShell.html | 5 | ||||
-rw-r--r-- | nuttx/libc/Kconfig | 1 | ||||
-rw-r--r-- | nuttx/libc/time/lib_localtime.c | 2 |
11 files changed, 30 insertions, 24 deletions
diff --git a/apps/nshlib/Kconfig b/apps/nshlib/Kconfig index 45f56be29..b60bd08ae 100644 --- a/apps/nshlib/Kconfig +++ b/apps/nshlib/Kconfig @@ -179,8 +179,8 @@ config NSH_DISABLE_CMP config NSH_DISABLE_DATE bool "Disable date" - default n - depends on RTC + default n if RTC + default y if !RTC config NSH_DISABLE_DD bool "Disable dd" diff --git a/apps/nshlib/Makefile b/apps/nshlib/Makefile index 9f2e504bc..69f2f0a18 100644 --- a/apps/nshlib/Makefile +++ b/apps/nshlib/Makefile @@ -42,7 +42,7 @@ include $(APPDIR)/Make.defs ASRCS = 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_envcmds.c nsh_dbgcmds.c +CSRCS += nsh_timcmds.c nsh_envcmds.c nsh_dbgcmds.c ifeq ($(CONFIG_NFILE_STREAMS),0) CSRCS += nsh_stdsession.c @@ -69,10 +69,6 @@ CSRCS += nsh_routecmds.c endif endif -ifeq ($(CONFIG_RTC),y) -CSRCS += nsh_timcmds.c -endif - ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y) CSRCS += nsh_mntcmds.c endif diff --git a/apps/nshlib/README.txt b/apps/nshlib/README.txt index 9da35acff..275f15185 100644 --- a/apps/nshlib/README.txt +++ b/apps/nshlib/README.txt @@ -343,8 +343,7 @@ o cp <source-path> <dest-path> o date [-s "MMM DD HH:MM:SS YYYY"] - Show or set the current date and time. This command is only supported - if the platform supported RTC hardware (CONFIG_RTC=y). + Show or set the current date and time. Only one format is used both on display and when setting the date/time: MMM DD HH:MM:SS YYYY. For example, diff --git a/apps/nshlib/nsh.h b/apps/nshlib/nsh.h index 4d612a490..1a544429b 100644 --- a/apps/nshlib/nsh.h +++ b/apps/nshlib/nsh.h @@ -848,7 +848,7 @@ void nsh_usbtrace(void); int cmd_lbracket(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #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); #endif diff --git a/apps/nshlib/nsh_command.c b/apps/nshlib/nsh_command.c index fa8efa9c5..edc858e09 100644 --- a/apps/nshlib/nsh_command.c +++ b/apps/nshlib/nsh_command.c @@ -140,7 +140,7 @@ static const struct cmdmap_s g_cmdmap[] = # 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\"]" }, #endif diff --git a/apps/nshlib/nsh_fscmds.c b/apps/nshlib/nsh_fscmds.c index 3900fc64a..06947acc7 100644 --- a/apps/nshlib/nsh_fscmds.c +++ b/apps/nshlib/nsh_fscmds.c @@ -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, FAR struct dirent *entryp, FAR void *pvarg) { - unsigned int lsflags = (unsigned int)pvarg; + unsigned int lsflags = (unsigned int)((uintptr_t)pvarg); int ret; /* 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 */ - ret = ls_handler(vtbl, fullpath, NULL, (void*)lsflags); + ret = ls_handler(vtbl, fullpath, NULL, (FAR void *)((uintptr_t)lsflags)); } else { /* List the directory contents */ 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) { /* 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)); } } diff --git a/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c index a7a35e8f2..e9d3aef97 100644 --- a/apps/nshlib/nsh_parse.c +++ b/apps/nshlib/nsh_parse.c @@ -365,7 +365,7 @@ static pthread_addr_t nsh_child(pthread_addr_t arg) dbg("BG %s complete\n", carg->argv[0]); nsh_releaseargs(carg); - return (void*)ret; + return (pthread_addr_t)((uintptr_t)ret); } #endif diff --git a/apps/nshlib/nsh_timcmds.c b/apps/nshlib/nsh_timcmds.c index 3fa1a06b6..992cd8ecb 100644 --- a/apps/nshlib/nsh_timcmds.c +++ b/apps/nshlib/nsh_timcmds.c @@ -65,7 +65,7 @@ * Private Data ****************************************************************************/ -#if defined (CONFIG_RTC) && !defined(CONFIG_NSH_DISABLE_DATE) +#ifndef CONFIG_NSH_DISABLE_DATE static FAR const char * const g_datemontab[] = { "jan", "feb", "mar", "apr", "may", "jun", @@ -85,7 +85,7 @@ static FAR const char * const g_datemontab[] = * 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) { int i; @@ -105,7 +105,7 @@ static inline int date_month(FAR const char *abbrev) * 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 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 ****************************************************************************/ -#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, 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; } + tm.tm_mday = (int)result; /* 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; } + tm.tm_hour = (int)result; /* 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; } + tm.tm_min = (int)result; /* 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; } + tm.tm_sec = (int)result; /* 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; } + tm.tm_year = (int)result - 1900; /* 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); return ERROR; } + return OK; errout_bad_parm: @@ -267,7 +273,7 @@ errout_bad_parm: * 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) { FAR char *newtime = NULL; diff --git a/nuttx/Documentation/NuttShell.html b/nuttx/Documentation/NuttShell.html index ff55c0655..244a7889a 100644 --- a/nuttx/Documentation/NuttShell.html +++ b/nuttx/Documentation/NuttShell.html @@ -8,7 +8,7 @@ <tr align="center" bgcolor="#e4e4e4"> <td> <h1><big><font color="#3c34ec"><i>NuttShell (NSH)</i></font></big></h1> - <p>Last Updated: August 7, 2014</p> + <p>Last Updated: April 11, 2015</p> </td> </tr> </table> @@ -1181,7 +1181,6 @@ date [-s "MMM DD HH:MM:SS YYYY"] <p> <b>Synopsis</b>. Show or set the current date and time. - This command is only supported if the platform supported RTC hardware (<code>CONFIG_RTC=y</code>). </p> <p> Only one format is used both on display and when setting the date/time: @@ -2568,7 +2567,7 @@ nsh> </tr> <tr> <td><b><code>date</code></b></td> - <td><code>CONFIG_RTC</code></td> + <td><br></td> <td><code>CONFIG_NSH_DISABLE_DATE</code></td> </tr> <tr> diff --git a/nuttx/libc/Kconfig b/nuttx/libc/Kconfig index 967a9f4d4..0ee8e6b5a 100644 --- a/nuttx/libc/Kconfig +++ b/nuttx/libc/Kconfig @@ -288,6 +288,7 @@ endif config TIME_EXTENDED bool "Add day of week, year support" default "n" + depends on !LIBC_LOCALTIME ---help--- Selecting TIME_EXTENDED adds tm_wday, tm_yday and tm_isdst to the tm struct. This allows integration with 3rd party libraries diff --git a/nuttx/libc/time/lib_localtime.c b/nuttx/libc/time/lib_localtime.c index 26f0c17ce..646b3e6df 100644 --- a/nuttx/libc/time/lib_localtime.c +++ b/nuttx/libc/time/lib_localtime.c @@ -2158,6 +2158,7 @@ static time_t time2sub(struct tm *const tmp, li = y + (1 < yourtm.tm_mon); yourtm.tm_mday += year_lengths[isleap(li)]; } + while (yourtm.tm_mday > DAYSPERLYEAR) { li = y + (1 < yourtm.tm_mon); @@ -2167,6 +2168,7 @@ static time_t time2sub(struct tm *const tmp, return -1; } } + for (;;) { i = mon_lengths[isleap(y)][yourtm.tm_mon]; |