1
/* hp.c - support for HP Powertrust UPS
3
Copyright (C) 2002 Richard Muratti <rick@ccoz.com>
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
I have two HP Powertrust units
22
A2997A 1800VA Rack Mount
23
A2941A 600VA Floor Standing
25
Here's what i have discovered about these units.
27
+--------+-----+------+------+
28
|Cables | UPS | DB25 | DB9* |
29
|--------+-----+------+------+
30
|Receive | 1 | 3 | 3 |
31
|Transmit| 2 | 2 | 2 |
33
|--------+-----+------+------+
35
*) Cable used for A2994A; RX and TX appear to be exchanged
42
Online Offline Comment
44
A $ ! Status % Low Batt
45
B 066.7 066.7 Battery Voltage
49
F 050.0 050.0 Frequency
54
K > < KnnnKnnn Kill UPS after nnn seconds (ie dont restart)
55
L 233.0 000.0 Line Voltage
57
N NM NM [CR] gives CM response
58
O 231.0 231.0 Output Voltage
59
P ddd.d ddd.d unsupported/future values
61
R ddd.d ddd.d unsupported/future values
62
S < > SnnnSnnn Shutdown UPS after nnn is seconds
64
U > > Self test 10 Sec
65
V 1.00 1.00 Firmware Version
66
W HP^... HP^... ID String + Capablilities
69
Z > < ZnnnZnnn does something but what???
73
On power up UPS will send '('
74
On power good UPS will send '$' ie after going off batt
75
On power fail UPS will send '!'
76
On low batt UPS will send '%'
78
It seems that they are sent only once
79
so its best to poll for them using 'A'
81
Shutdown/kill only work if UPS is on battery.
82
To force set UPS in test mode 'U' then issue
85
UPS sends ')' on successful shutdown
90
What do P & R values represent.
91
What does ZnnnZnnn do.
95
if you can add to the above please feel fee to do so
96
but email me with any changes.
104
#include <sys/ioctl.h>
107
#define IGNCHARS "\n"
109
#define NUM_MODELS sizeof(modeltab)/sizeof(modeltab[0])
114
/* used external variables */
115
extern int debug_level; /* debug level, set by "-D" in main.c */
116
extern int sddelay; /* shutdown delay, set by "-d $delay" in main.c */
117
extern int do_forceshutdown; /* shutdown delay, set by "-k" in main.c */
126
{ "A2997A","HP^V230^F50^R01800^O230^P1"},
127
{ "A2941A","HP^V230^F50^R00600^O230^P1"},
128
{ "A2994A","HP^V230^F50^R01300^O230^P1"}
131
Some Models may have more than one id string
132
ie 110 volt countries
139
/* TODO: roll this into upscommon ala bestups */
140
void sendstring(char * string, int len, int delay)
144
for (i=0; (i<len); i++) {
145
upssendchar(string[i]);
151
void instcmd (int auxcmd, int dlen, char *data)
154
/* TODO: reply to upsd? */
158
case CMD_BTEST0: /* Stop Battery Test*/
161
case CMD_BTEST1: /* Start Battery Test*/
165
upslogx(LOG_INFO,"instcmd: unknown or unimplemented type 0x%04x\n",auxcmd);
174
upsh.instcmd = instcmd;
179
void init_serial(void)
181
int clr_bit = TIOCM_DTR | TIOCM_RTS;
182
ioctl(upsfd, TIOCMBIC, &clr_bit);
185
/* replacement for the old "installinfo" hack-job */
186
static void poll_data(const char *var, char reqchar)
190
upssendchar(reqchar);
191
upsrecv(tmp, sizeof(tmp), ENDCHAR, IGNCHARS);
193
dstate_setinfo(var, "%s", tmp);
196
void ups_model (void)
200
/* Get Ident String */
201
poll_data("ups.id", 'W');
204
/* Lookup UPS Model */
205
for (i=0; i < NUM_MODELS;i++) {
206
if (strncmp (dstate_getinfo("ups.id"),modeltab[i].id_string,strlen(modeltab[i].id_string)) == 0)
207
dstate_setinfo("ups.model", "%s", modeltab[i].model);
211
void upsdrv_initinfo(void)
213
dstate_setinfo("ups.mfr", "HP");
215
dstate_addcmd("battery.test.start");
216
dstate_addcmd("battery.test.stop");
220
printf("Detected %s [%s] on %s\n", dstate_getinfo("ups.mfr"),
221
dstate_getinfo("ups.model"), device_path);
227
void upsdrv_updateinfo(void)
229
unsigned char recBuf[10];
232
poll_data("input.voltage", 'L');
233
poll_data("output.voltage", 'O');
234
poll_data("input.frequency", 'F');
235
poll_data("ups.temperature", 'C');
236
poll_data("battery.voltage", 'B');
239
upsrecv((char *)recBuf,sizeof(recBuf)-1,ENDCHAR,IGNCHARS);
245
case '%': /* on battery, low battery */
250
case '!': /* on battery */
254
case '$': /* on line */
259
upslogx(LOG_INFO,"unknown UPS status byte 0x%04x\n",
262
return; /* don't commit */
268
void upsdrv_shutdown(void)
273
/* Put UPS in Self Test Mode */
279
/* Issue Shutdown/Kill Command */
280
if (sdtype == SD_RESTART) {
281
printf("UPS shutdown in '%d' seconds.\nUPS will RESTART on AC Power Good\n", sddelay);
282
snprintf (tmp, sizeof(tmp), "S%03dS%03d",sddelay,sddelay);
284
printf("UPS shutdown in '%d' seconds.\nUPS will NOT RESTART on AC Power Good\n", sddelay);
285
snprintf (tmp, sizeof(tmp), "K%03dK%03d",sddelay,sddelay);
288
sendstring (tmp,9,10);
291
void upsdrv_help(void)
293
printf("\nShutdown types:\n");
294
printf(" restart: UPS Will shutdown and will RESTART on AC Power Good (default)\n");
295
printf(" halt: UPS Will shutdown and will NOT RESTART on AC Power Good\n");
299
/* list flags and values that you want to receive via -x */
300
void upsdrv_makevartable(void)
302
/* allow '-x xyzzy' */
303
/* addvar(VAR_FLAG, "xyzzy", "Enable xyzzy mode"); */
305
/* allow '-x foo=<some value>' */
307
addvar(VAR_VALUE, "shutdown", "halt/<restart>");
310
void upsdrv_banner(void)
312
printf("Network UPS Tools - HP Powertrust UPS driver 0.01 (%s)\n", UPS_VERSION);
315
void upsdrv_initups(void)
317
/* this driver doesn't do sanity checks in upsdrv_updateinfo */
321
open_serial (device_path,B1200);
325
if (NULL == getval("shutdown"))
328
if (strcmp (getval("shutdown"),"halt") == 0)
333
void upsdrv_cleanup(void)