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"); }
static void timeInfo(void) { scheduleMsg(logger, "chTimeNow as seconds = %d", getTimeNowSeconds()); scheduleMsg(logger, "hal seconds = %d", halTime.get() / 168000000LL); #if EFI_RTC || defined(__DOXYGEN__) int unix = rtcGetTimeUnixSec(&RTCD1) - rtcStartTime; scheduleMsg(logger, "unix seconds = %d", unix); #endif }
/** * @brief Gets raw time from RTC and converts it to unix format. * * @param[in] rtcp pointer to RTC driver structure * @return Unix time value in microseconds. * * @api */ uint64_t rtcGetTimeUnixUsec(RTCDriver *rtcp) { #if STM32_RTC_HAS_SUBSECONDS uint64_t result = 0; RTCTime timespec = {0,0}; rtcGetTime(rtcp, ×pec); result = (uint64_t)timespec.tv_sec * 1000000; return result + timespec.tv_msec * 1000; #else return (uint64_t)rtcGetTimeUnixSec(rtcp) * 1000000; #endif }
void initTimePerfActions(Logging *sharedLogger) { logger = sharedLogger; #if EFI_RTC || defined(__DOXYGEN__) rtcStartTime = rtcGetTimeUnixSec(&RTCD1); #endif // initOutputPin("test pad", &testOutput, TEST_PORT, TEST_PIN); addConsoleActionI("perftest", runTests); addConsoleAction("timeinfo", timeInfo); addConsoleAction("chtest", runChibioTest); }
/** * @brief Gets raw time from RTC and converts it to unix format. * * @param[in] rtcp pointer to RTC driver structure * @return Unix time value in microseconds. * * @api */ uint64_t rtcGetTimeUnixUsec(RTCDriver *rtcp) { #if STM32_RTC_HAS_SUBSECONDS uint64_t result = 0; RTCTime timespec = {0,0,FALSE,0}; struct tm timp; rtcGetTime(rtcp, ×pec); stm32_rtc_bcd2tm(&timp, ×pec); result = (uint64_t)mktime(&timp) * 1000000; return result + timespec.tv_msec * 1000; #else return (uint64_t)rtcGetTimeUnixSec(rtcp) * 1000000; #endif }
/** * Create human readable name for file. */ static size_t name_from_time(char *buf){ time_t t = 0; int32_t const *timezone = (const int32_t*)param_registry.valueSearch("TIME_zone"); t = rtcGetTimeUnixSec(&RTCD1); if (timezone != NULL) t += *timezone * 60 * 60; #if MAVLINK_LOG_FORMAT return strftime(buf, MAX_FILENAME_SIZE, "%F_%H.%M.%S.mavlink", localtime(&t)); #else return strftime(buf, MAX_FILENAME_SIZE, "%F_%H.%M.%S.raw", localtime(&t)); #endif }
void ln_now(struct ln_date *date) { struct tm timp; time_t unix_time; /* UT date and time */ unix_time = rtcGetTimeUnixSec(&RTCD1); if (unix_time == -1){ return; } else{ rtcGetTimeTm(&RTCD1, &timp); date->years = timp.tm_year+1900; date->months = timp.tm_mon+1; date->days = timp.tm_mday; date->hours = timp.tm_hour; date->minutes = timp.tm_min; date->seconds = timp.tm_sec; } }
void printDateTime(void) { static time_t unix_time; struct tm timp; unix_time = rtcGetTimeUnixSec(&RTCD1); if (unix_time == -1) { scheduleMsg(&logger, "incorrect time in RTC cell"); } else { scheduleMsg(&logger, "%D - unix time", unix_time); rtcGetTimeTm(&RTCD1, &timp); appendMsgPrefix(&logger); appendPrintf(&logger, "Current RTC time in GMT is: %04u-%02u-%02u %02u:%02u:%02u", timp.tm_year + 1900, timp.tm_mon + 1, timp.tm_mday, timp.tm_hour, timp.tm_min, timp.tm_sec); appendMsgPostfix(&logger); scheduleLogging(&logger); } }
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; }
void cmd_getLocalTime(BaseSequentialStream *chp, int argc, char *argv) { (void) argv; struct tm timp; time_t unix_time; char date[10]; if (argc != 0 ) { chprintf(chp, "0\n"); return; } unix_time = rtcGetTimeUnixSec(&RTCD1); if (unix_time == -1){ chprintf(chp, "incorrect time in RTC cell\r\n"); chprintf(chp, "0"); return; } else{ rtcGetTimeTm(&RTCD1, &timp); strftime(date,10,"%H:%M:%S",&timp); chprintf(chp, "%s#",date); } }
/* * time implementation */ extern "C" int _gettimeofday( struct timeval *ptimeval, void *ptimezone) { (void)ptimezone; (void)ptimeval; return (int)rtcGetTimeUnixSec(&RTCD1); }
void initRtc(void) { #if EFI_RTC || defined(__DOXYGEN__) rtcGetTimeUnixSec(&RTCD1); // this would test RTC, see 'rtcWorks' variable, see #311 printMsg(&logger, "initRtc()"); #endif /* EFI_RTC */ }
time_t secondsinceepoch() { return rtcGetTimeUnixSec((RTCDriver *)&RTCD1); }