|
2 | 2 | * DreamShell ##version## * |
3 | 3 | * commands.c * |
4 | 4 | * DreamShell CMD * |
5 | | - * (c)2004-2023 SWAT * |
| 5 | + * (c)2004-2024 SWAT * |
6 | 6 | * http://www.dc-swat.ru * |
7 | 7 | ****************************/ |
8 | 8 |
|
@@ -2007,6 +2007,57 @@ static int builtin_callfunc(int argc, char *argv[]) { |
2007 | 2007 | } |
2008 | 2008 |
|
2009 | 2009 |
|
| 2010 | +static int builtin_rtc(int argc, char *argv[]) { |
| 2011 | + |
| 2012 | + if(argc == 1) { |
| 2013 | + ds_printf("Usage: %s option args...\n" |
| 2014 | + "Options: \n" |
| 2015 | + " -s, --set -Set value\n" |
| 2016 | + " -g, --get -Get value\n", argv[0]); |
| 2017 | + ds_printf("Arguments: \n" |
| 2018 | + " -u, --unix -UNIX time to set\n"); |
| 2019 | + return CMD_NO_ARG; |
| 2020 | + } |
| 2021 | + |
| 2022 | + int set_rtc_value = 0, get_rtc_value = 0; |
| 2023 | + int input_value = 0; |
| 2024 | + time_t unix_time; |
| 2025 | + struct tm *time; |
| 2026 | + |
| 2027 | + struct cfg_option options[] = { |
| 2028 | + {"set", 's', NULL, CFG_BOOL, (void *) &set_rtc_value, 0}, |
| 2029 | + {"get", 'g', NULL, CFG_BOOL, (void *) &get_rtc_value, 0}, |
| 2030 | + {"unix", 'u', NULL, CFG_INT, (void *) &input_value, 0}, |
| 2031 | + CFG_END_OF_LIST |
| 2032 | + }; |
| 2033 | + |
| 2034 | + CMD_DEFAULT_ARGS_PARSER(options); |
| 2035 | + |
| 2036 | + if(set_rtc_value) { |
| 2037 | + if(input_value > 0) { |
| 2038 | + unix_time = (time_t)input_value; |
| 2039 | + rtc_set_unix_secs(unix_time); |
| 2040 | + } |
| 2041 | + return CMD_OK; |
| 2042 | + } |
| 2043 | + |
| 2044 | + if(get_rtc_value) { |
| 2045 | + unix_time = rtc_unix_secs(); |
| 2046 | + time = gmtime(&unix_time); |
| 2047 | + |
| 2048 | + if(unix_time < 0 || time == NULL) { |
| 2049 | + ds_printf("DS_ERROR: RTC value is invalid"); |
| 2050 | + return CMD_ERROR; |
| 2051 | + } |
| 2052 | + ds_printf("DS_INFO: %s", ctime(&unix_time)); |
| 2053 | + return CMD_OK; |
| 2054 | + } |
| 2055 | + |
| 2056 | + ds_printf("DS_ERROR: There is no option.\n"); |
| 2057 | + return CMD_NO_ARG; |
| 2058 | +} |
| 2059 | + |
| 2060 | + |
2010 | 2061 | /* Setup all our builtins */ |
2011 | 2062 | int InitCmd() { |
2012 | 2063 |
|
@@ -2049,6 +2100,7 @@ int InitCmd() { |
2049 | 2100 | AddCmd("console", "Console manager", (CmdHandler *) builtin_console); |
2050 | 2101 | AddCmd("speedtest", "Testing r/w speed of device", (CmdHandler *) builtin_speedtest); |
2051 | 2102 | AddCmd("callfunc", "Call any exported function", (CmdHandler *) builtin_callfunc); |
| 2103 | + AddCmd("rtc", "Real Time Clock manager", (CmdHandler *) builtin_rtc); |
2052 | 2104 | //ds_printf("Command list initialised.\n"); |
2053 | 2105 | return 1; |
2054 | 2106 | } |
|
0 commit comments