diff --git a/firmware/application/shell.hpp b/firmware/application/shell.hpp index 1d672eda..7c3b08f6 100644 --- a/firmware/application/shell.hpp +++ b/firmware/application/shell.hpp @@ -36,7 +36,7 @@ * @brief Shell maximum arguments per command. */ #if !defined(SHELL_MAX_ARGUMENTS) || defined(__DOXYGEN__) -#define SHELL_MAX_ARGUMENTS 4 +#define SHELL_MAX_ARGUMENTS 6 #endif /** diff --git a/firmware/application/usb_serial_shell.cpp b/firmware/application/usb_serial_shell.cpp index 64435990..c3f4fb7d 100644 --- a/firmware/application/usb_serial_shell.cpp +++ b/firmware/application/usb_serial_shell.cpp @@ -584,6 +584,37 @@ static void cmd_sd_write(BaseSequentialStream* chp, int argc, char* argv[]) { chprintf(chp, "ok\r\n"); } +static void cmd_rtcget(BaseSequentialStream* chp, int argc, char* argv[]) { + (void)chp; + (void)argc; + (void)argv; + + rtc::RTC datetime; + rtcGetTime(&RTCD1, &datetime); + + chprintf(chp, "Current time: %04d-%02d-%02d %02d:%02d:%02d\r\n", datetime.year(), datetime.month(), datetime.day(), datetime.hour(), datetime.minute(), datetime.second()); +} + +static void cmd_rtcset(BaseSequentialStream* chp, int argc, char* argv[]) { + const char* usage = + "usage: rtcset [year] [month] [day] [hour] [minute] [second]\r\n" + " all fields are required; milliseconds zero when set\r\n" + " (fractional seconds are not supported)\r\n"; + + if (argc != 6) { + chprintf(chp, usage); + return; + } + + rtc::RTC new_datetime{ + (uint16_t)strtol(argv[0], NULL, 10), (uint8_t)strtol(argv[1], NULL, 10), + (uint8_t)strtol(argv[2], NULL, 10), (uint32_t)strtol(argv[3], NULL, 10), + (uint32_t)strtol(argv[4], NULL, 10), (uint32_t)strtol(argv[5], NULL, 10)}; + rtcSetTime(&RTCD1, &new_datetime); + + chprintf(chp, "ok\r\n"); +} + static void cpld_info(BaseSequentialStream* chp, int argc, char* argv[]) { const char* usage = "usage: cpld_info \r\n" @@ -995,6 +1026,8 @@ static const ShellCommand commands[] = { {"read", cmd_sd_read}, {"write", cmd_sd_write}, {"filesize", cmd_sd_filesize}, + {"rtcget", cmd_rtcget}, + {"rtcset", cmd_rtcset}, {"cpld_info", cpld_info}, {"cpld_read", cmd_cpld_read}, {"accessibility_readall", cmd_accessibility_readall},