Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Console.cpp
- Revision:
- 4:8e1c0e634ba6
- Parent:
- 3:c97f4e7f2685
diff -r c97f4e7f2685 -r 8e1c0e634ba6 Console.cpp --- a/Console.cpp Sat Mar 17 15:02:12 2018 +0200 +++ b/Console.cpp Sat Mar 17 15:25:04 2018 +0200 @@ -5,6 +5,8 @@ * Author: Janus */ #include <ctype.h> +#include <time.h> +#include <stdlib.h> #include "mbed_stats.h" @@ -57,11 +59,37 @@ } } +void Console::date(int argc,char *argv[]) +{ + time_t seconds = time(0); + + if(argc > 5) + { + printf("Set time %s %s %s %s:%s\n", argv[1], argv[2], argv[3], argv[4], argv[5]); + + struct tm t; + // adjust for tm structure required values + t.tm_year = atoi(argv[1]) - 1900; + t.tm_mon = atoi(argv[2]) - 1; + t.tm_mday = atoi(argv[3]); + t.tm_hour = atoi(argv[4]); + t.tm_min = atoi(argv[5]); + t.tm_sec = 0; + set_time(mktime(&t)); + } + + seconds = time(0); + // printf("Seconds since January 1, 1970: %d\n", (int)seconds); + printf("Date: %s", ctime(&seconds)); + +} + const Console::cmd_list_t shellCommands[] = { {"MBED OS" ,0,0,0}, - {"h", "", "Show this help info", Console::help}, - {"dt", "", "Dump Thread info", Console::dumpThreadInfo}, + {"h", "", "Show this help info", Console::help}, + {"dt", "", "Dump Thread info", Console::dumpThreadInfo}, + {"date", "<yyyy mm dd HH:MM>", "show / set current time", Console::date}, {0,0,0} };