Beispiel #1
0
void http_alarm(char *rx, unsigned int rx_len)
{
  unsigned int i, save;
  char *time, *item;
  ALARMTIME t;

  save=0;
  time=0; item=0;
  for(; rx_len!=0;)
  {
         if(strncmpi(rx, "time=", 5) == 0)
    { rx += 5; rx_len -= 5; time = rx; i = url_decode(rx, rx, rx_len); rx += i; rx_len -= i; }
    else if(strncmpi(rx, "item=", 5) == 0)
    { rx += 5; rx_len -= 5; item = rx; i = url_decode(rx, rx, rx_len); rx += i; rx_len -= i; }
    else if(strncmpi(rx, "save=", 5) == 0)
    { rx += 5; rx_len -= 5; save = 1; }
    else
    { rx++;    rx_len--; }
  }

  if(save && time && item)
  {
    if((strlen(time) > 3) || (strlen(item) > 0))
    {
      i = atoi(item);
      alarm_parsetime(time, &t);
      alarm_settime(i, &t);
      alarm_load();
      menu_drawwnd(1);
    }
  }

  return;
}
static int sunxi_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct sunxi_rtc *rtc_dev = platform_get_drvdata(pdev);
	struct rtc_time *tm_set = &alrm->time, tm_now;
	unsigned long time_set = 0, time_now = 0;
	int ret = 0;

	ret = sunxi_rtc_read_time(dev, &tm_now);

	pr_info("%s(%d): time to set (%d-%d-%d %d:%d:%d), get cur time (%d-%d-%d %d:%d:%d)\n", __func__, __LINE__,
		tm_set->tm_year + 1900,	tm_set->tm_mon + 1, tm_set->tm_mday, tm_set->tm_hour, tm_set->tm_min, tm_set->tm_sec,
		tm_now.tm_year + 1900, tm_now.tm_mon + 1, tm_now.tm_mday, tm_now.tm_hour, tm_now.tm_min, tm_now.tm_sec);

	/* prevent the application seting the error time */
	if (!time_valid(tm_set)) {
		pr_err("%s(%d) err: time to set is not valid!\n", __func__, __LINE__);
		return -EINVAL;
	}

	/* if alarm date is before now, omit it */
	rtc_tm_to_time(tm_set, &time_set);
	rtc_tm_to_time(&tm_now, &time_now);
	if (!ret && time_set <= time_now) {
		pr_err("%s(%d) err: the day has been passed!\n", __func__, __LINE__);
		return -EINVAL;
	}

	mutex_lock(&rtc_dev->mutex);

	/* disable alarm */
	alarm_disable(rtc_dev);

	/* set alarm time */
	if (alarm_settime(rtc_dev, &alrm->time)) {
		mutex_unlock(&rtc_dev->mutex);
		pr_err("%s(%d) err: set alarm time failed!\n", __func__, __LINE__);
		return -EINVAL;
	}

	pr_info("%s(%d): alarm->enabled=%d\n", __func__, __LINE__, alrm->enabled);
	/* enable alarm if flag set */
	if (alrm->enabled) {
		arisc_enable_nmi_irq(); /* temperally, but no better way */
		alarm_enable(rtc_dev);
	}

	mutex_unlock(&rtc_dev->mutex);
	return 0;
}