Suport an additional device.

from henning
This commit is contained in:
mbalmer 2006-04-27 19:46:24 +00:00
parent 7686a799c8
commit 031f2f5572
3 changed files with 154 additions and 2 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.18 2005/10/24 05:14:13 fgsch Exp $
# $OpenBSD: Makefile,v 1.19 2006/04/27 19:46:24 mbalmer Exp $
COMMENT= "UPS monitoring program supporting many brands"
COMMENT-cgi= "CGIs for monitoring Nut-based UPSs"
@ -6,7 +6,7 @@ COMMENT-snmp= "driver for monitoring UPSs via SNMP"
VERSION= 2.0.0
DISTNAME= nut-${VERSION}
PKGNAME= ${DISTNAME}p1
PKGNAME= ${DISTNAME}p2
PKGNAME-cgi= nut-cgi-${VERSION}p0
PKGNAME-snmp= nut-snmp-${VERSION}p0
CATEGORIES= sysutils

View File

@ -0,0 +1,142 @@
$OpenBSD: patch-drivers_fentonups_c,v 1.1 2006/04/27 19:46:24 mbalmer Exp $
--- drivers/fentonups.c.orig Tue Apr 25 23:33:03 2006
+++ drivers/fentonups.c Wed Apr 26 00:11:06 2006
@@ -33,14 +33,17 @@ static float lowvolt = 0, voltrange;
static int lownorm, highnorm;
/* handle devices which don't give a properly formatted I string */
-static int check_mtab2(const char *raw)
+static int check_mtab2(const char *raw, int israw)
{
int i;
char *cooked;
- /* trim off the leading # and any trailing spaces */
- cooked = xstrdup(&raw[1]);
- rtrim(cooked, ' ');
+ if (israw) {
+ /* trim off the leading # and any trailing spaces */
+ cooked = xstrdup(&raw[1]);
+ rtrim(cooked, ' ');
+ } else
+ cooked = xstrdup(raw);
for (i = 0; mtab2[i].id != NULL; i++) {
if (!strcmp(cooked, mtab2[i].id)) {
@@ -74,7 +77,7 @@ static void guessmodel(const char *raw)
char mch, *mstr;
/* first see if it's in the mtab2 */
- if (check_mtab2(raw))
+ if (check_mtab2(raw, 1))
return;
mch = raw[17];
@@ -175,28 +178,36 @@ static char *get_id(void)
void upsdrv_initinfo(void)
{
int modelnum, i, ret;
- char temp[256], model[32], *raw;
+ char temp[256], qmodel[32], *model, *raw = NULL;
- raw = get_id();
+ model = getval("model");
- if (!raw)
- fatalx("Unable to detect a Fenton or Megatec protocol UPS");
+ if (!model) {
+ raw = get_id();
- snprintf(temp, sizeof(temp), "%s", raw);
+ if (!raw)
+ fatalx("Unable to detect a Fenton or Megatec protocol UPS");
- temp[11] = 0;
- temp[27] = 0;
+ snprintf(temp, sizeof(temp), "%s", raw);
- /* manufacturer */
- rtrim(&temp[1], ' ');
- dstate_setinfo("ups.mfr", &temp[1], 0, 0);
+ temp[11] = 0;
+ temp[27] = 0;
- /* L660A = PowerPal (L) @ 660 VA, American (A) version (115V) */
+ /* manufacturer */
+ rtrim(&temp[1], ' ');
+ dstate_setinfo("ups.mfr", &temp[1], 0, 0);
- /* grab full model string */
- rtrim(&temp[17], ' ');
- snprintf(model, sizeof(model), "%s", &temp[17]);
+ /* L660A = PowerPal (L) @ 660 VA, American (A) version (115V) */
+ /* grab full model string */
+ rtrim(&temp[17], ' ');
+ snprintf(qmodel, sizeof(qmodel), "%s", &temp[17]);
+ model = qmodel;
+ }
+
+ if (!model)
+ fatalx("unable to determine model");
+
modelnum = -1;
/* figure out official model name and voltage info from table */
@@ -210,20 +221,27 @@ void upsdrv_initinfo(void)
}
}
- /* table lookup fails -> guess */
- if (modelnum == -1)
- guessmodel(raw);
- else {
- dstate_setinfo("ups.model", "%s", modeltab[modelnum].desc);
+ if (model && modelnum == -1)
+ if (check_mtab2(model, 0) == 0)
+ fatalx("no such model: %s", model);
- dstate_setinfo("input.transfer.low", "%d",
- modeltab[modelnum].lowxfer);
+ if (raw) {
+ /* table lookup fails -> guess */
+ if (modelnum == -1)
+ guessmodel(raw);
+ else {
+ dstate_setinfo("ups.model", "%s",
+ modeltab[modelnum].desc);
- dstate_setinfo("input.transfer.high", "%d",
- modeltab[modelnum].highxfer);
+ dstate_setinfo("input.transfer.low", "%d",
+ modeltab[modelnum].lowxfer);
- lownorm = modeltab[modelnum].lownorm;
- highnorm = modeltab[modelnum].highnorm;
+ dstate_setinfo("input.transfer.high", "%d",
+ modeltab[modelnum].highxfer);
+
+ lownorm = modeltab[modelnum].lownorm;
+ highnorm = modeltab[modelnum].highnorm;
+ }
}
/* now add instant command support info */
@@ -231,7 +249,8 @@ void upsdrv_initinfo(void)
dstate_addcmd("test.battery.stop");
printf("Detected %s on %s\n", dstate_getinfo("ups.model"), device_path);
- free(raw);
+ if (raw)
+ free(raw);
/* paranoia - cancel any shutdown that might already be running */
ret = ser_send(upsfd, "C\r");
@@ -406,6 +425,7 @@ void upsdrv_help(void)
void upsdrv_makevartable(void)
{
+ addvar(VAR_VALUE, "model", "force model");
}
void upsdrv_banner(void)

View File

@ -0,0 +1,10 @@
$OpenBSD: patch-drivers_fentonups_h,v 1.1 2006/04/27 19:46:24 mbalmer Exp $
--- drivers/fentonups.h.orig Tue Apr 25 23:32:16 2006
+++ drivers/fentonups.h Wed Apr 26 00:09:19 2006
@@ -81,5 +81,6 @@ struct {
{ "WELI 500 1.0", "Giant Power", "MT650", 10.6, 3.7, 170, 180, 270, 280, 0 },
{ "SMART-UPS 1800VA T18Q16AG", "Effekta", "MT 2000 RM",
50.0, 19.5, 171, 200, 260, 278, 1 },
+ { "XS3000R", "Online", "Xanto S3000R", 1.81, 0.44, 165, 200, 240, 275, 1 },
{ NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0 }
};