You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.0 KiB
62 lines
1.0 KiB
#include <stdio.h>
|
|
#include <time.h>
|
|
|
|
#include <console.h>
|
|
#include <rtc.h>
|
|
|
|
#include <shell/rtc.h>
|
|
|
|
int shell_date(struct console *con, size_t argc, const char **argv)
|
|
{
|
|
struct tm now;
|
|
|
|
(void)argv;
|
|
(void)argc;
|
|
|
|
rtc_get_time(&now);
|
|
|
|
fprintf(con->fp, "%02d:%02d:%02d %02d-%02d-%d\n",
|
|
now.tm_hour + 1, now.tm_min, now.tm_sec,
|
|
now.tm_mday, now.tm_mon + 1, now.tm_year + 1900);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int shell_time(struct console *con, size_t argc, const char **argv)
|
|
{
|
|
struct tm now;
|
|
|
|
(void)argv;
|
|
(void)argc;
|
|
|
|
rtc_get_time(&now);
|
|
|
|
fprintf(con->fp, "%ld\n", mktime(&now));
|
|
|
|
return 0;
|
|
}
|
|
|
|
int shell_set_date(struct console *con, size_t argc, const char **argv)
|
|
{
|
|
struct tm now;
|
|
|
|
if (argc < 2) {
|
|
fprintf(con->fp, "usage: set-date <format> <date>\n");
|
|
return -1;
|
|
}
|
|
|
|
rtc_get_time(&now);
|
|
|
|
if (!strptime(argv[1], argv[0], &now)) {
|
|
fprintf(con->fp, "error\n");
|
|
return -1;
|
|
}
|
|
|
|
rtc_init(&now);
|
|
|
|
fprintf(con->fp, "%02d:%02d:%02d %02d-%02d-%d\n",
|
|
now.tm_hour + 1, now.tm_min, now.tm_sec,
|
|
now.tm_mday, now.tm_mon + 1, now.tm_year + 1900);
|
|
|
|
return 0;
|
|
}
|
|
|