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

« back to all changes in this revision

Viewing changes to models/newapc.h

  • 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
 
/* newapc.h - command table for APC smart protocol units
2
 
 
3
 
        $Id: newapc.h,v 1.1.1.2 2002/03/04 11:43:51 cvs Exp $
4
 
 
5
 
   Copyright (C) 1999  Russell Kroll <rkroll@exploits.org>
6
 
             (C) 2000  Nigel Metheringham <Nigel.Metheringham@Intechnology.co.uk>
7
 
 
8
 
   This program is free software; you can redistribute it and/or modify
9
 
   it under the terms of the GNU General Public License as published by
10
 
   the Free Software Foundation; either version 2 of the License, or
11
 
   (at your option) any later version.
12
 
 
13
 
   This program is distributed in the hope that it will be useful,
14
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
   GNU General Public License for more details.
17
 
 
18
 
   You should have received a copy of the GNU General Public License
19
 
   along with this program; if not, write to the Free Software
20
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
 
*/
22
 
 
23
 
#include <ctype.h>
24
 
#include <sys/ioctl.h>
25
 
#include <sys/termios.h>
26
 
#include "timehead.h"
27
 
#include "shared-tables.h"
28
 
 
29
 
#define APC_TABLE_VERSION       "$Revision: 1.1.1.2 $"
30
 
 
31
 
/* Basic UPS reply line structure */
32
 
#define ENDCHAR 10              /* APC ends responses with LF */
33
 
#define IGNCHARS "\015+$|!~%?=*#&"      /* special characters to ignore */
34
 
#define MINIGNCHARS "\015+$|!"  /* minimum set of special characters to ignore */
35
 
 
36
 
/* dangerous instant commands must be reconfirmed within a 12 second window */
37
 
#define CONFIRM_DANGEROUS_COMMANDS 1
38
 
#define MINCMDTIME      3
39
 
#define MAXCMDTIME      15
40
 
 
41
 
 
42
 
/* Driver command table flag values */
43
 
#define APC_TYPEMASK    3
44
 
#define APC_POLL        0x10    /* Poll this variable */
45
 
#define APC_IGNORE      0x20    /* Never poll this */
46
 
#define APC_CMD         0x60    /* This is a command - => ignored by collector */
47
 
#define APC_NASTY       0x80    /* Nasty command - take care */
48
 
#define APC_REPEAT      0x100   /* Command needs sending twice */
49
 
#define APC_PRESENT     0x1000  /* Capability seen on this UPS */
50
 
#define APC_FORMATMASK  0xFF0000 /* Mask for apc data formats */
51
 
#define APC_F_ST        0x010000 /* Status format */
52
 
#define APC_F_PERCENT   0x020000 /* Data in a percent format */
53
 
#define APC_F_VOLT      0x030000 /* Data in a voltage format */
54
 
#define APC_F_AMP       0x040000 /* Data in a current/amp format */
55
 
#define APC_F_CELCIUS   0x050000 /* Data in a temp/C format */
56
 
#define APC_F_HEX       0x060000 /* Data in a hex number format */
57
 
#define APC_F_DEC       0x070000 /* Data in a decimal format */
58
 
#define APC_F_SECONDS   0x100000 /* Time in seconds */
59
 
#define APC_F_MINUTES   0x110000 /* Time in minutes */
60
 
#define APC_F_HOURS     0x120000 /* Time in hours */
61
 
#define APC_F_LEAVE     0       /* Just pass this through */
62
 
 
63
 
#define CMD_MASK        0x2000  /* Mask off CMD_ from INFO_ */
64
 
#define DRV_MASK        0x4000  /* Mask off DRV_ values */
65
 
 
66
 
#define DRV_CMDSET      0x4001  /* Query command set */
67
 
#define DRV_CAPABILITY  0x4002  /* Query capabilities */
68
 
#define DRV_NEXT        0x4003  /* Next value */
69
 
#define DRV_SMART       0x4004  /* Enter Smart mode */
70
 
#define DRV_ABORT       0x4005  /* Abort shutdown */
71
 
#define DRV_SHUTDN      0x4006  /* Do shutdown */
72
 
#define DRV_SEP         0x4007  /* Separator char */
73
 
#define DRV_RESET       0x4008  /* Reset the thing */
74
 
#define DRV_INFO        0x4009  /* Some APC info */
75
 
 
76
 
struct apc_cmdtab_t {
77
 
        int             info_type;      /* the INFO_ index */
78
 
        int             info_len;       /* length of INFO data if writable */
79
 
        unsigned int    info_flags;     /* INFO flag values - NB Flag enum/rw set by cap check */
80
 
        unsigned int    driver_flags;   /* driver specific flags */
81
 
        char *          name;           /* name - mostly derived from netvars data */
82
 
        char *          desc;           /* description - mostly derived from netvars data */
83
 
        char            cmd;            /* command character */
84
 
} apc_cmdtab[] = {
85
 
        /* InfoType   Len  InfoFlags    DriverFlags             Name  Desc      CmdChar */
86
 
        {INFO_MODEL,    0, 0,           0,                      NULL, NULL,     0x01},
87
 
        {INFO_SERIAL,   0, 0,           0,                      NULL, NULL,     'n'},
88
 
        {INFO_UTILITY,  0, 0,           APC_POLL|APC_F_VOLT,    NULL, NULL,     'L'},
89
 
        {INFO_BATTPCT,  0, 0,           APC_POLL|APC_F_PERCENT, NULL, NULL,     'f'},
90
 
        {INFO_STATUS,   0, 0,           APC_POLL|APC_F_ST,      NULL, NULL,     'Q'},
91
 
        {INFO_UPSTEMP,  0, 0,           APC_POLL|APC_F_CELCIUS, NULL, NULL,     'C'},
92
 
        {INFO_ACFREQ,   0, 0,           APC_POLL|APC_F_DEC,     NULL, NULL,     'F'},
93
 
        {INFO_LOADPCT,  0, 0,           APC_POLL|APC_F_PERCENT, NULL, NULL,     'P'},
94
 
        {INFO_LOWXFER,  0, 0,           APC_F_VOLT,             NULL, NULL,     'l'},
95
 
        {INFO_HIGHXFER, 0, 0,           APC_F_VOLT,             NULL, NULL,     'u'},
96
 
        {INFO_AMBHUMID, 0, 0,           APC_POLL|APC_F_PERCENT, NULL, NULL,     'h'},
97
 
        {INFO_AMBTEMP,  0, 0,           APC_POLL|APC_F_CELCIUS, NULL, NULL,     't'},
98
 
        {INFO_CONTACTS, 0, 0,           APC_POLL|APC_F_HEX,     NULL, NULL,     'i'},
99
 
        {INFO_UPSIDENT, 8, FLAG_RW | FLAG_STRING,
100
 
                                        0,                      NULL, NULL,     'c'},
101
 
        {INFO_WAKEDELAY,0, 0,           APC_F_SECONDS,          NULL, NULL,     'r'},
102
 
        {INFO_LINESENS, 0, 0,           0,                      NULL, NULL,     's'},
103
 
        {INFO_WAKETHRSH,0, 0,           APC_F_PERCENT,          NULL, NULL,     'e'},
104
 
        {INFO_REQVOLT,  0, 0,           APC_F_VOLT,             NULL, NULL,     'o'},
105
 
        {INFO_LOBATTIME,0, 0,           APC_F_MINUTES,          NULL, NULL,     'q'},
106
 
        {INFO_PDNGRACE, 0, 0,           APC_F_SECONDS,          NULL, NULL,     'p'},
107
 
        {INFO_ALRMDELAY,0, 0,           0,                      NULL, NULL,     'k'},
108
 
        {INFO_SLFTSTINT,0, 0,           APC_F_HOURS,            NULL, NULL,     'E'},
109
 
        {INFO_FIRMREV,  0, 0,           0,                      NULL, NULL,     'b'},
110
 
        {INFO_REG1,     0, 0,           APC_POLL|APC_F_HEX,     NULL, NULL,     '~'},
111
 
        {INFO_REG2,     0, 0,           APC_POLL|APC_F_HEX,     NULL, NULL,     0x27},
112
 
        {INFO_REG3,     0, 0,           APC_POLL|APC_F_HEX,     NULL, NULL,     '8'},
113
 
        {INFO_LINEQUAL, 0, 0,           APC_POLL|APC_F_HEX,     NULL, NULL,     '9'},
114
 
        {INFO_BATTPACKS,0, 0,           APC_F_DEC,              NULL, NULL,     '>'},
115
 
        {INFO_BADPACKS, 0, 0,           APC_F_DEC,              NULL, NULL,     '<'},
116
 
        {INFO_BATTVOLT, 0, 0,           APC_POLL|APC_F_VOLT,    NULL, NULL,     'B'},
117
 
        {INFO_XFERWHY,  0, 0,           APC_POLL,               NULL, NULL,     'G'},
118
 
        {INFO_MAXUTIL,  0, 0,           APC_POLL|APC_F_VOLT,    NULL, NULL,     'M'},
119
 
        {INFO_MINUTIL,  0, 0,           APC_POLL|APC_F_VOLT,    NULL, NULL,     'N'},
120
 
        {INFO_OUTVOLT,  0, 0,           APC_POLL|APC_F_VOLT,    NULL, NULL,     'O'},
121
 
        {INFO_SLFTSTRES,0, 0,           APC_POLL,               NULL, NULL,     'X'},
122
 
        {INFO_RUNTIME,  0, 0,           APC_POLL|APC_F_MINUTES, NULL, NULL,     'j'},
123
 
        {INFO_MFRDATE,  0, 0,           0,                      NULL, NULL,     'm'},
124
 
        {INFO_TEMPMAX,  0, 0,           APC_F_CELCIUS,          NULL, NULL,     '['},
125
 
        {INFO_TEMPMIN,  0, 0,           APC_F_CELCIUS,          NULL, NULL,     ']'},
126
 
        {INFO_HUMDMAX,  0, 0,           APC_F_PERCENT,          NULL, NULL,     '{'},
127
 
        {INFO_HUMDMIN,  0, 0,           APC_F_PERCENT,          NULL, NULL,     '}'},
128
 
        {INFO_FIRMREV1, 0, 0,           0,                      NULL, NULL,     'V'},
129
 
        {INFO_FIRMREV2, 0, 0,           0,                      NULL, NULL,     'v'},
130
 
        {INFO_NOMBATVLT,0, 0,           0,                      NULL, NULL,     'g'},
131
 
        {INFO_BATTDATE, 8, FLAG_RW | FLAG_STRING
132
 
                        ,               0,                      NULL, NULL,     'x'},
133
 
        {INFO_COPYRIGHT,0, 0,           0,                      NULL, NULL,     'y'},
134
 
        {INFO_DIPSWCH,  0, 0,           APC_F_HEX,              NULL, NULL,     '7'},
135
 
        {INFO_OUTVLTSEL,0, 0,           APC_F_VOLT,             NULL, NULL,     0x15},
136
 
        {INFO_CURRENT,  0, 0,           APC_POLL|APC_F_AMP,     NULL, NULL,     '/'},
137
 
        {INFO_LOADPWR,  0, 0,           APC_POLL|APC_F_PERCENT, NULL, NULL,     0x5C},
138
 
        {INFO_LANGUAGE, 0, 0,           0,                      NULL, NULL,     0x0C},
139
 
        {INFO_ALRMENA,  0, 0,           APC_F_HEX,              NULL, NULL,     'I'},
140
 
        {INFO_ALRMSTAT, 0, 0,           0,                      NULL, NULL,     'J'},
141
 
        {INFO_AMBHUMID2,0, 0,           APC_POLL|APC_F_PERCENT, NULL, NULL,     'H'},
142
 
        {INFO_AMBTEMP2, 0, 0,           APC_POLL|APC_F_CELCIUS, NULL, NULL,     'T'},
143
 
 
144
 
        /* Commands - in same array for neatness :-) */
145
 
        {CMD_OFF,       0, 0,           APC_CMD|APC_NASTY|APC_REPEAT,
146
 
                                                                NULL, NULL,     'Z'},
147
 
        {CMD_ON,        0, 0,           APC_CMD|APC_REPEAT,     NULL, NULL,     0x0E},
148
 
        {CMD_BTEST0,    0, 0,           APC_CMD,                NULL, NULL,     'W'},
149
 
        {CMD_BTEST1,    0, 0,           APC_CMD,                NULL, NULL,     'W'},
150
 
        {CMD_CAL0,      0, 0,           APC_CMD,                NULL, NULL,     'D'},
151
 
        {CMD_CAL1,      0, 0,           APC_CMD,                NULL, NULL,     'D'},
152
 
        {CMD_FPTEST,    0, 0,           APC_CMD,                NULL, NULL,     'A'},
153
 
        {CMD_DUMB,      0, 0,           APC_CMD|APC_NASTY,      NULL, NULL,     'R'},
154
 
        {CMD_SIMPWF,    0, 0,           APC_CMD,                NULL, NULL,     'U'},
155
 
        {CMD_SOFTDOWN,  0, 0,           APC_CMD|APC_NASTY,      NULL, NULL,     'S'},
156
 
        {CMD_SHUTDOWN,  0, 0,           APC_CMD|APC_NASTY|APC_REPEAT,
157
 
                                                                NULL, NULL,     'K'},
158
 
        {CMD_BYPASS,    0, 0,           APC_CMD,                NULL, NULL,     '^'},
159
 
 
160
 
        /* Driver specific stuff - ie query functions etc */
161
 
        {DRV_CMDSET,    0, 0,           APC_IGNORE,     "#CMDSET",
162
 
                                                        "Command query",        'a'},
163
 
        {DRV_CAPABILITY,0, 0,           APC_IGNORE,     "#CAPAB",
164
 
                                                        "Capabilities query",   26},
165
 
        {DRV_NEXT,      0, 0,           APC_IGNORE,     "#NEXT",
166
 
                                                        "Next value",           '-'},
167
 
        {DRV_SMART,     0, 0,           APC_IGNORE,     "#SMART",
168
 
                                                        "Enter Smart mode",     'Y'},
169
 
        {DRV_ABORT,     0, 0,           APC_IGNORE,     "#ABORT",
170
 
                                                        "Abort",                0x7F},
171
 
        {DRV_SHUTDN,    0, 0,           APC_IGNORE,     "#SHUTDN",
172
 
                                                        "Shutdown",             '@'},
173
 
        {DRV_SEP,       0, 0,           APC_IGNORE,     "#SEP",
174
 
                                                        "Data separator",       '.'},
175
 
        {DRV_RESET,     0, 0,           APC_IGNORE,     "#RESET",
176
 
                                                        "Reset to defaults",    'z'},
177
 
        {DRV_INFO,      0, 0,           APC_IGNORE,     "#INFO",
178
 
                                                        "Some APC system info", ')'},
179
 
 
180
 
        {0,             0, 0,           0,                      NULL, NULL,     0},
181
 
};
182
 
 
183
 
 
184
 
/*
185
 
 * Local variables:
186
 
 *  c-indent-level: 8
187
 
 *  c-basic-offset: 8
188
 
 * End:
189
 
 */