void cmd_setLocalTime(BaseSequentialStream *chp, int argc, char *argv) { struct tm timp,*ptm; time_t unix_time; if (argc != 1 ) { chprintf(chp, "0"); return; } //http://pubs.opengroup.org/onlinepubs/007904975/functions/strptime.html if (strptime(argv, "%H:%M:%S", &timp) == NULL) { chprintf(chp, "0"); return; } unix_time = rtcGetTimeUnixSec(&RTCD1); ptm = gmtime(&unix_time); timp.tm_year= ptm->tm_year; timp.tm_mon= ptm->tm_mon; timp.tm_mday= ptm->tm_mday; timp.tm_isdst=0; unix_time=mktime(&timp); if (unix_time == -1){ chprintf(chp, "0"); return; } rtcSetTimeUnixSec(&RTCD1, unix_time); chprintf(chp, "1"); }
void setDateTime(const char *strDate) { if (strlen(strDate) > 0) { time_t unix_time = atoi(strDate); if (unix_time > 0) { rtcSetTimeUnixSec(&RTCD1, unix_time); printDateTime(); return; } } scheduleMsg(&logger, "date_set Date parameter %s is wrong\r\n", strDate); }
void cmd_date(BaseSequentialStream *chp, int argc, char *argv[]){ (void)argv; (void)chp; struct tm timp; RTCTime psas_time; if (argc == 0) { goto ERROR; } if ((argc == 1) && (strcmp(argv[0], "get") == 0)){ psas_rtc_lld_get_time(&RTCD1, &psas_time); psas_stm32_rtc_bcd2tm(&timp, &psas_time); unix_time = mktime(&timp); if (unix_time == -1){ SHELLDBG("incorrect time in RTC cell\r\n"); } else{ SHELLDBG("%Ds %Dus %s",unix_time, psas_time.tv_msec, " - unix time\r\n"); SHELLDBG("%lu\r\n", psas_rtc_s.fc_boot_time_mark ); rtcGetTimeTm(&RTCD1, &timp); SHELLDBG("%s%s",asctime(&timp)," - formatted time string\r\n"); } // } return; } if ((argc == 2) && (strcmp(argv[0], "set") == 0)){ unix_time = atol(argv[1]); if (unix_time > 0){ rtcSetTimeUnixSec(&RTCD1, unix_time); return; } else{ goto ERROR; } } else{ goto ERROR; } ERROR: SHELLDBG("Usage: date get\r\n"); SHELLDBG(" date set N\r\n"); SHELLDBG("where N is time in seconds sins Unix epoch\r\n"); SHELLDBG("you can get current N value from unix console by the command\r\n"); SHELLDBG("%s", "date +\%s\r\n"); return; }
static void cmd_date(BaseSequentialStream *chp, int argc, char *argv[]){ (void)argv; struct tm timp; if (argc == 0) { goto ERROR; } if ((argc == 1) && (strcmp(argv[0], "get") == 0)){ unix_time = rtcGetTimeUnixSec(&RTCD1); if (unix_time == -1){ chprintf(chp, "incorrect time in RTC cell\r\n"); } else{ chprintf(chp, "%D%s",unix_time," - unix time\r\n"); rtcGetTimeTm(&RTCD1, &timp); chprintf(chp, "%s%s",asctime(&timp)," - formatted time string\r\n"); } return; } if ((argc == 2) && (strcmp(argv[0], "set") == 0)){ unix_time = atol(argv[1]); if (unix_time > 0){ rtcSetTimeUnixSec(&RTCD1, unix_time); return; } else{ goto ERROR; } } else{ goto ERROR; } ERROR: chprintf(chp, "Usage: date get\r\n"); chprintf(chp, " date set N\r\n"); chprintf(chp, "where N is time in seconds sins Unix epoch\r\n"); chprintf(chp, "you can get current N value from unix console by the command\r\n"); chprintf(chp, "%s", "date +\%s\r\n"); return; }