Beispiel #1
0
void
clock_localtime (struct clock_datetime_t *d, uint32_t timestamp)
{
#if TIMEZONE == TIMEZONE_CEST
  clock_datetime (d, timestamp);
  /* We must determine, if we have CET or CEST */
  int8_t last_sunday = last_sunday_in_month (d->day, d->dow);
  /* march until october can be summer time */
  if (d->month < 3 || d->month > 10)
    {
      timestamp += 3600;
    }
  else if (d->month == 3
	   && (last_sunday == -1 || (last_sunday == 0 && d->hour < 1)))
    {
      timestamp += 3600;
    }
  else if (d->month == 10
	   && (last_sunday == 1 || (last_sunday == 0 && d->hour > 1)))
    {
      timestamp += 3600;
    }
  else
    {
      timestamp += 7200;
    }
#endif
  clock_datetime (d, timestamp);
}
Beispiel #2
0
void
cron_periodic(void)
{
  clock_datetime_t d, ld;
  uint32_t timestamp = clock_get_time();

  /* fix last_check */
  if (timestamp < last_check)
  {
    clock_datetime(&d, timestamp);
    last_check = timestamp - d.sec;
    return;
  }

  /* Check tasks at most once in a minute and only if at least one exists */
  if (!head || (timestamp - last_check) < 60)
    return;

  /* get time and date from unix timestamp */
  clock_datetime(&d, timestamp);
  clock_localtime(&ld, timestamp);

  /* truncate secs */
  timestamp -= d.sec;

#ifdef CRON_ANACRON_SUPPORT
  uint8_t skip_anacron = 0;
  if ((timestamp - last_check) > 60)
    skip_anacron = cron_anacron(last_check, timestamp);
#endif

  /* check every event for a match */
  struct cron_event_linkedlist *current = head;
  struct cron_event_linkedlist *exec;
  while (current)
  {
    /* backup current cronjob and advance current */
    exec = current;
    current = current->next;

#ifdef CRON_ANACRON_SUPPORT
    if (skip_anacron && exec->event.anacron)
      continue;
#endif
    /* if it matches all conditions , execute the handler function */
    if (cron_check_event(&exec->event.cond, exec->event.use_utc, &d, &ld))
      cron_execute(exec);
  }

  /* save the actual timestamp */
  last_check = timestamp;
}
Beispiel #3
0
void
clock_localtime(clock_datetime_t * d, const timestamp_t t)
{
  timestamp_t localtime = t + UTCTIME;
  clock_datetime(d, localtime);
  clock_tz_compute(d->year);
  uint8_t isdst = clock_is_dst(t);
  if (isdst)
  {
    localtime += DSTTIME;
    clock_datetime(d, localtime);
    d->isdst = isdst;
  }
}
Beispiel #4
0
void 
cron_periodic(void)
/* {{{ */ {
    /* convert time to something useful */
    struct clock_datetime_t d;
    uint32_t timestamp = clock_get_time();

    /* Only check the tasks every minute */
    if ((timestamp - last_check) < 60) return;

    clock_datetime(&d, timestamp);

    struct cron_event_t event;

    /* check every event for a match */
    for (uint8_t i = 0; ; i++) {
        memcpy_P(&event, &events[i], sizeof(struct cron_event_t));

        /* end of task list reached */
        if (event.handler == NULL) break;

        uint8_t r = cron_check_event(&event, &d);

        /* if it matches, execute the handler function */
        if (r > 0) {
            event.handler();
        }

    }

    /* save the actual timestamp */
    last_check = timestamp - d.sec;

} /* }}} */
Beispiel #5
0
void
cron_static_periodic(void)
{
  /* convert time to something useful */
  clock_datetime_t d, ld;
  uint32_t timestamp = clock_get_time();

  /* fix last_check */
  if (timestamp < last_check)
  {
    clock_datetime(&d, timestamp);
    last_check = timestamp - d.sec;
    return;
  }

  /* Only check the tasks every minute */
  if ((timestamp - last_check) < 60)
    return;

  clock_datetime(&d, timestamp);
  clock_localtime(&ld, timestamp);

  struct cron_static_event_t event;

  /* check every event for a match */
  for (uint8_t i = 0;; i++)
  {
    memcpy_P(&event, &events[i], sizeof(struct cron_static_event_t));

    /* end of task list reached */
    if (event.handler == NULL)
      break;

    /* if it matches, execute the handler function */
    if (cron_check_event(&event.cond, event.use_utc, &d, &ld))
    {
      event.handler();
    }
  }

  /* save the actual timestamp */
  last_check = timestamp - d.sec;
}
Beispiel #6
0
uint8_t
cron_anacron(uint32_t starttime, uint32_t endtime)
{
  clock_datetime_t d, ld;
  struct cron_event_linkedlist *curr;

  /* count anacron jobs and set pending */
  uint8_t count = 0;
  for (curr = head; curr != 0; curr = curr->next)
  {
    if ((curr->event.anacron_pending = curr->event.anacron))
      count++;
  }
#ifdef DEBUG_CRON
  debug_printf("cron: %i anacron jobs found\n", count);
#endif
  if (count == 0)
    return 0;

  /* alloc space for anacron list */
  struct cron_event_linkedlist **tab =
    __builtin_alloca(count * sizeof(struct cron_event_linkedlist *));
  if (!tab)
  {
#ifdef DEBUG_CRON
    debug_printf("cron: not enough ram!\n");
#endif
    return 0;
  }

  /* limit range */
  if ((endtime - starttime) > CRON_ANACRON_MAXAGE)
    starttime = endtime - CRON_ANACRON_MAXAGE;

  /* prepare anacron tab (reverse time order!!) */
  uint8_t pos = 0;
  uint32_t timestamp;
  for (timestamp = endtime; timestamp > starttime && pos < count;
       timestamp -= 60)
  {
    clock_datetime(&d, timestamp);
    clock_localtime(&ld, timestamp);

    for (curr = head; curr != 0; curr = curr->next)
    {
      if (curr->event.anacron_pending &&
          cron_check_event(&curr->event.cond, curr->event.use_utc, &d, &ld))
      {
        curr->event.anacron_pending = 0;
        tab[pos++] = curr;
      }
    }
  }
#ifdef DEBUG_CRON
  debug_printf("cron: %i pending anacron jobs\n", pos);
#endif

  /* process jobs */
  while (pos)
    cron_execute(tab[--pos]);

  return 1;
}