1
/* multilink.c - support for Liebert UPS models via MultiLink cable.
3
Copyright (C) 2001 Rick Lyons <rick@powerup.com.au>
4
Copyright (C) 1999 Russell Kroll <rkroll@exploits.org>
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
30
#include <sys/types.h>
31
#include <sys/ioctl.h>
32
#include <sys/termios.h>
40
#include "upscommon.h"
43
#define ML_ONBATTERY 0x55
50
create_info(INFO_MAX, shmok);
52
/* setup the basics */
54
addinfo (INFO_MFR,"Liebert", FLAG_STRING, 0);
55
addinfo (INFO_MODEL,"MultiLink", FLAG_STRING, 0);
56
addinfo (INFO_STATUS, "", 0, 0);
59
/* normal idle loop - keep up with the current state of the UPS */
60
void updateinfo (void)
62
int flags, ob, bl, ret;
70
if (read(upsfd, &c, 1) == 1) {
71
while (read(upsfd, &c, 1) == 1)
73
if (c == ML_ONBATTERY)
77
ret = ioctl (upsfd, TIOCMGET, &flags);
80
upslog(LOG_INFO, "ioctl failed");
84
bl = (flags & TIOCM_CD);
89
strcat (temp, "LB "); /* low battery */
92
strcat (temp, "OB"); /* on battery */
94
strcat (temp, "OL"); /* on line */
96
setinfo(INFO_STATUS, "%s", temp);
101
/* install pointers to functions for msg handlers called from msgparse */
102
void setuphandlers(void)
107
void usage(char *prog)
109
printf ("usage: %s [-h] [-m <model>] [-M <mfr>] <device>\n", prog);
110
printf ("Example: %s /dev/ttyS0\n", prog);
113
void help(char *prog)
115
printf ("usage: %s [-h] [-m <model>] [-M <mfr>] <device>\n", prog);
117
printf ("-h - display this help\n");
118
printf ("-m <model> - set model name to <model>\n");
119
printf ("-M <mfr> - set manufacturer name to <mfr>\n");
120
printf ("<device> - /dev entry corresponding to UPS port\n");
123
/* Open the serial port. The upscommon routines aren't used because
124
they lose bits off the MCR required to make TX/RX work, and we
125
set up the port to make use of VMIN/VTIME.
128
open_serial_ml(char *port)
133
signal(SIGALRM, openfail);
136
if ((upsfd = open(port, O_RDWR)) == -1)
137
fatal("Unable to open %s", port);
141
lockport(upsfd, port);
143
if (ioctl(upsfd, TIOCMGET, &flags))
146
if (ioctl(upsfd, TIOCMSET, &flags))
149
tcgetattr(upsfd, &tio);
153
tcsetattr(upsfd, TCSANOW, &tio);
156
int main (int argc, char **argv)
158
char *portname, *prog, *forcemodel = NULL, *forcemfr = NULL;
161
printf ("Network UPS Tools - Liebert MultiLink UPS driver 1.0 (%s)\n", UPS_VERSION);
162
openlog ("multilink", LOG_PID, LOG_FACILITY);
165
while ((i = getopt(argc, argv, "+hm:M:")) != EOF) {
194
for (i = strlen(argv[0]); i >= 0; i--)
195
if (argv[0][i] == '/') {
196
portname = &argv[0][i+1];
200
if (portname == NULL) {
201
printf ("Unable to abbreviate %s\n", argv[0]);
205
snprintf (statefn, sizeof(statefn), "%s/multilink-%s", STATEPATH,
207
open_serial_ml(argv[0]);
211
/* replace model/mfr info if specified on command line */
213
setinfo(INFO_MFR, "%s", forcemfr);
216
setinfo(INFO_MODEL, "%s", forcemodel);
218
createmsgq(); /* try to create IPC message queue */
224
pidfn = xmalloc(SMALLBUF);
225
snprintf(pidfn, sizeof(pidfn), "multilink-%s", portname);
231
/* wait up to 2 seconds for a message from the upsd */
234
upslogx(LOG_INFO, "Received a message from upsd");