/* add another UPS for monitoring from ups.conf */ static void ups_create(const char *fn, const char *name, const char *desc) { upstype_t *temp; for (temp = firstups; temp != NULL; temp = temp->next) { if (!strcasecmp(temp->name, name)) { upslogx(LOG_ERR, "UPS name [%s] is already in use!", name); return; } } /* grab some memory and add the info */ temp = xcalloc(1, sizeof(*temp)); temp->fn = xstrdup(fn); temp->name = xstrdup(name); if (desc) { temp->desc = xstrdup(desc); } temp->stale = 1; temp->retain = 1; temp->sock_fd = sstate_connect(temp); /* preload this to the current time to avoid false staleness */ clock_monotonic(&temp->last_heard); temp->next = firstups; firstups = temp; num_ups++; }
void upsdrv_initups(void) { extrafd = upsfd = sstate_connect(); }
void upsdrv_updateinfo(void) { time_t now = time(NULL); if (sstate_dead(15)) { sstate_disconnect(); extrafd = upsfd = sstate_connect(); return; } if (sstate_readline()) { sstate_disconnect(); return; } if (ups.timer.shutdown >= 0) { ups.timer.shutdown -= difftime(now, last_poll); if (ups.timer.shutdown < 0) { const char *val; ups.timer.shutdown = -1; outlet = 0; val = getval("load.off"); if (val) { char buf[SMALLBUF]; snprintf(buf, sizeof(buf), "INSTCMD %s\n", val); sstate_sendline(buf); } } } else if (ups.timer.start >= 0) { if (online) { ups.timer.start -= difftime(now, last_poll); } else { ups.timer.start = ondelay; } if (ups.timer.start < 0) { const char *val; ups.timer.start = -1; outlet = 1; val = getval("load.on"); if (val) { char buf[SMALLBUF]; snprintf(buf, sizeof(buf), "INSTCMD %s\n", val); sstate_sendline(buf); } dstate_setinfo("ups.status", "%s", ups.status); } } else if (!online && outlet) { if (battery.charge.act < battery.charge.low) { upslogx(LOG_INFO, "Battery charge low"); instcmd("shutdown.return", NULL); } else if (battery.runtime.act < battery.runtime.low) { upslogx(LOG_INFO, "Battery runtime low"); instcmd("shutdown.return", NULL); } } dstate_setinfo("ups.timer.shutdown", "%d", ups.timer.shutdown); dstate_setinfo("ups.timer.start", "%d", ups.timer.start); last_poll = now; }
int upsdrv_initups(void) { extrafd = upsfd = sstate_connect(); return 1; }