shell: rtc: add commands to get and set the date

This commit is contained in:
S.J.R. van Schaik 2017-07-27 10:39:47 +02:00
parent 161acf1731
commit acdc364fab
2 changed files with 57 additions and 0 deletions

View file

@ -44,6 +44,7 @@ obj-y += source/shell/cmd.o
obj-y += source/shell/flash.o
obj-y += source/shell/ftl.o
obj-y += source/shell/mufs.o
obj-y += source/shell/rtc.o
obj = $(addprefix $(BUILD)/, $(obj-y))

56
source/shell/rtc.c Normal file
View file

@ -0,0 +1,56 @@
#include <stdio.h>
#include <time.h>
#include <console.h>
#include <rtc.h>
#include <shell/rtc.h>
void shell_date(struct console *con, const char **argv, size_t argc)
{
struct tm now;
(void)argv;
(void)argc;
rtc_get_time(&now);
fprintf(con->fp, "%02d:%02d:%02d %02d-%02d-%d\n",
now.tm_hour, now.tm_min, now.tm_sec,
now.tm_mday, now.tm_mon + 1, now.tm_year + 1900);
}
void shell_time(struct console *con, const char **argv, size_t argc)
{
struct tm now;
(void)argv;
(void)argc;
rtc_get_time(&now);
fprintf(con->fp, "%ld\n", mktime(&now));
}
void shell_set_date(struct console *con, const char **argv, size_t argc)
{
struct tm now;
if (argc < 2) {
fprintf(con->fp, "usage: set-date <format> <date>\n");
return;
}
rtc_get_time(&now);
if (!strptime(argv[1], argv[0], &now)) {
fprintf(con->fp, "error\n");
return;
}
rtc_init(&now);
fprintf(con->fp, "%02d:%02d:%02d %02d-%02d-%d\n",
now.tm_hour, now.tm_min, now.tm_sec,
now.tm_mday, now.tm_mon + 1, now.tm_year + 1900);
}