Example #1
0
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;
}
Example #2
0
/**
 * @brief   Get current time in format suitable for usage in FatFS.
 *
 * @param[in] rtcp      pointer to RTC driver structure
 * @return              FAT time value.
 *
 * @api
 */
uint32_t rtcGetTimeFat(RTCDriver *rtcp) {
  uint32_t fattime = 0;
  struct tm *timp = NULL;

  rtcGetTimeTm(rtcp, timp);

  fattime |= (timp->tm_sec / 2);
  fattime |= (timp->tm_min) << 5;
  fattime |= (timp->tm_hour) << 11;
  fattime |= (timp->tm_mday) << 16;
  fattime |= (timp->tm_mon + 1) << 21;
  fattime |= (timp->tm_year - 80) << 25;
  return fattime;
}
Example #3
0
/**
 * @brief   Get current time in format suitable for usage in FatFS.
 *
 * @param[in] rtcp      pointer to RTC driver structure
 * @return              FAT time value.
 *
 * @api
 */
uint32_t rtcGetTimeFatFromCounter(RTCDriver *rtcp) {
  uint32_t fattime;
  struct tm timp;

  rtcGetTimeTm(rtcp, &timp);

  fattime  = (timp.tm_sec)       >> 1;
  fattime |= (timp.tm_min)       << 5;
  fattime |= (timp.tm_hour)      << 11;
  fattime |= (timp.tm_mday)      << 16;
  fattime |= (timp.tm_mon + 1)   << 21;
  fattime |= (timp.tm_year - 80) << 25;

  return fattime;
}
Example #4
0
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;
	}
}
Example #5
0
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);
	}
}
Example #6
0
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;
}
Example #7
0
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);
  }  
}
Example #8
0
void dateToString(char *lcd_str) {
#if EFI_RTC || defined(__DOXYGEN__)
	// todo:
	// re-implement this along the lines of 	chvprintf("%04u-%02u-%02u %02u:%02u:%02u\r\n", timp.tm_year + 1900, timp.tm_mon + 1, timp.tm_mday, timp.tm_hour,
	// timp.tm_min, timp.tm_sec);
	// this would require a temporary mem stream - see datalogging and other existing usages

	strcpy(lcd_str, "00/00 00:00:00\0");
	struct tm timp;
	rtcGetTimeTm(&RTCD1, &timp);			// get RTC date/time
	
	put2(0, lcd_str, timp.tm_mon + 1);
	put2(3, lcd_str, timp.tm_mday);
	put2(6, lcd_str, timp.tm_hour);
	put2(9, lcd_str, timp.tm_min);
	put2(12, lcd_str, timp.tm_sec);

#else
	lcd_str[0] = 0;
#endif /* EFI_RTC */
}
Example #9
0
bool dateToStringShort(char *lcd_str) {
#if EFI_RTC || defined(__DOXYGEN__)
	strcpy(lcd_str, "0000_000000\0");
	struct tm timp;
	rtcGetTimeTm(&RTCD1, &timp);
	if (timp.tm_year < 116 || timp.tm_year > 130) {
		// 2016 to 2030 is the valid range
		lcd_str[0] = 0;
		return false;
	}
	put2(0, lcd_str, timp.tm_mon + 1);
	put2(2, lcd_str, timp.tm_mday);
	put2(5, lcd_str, timp.tm_hour);
	put2(7, lcd_str, timp.tm_min);
	put2(9, lcd_str, timp.tm_sec);

	return true;
#else
	lcd_str[0] = 0;
	return false;
#endif
}
Example #10
0
File: main.c Project: 0x00f/ChibiOS
void cmd_sdiotest(BaseSequentialStream *chp, int argc, char *argv[]){
  (void)argc;
  (void)argv;
  FRESULT err;
  uint32_t clusters;
  FATFS *fsp;
  FIL FileObject;
  //FILINFO FileInfo;
  size_t bytes_written;
  struct tm timp;

#if !HAL_USE_RTC
  chprintf(chp, "ERROR! Chibios compiled without RTC support.");
  chprintf(chp, "Enable HAL_USE_RCT in you halconf.h");
  chThdSleepMilliseconds(100);
  return;
#endif

  chprintf(chp, "Trying to connect SDIO... ");
  chThdSleepMilliseconds(100);

  if (!sdcConnect(&SDCD1)) {
    chprintf(chp, "OK\r\n");
    chprintf(chp, "Register working area for filesystem... ");
    chThdSleepMilliseconds(100);
    err = f_mount(0, &SDC_FS);
    if (err != FR_OK){
      chSysHalt();
    }
    else{
      fs_ready = TRUE;
      chprintf(chp, "OK\r\n");
    }

    chprintf(chp, "Mounting filesystem... ");
    chThdSleepMilliseconds(100);
    err = f_getfree("/", &clusters, &fsp);
    if (err != FR_OK) {
      chSysHalt();
    }
    chprintf(chp, "OK\r\n");
    chprintf(chp,
             "FS: %lu free clusters, %lu sectors per cluster, %lu bytes free\r\n",
             clusters, (uint32_t)SDC_FS.csize,
             clusters * (uint32_t)SDC_FS.csize * (uint32_t)MMCSD_BLOCK_SIZE);

    rtcGetTimeTm(&RTCD1, &timp);
    chprintf(chp, "Current RTC time is: ");
    chprintf(chp, "%u-%u-%u %u:%u:%u\r\n",
      timp.tm_year+1900, timp.tm_mon+1, timp.tm_mday, timp.tm_hour, timp.tm_min,
      timp.tm_sec);

    chprintf(chp, "Creating empty file 'tmstmp.tst'... ");
    chThdSleepMilliseconds(100);
    err = f_open(&FileObject, "0:tmstmp.tst", FA_WRITE | FA_OPEN_ALWAYS);
    if (err != FR_OK) {
      chSysHalt();
    }
    chprintf(chp, "OK\r\n");

    chprintf(chp, "Write some data in it... ");
    chThdSleepMilliseconds(100);
    err = f_write(&FileObject, "tst", sizeof("tst"), (void *)&bytes_written);
    if (err != FR_OK) {
      chSysHalt();
    }
    else
      chprintf(chp, "OK\r\n");

    chprintf(chp, "Closing file 'tmstmp.tst'... ");
    chThdSleepMilliseconds(100);
    err = f_close(&FileObject);
    if (err != FR_OK) {
      chSysHalt();
    }
    else
      chprintf(chp, "OK\r\n");

//    chprintf(chp, "Obtaining file info ... ");
//    chThdSleepMilliseconds(100);
//    err = f_stat("0:tmstmp.tst", &FileInfo);
//    if (err != FR_OK) {
//      chSysHalt();
//    }
//    else{
//      chprintf(chp, "OK\r\n");
//      chprintf(chp, "    Timestamp: %u-%u-%u %u:%u:%u\r\n",
//                         ((FileInfo.fdate >> 9) & 127) + 1980,
//                         (FileInfo.fdate >> 5) & 15,
//                         FileInfo.fdate & 31,
//                         (FileInfo.ftime >> 11) & 31,
//                         (FileInfo.ftime >> 5) & 63,
//                         (FileInfo.ftime & 31) * 2);
//    }

    chprintf(chp, "Umounting filesystem... ");
    f_mount(0, NULL);
    chprintf(chp, "OK\r\n");

    chprintf(chp, "Disconnecting from SDIO...");
    chThdSleepMilliseconds(100);
    if (sdcDisconnect(&SDCD1))
      chSysHalt();
    chprintf(chp, " OK\r\n");
    chprintf(chp, "------------------------------------------------------\r\n");
    chprintf(chp, "Now you can remove memory card and check timestamp on PC.\r\n");
    chThdSleepMilliseconds(100);
  }
  else{
    chSysHalt();
  }
}
Example #11
0
void date_get_tm(struct tm *timp) {
	(void)timp;
#if EFI_RTC || defined(__DOXYGEN__)
	rtcGetTimeTm(&RTCD1, timp);
#endif /* EFI_RTC */
}