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
2014-09-19 23:31:26 +02:00

75 lines
1.4 KiB
C

/**
* Shell commands for real time clock
*
* Copyright (C) 2013 INRIA.
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. 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
#include "rtc.h"
static void _gettime_handler(void)
{
struct tm now;
rtc_get_localtime(&now);
printf("%s", asctime(&now));
}
static void _settime_handler(char **argv)
{
do {
short i1, i2, i3;
int res = sscanf(argv[1], "%6hd-%6hd-%6hd", &i1, &i2, &i3);
if (res != 3) {
break;
}
struct tm now;
now.tm_year = i1 - 1900;
now.tm_mon = i2 - 1;
now.tm_mday = i3;
res = sscanf(argv[2], "%6hd:%6hd:%6hd", &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");
return;
} while (0);
printf("Usage: %s YYYY-MM-DD hh:mm:ss\n", argv[0]);
}
void _date_handler(int argc, char **argv)
{
if (argc != 3) {
_gettime_handler();
}
else {
_settime_handler(argv);
}
}
#endif