1
/* newapc.h - command table for APC smart protocol units
3
$Id: newapc.h,v 1.1.1.2 2002/03/04 11:43:51 cvs Exp $
5
Copyright (C) 1999 Russell Kroll <rkroll@exploits.org>
6
(C) 2000 Nigel Metheringham <Nigel.Metheringham@Intechnology.co.uk>
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
24
#include <sys/ioctl.h>
25
#include <sys/termios.h>
28
#define APC_TABLE_VERSION "version 2.0"
30
/* Basic UPS reply line structure */
31
#define ENDCHAR 10 /* APC ends responses with LF */
32
#define IGNCHARS "\015+$|!~%?=*#&" /* special characters to ignore */
33
#define MINIGNCHARS "\015+$|!" /* minimum set of special characters to ignore */
35
/* dangerous instant commands must be reconfirmed within a 12 second window */
39
/* it only does two strings, and they're both the same length */
44
/* serial protocol: special commands - initialization and such */
45
#define APC_STATUS 'Q'
46
#define APC_GOSMART 'Y'
47
#define APC_CMDSET 'a'
48
#define APC_CAPABILITY 26 /* ^Z */
49
#define APC_NEXTVAL '-'
53
/* Driver command table flag values */
55
#define APC_POLL 0x0001 /* Poll this variable regularly */
56
#define APC_IGNORE 0x0002 /* Never poll this */
57
#define APC_PRESENT 0x0004 /* Capability seen on this UPS */
59
#define APC_RW 0x0010 /* read-write variable */
60
#define APC_ENUM 0x0020 /* enumerated type */
61
#define APC_STRING 0x0040 /* string */
63
#define APC_NASTY 0x0100 /* Nasty command - take care */
64
#define APC_REPEAT 0x0200 /* Command needs sending twice */
66
#define APC_FORMATMASK 0xFF0000 /* Mask for apc data formats */
68
#define APC_F_PERCENT 0x020000 /* Data in a percent format */
69
#define APC_F_VOLT 0x030000 /* Data in a voltage format */
70
#define APC_F_AMP 0x040000 /* Data in a current/amp format */
71
#define APC_F_CELSIUS 0x050000 /* Data in a temp/C format */
72
#define APC_F_HEX 0x060000 /* Data in a hex number format */
73
#define APC_F_DEC 0x070000 /* Data in a decimal format */
74
#define APC_F_SECONDS 0x100000 /* Time in seconds */
75
#define APC_F_MINUTES 0x110000 /* Time in minutes */
76
#define APC_F_HOURS 0x120000 /* Time in hours */
77
#define APC_F_LEAVE 0 /* Just pass this through */
80
const char *name; /* the variable name */
81
unsigned int flags; /* various flags */
82
char cmd; /* command character */
86
{ "ups.firmware", 0, 'b' },
87
{ "ups.firmware.aux", 0, 'v' },
88
{ "ups.model", 0, 0x01 },
90
/* FUTURE: depends on variable naming scheme */
92
{ "ups.model.code", 0, 'V' },
95
{ "ups.serial", 0, 'n' },
96
{ "ups.mfr.date", 0, 'm' },
98
{ "ups.temperature", APC_POLL|APC_F_CELSIUS, 'C' },
99
{ "ups.load", APC_POLL|APC_F_PERCENT, 'P' },
101
{ "ups.test.interval", APC_F_HOURS, 'E' },
102
{ "ups.test.result", APC_POLL, 'X' },
104
{ "ups.delay.start", APC_F_SECONDS, 'r' },
105
{ "ups.delay.shutdown", APC_F_SECONDS, 'p' },
107
{ "ups.id", APC_STRING, 'c' },
109
{ "ups.contacts", APC_POLL|APC_F_HEX, 'i' },
110
{ "ups.display.language",
113
{ "input.voltage", APC_POLL|APC_F_VOLT, 'L' },
114
{ "input.frequency", APC_POLL|APC_F_DEC, 'F' },
115
{ "input.sensitivity", 0, 's' },
116
{ "input.quality", APC_POLL|APC_F_HEX, '9' },
118
{ "input.transfer.low", APC_F_VOLT, 'l' },
119
{ "input.transfer.high",
121
{ "input.transfer.reason",
124
{ "input.voltage.maximum",
125
APC_POLL|APC_F_VOLT, 'M' },
126
{ "input.voltage.minimum",
127
APC_POLL|APC_F_VOLT, 'N' },
129
{ "output.current", APC_POLL|APC_F_AMP, '/' },
130
{ "output.voltage", APC_POLL|APC_F_VOLT, 'O' },
131
{ "output.voltage.target.battery",
134
{ "ambient.humidity", APC_POLL|APC_F_PERCENT, 'h' },
135
{ "ambient.humidity.alarm.maximum",
136
APC_F_PERCENT, '{' },
137
{ "ambient.humidity.alarm.minimum",
138
APC_F_PERCENT, '}' },
140
{ "ambient.temperature",
141
APC_POLL|APC_F_CELSIUS, 't' },
142
{ "ambient.temperature.alarm.maximum",
143
APC_F_CELSIUS, '[' },
144
{ "ambient.temperature.alarm.minimum",
145
APC_F_CELSIUS, ']' },
147
{ "battery.date", APC_STRING, 'x' },
149
{ "battery.charge", APC_POLL|APC_F_PERCENT, 'f' },
150
{ "battery.charge.restart",
151
APC_F_PERCENT, 'e' },
153
{ "battery.voltage", APC_POLL|APC_F_VOLT, 'B' },
154
{ "battery.voltage.nominal",
157
{ "battery.runtime", APC_POLL|APC_F_MINUTES, 'j' },
158
{ "battery.runtime.low",
159
APC_F_MINUTES, 'q' },
161
{ "battery.packs", APC_F_DEC, '>' },
162
{ "battery.packs.bad", APC_F_DEC, '<' },
163
{ "battery.alarm.threshold",
167
I = alarm enable (hex field) - split into alarm.n.enable
168
J = alarm status (hex field) - split into alarm.n.status
170
0x15 = output voltage selection (APC_F_VOLT)
171
0x5C = load power (APC_POLL|APC_F_PERCENT)
178
/* ------ instant commands ------ */
180
#define APC_CMD_FPTEST 'A'
181
#define APC_CMD_CALTOGGLE 'D'
182
#define APC_CMD_SHUTDOWN 'K'
183
#define APC_CMD_SOFTDOWN 'S'
184
#define APC_CMD_SIMPWF 'U'
185
#define APC_CMD_BTESTTOGGLE 'W'
186
#define APC_CMD_OFF 'Z'
188
#define APC_CMD_ON 0x0E /* ^N */
189
#define APC_CMD_BYPTOGGLE '^'
191
struct apc_cmdtab_t {
197
{ "load.off", APC_NASTY|APC_REPEAT, APC_CMD_OFF },
198
{ "load.on", APC_REPEAT, APC_CMD_ON },
200
{ "test.panel.start", 0, APC_CMD_FPTEST },
202
{ "test.failure.start", 0, APC_CMD_SIMPWF },
204
{ "test.battery.start", 0, APC_CMD_BTESTTOGGLE },
205
{ "test.battery.stop", 0, APC_CMD_BTESTTOGGLE },
207
{ "shutdown.return", APC_NASTY, APC_CMD_SOFTDOWN },
208
{ "shutdown.stayoff", APC_NASTY|APC_REPEAT, APC_CMD_SHUTDOWN },
210
{ "calibrate.start", 0, APC_CMD_CALTOGGLE },
211
{ "calibrate.stop", 0, APC_CMD_CALTOGGLE },
213
{ "bypass.start", 0, APC_CMD_BYPTOGGLE },
214
{ "bypass.stop", 0, APC_CMD_BYPTOGGLE },
219
/* things to ignore in protocol_verify - useless variables, etc. */
220
#define CMD_IGN_CHARS "\032-78@.,~\047\177QHRTYayz)1IJ"