RIOT/sys/shell/commands/sc_rtc.c
René Kijewski c507632e50 Use argc and argv in shell handlers
Compare #708.

Now the tokenization of an input line is done by the shell itself. You
may quote arguments with `"..."`. Empty arguments, supplied by `""` are
preserved. Spaces in between arguments are squasheds; spaces inside
quotes are preserved.

You cannot partially quote an argument. You must not use
- `cmd "abc`,
- `cmd abc"def"`, or
- `cmd "abc"def`.
2014-02-25 17:54:17 +01:00

71 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. 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 *c)
{
struct tm now;
int res;
uint16_t month, epoch_year;
res = sscanf(c, "%hu-%hu-%u %u:%u:%u",
&epoch_year,
&month,
(unsigned int *) &(now.tm_mday),
(unsigned int *) &(now.tm_hour),
(unsigned int *) &(now.tm_min),
(unsigned int *) &(now.tm_sec));
if (res < 6) {
printf("Usage: date YYYY-MM-DD hh:mm:ss\n");
return;
}
else {
puts("OK");
}
now.tm_year = epoch_year - 1900;
now.tm_mon = month - 1;
rtc_set_localtime(&now);
}
void _date_handler(int argc, char **argv)
{
if (argc == 1) {
_gettime_handler();
}
else {
_settime_handler(argv[1]);
}
}
#endif