1 /* apcupsd-ups.h - NUT client driver to apcupsd
2 
3    Copyright (C)
4        2005 - 2010  Arnaud Quette <http://arnaud.quette.free.fr/contact.html>
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 #ifndef NUT_APCUPSD_UPS_H_SEEN
22 #define NUT_APCUPSD_UPS_H_SEEN 1
23 
24 /* from usbhid-ups.h */
25 /* --------------------------------------------------------------- */
26 /* Struct & data for ups.status processing                         */
27 /* --------------------------------------------------------------- */
28 
29 typedef struct {
30 	const char	*status_str;	/* ups.status string */
31 	int		status_value;	/* ups.status value */
32 } status_lkp_t;
33 
34 #define STATUS_CAL		1       /* calibration */
35 #define STATUS_TRIM		2       /* SmartTrim */
36 #define STATUS_BOOST		4       /* SmartBoost */
37 #define STATUS_OL		8       /* on line */
38 #define STATUS_OB		16      /* on battery */
39 #define STATUS_OVER		32      /* overload */
40 #define STATUS_LB		64      /* low battery */
41 #define STATUS_RB		128     /* replace battery */
42 #define STATUS_BYPASS		256	/* on bypass */
43 #define STATUS_OFF		512	/* ups is off */
44 #define STATUS_CHRG		1024	/* charging */
45 #define STATUS_DISCHRG		2048	/* discharging */
46 
47 /*
48 static status_lkp_t status_info[] = {
49   { "CAL", STATUS_CAL },
50   { "TRIM", STATUS_TRIM },
51   { "BOOST", STATUS_BOOST },
52   { "OL", STATUS_OL },
53   { "OB", STATUS_OB },
54   { "OVER", STATUS_OVER },
55   { "LB", STATUS_LB },
56   { "RB", STATUS_RB },
57   { "BYPASS", STATUS_BYPASS },
58   { "OFF", STATUS_OFF },
59   { "CHRG", STATUS_CHRG },
60   { "DISCHRG", STATUS_DISCHRG },
61   { "NULL", 0 },
62 };
63 */
64 /* from usbhid-ups.h */
65 
66 typedef struct {
67 	char	hid_value;	/* HID value */
68 	char	*nut_value;	/* NUT value */
69 } info_enum_t;
70 
71 /* --------------------------------------------------------------- */
72 /* Structure containing information about how to get/set data      */
73 /* from/to the UPS and convert these to/from NUT standard          */
74 /* --------------------------------------------------------------- */
75 
76 typedef struct {
77 	const char	*apcupsd_item;
78 	const char	*info_type;	/* NUT variable name */
79 	int	info_flags;	/* NUT flags (to set in addinfo) */
80 	float	info_len;	/* if ST_FLAG_STRING: length of the string */
81 				/* if HU_TYPE_CMD: command value ; multiplier (or max len) otherwise */
82 	const char	*default_value;	/* if HU_FLAG_ABSENT: default value ; format otherwise */
83 	int	drv_flags;	/* */
84 	char	**var_values;	/* all possible values for this variable (allows to check data...) */
85 				/* FIXME: "void *" so we can have bound or enum */
86 /*	interpreter interpret;	*/	/* FFE: interpreter fct, NULL if not needed  */
87 } apcuspd_info_t;
88 
89 /* data flags */
90 #define DU_FLAG_NONE			0
91 #define DU_FLAG_INIT			1		/* intialy show element to upsd */
92 #define DU_FLAG_STATUS			2
93 #define DU_FLAG_DATE			4
94 #define DU_FLAG_TIME			8
95 #define DU_FLAG_FW1			16
96 #define DU_FLAG_FW2			32
97 #define DU_FLAG_PRESERVE 	64
98 
99 /* ------------ */
100 /*  Data table  */
101 /* ------------ */
102 
103 static apcuspd_info_t nut_data[] =
104 {
105 	{ NULL, "ups.mfr", ST_FLAG_STRING | ST_FLAG_RW, 32, "APC", DU_FLAG_INIT, NULL },
106 	{ "MODEL", "ups.model", ST_FLAG_STRING | ST_FLAG_RW, 32, "Unknown UPS", DU_FLAG_INIT, NULL },
107 	{ "STATUS", "ups.status", ST_FLAG_STRING | ST_FLAG_RW, 32, "OFF", DU_FLAG_INIT|DU_FLAG_STATUS, NULL },
108 	{ "SERIALNO", "ups.serial", ST_FLAG_STRING | ST_FLAG_RW, 32, NULL, DU_FLAG_NONE, NULL },
109 	{ "LOADPCT", "ups.load", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL },
110 	{ "DATE", "ups.time", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_TIME, NULL },
111 	{ "DATE", "ups.date", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_DATE, NULL },
112 	{ "MANDATE", "ups.mfr.date", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_NONE, NULL },
113 	{ "FIRMWARE", "ups.firmware", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_FW1, NULL },
114 	{ "FIRMWARE", "ups.firmware.aux", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_FW2, NULL },
115 	{ "ITEMP", "ups.temperature", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL },
116 	{ "UPSNAME", "ups.id", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_NONE, NULL },
117 	{ "DWAKE", "ups.delay.start", ST_FLAG_RW, 1, "%.0f", DU_FLAG_NONE, NULL },
118 	{ "DSHUTD", "ups.delay.shutdown", ST_FLAG_RW, 1, "%.0f", DU_FLAG_NONE, NULL },
119 	{ "STESTI", "ups.test.interval", ST_FLAG_RW, 1, "%.0f", DU_FLAG_NONE, NULL },
120 	{ "SELFTEST", "ups.test.result", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_NONE, NULL },
121 	{ "LINEV", "input.voltage", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL },
122 	{ "MAXLINEV", "input.voltage.maximum", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL },
123 	{ "MINLINEV", "input.voltage.minimum", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL },
124 	{ "NOMINV", "input.voltage.nominal", 0, 1, "%.0f", DU_FLAG_NONE, NULL },
125 	{ "NOMOUTV", "output.voltage.nominal", 0, 1, "%.0f", DU_FLAG_NONE, NULL },
126 	{ "LASTXFER", "input.transfer.reason", ST_FLAG_STRING | ST_FLAG_RW, 32, NULL, DU_FLAG_NONE, NULL },
127 	{ "LOTRANS", "input.transfer.low", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL },
128 	{ "HITRANS", "input.transfer.high", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL },
129 	{ "SENSE", "input.sensitivity", ST_FLAG_STRING | ST_FLAG_RW, 1, NULL, DU_FLAG_NONE, NULL },
130 	{ "LINEFREQ", "input.frequency", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL },
131 	{ "OUTPUTV", "output.voltage", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL },
132 	{ "LINEFREQ", "output.frequency", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL },
133 	{ "BCHARGE", "battery.charge", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_PRESERVE, NULL },
134 	{ "MBATTCHG", "battery.charge.low", ST_FLAG_RW, 1, "%.0f", DU_FLAG_NONE, NULL },
135 	{ "BATTDATE", "battery.date", ST_FLAG_STRING /* | ST_FLAG_RW */, 16, NULL, DU_FLAG_DATE, NULL },
136 	{ "BATTV", "battery.voltage", 0, 1, "%1.1f", DU_FLAG_NONE, NULL },
137 	{ "NOMBATTV", "battery.voltage.nominal", 0, 1, "%1.1f", DU_FLAG_NONE, NULL },
138 	{ "TIMELEFT", "battery.runtime", ST_FLAG_RW, 60, "%1.1f", DU_FLAG_PRESERVE, NULL },
139 	{ "MINTIMEL", "battery.runtime.low", ST_FLAG_RW, 60, "%.0f", DU_FLAG_NONE, NULL },
140 	{ "RETPCT", "battery.charge.restart", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL },
141 	{ "NOMPOWER", "ups.realpower.nominal", 0, 1, "%1.1f", DU_FLAG_INIT, NULL },
142 	{ "LOAD_W", "ups.realpower", 0, 1, "%1.1f", DU_FLAG_NONE, NULL },
143 	{ "LOADAPNT", "power.percent", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL },
144 	{ "OUTCURNT", "output.current", 0, 1, "%1.2f", DU_FLAG_NONE, NULL },
145 	{ "LOAD_VA", "ups.power", 0, 1, "%1.1f", DU_FLAG_NONE, NULL },
146 	{ "NOMAPNT", "ups.power.nominal", 0, 1, "%.0f", DU_FLAG_INIT, NULL },
147 	{ NULL, NULL, 0, 0, NULL, DU_FLAG_NONE, NULL }
148 };
149 
150 #endif  /* NUT_APCUPSD_UPS_H_SEEN */
151