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

« back to all changes in this revision

Viewing changes to drivers/cyberpower.c

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Quette
  • Date: 2004-05-28 13:10:01 UTC
  • mto: (16.1.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040528131001-yj2m9qcez4ya2w14
Tags: upstream-1.4.2
ImportĀ upstreamĀ versionĀ 1.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* cyberpower.c - Network UPS Tools driver for Cyber Power Systems units
 
2
 
 
3
   Copyright (C) 2001  Russell Kroll <rkroll@exploits.org>
 
4
   Copyright (C) 2002  Len White     <lwhite@darkfires.net>
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
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
 
19
*/
 
20
 
 
21
#include "main.h"
 
22
 
 
23
#include <sys/ioctl.h>
 
24
#include <sys/termios.h>
 
25
 
 
26
#include "timehead.h"
 
27
 
 
28
#define DRV_VERSION "0.22"
 
29
 
 
30
/* window for repeating dangerous command (shutdown.stayoff) */
 
31
#define MINCMDTIME      3
 
32
#define MAXCMDTIME      15
 
33
 
 
34
/* limit the amount of spew that goes in the syslog when we lose the UPS */
 
35
#define CP_ERR_LIMIT 10         /* start limiting after 10 in a row     */
 
36
#define CP_ERR_RATE 100         /* then only print every 100th error    */
 
37
 
 
38
        struct  sigaction sa;
 
39
        sigset_t cp_sigmask;
 
40
        unsigned int    poll_failures = 0;
 
41
 
 
42
/* ups frequency */
 
43
float frequency(unsigned char in)
 
44
{
 
45
        float freq[22] = { 63.0, 62.7, 62.4, 62.1, 61.8, 61.4, 61.1, 60.8, 60.5, 60.2, 60.0, 59.7, 59.4, 59.1, 58.8, 58.5, 58.3, 58.0, 57.7, 57.4, 57.2, 57.0 };
 
46
        int i, j;
 
47
        
 
48
        for (i = 0, j = 168; i < 23; j++, i++)
 
49
                if (in == j)
 
50
                        return (float)freq[i];
 
51
 
 
52
        return (float)60;
 
53
}
 
54
 
 
55
/* adjust bizarre UPS data to observed voltage data */
 
56
int voltconvert(unsigned char in)
 
57
{
 
58
        int v_end[43] = { 36, 51, 55, 60, 65, 70, 75, 80, 85, 91, 98, 103, 108, 113, 118, 123, 128, 133, 138, 143, 148, 153, 158, 163, 168, 173, 178, 183, 188, 193, 198, 203, 208, 213, 218, 223, 228, 233, 238, 243, 248, 253, 255 };
 
59
        int v_adj[43] = {  3,  4,  5,  4,  3,  2,  1,  0, -1, -2, -3,  -4,  -5,  -6,  -7,  -8,  -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20, -21, -22, -23, -24, -25, -26, -27, -28, -29, -30, -31, -32, -33, -34, -35 };
 
60
        int     i;
 
61
 
 
62
        if (in < 27)
 
63
                return 0;
 
64
 
 
65
        for (i = 0; i < 19; i++) { 
 
66
                if (in <= v_end[i]) {
 
67
                        return (in + v_adj[i]);
 
68
                }
 
69
        }
 
70
 
 
71
        return 0;
 
72
}
 
73
 
 
74
/* map UPS data to realistic percentages */
 
75
int battconvert(unsigned char in)
 
76
{
 
77
        int b_val[26] = {0, 1, 1, 2, 3, 4, 6, 8, 10, 12, 15, 18, 22, 26, 30, 35, 40, 46, 52, 58, 66, 73, 81, 88, 99, 100 }; /* XXX - for load of 0 */
 
78
 
 
79
        if (in > 185)
 
80
                return 100;
 
81
 
 
82
        if (in < 160)
 
83
                return 0;
 
84
 
 
85
        return (b_val[in - 160]);
 
86
}
 
87
 
 
88
/* Model mapping */
 
89
struct {
 
90
        int     first;
 
91
        int     second;
 
92
        char    *pcode;
 
93
        char    *model;
 
94
}     modelmap[] = {
 
95
      
 
96
        { 51, 51, "OP850", "850AVR"     },      /* O33 */
 
97
        { 52, 53, "OP1500", "1500AVR"   },      /* O45 */
 
98
        { 52, 51, "OP1250", "1250AVR"   },      /* O43 */
 
99
        { 52, 49, "OP700", "700AVR"     },      /* O41 */
 
100
        { 51, 57, "OP650", "650AVR"     },      /* O39 */
 
101
        { 51, 55, "OP900", "900AVR"     },      /* O37 */
 
102
        { 51, 49, "OP800", "800AVR"     },      /* O31 */
 
103
        { 50, 57, "OP500", "500AVR"     },      /* O29 */
 
104
        { 50, 55, "OP320", "320AVR"     },      /* O27 */
 
105
        {  0,  0, (char*) NULL, (char *) NULL }
 
106
};
 
107
 
 
108
/* more wacky mapping - get the picture yet? */
 
109
 
 
110
struct {
 
111
        int     st;
 
112
        int     end;
 
113
        int     sz;
 
114
        int     base;
 
115
}       temptab[] =
 
116
{
 
117
        {   0,  39, 5,  0 },
 
118
        {  40,  43, 4,  8 }, 
 
119
        {  44,  78, 5,  9 },
 
120
        {  79,  82, 4, 16 },
 
121
        {  83, 117, 5, 17 },
 
122
        { 118, 121, 4, 24 },
 
123
        { 122, 133, 3, 25 },
 
124
        { 134, 135, 2, 29 },
 
125
        { 136, 143, 4, 30 },
 
126
        { 144, 146, 3, 32 },
 
127
        { 147, 150, 4, 33 },
 
128
        { 151, 156, 3, 34 },
 
129
        { 157, 164, 2, 36 },
 
130
        { 165, 170, 3, 40 },
 
131
        { 171, 172, 2, 42 },
 
132
        { 173, 175, 3, 43 },
 
133
        { 176, 183, 2, 44 },
 
134
        { 184, 184, 1, 48 },
 
135
        { 185, 188, 2, 49 },
 
136
        { 189, 190, 2, 51 },
 
137
        { 191, 191, 1, 52 },
 
138
        { 192, 193, 2, 53 },
 
139
        { 194, 194, 1, 54 },
 
140
        { 195, 196, 2, 55 },
 
141
        { 197, 197, 1, 56 },
 
142
        { 198, 199, 2, 57 },
 
143
        { 200, 200, 1, 58 },
 
144
        { 201, 202, 2, 59 },
 
145
        { 203, 203, 1, 60 },
 
146
        { 204, 205, 2, 61 },
 
147
        { 206, 206, 1, 62 },
 
148
        { 207, 208, 2, 63 },
 
149
        { 209, 209, 1, 64 },
 
150
        { 210, 211, 2, 65 },
 
151
        { 212, 212, 1, 66 },
 
152
        { 213, 213, 1, 67 },
 
153
        { 214, 214, 1, 68 },
 
154
        { 215, 215, 1, 69 },
 
155
        { 216, 255, 40, 70 },
 
156
        {   0,   0, 0,  0 },
 
157
};
 
158
 
 
159
float tempconvert(unsigned char in)
 
160
{
 
161
        int     i, j, found, count;
 
162
 
 
163
        found = -1;
 
164
        for (i = 0; temptab[i].sz != 0; i++)
 
165
                if ((temptab[i].st <= in) && (temptab[i].end >= in))
 
166
                        found = i;
 
167
 
 
168
        if (found == -1) {
 
169
                upslogx(LOG_ERR, "tempconvert: unhandled value %d", in);
 
170
                return 0;
 
171
        }
 
172
 
 
173
        count = temptab[found].end - temptab[found].st + 1;
 
174
 
 
175
        for (i = 0; i < count; i++) {
 
176
                j = temptab[found].st + (i * temptab[found].sz);
 
177
 
 
178
                if ((in - j) < temptab[found].sz) {
 
179
                        return ((float)((in - j) / temptab[found].sz) + 
 
180
                                temptab[found].base + i);
 
181
                }
 
182
        }
 
183
 
 
184
        upslogx(LOG_ERR, "tempconvert: fell through with %d", in);
 
185
        return 0;
 
186
}
 
187
 
 
188
void sendtoups(char ch)
 
189
{
 
190
        write(upsfd, &ch, 1);
 
191
        usleep(50000);
 
192
}
 
193
 
 
194
static void read_timeout(int sig)
 
195
{
 
196
        /* ignore this */
 
197
        return;
 
198
}
 
199
 
 
200
static int confirm_write(const unsigned char *buf, int buflen)
 
201
{
 
202
        int     i, ret;
 
203
        unsigned        char    ch;
 
204
 
 
205
        for (i = 0; i < buflen; i++) {
 
206
                ret = write(upsfd, &buf[i], 1);
 
207
 
 
208
                if (ret < 1)
 
209
                        return 0;
 
210
 
 
211
                usleep(50000);
 
212
        }
 
213
 
 
214
        ch = 13;
 
215
        write(upsfd, &ch, 1);
 
216
 
 
217
        for (i = 0; i < buflen; i++) {
 
218
 
 
219
                alarm(2);
 
220
                ret = read(upsfd, &ch, 1);
 
221
                alarm(0);
 
222
 
 
223
                if (ch != buf[i]) {
 
224
                        upsdebugx(1, "mismatch at position %d", i);
 
225
                        return 0;
 
226
                }
 
227
        }
 
228
 
 
229
        /* made it this far, so it must have heard us */
 
230
 
 
231
        return 1;       /* success */
 
232
}
 
233
 
 
234
/* provide a quick status check to select the right shutdown command */
 
235
static int ups_on_line(void)
 
236
{
 
237
        int     ret, count;
 
238
        char    buf[SMALLBUF], ch;
 
239
 
 
240
        sendtoups('D');
 
241
        sendtoups(13);
 
242
 
 
243
        count = 0;
 
244
 
 
245
        memset(buf, '\0', sizeof(buf));
 
246
        while (count < 14) {
 
247
 
 
248
                alarm(1);
 
249
                ret = read(upsfd, &ch, 1);
 
250
                alarm(0);
 
251
 
 
252
                if (ret < 1) {
 
253
                        upslogx(LOG_ERR, "Status read failed: assuming on battery");
 
254
                        return 0;
 
255
                }
 
256
 
 
257
                buf[count++] = ch;
 
258
        }
 
259
 
 
260
        if (buf[9] & 128)
 
261
                return 0;       /* on battery */
 
262
        
 
263
        return 1;       /* on line */
 
264
}
 
265
 
 
266
static void setup_sigalrm(void)
 
267
{
 
268
        sigemptyset(&cp_sigmask);
 
269
        sa.sa_mask = cp_sigmask;
 
270
        sa.sa_flags = 0;
 
271
        sa.sa_handler = read_timeout;
 
272
        sigaction(SIGALRM, &sa, NULL);
 
273
}
 
274
 
 
275
/* power down the attached load immediately */
 
276
void upsdrv_shutdown(void)
 
277
{
 
278
        int     i, ret, sdlen;
 
279
        char    ch, buf[256];
 
280
        unsigned char   sdbuf[16];
 
281
 
 
282
        setup_sigalrm();
 
283
 
 
284
        /* get this thing's attention */
 
285
        for (i = 0; i < 10; i++) {
 
286
                printf("Trying to wake up the ups... ");
 
287
                fflush(stdout);
 
288
 
 
289
                alarm(5);
 
290
                
 
291
                ch = 13;
 
292
                write(upsfd, &ch, 1);
 
293
 
 
294
                ret = read(upsfd, buf, sizeof(buf));
 
295
                alarm(0);
 
296
 
 
297
                if (ret > 0) {
 
298
                        printf("OK\n");
 
299
                        break;
 
300
                }
 
301
 
 
302
                printf("failed\n");
 
303
        }
 
304
 
 
305
        usleep(250000);
 
306
 
 
307
        if (ups_on_line() == 1) {
 
308
 
 
309
                /* this does not come back when on battery! */
 
310
 
 
311
                printf("Online: sending 7 byte command (back in about 45 sec)\n");
 
312
 
 
313
                sdlen = 7;
 
314
                sdbuf[0] = 'S';
 
315
 
 
316
                sdbuf[1] = 0x00;                /* how long until shutdown */
 
317
                sdbuf[2] = 0x00;                /* 0 = nearly immediate */
 
318
 
 
319
                sdbuf[3] = 'R';
 
320
                sdbuf[4] = 0x00;                /* how long to stay off */
 
321
                sdbuf[5] = 0x01;                /* 0 = about 13 seconds */
 
322
                                                /* 1 = about 45 seconds */
 
323
 
 
324
                sdbuf[6] = 'W';
 
325
        
 
326
        } else {
 
327
 
 
328
                /* this one is one-way when on-line, but is the only
 
329
                 * known way to come back online when on battery ... 
 
330
                 */
 
331
 
 
332
                printf("On battery: sending 4 byte command (back when line power returns)\n");
 
333
 
 
334
                sdlen = 4;
 
335
                sdbuf[0] = 'S';
 
336
                sdbuf[1] = 0x00;
 
337
                sdbuf[2] = 0x00;
 
338
                sdbuf[3] = 'W';
 
339
        }
 
340
 
 
341
        printf("Sending command...");
 
342
        fflush(stdout);
 
343
 
 
344
        for (i = 0; i < 10; i++) {
 
345
 
 
346
                if (confirm_write(sdbuf, sdlen)) {
 
347
                        printf(" confirmed\n");
 
348
                        break;
 
349
                }
 
350
 
 
351
                printf("failed, retrying...");
 
352
                fflush(stdout);
 
353
        }
 
354
}
 
355
 
 
356
static void pollfail(const char *why)
 
357
{
 
358
        poll_failures++;
 
359
 
 
360
        if ((poll_failures == CP_ERR_LIMIT) || 
 
361
                ((poll_failures % CP_ERR_RATE) == 0)) {
 
362
                upslogx(LOG_WARNING, "Warning: excessive poll failures, "
 
363
                        "limiting error reporting");
 
364
        }
 
365
 
 
366
        if ((poll_failures < CP_ERR_LIMIT) ||
 
367
                ((poll_failures % CP_ERR_RATE) == 0)) {
 
368
                upslogx(LOG_ERR, "UPS status unavailable: %s", why);
 
369
        }
 
370
}
 
371
 
 
372
void upsdrv_updateinfo(void)
 
373
{
 
374
        int     ret, count;
 
375
        char    ch, buf[SMALLBUF];
 
376
 
 
377
        sendtoups('D');
 
378
        sendtoups(13);
 
379
 
 
380
        count = 0;
 
381
 
 
382
        memset(buf, '\0', sizeof(buf));
 
383
        while (count < 14) {
 
384
 
 
385
                alarm(1);
 
386
                ret = read(upsfd, &ch, 1);
 
387
                alarm(0);
 
388
 
 
389
                if (ret < 1) {
 
390
                        pollfail("Short read from UPS");
 
391
                        dstate_datastale();
 
392
                        return;
 
393
                }
 
394
 
 
395
                buf[count++] = ch;
 
396
        }
 
397
 
 
398
        if (buf[0] != '#') {
 
399
                upslogx(LOG_ERR, "Invalid start char 0x%02x", buf[0] & 0xff);
 
400
                dstate_datastale();
 
401
                return;
 
402
        }
 
403
 
 
404
        if ((buf[4] != 46) || (buf[8] != 46)) {
 
405
                upslogx(LOG_ERR, "Invalid separator in response");
 
406
                dstate_datastale();
 
407
                return;
 
408
        }
 
409
 
 
410
        poll_failures = 0;
 
411
 
 
412
        dstate_setinfo("input.frequency",  "%2.1f", frequency(buf[7]));
 
413
        dstate_setinfo("ups.temperature", "%2.1f", tempconvert(buf[6]));
 
414
        dstate_setinfo("battery.charge", "%03d", battconvert(buf[5]));
 
415
        dstate_setinfo("ups.load", "%03d", (buf[3] & 0xff) * 2);
 
416
        dstate_setinfo("input.voltage", "%03d", voltconvert(buf[1]));
 
417
 
 
418
        status_init();
 
419
 
 
420
        if (buf[9] & 2)
 
421
                status_set("OFF");
 
422
 
 
423
        if (buf[9] & 64)
 
424
                status_set("LB");
 
425
 
 
426
        if (buf[9] & 128)
 
427
                status_set("OB");
 
428
        else
 
429
                status_set("OL");
 
430
 
 
431
        status_commit();
 
432
        dstate_dataok();
 
433
}
 
434
 
 
435
static int get_ident(char *buf, size_t bufsize)
 
436
{
 
437
        int     ret, tries, count;
 
438
        char    ch;
 
439
 
 
440
        for (tries = 0; tries < 3; tries++) {
 
441
                sendtoups('F');
 
442
                sendtoups(13);
 
443
 
 
444
                memset(buf, '\0', bufsize);
 
445
 
 
446
                alarm(1);
 
447
                ret = read(upsfd, &ch, 1);
 
448
                alarm(0);
 
449
 
 
450
                count = 0;
 
451
                while (ret == 1) {
 
452
                        buf[count++] = ch;
 
453
        
 
454
                        if ((buf[0] == '.') && (ch == 13))
 
455
                                return 1;
 
456
 
 
457
                        /* reading way too much */
 
458
                        if (count == bufsize) {
 
459
                                memset(buf, '\0', bufsize);
 
460
                                count = 0;
 
461
                        }                               
 
462
 
 
463
                        alarm(1);
 
464
                        ret = read(upsfd, &ch, 1);
 
465
                        alarm(0);
 
466
                }
 
467
 
 
468
                /* if we got here, then the read failed somehow */
 
469
        }
 
470
 
 
471
        upslogx(LOG_INFO, "Giving up on hardware detection after 3 tries");
 
472
 
 
473
        return 0;
 
474
}
 
475
 
 
476
static int detect_hardware(void)
 
477
{
 
478
        int     i, foundmodel = 0;
 
479
        char    buf[SMALLBUF];
 
480
 
 
481
        if (!get_ident(buf, sizeof(buf)))
 
482
                fatalx("Unable to get initial hardware info string");
 
483
 
 
484
        if (buf[0] != '.') {
 
485
                upslogx(LOG_ERR, "Invalid start model string 0x%02x", buf[0] & 0xff);
 
486
                return -1;
 
487
        }
 
488
 
 
489
        for (i = 0; modelmap[i].model != NULL; i++) {
 
490
                if (buf[3] == modelmap[i].first &&
 
491
                        buf[4] == modelmap[i].second) {
 
492
              
 
493
                        dstate_setinfo("ups.model", "%s", modelmap[i].model);
 
494
                        foundmodel = 1;
 
495
                        break;
 
496
                }
 
497
        }
 
498
           
 
499
        if (!foundmodel)
 
500
                dstate_setinfo("ups.model", "Unknown model - %c%c", 
 
501
                        buf[3], buf[4]);
 
502
 
 
503
        dstate_setinfo("ups.firmware", "%c.%c%c%c", 
 
504
                buf[16], buf[17], buf[18], buf[19]);
 
505
        return 0;
 
506
}
 
507
 
 
508
/* FUTURE: allow variable length tests (additional data from instcmd) */
 
509
static int instcmd_btest(void)
 
510
{
 
511
        int     i, clen;
 
512
        char    cbuf[8];
 
513
 
 
514
        clen = 2;
 
515
        cbuf[0] = 'T';
 
516
        cbuf[1] = 0x80;         /* try for a brief test: about 20 seconds */
 
517
 
 
518
        for (i = 0; i < 3; i++)
 
519
                if (confirm_write(cbuf, clen))
 
520
                        return STAT_INSTCMD_HANDLED;    /* FUTURE: success */
 
521
 
 
522
        upslogx(LOG_WARNING, "btest: UPS failed to confirm command");
 
523
 
 
524
        return STAT_INSTCMD_HANDLED;            /* FUTURE: failed */
 
525
}
 
526
 
 
527
static int instcmd_stayoff(void)
 
528
{
 
529
        int     i, clen;
 
530
        char    cbuf[8];
 
531
        double  elapsed;
 
532
        time_t  now;
 
533
        static  time_t  last = 0;
 
534
 
 
535
        time(&now);
 
536
 
 
537
        elapsed = difftime(now, last);
 
538
        last = now;
 
539
 
 
540
        /* for safety this must be repeated in a small window of time */
 
541
        if ((elapsed < MINCMDTIME) || (elapsed > MAXCMDTIME)) {
 
542
                upsdebugx(1, "instcmd_shutdown: outside window (%2.0f)",
 
543
                        elapsed);
 
544
                return STAT_INSTCMD_HANDLED;            /* FUTURE: again */
 
545
        }
 
546
 
 
547
        /* this is a one-way trip unless you happen to be on battery */
 
548
 
 
549
        clen = 4;               
 
550
        cbuf[0] = 'S';
 
551
        cbuf[1] = 0x00;
 
552
        cbuf[2] = 0x00;         
 
553
        cbuf[3] = 'W';
 
554
 
 
555
        for (i = 0; i < 3; i++)
 
556
                if (confirm_write(cbuf, clen))
 
557
                        return STAT_INSTCMD_HANDLED;    /* FUTURE: success */
 
558
 
 
559
        upslogx(LOG_WARNING, "instcmd_shutdown: UPS failed to confirm command");
 
560
 
 
561
        return STAT_INSTCMD_HANDLED;            /* FUTURE: failed */
 
562
}       
 
563
 
 
564
int instcmd(const char *cmdname, const char *extra)
 
565
{
 
566
        if (!strcasecmp(cmdname, "test.battery.start"))
 
567
                return instcmd_btest();
 
568
        if (!strcasecmp(cmdname, "shutdown.stayoff"))
 
569
                return instcmd_stayoff();
 
570
 
 
571
        upslogx(LOG_NOTICE, "instcmd: unknown command [%s]", cmdname);
 
572
        return STAT_INSTCMD_UNKNOWN;
 
573
}
 
574
 
 
575
/* install pointers to functions for msg handlers called from msgparse */
 
576
static void setuphandlers(void)
 
577
{
 
578
        upsh.new_instcmd = instcmd;
 
579
}
 
580
 
 
581
void upsdrv_banner(void)
 
582
{
 
583
        printf("Network UPS Tools - CyberPower driver %s (%s)\n", 
 
584
                DRV_VERSION, UPS_VERSION);
 
585
 
 
586
        experimental_driver = 1;
 
587
}
 
588
 
 
589
void upsdrv_help(void)
 
590
{
 
591
}
 
592
 
 
593
void upsdrv_makevartable(void)
 
594
{
 
595
}
 
596
 
 
597
/* prep the serial port */
 
598
void upsdrv_initups(void)
 
599
{
 
600
        int dtr_bit = TIOCM_DTR;
 
601
        int rts_bit = TIOCM_RTS;
 
602
        struct termios tio;
 
603
 
 
604
        open_serial(device_path, B1200);
 
605
 
 
606
        /* dtr high, rts high */
 
607
        ioctl(upsfd, TIOCMBIS, &rts_bit);
 
608
        ioctl(upsfd, TIOCMBIS, &dtr_bit);
 
609
 
 
610
        tcgetattr(upsfd, &tio);
 
611
        tio.c_cflag = 0 | CS8 | CLOCAL | ~CRTSCTS | CREAD;
 
612
        cfmakeraw(&tio);
 
613
        tio.c_cflag &= ~(PARODD|CSTOPB|HUPCL|CRTSCTS);
 
614
 
 
615
        cfsetispeed(&tio, B1200);
 
616
        cfsetospeed(&tio, B1200);
 
617
        tcsetattr(upsfd, TCSANOW, &tio);
 
618
 
 
619
        /* avoid getting stuck in read() */
 
620
        setup_sigalrm();
 
621
}
 
622
 
 
623
void upsdrv_initinfo(void)
 
624
{
 
625
        if (detect_hardware() == -1) {
 
626
                printf("Unable to detect a CyberPower UPS on port %s\n", 
 
627
                        device_path);
 
628
                printf("Check the cabling, port name or model name and try again\n");
 
629
                exit(1);
 
630
        }
 
631
 
 
632
        dstate_setinfo("ups.mfr", "CyberPower", 0, 0);
 
633
        dstate_setinfo("driver.version.internal", "%s", DRV_VERSION);
 
634
 
 
635
        /* poll once to put in some good data */
 
636
        upsdrv_updateinfo();
 
637
 
 
638
        printf("Detected %s on %s\n", dstate_getinfo("ups.model"), device_path); 
 
639
 
 
640
        dstate_addcmd("test.battery.start");
 
641
        dstate_addcmd("shutdown.stayoff");
 
642
 
 
643
        setuphandlers(); 
 
644
}
 
645
 
 
646
void upsdrv_cleanup(void)
 
647
{
 
648
}