mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-23 13:03:13 +00:00
[FL-1483] Cli: add time set feature to time command (#536)
* Cli: add time set feature to time command * Cli: better time set function feedback
This commit is contained in:
parent
961d61807c
commit
ed75bc2c39
1 changed files with 59 additions and 14 deletions
|
@ -66,23 +66,68 @@ void cli_command_uuid(Cli* cli, string_t args, void* context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void cli_command_date(Cli* cli, string_t args, void* context) {
|
void cli_command_date(Cli* cli, string_t args, void* context) {
|
||||||
RTC_DateTypeDef date;
|
|
||||||
RTC_TimeTypeDef time;
|
RTC_TimeTypeDef time;
|
||||||
|
RTC_DateTypeDef date;
|
||||||
|
|
||||||
// TODO add get_datetime to core, not use HAL here
|
if(string_size(args) > 0) {
|
||||||
// READ ORDER MATTERS! Time then date.
|
uint16_t Hours, Minutes, Seconds, Month, Date, Year, WeekDay;
|
||||||
HAL_RTC_GetTime(&hrtc, &time, RTC_FORMAT_BIN);
|
int ret = sscanf(
|
||||||
HAL_RTC_GetDate(&hrtc, &date, RTC_FORMAT_BIN);
|
string_get_cstr(args),
|
||||||
|
"%hu:%hu:%hu %hu-%hu-%hu %hu",
|
||||||
|
&Hours,
|
||||||
|
&Minutes,
|
||||||
|
&Seconds,
|
||||||
|
&Month,
|
||||||
|
&Date,
|
||||||
|
&Year,
|
||||||
|
&WeekDay);
|
||||||
|
if(ret == 7) {
|
||||||
|
time.Hours = Hours;
|
||||||
|
time.Minutes = Minutes;
|
||||||
|
time.Seconds = Seconds;
|
||||||
|
time.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
|
||||||
|
time.StoreOperation = RTC_STOREOPERATION_RESET;
|
||||||
|
date.WeekDay = WeekDay;
|
||||||
|
date.Month = Month;
|
||||||
|
date.Date = Date;
|
||||||
|
date.Year = Year - 2000;
|
||||||
|
HAL_RTC_SetTime(&hrtc, &time, RTC_FORMAT_BIN);
|
||||||
|
HAL_RTC_SetDate(&hrtc, &date, RTC_FORMAT_BIN);
|
||||||
|
|
||||||
string_t datetime_str;
|
// Verification
|
||||||
string_init(datetime_str);
|
HAL_RTC_GetTime(&hrtc, &time, RTC_FORMAT_BIN);
|
||||||
|
HAL_RTC_GetDate(&hrtc, &date, RTC_FORMAT_BIN);
|
||||||
string_cat_printf(datetime_str, "%.2d:%.2d:%.2d ", time.Hours, time.Minutes, time.Seconds);
|
printf(
|
||||||
string_cat_printf(datetime_str, "%.2d-%.2d-%.2d", date.Month, date.Date, 2000 + date.Year);
|
"New time is: %.2d:%.2d:%.2d %.2d-%.2d-%.2d %d",
|
||||||
|
time.Hours,
|
||||||
printf(string_get_cstr(datetime_str));
|
time.Minutes,
|
||||||
|
time.Seconds,
|
||||||
string_clear(datetime_str);
|
date.Month,
|
||||||
|
date.Date,
|
||||||
|
2000 + date.Year,
|
||||||
|
date.WeekDay);
|
||||||
|
} else {
|
||||||
|
printf(
|
||||||
|
"Invalid time format, use `hh:mm:ss MM-DD-YYYY WD`. sscanf %d %s",
|
||||||
|
ret,
|
||||||
|
string_get_cstr(args));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// TODO add get_datetime to core, not use HAL here
|
||||||
|
// READ ORDER MATTERS! Time then date.
|
||||||
|
HAL_RTC_GetTime(&hrtc, &time, RTC_FORMAT_BIN);
|
||||||
|
HAL_RTC_GetDate(&hrtc, &date, RTC_FORMAT_BIN);
|
||||||
|
printf(
|
||||||
|
"%.2d:%.2d:%.2d %.2d-%.2d-%.2d %d",
|
||||||
|
time.Hours,
|
||||||
|
time.Minutes,
|
||||||
|
time.Seconds,
|
||||||
|
date.Month,
|
||||||
|
date.Date,
|
||||||
|
2000 + date.Year,
|
||||||
|
date.WeekDay);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cli_command_log(Cli* cli, string_t args, void* context) {
|
void cli_command_log(Cli* cli, string_t args, void* context) {
|
||||||
|
|
Loading…
Reference in a new issue