#include #include #include #include #include #include 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, 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_time(struct console *con, size_t argc, const char **argv) { struct tm now; time_t time; if (argc < 1) { fprintf(con->fp, "usage: set-time \n"); return -1; } time = (time_t)strtoul(argv[0], NULL, 0); gmtime_r(&time, &now); 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); 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 \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, now.tm_min, now.tm_sec, now.tm_mday, now.tm_mon + 1, now.tm_year + 1900); return 0; }