031f2f5572
from henning
143 lines
3.7 KiB
Plaintext
143 lines
3.7 KiB
Plaintext
$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)
|