X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/e63b2f75607905fedf00cfd9fe644b26af715ffd..910e72069ea19a79e06e7146a5e42d0bb05a9c2f:/avr/cmd_date.c diff --git a/avr/cmd_date.c b/avr/cmd_date.c index 3beebee..3e2e016 100644 --- a/avr/cmd_date.c +++ b/avr/cmd_date.c @@ -1,4 +1,6 @@ /* + * (C) Copyright 2014 Leo C. + * * (C) Copyright 2001 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * @@ -127,16 +129,18 @@ command_ret_t do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { struct tm t; char buf[30]; - int rcode = CMD_RET_SUCCESS; + int rc; + command_ret_t rcode = CMD_RET_FAILURE; (void) cmdtp; (void) flag; switch (argc) { case 2: /* set date & time */ /* initialize t with current time */ - rcode = rtc_get (&t); - - if(!rcode) { + if(rtc_get(&t) < 0) { + my_puts_P(PSTR("## Get date failed\n")); + break; + } else { /* insert new date & time */ if (mk_date (argv[1], &t) != 0) { my_puts_P(PSTR("## Bad date format\n")); @@ -148,22 +152,24 @@ command_ret_t do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) gmtime_r(&time, &t); /* and write to RTC */ - rcode = rtc_set (&t); - if(rcode) + if(rtc_set(&t) < 0) { my_puts_P(PSTR("## Set date failed\n")); - } else { - my_puts_P(PSTR("## Get date failed\n")); + break; + } } /* FALL TROUGH */ case 1: /* get date & time */ - rcode = rtc_get (&t); - - if (rcode) { + rc = rtc_get(&t); + if (rc >= 0) { + asctime_r(&t, buf); + printf_P(PSTR("%s"), buf); + if (rc == 1) + printf_P(PSTR(" (Invalid)")); + putchar('\n'); + rcode = CMD_RET_SUCCESS; + } else { my_puts_P(PSTR("## Get date failed\n")); - break; } - asctime_r(&t, buf); - printf_P(PSTR("%s\n"), buf); break; default: