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

« back to all changes in this revision

Viewing changes to drivers/newapc.h

  • 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:
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
 
 
28
 
#define APC_TABLE_VERSION       "version 2.0"
29
 
 
30
 
/* Basic UPS reply line structure */
31
 
#define ENDCHAR 10              /* APC ends responses with LF */
32
 
#define IGNCHARS "\015+$|!~%?=*#&"      /* special characters to ignore */
33
 
#define MINIGNCHARS "\015+$|!"  /* minimum set of special characters to ignore */
34
 
 
35
 
/* dangerous instant commands must be reconfirmed within a 12 second window */
36
 
#define MINCMDTIME      3
37
 
#define MAXCMDTIME      15
38
 
 
39
 
/* it only does two strings, and they're both the same length */
40
 
#define APC_STRLEN      8
41
 
 
42
 
/* --------------- */
43
 
 
44
 
/* serial protocol: special commands - initialization and such */
45
 
#define APC_STATUS      'Q'
46
 
#define APC_GOSMART     'Y'
47
 
#define APC_CMDSET      'a'
48
 
#define APC_CAPABILITY  26      /* ^Z */
49
 
#define APC_NEXTVAL     '-'
50
 
 
51
 
/* --------------- */
52
 
 
53
 
/* Driver command table flag values */
54
 
 
55
 
#define APC_POLL        0x0001  /* Poll this variable regularly         */
56
 
#define APC_IGNORE      0x0002  /* Never poll this                      */
57
 
#define APC_PRESENT     0x0004  /* Capability seen on this UPS          */
58
 
 
59
 
#define APC_RW          0x0010  /* read-write variable                  */
60
 
#define APC_ENUM        0x0020  /* enumerated type                      */
61
 
#define APC_STRING      0x0040  /* string                               */
62
 
 
63
 
#define APC_NASTY       0x0100  /* Nasty command - take care            */
64
 
#define APC_REPEAT      0x0200  /* Command needs sending twice          */
65
 
 
66
 
#define APC_FORMATMASK  0xFF0000 /* Mask for apc data formats */
67
 
 
68
 
#define APC_F_PERCENT   0x020000 /* Data in a percent format */
69
 
#define APC_F_VOLT      0x030000 /* Data in a voltage format */
70
 
#define APC_F_AMP       0x040000 /* Data in a current/amp format */
71
 
#define APC_F_CELSIUS   0x050000 /* Data in a temp/C format */
72
 
#define APC_F_HEX       0x060000 /* Data in a hex number format */
73
 
#define APC_F_DEC       0x070000 /* Data in a decimal format */
74
 
#define APC_F_SECONDS   0x100000 /* Time in seconds */
75
 
#define APC_F_MINUTES   0x110000 /* Time in minutes */
76
 
#define APC_F_HOURS     0x120000 /* Time in hours */
77
 
#define APC_F_LEAVE     0       /* Just pass this through */
78
 
 
79
 
struct apc_vartab_t {
80
 
        const   char    *name;          /* the variable name */
81
 
        unsigned int    flags;          /* various flags                */
82
 
        char            cmd;            /* command character */
83
 
 
84
 
} apc_vartab[] = {
85
 
 
86
 
        { "ups.firmware",       0,                      'b' },
87
 
        { "ups.firmware.aux",   0,                      'v' },
88
 
        { "ups.model",          0,                      0x01 },
89
 
 
90
 
/* FUTURE: depends on variable naming scheme */
91
 
#if 0
92
 
        { "ups.model.code",     0,                      'V' },
93
 
#endif
94
 
 
95
 
        { "ups.serial",         0,                      'n' },
96
 
        { "ups.mfr.date",       0,                      'm' },
97
 
 
98
 
        { "ups.temperature",    APC_POLL|APC_F_CELSIUS, 'C' },
99
 
        { "ups.load",           APC_POLL|APC_F_PERCENT, 'P' },
100
 
 
101
 
        { "ups.test.interval",  APC_F_HOURS,            'E' },
102
 
        { "ups.test.result",    APC_POLL,               'X' },
103
 
 
104
 
        { "ups.delay.start",    APC_F_SECONDS,          'r' },
105
 
        { "ups.delay.shutdown", APC_F_SECONDS,          'p' },
106
 
 
107
 
        { "ups.id",             APC_STRING,             'c' },
108
 
 
109
 
        { "ups.contacts",       APC_POLL|APC_F_HEX,     'i' },
110
 
        { "ups.display.language",
111
 
                                0,                      0x0C },
112
 
 
113
 
        { "input.voltage",      APC_POLL|APC_F_VOLT,    'L' },
114
 
        { "input.frequency",    APC_POLL|APC_F_DEC,     'F' },
115
 
        { "input.sensitivity",  0,                      's' },
116
 
        { "input.quality",      APC_POLL|APC_F_HEX,     '9' },
117
 
 
118
 
        { "input.transfer.low", APC_F_VOLT,             'l' },
119
 
        { "input.transfer.high",
120
 
                                APC_F_VOLT,             'u' },
121
 
        { "input.transfer.reason", 
122
 
                                APC_POLL,               'G' },
123
 
 
124
 
        { "input.voltage.maximum",
125
 
                                APC_POLL|APC_F_VOLT,    'M' },
126
 
        { "input.voltage.minimum",
127
 
                                APC_POLL|APC_F_VOLT,    'N' },
128
 
 
129
 
        { "output.current",     APC_POLL|APC_F_AMP,     '/' },
130
 
        { "output.voltage",     APC_POLL|APC_F_VOLT,    'O' },
131
 
        { "output.voltage.target.battery",  
132
 
                                APC_F_VOLT,             'o' },
133
 
 
134
 
        { "ambient.humidity",   APC_POLL|APC_F_PERCENT, 'h' },
135
 
        { "ambient.humidity.alarm.maximum", 
136
 
                                APC_F_PERCENT,          '{' },
137
 
        { "ambient.humidity.alarm.minimum", 
138
 
                                APC_F_PERCENT,          '}' },
139
 
 
140
 
        { "ambient.temperature",        
141
 
                                APC_POLL|APC_F_CELSIUS, 't' },
142
 
        { "ambient.temperature.alarm.maximum",  
143
 
                                APC_F_CELSIUS,          '[' },
144
 
        { "ambient.temperature.alarm.minimum",  
145
 
                                APC_F_CELSIUS,          ']' },
146
 
 
147
 
        { "battery.date",       APC_STRING,             'x' },
148
 
 
149
 
        { "battery.charge",     APC_POLL|APC_F_PERCENT, 'f' },
150
 
        { "battery.charge.restart",  
151
 
                                APC_F_PERCENT,          'e' },
152
 
 
153
 
        { "battery.voltage",    APC_POLL|APC_F_VOLT,    'B' },
154
 
        { "battery.voltage.nominal", 
155
 
                                0,                      'g' },
156
 
 
157
 
        { "battery.runtime",    APC_POLL|APC_F_MINUTES, 'j' },
158
 
        { "battery.runtime.low",
159
 
                                APC_F_MINUTES,          'q' },
160
 
 
161
 
        { "battery.packs",      APC_F_DEC,              '>' },
162
 
        { "battery.packs.bad",  APC_F_DEC,              '<' },
163
 
        { "battery.alarm.threshold", 
164
 
                                0,                      'k' },
165
 
        /* todo:
166
 
 
167
 
           I = alarm enable (hex field) - split into alarm.n.enable
168
 
           J = alarm status (hex field) - split into alarm.n.status
169
 
 
170
 
        0x15 = output voltage selection (APC_F_VOLT)
171
 
        0x5C = load power (APC_POLL|APC_F_PERCENT)
172
 
 
173
 
         */
174
 
 
175
 
        {NULL,          0,                              0},
176
 
};
177
 
 
178
 
/* ------ instant commands ------ */
179
 
 
180
 
#define APC_CMD_FPTEST          'A'
181
 
#define APC_CMD_CALTOGGLE       'D'
182
 
#define APC_CMD_SHUTDOWN        'K'
183
 
#define APC_CMD_SOFTDOWN        'S'
184
 
#define APC_CMD_SIMPWF          'U'
185
 
#define APC_CMD_BTESTTOGGLE     'W'
186
 
#define APC_CMD_OFF             'Z'
187
 
 
188
 
#define APC_CMD_ON              0x0E            /* ^N */
189
 
#define APC_CMD_BYPTOGGLE       '^'
190
 
 
191
 
struct apc_cmdtab_t {
192
 
        const   char    *name;
193
 
        int     flags;
194
 
        char    cmd;
195
 
} apc_cmdtab[] =
196
 
{
197
 
        { "load.off",           APC_NASTY|APC_REPEAT,   APC_CMD_OFF       },
198
 
        { "load.on",            APC_REPEAT,             APC_CMD_ON        },
199
 
 
200
 
        { "test.panel.start",   0,                      APC_CMD_FPTEST    },
201
 
 
202
 
        { "test.failure.start", 0,                      APC_CMD_SIMPWF    },
203
 
 
204
 
        { "test.battery.start", 0,                      APC_CMD_BTESTTOGGLE },
205
 
        { "test.battery.stop",  0,                      APC_CMD_BTESTTOGGLE },
206
 
 
207
 
        { "shutdown.return",    APC_NASTY,              APC_CMD_SOFTDOWN  },
208
 
        { "shutdown.stayoff",   APC_NASTY|APC_REPEAT,   APC_CMD_SHUTDOWN  },
209
 
 
210
 
        { "calibrate.start",    0,                      APC_CMD_CALTOGGLE },
211
 
        { "calibrate.stop",     0,                      APC_CMD_CALTOGGLE },
212
 
 
213
 
        { "bypass.start",       0,                      APC_CMD_BYPTOGGLE },
214
 
        { "bypass.stop",        0,                      APC_CMD_BYPTOGGLE },
215
 
 
216
 
        { NULL, 0                                       }
217
 
};
218
 
 
219
 
/* things to ignore in protocol_verify - useless variables, etc. */
220
 
#define CMD_IGN_CHARS "\032-78@.,~\047\177QHRTYayz)1IJ"
221
 
 
222
 
/*
223
 
 * Local variables:
224
 
 *  c-indent-level: 8
225
 
 *  c-basic-offset: 8
226
 
 * End:
227
 
 */