1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/sys/shell/commands/sc_rtc.c

75 lines
1.4 KiB
C
Raw Normal View History

/**
* Shell commands for real time clock
*
* 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
* Public License. See the file LICENSE in the top level directory for more
* details.
*
* @ingroup shell_commands
* @{
* @file sc_rtc.c
* @brief provides shell commands to access the rtc
* @author Oliver Hahm <oliver.hahm@inria.fr>
* @}
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#ifdef MODULE_RTC
2013-12-16 17:54:58 +01:00
#include "rtc.h"
static void _gettime_handler(void)
{
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)
{
struct tm now;
2014-02-26 14:08:54 +01:00
short i1, i2, i3;
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;
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);
puts("OK");
2014-02-26 14:08:54 +01:00
return;
} while (0);
2014-02-26 14:08:54 +01:00
printf("Usage: %s YYYY-MM-DD hh:mm:ss\n", argv[0]);
}
void _date_handler(int argc, char **argv)
{
2014-02-26 14:08:54 +01:00
if (argc != 3) {
_gettime_handler();
}
else {
2014-02-26 14:08:54 +01:00
_settime_handler(argv);
}
}
#endif