diff options
Diffstat (limited to 'main/common/date.c')
-rw-r--r-- | main/common/date.c | 181 |
1 files changed, 91 insertions, 90 deletions
diff --git a/main/common/date.c b/main/common/date.c index f7d56b0..e695908 100644 --- a/main/common/date.c +++ b/main/common/date.c @@ -1,7 +1,7 @@ /************************************************************************** * * Copyright (c) 2013 Alcatel-Lucent - * + * * Alcatel Lucent licenses this file to You under the Apache License, * Version 2.0 (the "License"); you may not use this file except in * compliance with the License. A copy of the License is contained the @@ -25,8 +25,8 @@ * be moved to the dev directory (if not already there). * This code expects a few HW-specific functions to be available... * - * getTimeAndDate(struct todinfo *); - * setTimeAndDate(struct todinfo *); + * getTimeAndDate(struct todinfo *); + * setTimeAndDate(struct todinfo *); * * If setTimeAndDate() is passed '0', then it is this code's attempt * to disable the TOD oscillator (to reduce battery drain). @@ -42,119 +42,120 @@ #include "date.h" /* rangecheck(): - Return 0 if value is outside the range of high and low; else 1. + Return 0 if value is outside the range of high and low; else 1. */ static int rangecheck(int value, char *name, int low, int high) { - if ((value < low) || (value > high)) { - printf("%s outside valid range of %d - %d\n", - name,low,high); - return(0); - } - return(1); + if((value < low) || (value > high)) { + printf("%s outside valid range of %d - %d\n", + name,low,high); + return(0); + } + return(1); } int showDate(int center) { - int (*pfunc)(char *, ...); - struct todinfo now; + int (*pfunc)(char *, ...); + struct todinfo now; - getTimeAndDate(&now); + getTimeAndDate(&now); - if (center) - pfunc = cprintf; - else - pfunc = printf; + if(center) { + pfunc = cprintf; + } else { + pfunc = printf; + } - pfunc("%02d/%02d/%04d @ %02d:%02d:%02d\n", - now.month,now.date,now.year, - now.hour,now.minute,now.second); + pfunc("%02d/%02d/%04d @ %02d:%02d:%02d\n", + now.month,now.date,now.year, + now.hour,now.minute,now.second); - return(0); + return(0); } char *DateHelp[] = { - "Display (mm/dd/yyyy@hh:mm:ss) or modify time and date.", - "[{day date month year hour min sec}]", + "Display (mm/dd/yyyy@hh:mm:ss) or modify time and date.", + "[{day date month year hour min sec}]", #if INCLUDE_VERBOSEHELP - "Where...", - " day: 1-7 (sun=1)", - " date: 1-31", - " month: 1-12", - " year: full number (i.e. 2006)", - " hour: 0-23", - " min: 0-59", - " sec: 0-59", - "Note: 'date off' disables the oscillator (if HW supports this)", + "Where...", + " day: 1-7 (sun=1)", + " date: 1-31", + " month: 1-12", + " year: full number (i.e. 2006)", + " hour: 0-23", + " min: 0-59", + " sec: 0-59", + "Note: 'date off' disables the oscillator (if HW supports this)", #endif - 0 + 0 }; int DateCmd(int argc,char *argv[]) { - int rngchk; - struct todinfo now; - - if (argc == 1) { - showDate(0); - return(CMD_SUCCESS); - } - else if ((argc == 2) && !strcmp(argv[1],"off")) { - if (setTimeAndDate(0) < 0) { - printf("Clock can't be disabled\n"); - return(CMD_FAILURE); - } - return(CMD_SUCCESS); - } - else if (argc != 8) - return(CMD_PARAM_ERROR); - - now.day = (char)atoi(argv[1]); - now.date = (char)atoi(argv[2]); - now.month = (char)atoi(argv[3]); - now.year = atoi(argv[4]); - now.hour = (char)atoi(argv[5]); - now.minute = (char)atoi(argv[6]); - now.second = (char)atoi(argv[7]); - - rngchk = 0; - rngchk += rangecheck(now.day,"day",1,7); - rngchk += rangecheck(now.date,"date",1,31); - rngchk += rangecheck(now.month,"month",1,12); - rngchk += rangecheck(now.year,"year",0,9999); - rngchk += rangecheck(now.hour,"hour",0,23); - rngchk += rangecheck(now.minute,"minute",0,59); - rngchk += rangecheck(now.second,"second",0,59); - - if (rngchk != 7) - return(CMD_PARAM_ERROR); - - setTimeAndDate(&now); - return(CMD_SUCCESS); + int rngchk; + struct todinfo now; + + if(argc == 1) { + showDate(0); + return(CMD_SUCCESS); + } else if((argc == 2) && !strcmp(argv[1],"off")) { + if(setTimeAndDate(0) < 0) { + printf("Clock can't be disabled\n"); + return(CMD_FAILURE); + } + return(CMD_SUCCESS); + } else if(argc != 8) { + return(CMD_PARAM_ERROR); + } + + now.day = (char)atoi(argv[1]); + now.date = (char)atoi(argv[2]); + now.month = (char)atoi(argv[3]); + now.year = atoi(argv[4]); + now.hour = (char)atoi(argv[5]); + now.minute = (char)atoi(argv[6]); + now.second = (char)atoi(argv[7]); + + rngchk = 0; + rngchk += rangecheck(now.day,"day",1,7); + rngchk += rangecheck(now.date,"date",1,31); + rngchk += rangecheck(now.month,"month",1,12); + rngchk += rangecheck(now.year,"year",0,9999); + rngchk += rangecheck(now.hour,"hour",0,23); + rngchk += rangecheck(now.minute,"minute",0,59); + rngchk += rangecheck(now.second,"second",0,59); + + if(rngchk != 7) { + return(CMD_PARAM_ERROR); + } + + setTimeAndDate(&now); + return(CMD_SUCCESS); } int timeofday(int cmd, void *arg) { - int rc; - struct todinfo *now; - - rc = 0; - now = (struct todinfo *)arg; - - switch(cmd) { - case TOD_ON: - case TOD_OFF: - break; - case TOD_SET: - rc = setTimeAndDate(now); - break; - case TOD_GET: - rc = getTimeAndDate(now); - break; - } - return(rc); + int rc; + struct todinfo *now; + + rc = 0; + now = (struct todinfo *)arg; + + switch(cmd) { + case TOD_ON: + case TOD_OFF: + break; + case TOD_SET: + rc = setTimeAndDate(now); + break; + case TOD_GET: + rc = getTimeAndDate(now); + break; + } + return(rc); } |