~ubuntu-branches/ubuntu/saucy/nut/saucy

« back to all changes in this revision

Viewing changes to drivers/liebert.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2005-07-20 19:48:50 UTC
  • mto: (16.1.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20050720194850-oo61wjr33rrx2mre
Tags: upstream-2.0.2
ImportĀ upstreamĀ versionĀ 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
*/
23
23
 
24
24
#include "main.h"
 
25
#include "serial.h"
 
26
 
25
27
#include <sys/ioctl.h>
26
28
 
27
29
#define ML_ONBATTERY    0x55
60
62
/* normal idle loop - keep up with the current state of the UPS */
61
63
void upsdrv_updateinfo(void)
62
64
{
63
 
        int     flags, ob, lb, ret;
 
65
        int     flags, ret;
64
66
        char    c;
 
67
        unsigned int    ob, lb;
65
68
        static  unsigned int    ob_state = 0, ob_last = 0, ob_ctr = 0;
66
69
        static  unsigned int    lb_state = 0, lb_last = 0, lb_ctr = 0;
67
70
 
155
158
        dstate_dataok();
156
159
}
157
160
 
158
 
/*  Open the serial port.  The upscommon routines aren't used because
159
 
    they lose bits off the MCR required to make TX/RX work, and we
160
 
    set up the port to make use of VMIN/VTIME.
161
 
*/
162
 
static void open_serial_ml(const char *port)
163
 
{
164
 
        int     flags;
165
 
        struct termios tio;
166
 
 
167
 
        signal(SIGALRM, openfail);
168
 
        alarm(3);
169
 
 
170
 
        if ((upsfd = open(port, O_RDWR | O_NONBLOCK)) == -1)
171
 
                fatal("Unable to open %s", port);
172
 
 
173
 
        alarm(0);
174
 
 
175
 
        lockport(upsfd, port);
176
 
 
177
 
        if (ioctl(upsfd, TIOCMGET, &flags))
178
 
                fatal("get ioctl");
179
 
        flags |= TIOCM_RTS;
180
 
        if (ioctl(upsfd, TIOCMSET, &flags))
181
 
                fatal("set ioctl");
182
 
 
183
 
        tcgetattr(upsfd, &tio);
184
 
        cfmakeraw(&tio);
185
 
        tio.c_cflag |= CLOCAL;
186
 
        tio.c_cc[VMIN] = 0;
187
 
        tio.c_cc[VTIME] = 1;
188
 
        tcsetattr(upsfd, TCSANOW, &tio);
189
 
}
190
 
 
191
161
void upsdrv_banner(void)
192
162
{
193
163
        printf("Network UPS Tools - Liebert MultiLink UPS driver 1.0 (%s)\n", 
208
178
 
209
179
void upsdrv_initups(void)
210
180
{
211
 
        open_serial_ml(device_path);
 
181
        int rts_bit = TIOCM_RTS;
 
182
 
 
183
        upsfd = ser_open(device_path);
 
184
 
 
185
        /* raise RTS */
 
186
        ioctl(upsfd, TIOCMBIS, &rts_bit);
212
187
}
213
188
 
214
189
void upsdrv_cleanup(void)
215
190
{
 
191
        ser_close(upsfd, device_path);
216
192
}