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

« back to all changes in this revision

Viewing changes to models/bestuferrups.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
 
/* 
2
 
   bestuferrups.c - model specific routines for Best Power Micro-Ferrups
3
 
 
4
 
   This module is a 40% rewritten mangle of the bestfort module by
5
 
   Grant, which is a 75% rewritten mangle of the bestups module by
6
 
   Russell.   It has no test battery command since my ME700 does this
7
 
   by itself. (same as Grant's driver in this respect)
8
 
 
9
 
   Warning: I have not tested the -k function. 
10
 
 
11
 
   Copyright (C) 2000  John Stone  <johns@megapixel.com>
12
 
   Copyright (C) 2000  Grant Taylor <gtaylor@picante.com>
13
 
   Copyright (C) 1999  Russell Kroll <rkroll@exploits.org>
14
 
 
15
 
   This program is free software; you can redistribute it and/or modify
16
 
   it under the terms of the GNU General Public License as published by
17
 
   the Free Software Foundation; either version 2 of the License, or
18
 
   (at your option) any later version.
19
 
 
20
 
   This program is distributed in the hope that it will be useful,
21
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 
   GNU General Public License for more details.
24
 
 
25
 
   You should have received a copy of the GNU General Public License
26
 
   along with this program; if not, write to the Free Software
27
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
 
 
29
 
*/
30
 
 
31
 
#include <errno.h>
32
 
#include <fcntl.h>
33
 
#include <stdio.h>
34
 
#include <signal.h>
35
 
#include <stdlib.h>
36
 
#include <string.h>
37
 
#include <unistd.h>
38
 
#include <sys/file.h>
39
 
#include <sys/stat.h>
40
 
#include <sys/ioctl.h>
41
 
#include <sys/types.h>
42
 
#include <sys/termios.h>
43
 
#include <assert.h>
44
 
 
45
 
#include "config.h"
46
 
#include "proto.h"
47
 
#include "shared.h"
48
 
#include "version.h"
49
 
#include "upscommon.h"
50
 
#include "common.h"
51
 
 
52
 
#define INFOMAX  16
53
 
 
54
 
int debugging = 0;
55
 
 
56
 
        int     shmok = 1;
57
 
 
58
 
 
59
 
/* Blob of UPS configuration data from the formatconfig string */
60
 
struct {
61
 
  int valid;                    /* set to 1 when this is filled in */
62
 
 
63
 
  float  idealbvolts;           /* various interestin battery voltages */
64
 
  float  fullvolts;
65
 
  float  emptyvolts;
66
 
  int va;                       /* capacity of UPS in Volt-Amps */
67
 
  int watts;                    /* capacity of UPS in watts */
68
 
  int model;                    /* enumerated model type */
69
 
} fc;
70
 
 
71
 
 
72
 
/* Forward decls */
73
 
void setup_serial();
74
 
int readupsline (char *buf);
75
 
int execute_int(char *cmd, char *response);
76
 
 
77
 
/* Set up all the funky shared memory stuff used to communicate with upsd */
78
 
void initinfo (void)
79
 
{
80
 
        create_info (INFOMAX, shmok);
81
 
 
82
 
        /* now set up room for all future variables that are supported */
83
 
        addinfo (INFO_MFR, "", 0, 0);
84
 
        addinfo (INFO_MODEL, "", 0, 0);
85
 
        addinfo (INFO_UTILITY, "", 0, 0);
86
 
        addinfo (INFO_OUTVOLT, "", 0, 0);
87
 
        addinfo (INFO_ACFREQ, "", 0, 0);
88
 
        addinfo (INFO_LOADPCT, "", 0, 0);
89
 
        addinfo (INFO_BATTPCT, "", 0, 0);
90
 
        addinfo (INFO_UPSTEMP, "", 0, 0);
91
 
        addinfo (INFO_STATUS, "", 0, 0);
92
 
}
93
 
 
94
 
/* TODO: adapt to the standard upscommon open/send/recv calls */
95
 
 
96
 
/* This seems unlikely, as the current ones don't handle the
97
 
   unterminated line containing the prompt that you get back after
98
 
   each command.  Perhaps the thing is to make our own or something;
99
 
   the standard calls are nice in that they use alarms to do timeouts
100
 
   and such.  OTOH, the Fortress *always* babbles back at you giving
101
 
   at least a prompt...   */
102
 
 
103
 
int open_ups(char *filename)
104
 
{
105
 
  chdir("/dev");
106
 
 
107
 
  upsfd = open(filename, O_RDWR | O_NDELAY);
108
 
  if (upsfd == -1)
109
 
    fatal("open %s", filename);
110
 
  
111
 
  setup_serial();
112
 
  
113
 
  return upsfd;
114
 
}
115
 
 
116
 
void setup_serial()
117
 
{       
118
 
  struct        termios tio;
119
 
 
120
 
  /* Zero out the structure to prevent confusion.  It took me forever
121
 
     to figure out why my serial reading routines read everything from
122
 
     the UPS perfectly, except for the infuriating detail that all the
123
 
     `0's were missing: since it didn't wipe the c_cc part clean, the
124
 
     VSTART character got set to `0', so that got eaten.  The (horrid)
125
 
     example code from Best Power was immune to this problem since
126
 
     everything is a (n implicitly initialized) global.  */
127
 
 
128
 
  memset(&tio, 0, sizeof(tio));
129
 
  
130
 
  tio.c_iflag = IXON | IXOFF;
131
 
  tio.c_oflag = 0;
132
 
  tio.c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL);
133
 
  tio.c_lflag = 0;
134
 
  tio.c_cc[VMIN] = 1;
135
 
  tio.c_cc[VTIME] = 0;
136
 
  tio.c_cc[VSTART] = 17;        /* CTRL('q'); is not portable */
137
 
 
138
 
  if (tcsetattr (upsfd, TCSANOW, &tio) == -1)
139
 
    fatal("tcsetattr");
140
 
}
141
 
 
142
 
char readchar ()
143
 
{
144
 
  char  c='z';
145
 
  int   ret;
146
 
 
147
 
 
148
 
  /* It's not obvious that O_NDELAY was useful.  We should probably do
149
 
     selects with timeouts or set a timer against blocking i/o or
150
 
     something.  Luckily UPS's aren't prone to goign missing.  */
151
 
 
152
 
 readspot:
153
 
  ret = read (upsfd, &c, 1);
154
 
 
155
 
  if (ret > 0) {
156
 
    return (c & 0x7f);
157
 
  } else {
158
 
    if (ret == 0 || errno == EAGAIN) {
159
 
      sleep(1); 
160
 
      goto readspot;
161
 
    }
162
 
 
163
 
    perror("read error in readchar()");
164
 
    return 0;
165
 
  }
166
 
}
167
 
 
168
 
/* Run a command.  Put the response, or empty string if none, into
169
 
   buffer response.  God help you if the buffer is too short.  It
170
 
   would be best to not execute a continuous statement like
171
 
   `contstatus' ;) */
172
 
 
173
 
int execute(char *cmd, char *response)
174
 
{
175
 
  char junkbuf[256];
176
 
 
177
 
  /* First synchronize with a control-c and backspace.  Then we'll be
178
 
     at a "clean" prompt and ready to go. */
179
 
 
180
 
  return execute_int("\x08\x03", junkbuf) || execute_int(cmd,response);
181
 
}
182
 
 
183
 
int execute_int(char *cmd, char *response)
184
 
{
185
 
  int ret, prompt;
186
 
  char *ptr, linebuf[256];
187
 
  
188
 
  /* First send command string plus the \r */
189
 
  ptr = cmd;
190
 
  while (*ptr) {
191
 
  writespot1:
192
 
    ret = write(upsfd, ptr++, 1);
193
 
    if (ret == -1) {
194
 
      if (errno == EAGAIN) 
195
 
        goto writespot1;
196
 
 
197
 
      perror("execute(): write() failed");
198
 
      return -1;
199
 
    }
200
 
  }
201
 
 
202
 
 writespot2:
203
 
  ret = write(upsfd, "\r", 1);  /* carriage return */
204
 
  if (ret == -1) {
205
 
    if (errno==EAGAIN) 
206
 
      goto writespot2;
207
 
 
208
 
    perror("execute(): write() failed");
209
 
    return -1;
210
 
  }
211
 
 
212
 
  /* OK, now we read.  We expect to see what we just wrote, followed
213
 
     by some or no output, followed by a prompt ending in "=> " */
214
 
 
215
 
  if (strlen(cmd) && cmd[0] != '\x08') {
216
 
    int lineoffset = 0;
217
 
    do {                        /* read until we see our command */
218
 
      prompt = readupsline(linebuf);
219
 
      lineoffset = strlen(cmd) - strlen(linebuf);
220
 
    } while (0 != strcmp(cmd,linebuf+lineoffset) && prompt != -1);
221
 
  }
222
 
 
223
 
  response[0] = '\0';
224
 
  do {
225
 
    prompt = readupsline(linebuf);
226
 
 
227
 
    if (prompt) {
228
 
      /* the next prompt */
229
 
    } else if (strlen(linebuf) > 1 && linebuf[0] != '\r') {
230
 
      /* interesting output */
231
 
      strcat(response, linebuf);
232
 
      strcat(response, "\r");
233
 
    }
234
 
  } while (prompt == 0);
235
 
 
236
 
  return ((prompt == -1) ? -1 : 0);
237
 
}
238
 
 
239
 
/* 
240
 
   read a line from the UPS, terminated by either a '\r' or by a =>
241
 
   (the prompt).
242
 
 
243
 
   return -1 for error
244
 
   return 0 for normal lines
245
 
   return 1 for prompt lines
246
 
 */
247
 
int readupsline (char *buf)
248
 
{
249
 
  char  ch, *p;
250
 
  int l;
251
 
  
252
 
  p = buf;
253
 
  *p = '\0';
254
 
  l=0;
255
 
  
256
 
  while ((ch = readchar ())) {
257
 
    if (ch == '\n')
258
 
      continue;         /* absorb duplicate nl/crs */
259
 
    
260
 
    l++;
261
 
    
262
 
    /* done on carriage return/newline, don't include cr */
263
 
    if (ch == '\n' ||  ch == '\r') {
264
 
      *p = '\0';
265
 
      return 0;
266
 
    }
267
 
    
268
 
    /* include this character */
269
 
    *p++ = ch;
270
 
    
271
 
    /* done if last two chars are '=>' */
272
 
    if (l >= 2) {
273
 
      char *prompt = p-2;
274
 
      if (0 == memcmp(prompt, "=>", 2)) {
275
 
        *p = '\0';
276
 
        return 1;               /* one for prompt line */
277
 
      }
278
 
    }
279
 
  }
280
 
  
281
 
  *p = '\0';
282
 
  return -1;
283
 
}
284
 
 
285
 
void ups_sync()
286
 
{
287
 
  char  buf[256];
288
 
 
289
 
  printf ("Syncing: ");
290
 
  fflush (stdout);
291
 
 
292
 
  /* A bit better sanity might be good here.  As is, we expect the
293
 
     human to observe the time being totally not a time. */
294
 
 
295
 
  if (0 == execute("time", buf)) {
296
 
    fprintf(stderr, "UPS Time: %s\n", buf);
297
 
  } else {
298
 
    fprintf(stderr, "Error connecting to UPS.\n");
299
 
    exit(1);
300
 
  }
301
 
}
302
 
 
303
 
/* power down the attached load immediately */
304
 
void forceshutdown(char *port)
305
 
{
306
 
  char  temp[256];
307
 
 
308
 
  upslogx(LOG_INFO, "Initiating UPS shutdown\n");
309
 
  printf ("Initiating forced UPS shutdown!\n");
310
 
  
311
 
  open_ups(port);
312
 
  
313
 
  /* shutdown in 5 seconds, autostart later */
314
 
  execute("shutdown autostart 5", temp);
315
 
  
316
 
  printf ("Waiting for poweroff...\n");
317
 
  sleep (90);
318
 
  printf ("Hmm, did the shutdown fail?  Oh well...\n");
319
 
  exit (1);                               
320
 
}
321
 
 
322
 
void usage (char *prog)
323
 
{
324
 
  printf ("usage: %s [-h] [-k] [-D] <device>\n", prog);
325
 
  printf ("Example: %s /dev/ttyS0\n", prog);
326
 
  exit (1);
327
 
}
328
 
 
329
 
void help (char *prog)
330
 
{
331
 
  printf ("usage: %s [-h] [-k] <device>\n", prog);
332
 
  printf ("\n");
333
 
  printf ("-h       - display this help\n");
334
 
  printf ("-k       - force shutdown\n");
335
 
  printf ("-D       - run in foreground for debugging/testing\n");
336
 
  printf ("<device> - /dev entry corresponding to UPS port\n");
337
 
}
338
 
 
339
 
 
340
 
 
341
 
void ups_ident ()
342
 
{
343
 
  char  temp[256], fcstring[512];
344
 
 
345
 
  /* Obtain Model */
346
 
  if (0 != execute("id", fcstring)) {
347
 
    fprintf(stderr, "Failed execute in ups_ident()\n");
348
 
    exit(1);
349
 
  }
350
 
  
351
 
  /* response is a one-line packed string starting with $ */
352
 
  if (memcmp(fcstring, "Unit", 4)) {
353
 
    fprintf(stderr, "Bad response from formatconfig command in ups_ident()\n");
354
 
    fprintf(stderr, "id: %s\n", fcstring);
355
 
    exit(1);
356
 
  }
357
 
 
358
 
  if (debugging)
359
 
    fprintf(stderr, "id: %s\n", fcstring);
360
 
  
361
 
  /* chars 4:2  are a two-digit ascii hex enumerated model code */
362
 
  memcpy(temp, fcstring+9, 2);
363
 
  temp[2] = '\0';
364
 
 
365
 
  if (memcmp(temp, "ME", 2))  {
366
 
    fprintf(stderr, "Unknown model %s in ups_ident()\n", temp);
367
 
    exit(1);
368
 
  }
369
 
 
370
 
  /* hard code this to be an ME700 for now */
371
 
  fc.va = 700;
372
 
  fc.watts = 700;
373
 
 
374
 
  /* determine shutdown battery voltage */
375
 
  if (0 == execute("d 29", fcstring)) {
376
 
    sscanf(fcstring, "29 LowBat   %f", &fc.emptyvolts);
377
 
  }
378
 
 
379
 
  /* determine fully charged battery voltage */
380
 
  if (0 == execute("d 31", fcstring)) {
381
 
    sscanf(fcstring, "31 HiBatt   %f", &fc.fullvolts);
382
 
  }
383
 
 
384
 
  /* determine "ideal" voltage by a guess */
385
 
  fc.idealbvolts = ((fc.fullvolts - fc.emptyvolts) * 0.7) + fc.emptyvolts;
386
 
  
387
 
  setinfo(INFO_MFR, "%s", "Best Power");
388
 
  setinfo(INFO_MODEL, "%s %d", "Micro Ferrups (ME)", fc.va);
389
 
  
390
 
  fc.valid = 1;
391
 
  
392
 
  printf("Best Power %s detected\n", getdata(INFO_MODEL));
393
 
  printf("Battery voltages %5.1f nominal, %5.1f full, %5.1f empty\n", 
394
 
         fc.idealbvolts,
395
 
         fc.fullvolts,
396
 
         fc.emptyvolts);
397
 
  
398
 
  return;
399
 
}
400
 
 
401
 
void ups_update ()
402
 
{
403
 
  char fstring[512];
404
 
 
405
 
  if (! fc.valid) {
406
 
    fprintf(stderr, 
407
 
            "upsupdate run before ups_ident() read ups config\n");
408
 
    assert(0);
409
 
  }
410
 
 
411
 
  if (0==execute("f",fstring)) {
412
 
    int inverter=0, charger=0, vin=0, vout=0, btimeleft=0, linestat=0, 
413
 
      alstat=0, vaout=0;
414
 
    double ampsout=0.0, vbatt=0.0, battpercent=0.0, loadpercent=0.0,
415
 
      upstemp=0.0, acfreq=0.0;
416
 
    char tmp[16], statstr[128];
417
 
 
418
 
    /* Inverter status.  0=off 1=on */
419
 
    memcpy(tmp, fstring+16, 2);
420
 
    tmp[2] = '\0';
421
 
    inverter = atoi(tmp);
422
 
 
423
 
    /* Charger status.  0=off 1=on */
424
 
    memcpy(tmp, fstring+18, 2);
425
 
    tmp[2] = '\0';
426
 
    charger = atoi(tmp);
427
 
    
428
 
    /* Input Voltage. integer number */
429
 
    memcpy(tmp, fstring+24, 4);
430
 
    tmp[4] = '\0';
431
 
    vin = atoi(tmp);
432
 
 
433
 
    /* Output Voltage. integer number */
434
 
    memcpy(tmp, fstring+28, 4);
435
 
    tmp[4] = '\0';
436
 
    vout = atoi(tmp);
437
 
 
438
 
    /* Iout.  int times 10 */
439
 
    memcpy(tmp, fstring+36, 4);
440
 
    tmp[4] = '\0';
441
 
    ampsout = ((double)(atoi(tmp)) / 10.0);
442
 
 
443
 
    /* Battery voltage.  int times 10 */
444
 
    memcpy(tmp, fstring+50, 4);
445
 
    tmp[4] = '\0';
446
 
    vbatt = ((double)(atoi(tmp)) / 10.0);
447
 
 
448
 
    /* Volt-amps out.  int  */
449
 
    memcpy(tmp, fstring+40, 6);
450
 
    tmp[6] = '\0';
451
 
    vaout = atoi(tmp);
452
 
 
453
 
    /* Line status.  Bitmask */
454
 
    memcpy(tmp, fstring+72, 2);
455
 
    tmp[2] = '\0';
456
 
    linestat = atoi(tmp);
457
 
 
458
 
    /* Alarm status reg 1.  Bitmask */
459
 
    memcpy(tmp, fstring+20, 2);
460
 
    tmp[2] = '\0';
461
 
    alstat = atoi(tmp);
462
 
 
463
 
    /* Alarm status reg 2.  Bitmask */
464
 
    memcpy(tmp, fstring+22, 2);
465
 
    tmp[2] = '\0';
466
 
    alstat = alstat | (atoi(tmp) << 8);
467
 
 
468
 
    /* AC line frequency */
469
 
    memcpy(tmp, fstring+54, 4);
470
 
    tmp[4]= '\0';
471
 
    acfreq = ((double)(atoi(tmp)) / 100.0);
472
 
 
473
 
    /* Runtime remaining */
474
 
    memcpy(tmp, fstring+58, 4);
475
 
    tmp[4]= '\0';
476
 
    btimeleft = atoi(tmp);
477
 
 
478
 
    /* UPS Temperature */
479
 
    memcpy(tmp, fstring+62, 4);
480
 
    tmp[4]= '\0';
481
 
    upstemp = (double)(atoi(tmp));
482
 
 
483
 
    /* Percent Load */
484
 
    if (0 == execute("d 16", fstring)) {
485
 
      int l;
486
 
      sscanf(fstring, "16 FullLoad%% %d", &l);
487
 
      loadpercent = (double) l;
488
 
    }
489
 
 
490
 
    /* Compute battery percent left based on battery voltages. */
491
 
    battpercent = ((vbatt - fc.emptyvolts) 
492
 
                   / (fc.fullvolts - fc.emptyvolts) * 100.0);
493
 
    if (battpercent < 0.0) 
494
 
      battpercent = 0.0;
495
 
    else if (battpercent > 100.0)
496
 
      battpercent = 100.0;
497
 
    
498
 
    /* Compute status string */
499
 
    {
500
 
      int lowbatt, overload, replacebatt, boosting, trimming;
501
 
 
502
 
      lowbatt = alstat & (1<<1);
503
 
      overload = alstat & (1<<6);
504
 
      replacebatt = alstat & (1<<10);
505
 
      boosting = inverter && (linestat & (1<<2)) && (vin < 115);
506
 
      trimming = inverter && (linestat & (1<<2)) && (vin > 115);
507
 
 
508
 
      strcpy(tmp, inverter ? "OB" : "OL");
509
 
      if (lowbatt) strcat (tmp, " LB");
510
 
      if (trimming) strcat (tmp, " TRIM");
511
 
      if (boosting) strcat (tmp, " BOOST");
512
 
      if (replacebatt) strcat (tmp, " RB");
513
 
      if (overload) strcat (tmp, " OVER");
514
 
 
515
 
      strlcpy(statstr, tmp, sizeof(statstr));
516
 
 
517
 
    }
518
 
 
519
 
    if (debugging) {
520
 
      fprintf(stderr,
521
 
              "Poll: inverter %d charger %d vin %d vout %d vaout %d btimeleft %d\n",
522
 
              inverter, charger, vin, vout, vaout, btimeleft);
523
 
      fprintf(stderr,
524
 
              "      ampsout %5.1f vbatt %5.1f batpcnt %5.1f loadpcnt %5.1f upstemp %5.1f acfreq %5.2f\n",
525
 
              ampsout, vbatt, battpercent, loadpercent, upstemp, acfreq);
526
 
      fprintf(stderr,
527
 
              "      STATUS '%s'\n", statstr);
528
 
 
529
 
    }
530
 
 
531
 
    /* Stuff information into info structures */
532
 
 
533
 
    setinfo(INFO_STATUS, "%s", statstr);
534
 
 
535
 
    setinfo(INFO_UTILITY, "%05.1f", (double)vin);
536
 
 
537
 
    setinfo(INFO_OUTVOLT, "%05.1f", (double)vout);
538
 
 
539
 
    setinfo(INFO_BATTPCT, "%02.1f", battpercent);
540
 
 
541
 
    setinfo(INFO_LOADPCT, "%02.1f", loadpercent);
542
 
 
543
 
    setinfo(INFO_ACFREQ, "%05.2f", (double)acfreq);
544
 
 
545
 
    setinfo(INFO_UPSTEMP, "%05.1f", (double)upstemp);
546
 
 
547
 
    writeinfo();
548
 
  }
549
 
 
550
 
  return;
551
 
}
552
 
 
553
 
int main (int argc, char **argv)
554
 
{
555
 
        char    *prog, *portname;
556
 
        int     i;
557
 
 
558
 
        printf ("Network UPS Tools - Best Micro-Ferrups driver 0.1 (%s)\n", 
559
 
                UPS_VERSION);
560
 
        openlog ("bestuferrups", LOG_PID, LOG_FACILITY);
561
 
        prog = argv[0];
562
 
 
563
 
        while ((i = getopt(argc, argv, "+hk:D")) != EOF) {
564
 
                switch (i) {
565
 
                        case 'k':
566
 
                                forceshutdown(optarg);
567
 
                                break;
568
 
                        case 'D':
569
 
                          debugging = 1;
570
 
                                break;
571
 
                        case 'h':
572
 
                                help(prog);
573
 
                                break;
574
 
                        default:
575
 
                                usage(prog);
576
 
                                break;
577
 
                }
578
 
        }
579
 
 
580
 
        argc -= optind;
581
 
        argv += optind;
582
 
 
583
 
        if (argc != 1) {
584
 
                help (prog);
585
 
                exit (1);
586
 
        }
587
 
 
588
 
        droproot();
589
 
 
590
 
        portname = NULL;
591
 
        for (i = strlen(argv[0]); i >= 0; i--)
592
 
                if (argv[0][i] == '/') {
593
 
                        portname = &argv[0][i+1];
594
 
                        break;
595
 
                }
596
 
 
597
 
        if (portname == NULL) {
598
 
                printf ("Unable to abbreviate %s\n", argv[0]);
599
 
                exit (1);
600
 
        }
601
 
 
602
 
        snprintf (statefn, sizeof(statefn), "%s/bestuferrups-%s", STATEPATH,
603
 
                  portname);
604
 
 
605
 
        open_ups(portname);
606
 
 
607
 
        ups_sync();             /* get a prompt */
608
 
 
609
 
        initinfo();
610
 
        createmsgq();
611
 
 
612
 
#if 0
613
 
        setuphandlers();        /* seems uneeded? */
614
 
#endif
615
 
 
616
 
        ups_ident();            /* run formatconfig command and
617
 
                                   extract fixed information into
618
 
                                   global fc. struct */
619
 
 
620
 
#if 0
621
 
        /* Fortress does automagical testing monthly */
622
 
        addinfo (INFO_INSTCMD, "", 0, CMD_BTEST0);
623
 
        addinfo (INFO_INSTCMD, "", 0, CMD_BTEST1);
624
 
#endif
625
 
 
626
 
        printf ("Detected %s %s on %s\n", 
627
 
                getdata(INFO_MFR), 
628
 
                getdata(INFO_MODEL), 
629
 
                argv[0]);
630
 
 
631
 
        if (!debugging)
632
 
          background();
633
 
 
634
 
        for (;;) {
635
 
          ups_update();
636
 
          
637
 
          if (getupsmsg(2))       /* TODO: remove debug scaffolding */
638
 
            upslogx(LOG_INFO, "Received a message from upsd\n");
639
 
          
640
 
        }
641
 
 
642
 
        return 0;
643
 
}
644
 
 
645
 
 
646
 
#if 0
647
 
void instcmd (int auxcmd, int dlen, char *data)
648
 
{
649
 
  assert(0);
650
 
 
651
 
        /* TODO: reply to upsd? */
652
 
 
653
 
        switch (auxcmd) {
654
 
                case CMD_BTEST0:        /* stop battery test */
655
 
                        break;
656
 
                case CMD_BTEST1:        /* start battery test */
657
 
                        break;
658
 
                default:
659
 
                        upslogx(LOG_INFO, "instcmd: unknown type 0x%04x\n",
660
 
                                auxcmd);
661
 
        }
662
 
}
663
 
 
664
 
void setuphandlers()
665
 
{
666
 
  assert(0);
667
 
  /*    upsh.instcmd = instcmd; */
668
 
}
669
 
#endif /* 0 */
670
 
 
671