1
/* apcsmart.h - command table for APC smart protocol units
3
Copyright (C) 1999 Russell Kroll <rkroll@exploits.org>
4
(C) 2000 Nigel Metheringham <Nigel.Metheringham@Intechnology.co.uk>
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
#include <sys/ioctl.h>
26
#define APC_TABLE_VERSION "version 2.0"
2
* apcsmart.h - common defines for apcsmart driver
4
* Copyright (C) 1999 Russell Kroll <rkroll@exploits.org>
5
* (C) 2000 Nigel Metheringham <Nigel.Metheringham@Intechnology.co.uk>
6
* (C) 2011 Michal Soltys <soltys@ziu.info>
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
#ifndef __apcsmart_h__
24
#define __apcsmart_h__
26
#define DRIVER_NAME "APC Smart protocol driver"
27
#define DRIVER_VERSION "3.04"
29
#define ALT_CABLE_1 "940-0095B"
32
* alerts and other stuff for quick reference:
41
* * powering down now (only older models ?), handled by upsread()
42
* otherwise ignored (it doesn't have to be in ignore sets)
45
* & check alarm register for fail
50
* old ones for reference:
51
* #define IGNCHARS "\015+$|!~%?=#&"
52
* #define POLL_IGNORE "\015&|"
53
* #define POLL_ALERT "$!%+#?="
54
* #define MINIGNCHARS "\015+$|!"
55
* notice ~ that was present in IGNCHARS, but not in POLL_IGNORE - this kinda
56
* didn't make sense (?); new versions doesn't filter ~, but keep that in mind
57
* in case something obscure surfaces
58
* due to switch to ICANON tty mode, we removed \015 from ignored characters,
59
* as it's handled by IGNCR at read() level
28
62
/* Basic UPS reply line structure */
29
#define ENDCHAR 10 /* APC ends responses with LF */
31
/* these two are only used during startup */
32
#define IGNCHARS "\015+$|!~%?=*#&" /* special characters to ignore */
33
#define MINIGNCHARS "\015+$|!" /* minimum set of special characters to ignore */
35
/* normal polls: characters we don't want to parse (including a few alerts) */
36
#define POLL_IGNORE "\015?=*&|"
38
/* alert characters we care about - OL, OB, LB, not LB, RB */
39
#define POLL_ALERT "$!%+#"
41
#define UPSDELAY 50000 /* slow down multicharacter commands */
42
#define CMDLONGDELAY 1500000 /* some commands need a 1.5s gap for safety */
44
#define SER_WAIT_SEC 3 /* wait up to 3.0 sec for ser_get calls */
45
#define SER_WAIT_USEC 0
63
#define ENDCHAR 10 /* APC ends responses with LF (and CR, but it's IGNCRed) */
65
/* what to ignore during alert aware serial reads */
66
#define IGN_AACHARS "|&"
68
/* what alert_handler() should care about */
69
#define ALERT_CHARS "$!%+#?="
71
/* characters ignored by alertless reads */
72
#define IGN_CHARS IGN_AACHARS ALERT_CHARS
75
* these ones are used only during capability read, due to ^Z sending certain
76
* characters such as #; it seems it could be equal to just IGN_CHARS w/o #
77
* old: #define IGN_CCCHARS "|$!+"
79
#define IGN_CCCHARS "|&$!%+?=" /* capability check ignore set */
82
* command set 'a' command reports everything - protocol number, alerts and
85
#define IGN_CSCHARS "" /* command set ignore set */
47
87
/* dangerous instant commands must be reconfirmed within a 12 second window */
48
88
#define MINCMDTIME 3
51
91
/* it only does two strings, and they're both the same length */
52
92
#define APC_STRLEN 8
94
#define SER_D0 0x001 /* 0 sec., for flushes */
95
#define SER_DX 0x002 /* 200 ms for long/repeated cmds, in case of unexpected NAs */
96
#define SER_D1 0x004 /* 1.5 sec. */
97
#define SER_D3 0x008 /* 3 sec. (default) */
98
#define SER_AA 0x010 /* alert aware set */
99
#define SER_CC 0x020 /* capability check ign set */
100
#define SER_CS 0x040 /* command set ign set */
101
#define SER_TO 0x080 /* timeout allowed */
102
#define SER_HA 0x100 /* handle asterisk */
105
/* sets of the above (don't test against them, obviously */
108
* Some cmd codes to ignore (nut doesn't expose those, though the driver might
109
* use them internally (e.g. [a]). If you decide to support them at some
110
* point, remember about removing them from here !
112
#define APC_UNR_CMDS "\032\177~')-+8QRYayz"
54
114
/* --------------- */
58
#define APC_STAT_CAL 1 /* calibration */
59
#define APC_STAT_TRIM 2 /* SmartTrim */
60
#define APC_STAT_BOOST 4 /* SmartBoost */
61
#define APC_STAT_OL 8 /* on line */
62
#define APC_STAT_OB 16 /* on battery */
63
#define APC_STAT_OVER 32 /* overload */
64
#define APC_STAT_LB 64 /* low battery */
65
#define APC_STAT_RB 128 /* replace battery */
118
#define APC_STAT_CAL (1 << 0) /* calibration */
119
#define APC_STAT_TRIM (1 << 1) /* SmartTrim */
120
#define APC_STAT_BOOST (1 << 2) /* SmartBoost */
121
#define APC_STAT_OL (1 << 3) /* on line */
122
#define APC_STAT_OB (1 << 4) /* on battery */
123
#define APC_STAT_OVER (1 << 5) /* overload */
124
#define APC_STAT_LB (1 << 6) /* low battery */
125
#define APC_STAT_RB (1 << 7) /* replace battery */
67
/* serial protocol: special commands - initialization and such */
128
* serial protocol: special commands - initialization and such
129
* these are not exposed as instant commands
68
131
#define APC_STATUS 'Q'
69
132
#define APC_GOSMART 'Y'
70
133
#define APC_GODUMB 'R'
71
134
#define APC_CMDSET 'a'
72
#define APC_CAPABILITY 26 /* ^Z */
135
#define APC_CAPS '\032' /* ^Z */
73
136
#define APC_NEXTVAL '-'
77
/* Driver command table flag values */
79
#define APC_POLL 0x0001 /* Poll this variable regularly */
80
#define APC_IGNORE 0x0002 /* Never poll this */
81
#define APC_PRESENT 0x0004 /* Capability seen on this UPS */
83
#define APC_RW 0x0010 /* read-write variable */
84
#define APC_ENUM 0x0020 /* enumerated type */
85
#define APC_STRING 0x0040 /* string */
87
#define APC_NASTY 0x0100 /* Nasty command - take care */
88
#define APC_REPEAT 0x0200 /* Command needs sending twice */
90
#define APC_FORMATMASK 0xFF0000 /* Mask for apc data formats */
92
#define APC_F_PERCENT 0x020000 /* Data in a percent format */
93
#define APC_F_VOLT 0x030000 /* Data in a voltage format */
94
#define APC_F_AMP 0x040000 /* Data in a current/amp format */
95
#define APC_F_CELSIUS 0x050000 /* Data in a temp/C format */
96
#define APC_F_HEX 0x060000 /* Data in a hex number format */
97
#define APC_F_DEC 0x070000 /* Data in a decimal format */
98
#define APC_F_SECONDS 0x100000 /* Time in seconds */
99
#define APC_F_MINUTES 0x110000 /* Time in minutes */
100
#define APC_F_HOURS 0x120000 /* Time in hours */
101
#define APC_F_LEAVE 0 /* Just pass this through */
103
struct apc_vartab_t {
104
const char *name; /* the variable name */
105
unsigned int flags; /* various flags */
106
char cmd; /* command character */
110
{ "ups.firmware", 0, 'b' },
111
{ "ups.firmware.aux", 0, 'v' },
112
{ "ups.model", 0, 0x01 },
114
/* FUTURE: depends on variable naming scheme */
116
{ "ups.model.code", 0, 'V' },
137
#define APC_FW_OLD 'V'
138
#define APC_FW_NEW 'b'
143
/* default a.w.d. value / regex format for command '@' */
144
#define APC_AWDDEF "000"
145
#define APC_AWDFMT "^[0-9]{1,3}$"
147
/* maximum number of supported sdtype methods + regex format*/
148
#define APC_SDMAX "5"
149
#define APC_SDFMT "^[0-5]$"
119
{ "ups.serial", 0, 'n' },
120
{ "ups.mfr.date", 0, 'm' },
122
{ "ups.temperature", APC_POLL|APC_F_CELSIUS, 'C' },
123
{ "ups.load", APC_POLL|APC_F_PERCENT, 'P' },
125
{ "ups.test.interval", APC_F_HOURS, 'E' },
126
{ "ups.test.result", APC_POLL, 'X' },
128
{ "ups.delay.start", APC_F_SECONDS, 'r' },
129
{ "ups.delay.shutdown", APC_F_SECONDS, 'p' },
131
{ "ups.id", APC_STRING, 'c' },
133
{ "ups.contacts", APC_POLL|APC_F_HEX, 'i' },
134
{ "ups.display.language",
137
{ "input.voltage", APC_POLL|APC_F_VOLT, 'L' },
138
{ "input.frequency", APC_POLL|APC_F_DEC, 'F' },
139
{ "input.sensitivity", 0, 's' },
140
{ "input.quality", APC_POLL|APC_F_HEX, '9' },
142
{ "input.transfer.low", APC_F_VOLT, 'l' },
143
{ "input.transfer.high",
145
{ "input.transfer.reason",
148
{ "input.voltage.maximum",
149
APC_POLL|APC_F_VOLT, 'M' },
150
{ "input.voltage.minimum",
151
APC_POLL|APC_F_VOLT, 'N' },
153
{ "output.current", APC_POLL|APC_F_AMP, '/' },
154
{ "output.voltage", APC_POLL|APC_F_VOLT, 'O' },
155
{ "output.voltage.nominal",
158
{ "ambient.humidity", APC_POLL|APC_F_PERCENT, 'h' },
159
{ "ambient.humidity.high",
160
APC_F_PERCENT, '{' },
161
{ "ambient.humidity.low",
162
APC_F_PERCENT, '}' },
164
{ "ambient.temperature",
165
APC_POLL|APC_F_CELSIUS, 't' },
166
{ "ambient.temperature.high",
167
APC_F_CELSIUS, '[' },
168
{ "ambient.temperature.low",
169
APC_F_CELSIUS, ']' },
171
{ "battery.date", APC_STRING, 'x' },
173
{ "battery.charge", APC_POLL|APC_F_PERCENT, 'f' },
174
{ "battery.charge.restart",
175
APC_F_PERCENT, 'e' },
177
{ "battery.voltage", APC_POLL|APC_F_VOLT, 'B' },
178
{ "battery.voltage.nominal",
181
{ "battery.runtime", APC_POLL|APC_F_MINUTES, 'j' },
182
{ "battery.runtime.low",
183
APC_F_MINUTES, 'q' },
185
{ "battery.packs", APC_F_DEC, '>' },
186
{ "battery.packs.bad", APC_F_DEC, '<' },
187
{ "battery.alarm.threshold",
191
I = alarm enable (hex field) - split into alarm.n.enable
192
J = alarm status (hex field) - split into alarm.n.status
194
0x15 = output voltage selection (APC_F_VOLT)
195
0x5C = load power (APC_POLL|APC_F_PERCENT)
202
/* ------ instant commands ------ */
204
#define APC_CMD_FPTEST 'A'
205
#define APC_CMD_CALTOGGLE 'D'
206
#define APC_CMD_SHUTDOWN 'K'
207
#define APC_CMD_SOFTDOWN 'S'
208
#define APC_CMD_SIMPWF 'U'
209
#define APC_CMD_BTESTTOGGLE 'W'
210
#define APC_CMD_OFF 'Z'
212
#define APC_CMD_ON 0x0E /* ^N */
213
#define APC_CMD_BYPTOGGLE '^'
215
struct apc_cmdtab_t {
221
{ "load.off", APC_NASTY|APC_REPEAT, APC_CMD_OFF },
222
{ "load.on", APC_REPEAT, APC_CMD_ON },
224
{ "test.panel.start", 0, APC_CMD_FPTEST },
226
{ "test.failure.start", 0, APC_CMD_SIMPWF },
228
{ "test.battery.start", 0, APC_CMD_BTESTTOGGLE },
229
{ "test.battery.stop", 0, APC_CMD_BTESTTOGGLE },
231
{ "shutdown.return", APC_NASTY, APC_CMD_SOFTDOWN },
232
{ "shutdown.stayoff", APC_NASTY|APC_REPEAT, APC_CMD_SHUTDOWN },
234
{ "calibrate.start", 0, APC_CMD_CALTOGGLE },
235
{ "calibrate.stop", 0, APC_CMD_CALTOGGLE },
237
{ "bypass.start", 0, APC_CMD_BYPTOGGLE },
238
{ "bypass.stop", 0, APC_CMD_BYPTOGGLE },
243
/* things to ignore in protocol_verify - useless variables, etc. */
244
#define CMD_IGN_CHARS "\032-78@.,~\047\177QHRTYayz)1IJ"
246
/* compatibility with hardware that doesn't do APC_CMDSET ('a') */
249
const char *firmware;
250
const char *cmdchars;
255
{ "6QD", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 },
256
{ "6TI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 },
257
{ "6QI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 },
259
{ "5.4.D", "\1ABPQRSUYbdfgjmnx9", 0 },
261
{ "D6", "789ABCEFGKLMNOPQRSUVWXYZ", 0 },
262
{ "D5", "789ABCEFGKLMNOPQRSUVWXYZ", 0 },
263
{ "D4", "789ABCEFGKLMNOPQRSUVWXYZ", 0 },
265
{ "8QD", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 },
266
{ "8TI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 },
268
{ "0ZI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz/<>", 0 },
269
{ "5UI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz/<>", 0 },