Beispiel #1
0
/**
 * SNTP processing of received timestamp
 */
static void
sntp_process(u32_t *receive_timestamp)
{
  /* convert SNTP time (1900-based) to unix GMT time (1970-based)
   * if MSB is 0, SNTP time is 2036-based!
   */
  u32_t rx_secs = lwip_ntohl(receive_timestamp[0]);
  int is_1900_based = ((rx_secs & 0x80000000) != 0);
  u32_t t = is_1900_based ? (rx_secs - DIFF_SEC_1900_1970) : (rx_secs + DIFF_SEC_1970_2036);
  time_t tim = t;

#if SNTP_CALC_TIME_US
  u32_t us = lwip_ntohl(receive_timestamp[1]) / 4295;
  SNTP_SET_SYSTEM_TIME_US(t, us);
  /* display local time from GMT time */
  LWIP_DEBUGF(SNTP_DEBUG_TRACE, ("sntp_process: %s, %"U32_F" us", ctime(&tim), us));

#else /* SNTP_CALC_TIME_US */

  /* change system time and/or the update the RTC clock */
  SNTP_SET_SYSTEM_TIME(t);
  /* display local time from GMT time */
  LWIP_DEBUGF(SNTP_DEBUG_TRACE, ("sntp_process: %s", ctime(&tim)));
#endif /* SNTP_CALC_TIME_US */
  LWIP_UNUSED_ARG(tim);
}
Beispiel #2
0
/**
 * SNTP processing of received timestamp
 */
static void
sntp_process(u32_t *receive_timestamp)
{
  /* convert SNTP time (1900-based) to unix GMT time (1970-based)
   * @todo: if MSB is 1, SNTP time is 2036-based!
   */
  time_t t = (ntohl(receive_timestamp[0]) - DIFF_SEC_1900_1970);
  sntp_time  = t;
#if SNTP_CALC_TIME_US
  u32_t us = ntohl(receive_timestamp[1]) / 4295;
  SNTP_SET_SYSTEM_TIME_US(t, us);
  /* display local time from GMT time */
  //LWIP_DEBUGF(SNTP_DEBUG_TRACE, ("sntp_process: %s, %"U32_F" us", ctime(&t), us));
  LWIP_DEBUGF(SNTP_DEBUG_TRACE, "sntp_process: %lu, us", t);
/*  os_sprintf(deb,"sntp_process: %lu" , t);
  uart0_sendStr(deb);*/

#else /* SNTP_CALC_TIME_US */

  /* change system time and/or the update the RTC clock */
  SNTP_SET_SYSTEM_TIME(t);
  /* display local time from GMT time */
  //LWIP_DEBUGF(SNTP_DEBUG_TRACE, ("sntp_process: %s", ctime(&t)));
  LWIP_DEBUGF(SNTP_DEBUG_TRACE, "sntp_process: %lu, us", t);
/*  os_sprintf(deb, "sntp_process: %lu", t);
  uart0_sendStr(deb);*/
#endif /* SNTP_CALC_TIME_US */
  os_timer_disarm(&ntp_timer);
  ets_timer_arm_new(&ntp_timer,1000,1);
  //uart0_sendStr("Arming timer...\n");
}
/**
 * SNTP processing of received timestamp
 */
static void sntp_process(uint32_t *receive_timestamp) {
    /* Convert SNTP time (1900-based) to unix GMT time (1970-based)
     * @todo: if MSB is 1, SNTP time is 2036-based!
     */
    time_t t = (ntohl(receive_timestamp[0]) - DIFF_SEC_1900_1970);

#if SNTP_CALC_TIME_US
    u32_t us = ntohl(receive_timestamp[1]) / 4295;
    SNTP_SET_SYSTEM_TIME_US(t, us);
    /* Display local time from GMT time */
    LWIP_DEBUGF(SNTP_DEBUG_TRACE, ("sntp_process: %s, %"U32_F" us", ctime(&t), us));
#else /* SNTP_CALC_TIME_US */

    /* Change system time and/or the update the RTC clock */
    SNTP_SET_SYSTEM_TIME(t);
    /* Display local time from GMT time */
    LWIP_DEBUGF(SNTP_DEBUG_TRACE, ("sntp_process: %s", ctime(&t)));
#endif /* SNTP_CALC_TIME_US */
}