2596ff8b6d
preserve my changes to the fentonups driver, allowing the detection logic to be bypassed and a model to be forced - for UPSes that do implement the protocol except the identification command, which seems to be somewhat common the Xanto S3000R thing here behaves like that, and support for it is added ok mbalmer
143 lines
3.8 KiB
Plaintext
143 lines
3.8 KiB
Plaintext
$OpenBSD: patch-drivers_fentonups_c,v 1.2 2006/05/03 17:32:09 henning Exp $
|
|
--- drivers/fentonups.c.orig Thu May 26 14:22:27 2005
|
|
+++ drivers/fentonups.c Mon May 1 18:16:55 2006
|
|
@@ -34,14 +34,17 @@ static float lowvolt = 0, voltrange, chr
|
|
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)) {
|
|
@@ -77,7 +80,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];
|
|
@@ -179,28 +182,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", "%s", &temp[1]);
|
|
+ temp[11] = 0;
|
|
+ temp[27] = 0;
|
|
|
|
- /* L660A = PowerPal (L) @ 660 VA, American (A) version (115V) */
|
|
+ /* manufacturer */
|
|
+ rtrim(&temp[1], ' ');
|
|
+ dstate_setinfo("ups.mfr", "%s", &temp[1]);
|
|
|
|
- /* 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 */
|
|
@@ -216,20 +227,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 */
|
|
@@ -237,7 +255,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");
|
|
@@ -426,6 +445,7 @@ void upsdrv_help(void)
|
|
void upsdrv_makevartable(void)
|
|
{
|
|
addvar(VAR_VALUE, "lowbattvolt", "Set low battery level, in volts");
|
|
+ addvar(VAR_VALUE, "model", "force model");
|
|
}
|
|
|
|
void upsdrv_banner(void)
|