Пример #1
0
void net_time_setup(void) {
  //ledmatrix_setup();
  //ethernet_setup();
  //last_uptime = uptime;
  my_ethernet_setup();
  request_time();
}
Пример #2
0
uint8_t net_time_loop(uint8_t mode) {
  /*time_tick = uptime - last_uptime;
  last_uptime = uptime;
  if(time_tick > 0) {
    time += time_tick;
  }*/
    if(uptime % 180 == 0) {
      request_time();
    }

  //if(mode > 0) {
    time = time_boot_offset + uptime;
    //Fr, 21.06.2013 - 23:42:00
    struct tm format;
    gmtime_r(time, &format);
    correct_dst(&format);
    sprintf(text, "%c%c, %02d.%02d.%d - %02d:%02d:%02d",
      p_week[2*format.tm_wday],
      p_week[2*format.tm_wday+1],
      format.tm_mday,
      format.tm_mon + 1,
      format.tm_year + 1900,
      format.tm_hour,
      format.tm_min,
      format.tm_sec);

    writeText(text, 0);
  //}

  my_ethernet_loop();
  if(mode != 0 && time % 1800 == 1) {
    return 1;
  } else {
    return 0;
  }
}
Пример #3
0
/*
 * arc_poll - called by the transmit procedure
 */
static void
arc_poll(
	int unit,
	struct peer *peer
	)
{
	register struct arcunit *up;
	struct refclockproc *pp;
	int resync_needed;              /* Should we start a resync? */

	pp = peer->procptr;
	up = (struct arcunit *)pp->unitptr;
#if 0
	pp->lencode = 0;
	memset(pp->a_lastcode, 0, sizeof(pp->a_lastcode));
#endif

#if 0
	/* Flush input. */
	tcflush(pp->io.fd, TCIFLUSH);
#endif

	/* Resync if our next scheduled resync time is here or has passed. */
	resync_needed = ( !(pp->sloppyclockflag & CLK_FLAG2) &&
			  (up->next_resync <= current_time) );

#ifdef ARCRON_LEAPSECOND_KEEN
	/*
	  Try to catch a potential leap-second insertion or deletion quickly.

	  In addition to the normal NTP fun of clocks that don't report
	  leap-seconds spooking their hosts, this clock does not even
	  sample the radio sugnal the whole time, so may miss a
	  leap-second insertion or deletion for up to a whole sample
	  time.

	  To try to minimise this effect, if in the first few minutes of
	  the day immediately following a leap-second-insertion point
	  (ie in the first hour of the first day of the first and sixth
	  months), and if the last resync was in the previous day, and a
	  resync is not already in progress, resync the clock
	  immediately.

	*/
	if((possible_leap > 0) &&       /* Must be 00:XX 01/0{1,7}/XXXX. */
	   (!up->resyncing)) {          /* No resync in progress yet. */
		resync_needed = 1;
		possible_leap = -1;          /* Prevent multiple resyncs. */
		msyslog(LOG_NOTICE,"ARCRON: unit %d: checking for leap second",unit);
	}
#endif

	/* Do a resync if required... */
	if(resync_needed) {
		/* First, reset quality value to `unknown' so we can detect */
		/* when a quality message has been responded to by this     */
		/* being set to some other value.                           */
		up->quality = QUALITY_UNKNOWN;

		/* Note that we are resyncing... */
		up->resyncing = 1;

		/* Now actually send the resync command and an immediate poll. */
#ifdef DEBUG
		if(debug) { printf("arc: sending resync command (h\\r).\n"); }
#endif
		msyslog(LOG_NOTICE, "ARCRON: unit %d: sending resync command", unit);
		send_slow(up, pp->io.fd, "h\r");

		/* Schedule our next resync... */
		up->next_resync = current_time + DEFAULT_RESYNC_TIME;

		/* Drop through to request time if appropriate. */
	}

	/* If clock quality is too poor to trust, indicate a fault. */
	/* If quality is QUALITY_UNKNOWN and ARCRON_KEEN is defined,*/
	/* we'll cross our fingers and just hope that the thing     */
	/* synced so quickly we did not catch it---we'll            */
	/* double-check the clock is OK elsewhere.                  */
	if(
#ifdef ARCRON_KEEN
		(up->quality != QUALITY_UNKNOWN) &&
#else
		(up->quality == QUALITY_UNKNOWN) ||
#endif
		(up->quality < MIN_CLOCK_QUALITY_OK)) {
#ifdef DEBUG
		if(debug) {
			printf("arc: clock quality %d too poor.\n", up->quality);
		}
#endif
		pp->lencode = 0;
		refclock_report(peer, CEVNT_FAULT);
		return;
	}
	/* This is the normal case: request a timestamp. */
	request_time(unit, peer);
}