Imported Upstream version 2.6.2

This commit is contained in:
Arnaud Quette 2011-09-29 20:14:46 +02:00
parent a367d9bc54
commit 45043b58d0
246 changed files with 18228 additions and 1415 deletions

View file

@ -1,50 +1,88 @@
/* apcsmart.h - command table for APC smart protocol units
/*
* apcsmart.h - common defines for apcsmart driver
*
* Copyright (C) 1999 Russell Kroll <rkroll@exploits.org>
* (C) 2000 Nigel Metheringham <Nigel.Metheringham@Intechnology.co.uk>
* (C) 2011 Michal Soltys <soltys@ziu.info>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
Copyright (C) 1999 Russell Kroll <rkroll@exploits.org>
(C) 2000 Nigel Metheringham <Nigel.Metheringham@Intechnology.co.uk>
#ifndef __apcsmart_h__
#define __apcsmart_h__
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
#define DRIVER_NAME "APC Smart protocol driver"
#define DRIVER_VERSION "3.0"
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
#define ALT_CABLE_1 "940-0095B"
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* alerts and other stuff for quick reference:
*
* $ OL
* ! OB
* % LB
* + not LB anymore
* # RB
* ? OVER
* = not OVER anymore
* * powering down now (only older models ?), handled by upsread()
* otherwise ignored (it doesn't have to be in ignore sets)
*
* | eeprom change
* & check alarm register for fail
* ~ ???
*/
#include <ctype.h>
#include <sys/ioctl.h>
#include "serial.h"
#include "timehead.h"
#define APC_TABLE_VERSION "version 2.2"
/*
* old ones for reference:
* #define IGNCHARS "\015+$|!~%?=#&"
* #define POLL_IGNORE "\015&|"
* #define POLL_ALERT "$!%+#?="
* #define MINIGNCHARS "\015+$|!"
* notice ~ that was present in IGNCHARS, but not in POLL_IGNORE - this kinda
* didn't make sense (?); new versions doesn't filter ~, but keep that in mind
* in case something obscure surfaces
* due to switch to ICANON tty mode, we removed \015 from ignored characters,
* as it's handled by IGNCR at read() level
*/
/* Basic UPS reply line structure */
#define ENDCHAR 10 /* APC ends responses with LF */
#define ENDCHAR 10 /* APC ends responses with LF (and CR, but it's IGNCRed) */
/* characters ignored by default */
#define IGNCHARS "\015+$|!~%?=#&" /* special characters to ignore */
/* what to ignore during alert aware serial reads */
#define IGN_AACHARS "|&"
/* these one is used only during startup, due to ^Z sending certain characters such as # */
#define MINIGNCHARS "\015+$|!" /* minimum set of special characters to ignore */
/* what alert_handler() should care about */
#define ALERT_CHARS "$!%+#?="
/* normal polls: characters we don't want to parse (including a few alerts) */
#define POLL_IGNORE "\015&|"
/* characters ignored by alertless reads */
#define IGN_CHARS IGN_AACHARS ALERT_CHARS
/* alert characters we care about - OL, OB, LB, not LB, RB, OVER, not OVER */
#define POLL_ALERT "$!%+#?="
/*
* these ones are used only during capability read, due to ^Z sending certain
* characters such as #; it seems it could be equal to just IGN_CHARS w/o #
* old: #define IGN_CCCHARS "|$!+"
*/
#define IGN_CCCHARS "|&$!%+?=" /* capability check ignore set */
#define UPSDELAY 50000 /* slow down multicharacter commands */
#define CMDLONGDELAY 1500000 /* some commands need a 1.5s gap for safety */
#define SER_WAIT_SEC 3 /* wait up to 3.0 sec for ser_get calls */
#define SER_WAIT_USEC 0
/*
* command set 'a' command reports everything - protocol number, alerts and
* supported commands
*/
#define IGN_CSCHARS "" /* command set ignore set */
/* dangerous instant commands must be reconfirmed within a 12 second window */
#define MINCMDTIME 3
@ -53,239 +91,61 @@
/* it only does two strings, and they're both the same length */
#define APC_STRLEN 8
#define SER_D0 0x001 /* 0 sec., for flushes */
#define SER_DX 0x002 /* 200 ms for long/repeated cmds, in case of unexpected NAs */
#define SER_D1 0x004 /* 1.5 sec. */
#define SER_D3 0x008 /* 3 sec. (default) */
#define SER_AA 0x010 /* alert aware set */
#define SER_CC 0x020 /* capability check ign set */
#define SER_CS 0x040 /* command set ign set */
#define SER_TO 0x080 /* timeout allowed */
#define SER_HA 0x100 /* handle asterisk */
/* sets of the above (don't test against them, obviously */
/*
* Some cmd codes to ignore (nut doesn't expose those, though the driver might
* use them internally (e.g. [a]). If you decide to support them at some
* point, remember about removing them from here !
*/
#define APC_UNR_CMDS "\032\177~')-+8QRYayz"
/* --------------- */
/* status bits */
#define APC_STAT_CAL 1 /* calibration */
#define APC_STAT_TRIM 2 /* SmartTrim */
#define APC_STAT_BOOST 4 /* SmartBoost */
#define APC_STAT_OL 8 /* on line */
#define APC_STAT_OB 16 /* on battery */
#define APC_STAT_OVER 32 /* overload */
#define APC_STAT_LB 64 /* low battery */
#define APC_STAT_RB 128 /* replace battery */
#define APC_STAT_CAL 0x01 /* calibration */
#define APC_STAT_TRIM 0x02 /* SmartTrim */
#define APC_STAT_BOOST 0x04 /* SmartBoost */
#define APC_STAT_OL 0x08 /* on line */
#define APC_STAT_OB 0x10 /* on battery */
#define APC_STAT_OVER 0x20 /* overload */
#define APC_STAT_LB 0x40 /* low battery */
#define APC_STAT_RB 0x80 /* replace battery */
/* serial protocol: special commands - initialization and such */
/*
* serial protocol: special commands - initialization and such
* these are not exposed as instant commands
*/
#define APC_STATUS 'Q'
#define APC_GOSMART 'Y'
#define APC_GODUMB 'R'
#define APC_CMDSET 'a'
#define APC_CAPABILITY 26 /* ^Z */
#define APC_CAPS '\032' /* ^Z */
#define APC_NEXTVAL '-'
#define APC_FW_OLD 'V'
#define APC_FW_NEW 'b'
/* --------------- */
#define APC_LBUF 512
#define APC_SBUF 32
/* Driver command table flag values */
/* default a.w.d. value / regex format for command '@' */
#define APC_AWDDEF "000"
#define APC_AWDFMT "^[0-9]{1,3}$"
#define APC_POLL 0x0001 /* Poll this variable regularly */
#define APC_PRESENT 0x0004 /* Capability seen on this UPS */
/* maximum number of supported sdtype methods + regex format*/
#define APC_SDMAX "5"
#define APC_SDFMT "^[0-5]$"
#define APC_RW 0x0010 /* read-write variable */
#define APC_ENUM 0x0020 /* enumerated type */
#define APC_STRING 0x0040 /* string */
#define APC_NASTY 0x0100 /* Nasty command - take care */
#define APC_REPEAT 0x0200 /* Command needs sending twice */
#define APC_FORMATMASK 0xFF0000 /* Mask for apc data formats */
#define APC_F_PERCENT 0x020000 /* Data in a percent format */
#define APC_F_VOLT 0x030000 /* Data in a voltage format */
#define APC_F_AMP 0x040000 /* Data in a current/amp format */
#define APC_F_CELSIUS 0x050000 /* Data in a temp/C format */
#define APC_F_HEX 0x060000 /* Data in a hex number format */
#define APC_F_DEC 0x070000 /* Data in a decimal format */
#define APC_F_SECONDS 0x100000 /* Time in seconds */
#define APC_F_MINUTES 0x110000 /* Time in minutes */
#define APC_F_HOURS 0x120000 /* Time in hours */
#define APC_F_REASON 0x130000 /* Reason of transfer */
#define APC_F_LEAVE 0 /* Just pass this through */
typedef struct {
const char *name; /* the variable name */
unsigned int flags; /* various flags */
char cmd; /* command character */
} apc_vartab_t;
apc_vartab_t apc_vartab[] = {
{ "ups.firmware.old", 0, 'V' },
{ "ups.firmware", 0, 'b' },
{ "ups.firmware.aux", 0, 'v' },
{ "ups.model", 0, 0x01 },
{ "ups.serial", 0, 'n' },
{ "ups.mfr.date", 0, 'm' },
{ "ups.temperature", APC_POLL|APC_F_CELSIUS, 'C' },
{ "ups.load", APC_POLL|APC_F_PERCENT, 'P' },
{ "ups.test.interval", APC_F_HOURS, 'E' },
{ "ups.test.result", APC_POLL, 'X' },
{ "ups.delay.start", APC_F_SECONDS, 'r' },
{ "ups.delay.shutdown", APC_F_SECONDS, 'p' },
{ "ups.id", APC_STRING, 'c' },
{ "ups.contacts", APC_POLL|APC_F_HEX, 'i' },
{ "ups.display.language",
0, 0x0C },
{ "input.voltage", APC_POLL|APC_F_VOLT, 'L' },
{ "input.frequency", APC_POLL|APC_F_DEC, 'F' },
{ "input.sensitivity", 0, 's' },
{ "input.quality", APC_POLL|APC_F_HEX, '9' },
{ "input.transfer.low", APC_F_VOLT, 'l' },
{ "input.transfer.high",
APC_F_VOLT, 'u' },
{ "input.transfer.reason",
APC_POLL|APC_F_REASON, 'G' },
{ "input.voltage.maximum",
APC_POLL|APC_F_VOLT, 'M' },
{ "input.voltage.minimum",
APC_POLL|APC_F_VOLT, 'N' },
{ "output.current", APC_POLL|APC_F_AMP, '/' },
{ "output.voltage", APC_POLL|APC_F_VOLT, 'O' },
{ "output.voltage.nominal",
APC_F_VOLT, 'o' },
{ "ambient.humidity", APC_POLL|APC_F_PERCENT, 'h' },
{ "ambient.humidity.high",
APC_F_PERCENT, '{' },
{ "ambient.humidity.low",
APC_F_PERCENT, '}' },
{ "ambient.temperature",
APC_POLL|APC_F_CELSIUS, 't' },
{ "ambient.temperature.high",
APC_F_CELSIUS, '[' },
{ "ambient.temperature.low",
APC_F_CELSIUS, ']' },
{ "battery.date", APC_STRING, 'x' },
{ "battery.charge", APC_POLL|APC_F_PERCENT, 'f' },
{ "battery.charge.restart",
APC_F_PERCENT, 'e' },
{ "battery.voltage", APC_POLL|APC_F_VOLT, 'B' },
{ "battery.voltage.nominal",
0, 'g' },
{ "battery.runtime", APC_POLL|APC_F_MINUTES, 'j' },
{ "battery.runtime.low",
APC_F_MINUTES, 'q' },
{ "battery.packs", APC_F_DEC, '>' },
{ "battery.packs.bad", APC_F_DEC, '<' },
{ "battery.alarm.threshold",
0, 'k' },
/* todo:
I = alarm enable (hex field) - split into alarm.n.enable
J = alarm status (hex field) - split into alarm.n.status
0x15 = output voltage selection (APC_F_VOLT)
0x5C = load power (APC_POLL|APC_F_PERCENT)
*/
{NULL, 0, 0},
};
/* ------ instant commands ------ */
#define APC_CMD_FPTEST 'A'
#define APC_CMD_CALTOGGLE 'D'
#define APC_CMD_SHUTDOWN 'K'
#define APC_CMD_SOFTDOWN 'S'
#define APC_CMD_GRACEDOWN '@'
#define APC_CMD_SIMPWF 'U'
#define APC_CMD_BTESTTOGGLE 'W'
#define APC_CMD_OFF 'Z'
#define APC_CMD_ON 0x0E /* ^N */
#define APC_CMD_BYPTOGGLE '^'
typedef struct {
const char *name;
int flags;
char cmd;
} apc_cmdtab_t;
apc_cmdtab_t apc_cmdtab[] =
{
{ "load.off", APC_NASTY|APC_REPEAT, APC_CMD_OFF },
{ "load.on", APC_REPEAT, APC_CMD_ON },
{ "test.panel.start", 0, APC_CMD_FPTEST },
{ "test.failure.start", 0, APC_CMD_SIMPWF },
{ "test.battery.start", 0, APC_CMD_BTESTTOGGLE },
{ "test.battery.stop", 0, APC_CMD_BTESTTOGGLE },
{ "shutdown.return.grace",
APC_NASTY, APC_CMD_GRACEDOWN },
{ "shutdown.return", APC_NASTY, APC_CMD_SOFTDOWN },
{ "shutdown.stayoff", APC_NASTY|APC_REPEAT, APC_CMD_SHUTDOWN },
{ "calibrate.start", 0, APC_CMD_CALTOGGLE },
{ "calibrate.stop", 0, APC_CMD_CALTOGGLE },
{ "bypass.start", 0, APC_CMD_BYPTOGGLE },
{ "bypass.stop", 0, APC_CMD_BYPTOGGLE },
{ NULL, 0, 0 }
};
/* compatibility with hardware that doesn't do APC_CMDSET ('a') */
struct {
const char *firmware;
const char *cmdchars;
int flags;
} compat_tab[] = {
/* APC Matrix */
{ "0XI", "789ABCDEFGKLMNOPQRSTUVWXYZcefgjklmnopqrsuwxz/<>\\^\014\026", 0 },
{ "0XM", "789ABCDEFGKLMNOPQRSTUVWXYZcefgjklmnopqrsuwxz/<>\\^\014\026", 0 },
{ "0ZI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz/<>", 0 },
{ "5UI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz/<>", 0 },
{ "5ZM", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz/<>", 0 },
/* APC600 */
{ "6QD", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 },
{ "6QI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 },
{ "6TD", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 },
{ "6TI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 },
/* SmartUPS 900 */
{ "7QD", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 },
{ "7QI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 },
{ "7TD", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 },
{ "7TI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 },
/* SmartUPS 900I */
{ "7II", "79ABCEFGKLMNOPQSUVWXYZcfg", 0 },
/* SmartUPS 2000I */
{ "9II", "79ABCEFGKLMNOPQSUVWXYZcfg", 0 },
{ "9GI", "79ABCEFGKLMNOPQSUVWXYZcfg", 0 },
/* SmartUPS 1250 */
{ "8QD", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 },
{ "8QI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 },
{ "8TD", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 },
{ "8TI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 },
/* CS 350 */
{ "5.4.D", "\1ABPQRSUYbdfgjmnx9", 0 },
/* Smart-UPS 600 */
{ "D9", "789ABCEFGKLMNOPQRSUVWXYZ", 0 },
{ "D8", "789ABCEFGKLMNOPQRSUVWXYZ", 0 },
{ "D7", "789ABCEFGKLMNOPQRSUVWXYZ", 0 },
{ "D6", "789ABCEFGKLMNOPQRSUVWXYZ", 0 },
{ "D5", "789ABCEFGKLMNOPQRSUVWXYZ", 0 },
{ "D4", "789ABCEFGKLMNOPQRSUVWXYZ", 0 },
{ NULL, NULL, 0 },
};
#endif