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

tags/0.1.0
S.J.R. van Schaik 7 years ago
parent 161acf1731
commit acdc364fab
  1. 1
      Makefile
  2. 56
      source/shell/rtc.c

@ -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))

@ -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);
}
Loading…
Cancel
Save