2013-06-22 05:11:53 +02:00
|
|
|
/**
|
2014-02-11 18:15:43 +01:00
|
|
|
* Shell commands for real time clock
|
2013-06-22 05:11:53 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2013 INRIA.
|
|
|
|
*
|
2013-11-22 20:47:05 +01:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser General
|
2013-06-22 05:11:53 +02:00
|
|
|
* Public License. See the file LICENSE in the top level directory for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* @ingroup shell_commands
|
|
|
|
* @{
|
|
|
|
* @file sc_rtc.c
|
2014-02-11 18:15:43 +01:00
|
|
|
* @brief provides shell commands to access the rtc
|
2013-06-22 05:11:53 +02:00
|
|
|
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2010-11-04 18:16:39 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
2010-12-03 22:22:58 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#ifdef MODULE_RTC
|
2013-12-16 17:54:58 +01:00
|
|
|
#include "rtc.h"
|
2010-11-04 18:16:39 +01:00
|
|
|
|
2014-02-21 19:10:24 +01:00
|
|
|
static void _gettime_handler(void)
|
2013-06-22 05:11:53 +02:00
|
|
|
{
|
2010-11-04 18:16:39 +01:00
|
|
|
struct tm now;
|
|
|
|
rtc_get_localtime(&now);
|
|
|
|
|
|
|
|
printf("%s", asctime(&now));
|
|
|
|
}
|
|
|
|
|
2014-02-26 14:08:54 +01:00
|
|
|
static void _settime_handler(char **argv)
|
2013-06-22 05:11:53 +02:00
|
|
|
{
|
2010-11-04 18:16:39 +01:00
|
|
|
struct tm now;
|
2014-02-26 14:08:54 +01:00
|
|
|
short i1, i2, i3;
|
2010-11-04 18:16:39 +01:00
|
|
|
int res;
|
|
|
|
|
2014-02-26 14:08:54 +01:00
|
|
|
do {
|
|
|
|
res = sscanf(argv[1], "%hd-%hd-%hd", &i1, &i2, &i3);
|
|
|
|
if (res != 3) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
now.tm_year = i1 - 1900;
|
|
|
|
now.tm_mon = i2 - 1;
|
|
|
|
now.tm_mday = i3;
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2014-02-26 14:08:54 +01:00
|
|
|
res = sscanf(argv[2], "%hd:%hd:%hd", &i1, &i2, &i3);
|
|
|
|
if (res != 3) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
now.tm_hour = i1;
|
|
|
|
now.tm_min = i2;
|
|
|
|
now.tm_sec = i3;
|
|
|
|
|
|
|
|
rtc_set_localtime(&now);
|
2010-11-05 19:33:45 +01:00
|
|
|
puts("OK");
|
2014-02-26 14:08:54 +01:00
|
|
|
return;
|
|
|
|
} while (0);
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2014-02-26 14:08:54 +01:00
|
|
|
printf("Usage: %s YYYY-MM-DD hh:mm:ss\n", argv[0]);
|
2010-11-04 18:16:39 +01:00
|
|
|
}
|
|
|
|
|
2014-02-21 19:10:24 +01:00
|
|
|
void _date_handler(int argc, char **argv)
|
2013-06-22 05:11:53 +02:00
|
|
|
{
|
2014-02-26 14:08:54 +01:00
|
|
|
if (argc != 3) {
|
2013-06-22 05:11:53 +02:00
|
|
|
_gettime_handler();
|
|
|
|
}
|
|
|
|
else {
|
2014-02-26 14:08:54 +01:00
|
|
|
_settime_handler(argv);
|
2013-06-22 05:11:53 +02:00
|
|
|
}
|
2010-11-05 19:33:45 +01:00
|
|
|
}
|
2010-12-03 22:22:58 +01:00
|
|
|
|
|
|
|
#endif
|