File: apcsmart.h

package info (click to toggle)
nut 2.7.2-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 10,220 kB
  • ctags: 8,034
  • sloc: ansic: 66,197; sh: 12,738; python: 2,196; cpp: 1,710; makefile: 1,335; perl: 702; xml: 10
file content (172 lines) | stat: -rw-r--r-- 5,623 bytes parent folder | download
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
 * apcsmart.h - common defines for apcsmart driver
 *
 * Copyright (C) 1999  Russell Kroll <rkroll@exploits.org>
 *           (C) 2000  Nigel Metheringham <Nigel.Metheringham@Intechnology.co.uk>
 *           (C) 2011+ Michal Soltys <soltys@ziu.info>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#ifndef __apcsmart_h__
#define __apcsmart_h__

#define DRIVER_NAME	"APC Smart protocol driver"
#define DRIVER_VERSION	"3.1"

#define ALT_CABLE_1 "940-0095B"

/*
 * alerts and other stuff for quick reference:
 *
 * $ OL
 * ! OB
 * % LB
 * + not LB anymore
 * # RB
 * ? OVER
 * = not OVER anymore
 * * powering down now (only older models ?), handled by upsread()
 * 	otherwise ignored (it doesn't have to be in ignore sets)
 *
 * | eeprom change
 * & check alarm register for fail
 * ~ ???
 */

/*
 * old ones for reference:
 * 	#define IGNCHARS "\015+$|!~%?=#&"
 * 	#define POLL_IGNORE "\015&|"
 *	#define POLL_ALERT "$!%+#?="
 *	#define MINIGNCHARS "\015+$|!"
 * notice ~ that was present in IGNCHARS, but not in POLL_IGNORE - this kinda
 * didn't make sense (?); new versions doesn't filter ~, but keep that in mind
 * in case something obscure surfaces
 * due to switch to ICANON tty mode, we removed \015 from ignored characters,
 * as it's handled by IGNCR at read() level
 */

/*
 * about CR:
 * apparently windows is unable to ignore CRs by means of IGNCR flag (or
 * perhaps there is something else involved); so despite IGNCR we re-aad \015
 * to ignore sets for now; see:
 * http://article.gmane.org/gmane.comp.monitoring.nut.user/7762
 *
 * furthermore, since the canonical/non-canonical mode is user selectable now,
 * we have to ignore this character explicitly
 */

/* Basic UPS reply line structure */
#define ENDCHAR 10		/* APC ends responses with LF (and CR, but it's IGNCRed) */

/* what to ignore during alert aware serial reads */
#define IGN_AACHARS "\015|&"

/* what alert_handler() should care about */
#define ALERT_CHARS "$!%+#?="

/* characters ignored by alertless reads */
#define IGN_CHARS IGN_AACHARS ALERT_CHARS

/*
 * these ones are used only during Capability Check read, due to ^Z sending
 * certain characters such as #; it seems it could be equal to just IGN_CHARS
 * w/o # old: #define IGN_CCCHARS "|$!+"
 */
#define IGN_CCCHARS "\015|&$!%+?="	/* capability check ignore set */

/*
 * Command Set 'a' reports everything - protocol number, alerts and supported
 * commands
 */
#define IGN_CSCHARS ""	/* command set ignore set */

/* dangerous instant commands must be reconfirmed within a 12 second window */
#define MINCMDTIME	3
#define MAXCMDTIME	15

/* it only does two strings, and they're both the same length */
#define APC_STRLEN	8

#define SER_D0	0x001	/* 0 sec., for flushes */
#define SER_DX	0x002	/* 200 ms for long/repeated cmds, in case of unexpected NAs */
#define SER_D1	0x004	/* 1.5 sec. */
#define SER_D3	0x008	/* 3 sec. (default) */
#define SER_AA	0x010	/* Alert Aware set */
#define SER_CC	0x020	/* Capability Check ign set */
#define SER_CS	0x040	/* Command Set ign set */
#define SER_TO	0x080	/* timeout allowed */
#define SER_HA	0x100	/* handle asterisk */


/* sets of the above (don't test against them, obviously */

/*
 * Some cmd codes to ignore (nut doesn't expose those, though the driver might
 * use them internally (e.g. [a]). If you decide to support them at some
 * point, remember about removing them from here !
 */
#define APC_UNR_CMDS "\032\177~')-+8QRYayz"

/* --------------- */

/* status bits */

#define APC_STAT_CAL   (1 << 0)        /* calibration */
#define APC_STAT_TRIM  (1 << 1)        /* SmartTrim */
#define APC_STAT_BOOST (1 << 2)        /* SmartBoost */
#define APC_STAT_OL    (1 << 3)        /* on line */
#define APC_STAT_OB    (1 << 4)        /* on battery */
#define APC_STAT_OVER  (1 << 5)        /* overload */
#define APC_STAT_LB    (1 << 6)        /* low battery */
#define APC_STAT_RB    (1 << 7)        /* replace battery */

/*
 * serial protocol: special commands - initialization and such
 * these are not exposed as instant commands
 */
#define APC_STATUS	'Q'
#define APC_GOSMART	'Y'
#define APC_GODUMB	'R'
#define APC_CMDSET	'a'
#define APC_CMDSET_FMT	"^[0-9]\\.[^.]*\\.[^.]+$"
#define APC_CAPS	'\032'	/* ^Z */
#define APC_NEXTVAL	'-'
#define APC_FW_OLD	'V'
#define APC_FW_NEW	'b'

#define APC_LBUF	512
#define APC_SBUF	32

/* default a.w.d. value / regex format for command '@' */
#define APC_AWDFMT	"^[0-9]{1,3}$"

/* sdtype method regex format*/
#define APC_SDFMT	"^[0-5]$"

/* advorder method regex format*/
#define APC_ADVFMT	"^([0-4]{1,5}|[Nn][Oo])$"

/* error logging/debug related macros */

#define fatx(fmt, ...) fatalx(EXIT_FAILURE, "%s: " fmt, __func__ , ## __VA_ARGS__)
#define fate(fmt, ...) fatal_with_errno(EXIT_FAILURE, "%s: " fmt, __func__ , ## __VA_ARGS__)

#define logx(lev, fmt, ...) upslogx(lev, "%s: " fmt, __func__ , ## __VA_ARGS__)
#define debx(lev, fmt, ...) upsdebugx(lev, "%s: " fmt, __func__ , ## __VA_ARGS__)

#endif