27
27
#include <unistd.h>
28
28
#include "config.h"
30
#define DRIVER_VERSION "0.11"
32
#define MGE_UPS_SYSTEMS 0x0463
34
/* TODO: add other VendorID with HID compliant devices */
36
/* for formating finely model name */
38
int VendorID; /* ... */
39
char *basename; /* Name start by ... */
40
int size; /* size of comparison */
41
char *finalname; /* replace basename with this */
42
char *data2; /* complement iModel (MGE), or string to be searched for (APC) */
30
#define DRIVER_VERSION "0.23"
32
/* --------------------------------------------------------------- */
33
/* Supported Manufacturers IDs */
34
/* --------------------------------------------------------------- */
36
#define MGE_UPS_SYSTEMS 0x0463 /* All models */
37
#define APC 0x051d /* All models */
38
/* Unsupported! (need spec/hardware/help) */
39
#define MUSTEK 0x0665 /* models: 0x5161... */
40
#define TRIPPLITE 0x09ae /* models IDs? */
41
#define UNITEK 0x0F03 /* models: 0x0001... */
44
/* --------------------------------------------------------------- */
45
/* Model Name formating entries */
46
/* --------------------------------------------------------------- */
52
int comp_size; /* size of the comparison, -1 for full */
46
models_name_t models_names [] = {
47
/* MGE UPS SYSTEMS - EMOA models */
48
{ MGE_UPS_SYSTEMS, "ELLIPSE", 7,"ellipse", "UPS.Flow.[4].ConfigApparentPower", 0 },
49
{ MGE_UPS_SYSTEMS, "ellipse", 7, "ellipse premium", "UPS.PowerSummary.iModel", 2 },
50
{ MGE_UPS_SYSTEMS, "Evolution", 9, "evolution", "UPS.PowerSummary.iModel", 0 },
51
{ MGE_UPS_SYSTEMS, "EXtreme", 7, "Pulsar EXtreme", "UPS.PowerSummary.iModel", 0 },
52
/* MGE UPS SYSTEMS - US models */
53
{ MGE_UPS_SYSTEMS, "EX", 2, "Pulsar EX", "UPS.PowerSummary.iModel", 0 },
55
/* TODO: add other MGE devices => ESPRIT, GALAXY (3000_10 => 3000 10), ?PwTrust2? */
57
{ APC, "BackUPS Pro", 11, NULL, "FW", 0 },
58
{ APC, "Back-UPS ES", 11, NULL, "FW", 0 },
59
{ APC, "Smart-UPS", 9, NULL, "FW", 0 },
60
{ APC, "BackUPS ", 8, NULL, " ", 0 },
62
/* end of structure. */
63
{ 0, NULL, 0, NULL, NULL, 0 }
66
#define DEFAULT_ONDELAY 30 /* delay between return of utility power */
56
/* Driver's parameters */
57
#define HU_VAR_ONDELAY "ondelay"
58
#define HU_VAR_OFFDELAY "offdelay"
59
#define HU_VAR_POLLFREQ "pollfreq"
61
/* Parameters default values */
62
#define DEFAULT_ONDELAY 30 /* Delay between return of utility power */
67
63
/* and powering up of load, in seconds */
68
64
/* CAUTION: ondelay > offdelay */
69
#define DEFAULT_OFFDELAY 20 /* delay before power off, in seconds */
72
/* TODO: remaining "unused" items => need integration */
65
#define DEFAULT_OFFDELAY 20 /* Delay before power off, in seconds */
66
#define DEFAULT_POLLFREQ 30 /* Polling interval, in seconds */
67
/* The driver will wait for Interrupt */
68
/* and do "light poll" in the meantime */
70
#define MAX_STRING_SIZE 128
73
/* FIXME: remaining "unused" items => need integration */
73
74
#define BATT_MFRDATE 0x850085 /* manufacturer date */
74
75
#define BATT_ICHEMISTRY 0x850089 /* battery type */
75
76
#define BATT_IOEMINFORMATION 0x85008f /* battery OEM description */
78
/* for lookup between HID values and NUT values*/
79
/* --------------------------------------------------------------- */
80
/* Struct & data for ups.status processing */
81
/* --------------------------------------------------------------- */
84
char *status_str; /* ups.status string */
85
int status_value; /* ups.status value */
88
#define STATUS_CAL 1 /* calibration */
89
#define STATUS_TRIM 2 /* SmartTrim */
90
#define STATUS_BOOST 4 /* SmartBoost */
91
#define STATUS_OL 8 /* on line */
92
#define STATUS_OB 16 /* on battery */
93
#define STATUS_OVER 32 /* overload */
94
#define STATUS_LB 64 /* low battery */
95
#define STATUS_RB 128 /* replace battery */
96
#define STATUS_BYPASS 256 /* on bypass */
97
#define STATUS_OFF 512 /* ups is off */
98
#define STATUS_CHRG 1024 /* charging */
99
#define STATUS_DISCHRG 2048 /* discharging */
101
status_lkp_t status_info[] = {
102
{ "CAL", STATUS_CAL },
103
{ "TRIM", STATUS_TRIM },
104
{ "BOOST", STATUS_BOOST },
107
{ "OVER", STATUS_OVER },
110
{ "BYPASS", STATUS_BYPASS },
111
{ "OFF", STATUS_OFF },
112
{ "CHRG", STATUS_CHRG },
113
{ "DISCHRG", STATUS_DISCHRG },
118
/* --------------------------------------------------------------- */
119
/* Struct & data for lookup between HID and NUT values */
120
/* (From USB/HID, Power Devices Class standard) */
121
/* --------------------------------------------------------------- */
80
124
long hid_value; /* HID value */
81
125
char *nut_value; /* NUT value */
141
/* Structure containing info about one item that can be requested
142
from UPS and set in INFO. If no interpreter functions is defined,
143
use sprintf with given format string. If unit is not NONE, values
144
are converted according to the multiplier table
145
=> TODO: this description must be updated
194
/* --------------------------------------------------------------- */
195
/* Structure containing information about how to get/set data */
196
/* from/to the UPS and convert these to/from NUT standard */
197
/* --------------------------------------------------------------- */
148
char *info_type; /* INFO_ or CMD_ element */
149
int info_flags; /* flags to set in addinfo */
150
float info_len; /* length of strings if STR, */
151
/* cmd value if CMD, multiplier otherwise. */
152
char *hidpath; /* Full HID Object path or NULL */
153
char *dfl; /* default value (hidflags = ABSENT), format otherwise */
154
unsigned long hidflags; /* my flags */
200
char *info_type; /* NUT variable name */
201
int info_flags; /* NUT flags (to set in addinfo) */
202
float info_len; /* if ST_FLAG_STRING: length of the string */
203
/* if HU_TYPE_CMD: command value ; multiplier otherwise */
204
char *hidpath; /* Full HID Object path (or NULL for server side vars) */
205
int **numericpath; /* Full HID Object numeric path (for caching purpose, filled at runtime) */
206
char *dfl; /* if HU_FLAG_ABSENT: default value ; format otherwise */
207
unsigned long hidflags; /* driver's own flags */
155
208
info_lkp_t *hid2info; /* lookup table between HID and NUT values */
156
/* char *info_HID_format; *//* FFE: HID format for complex values */
157
/* interpreter interpret; *//* FFE: interpreter fct, NULL if not needed */
158
/* void *next; *//* next snmp_info_t */
210
/* char *info_HID_format; *//* FFE: HID format for complex values */
211
/* interpreter interpret; *//* FFE: interpreter fct, NULL if not needed */
212
/* void *next; *//* next hid_info_t */
216
/* Data walk modes */
217
#define HU_WALKMODE_INIT 1
218
#define HU_WALKMODE_QUICK_UPDATE 2
219
#define HU_WALKMODE_FULL_UPDATE 3
161
221
/* TODO: rework flags */
162
#define HU_FLAG_OK (1 << 0) /* show element to upsd. */
163
#define HU_FLAG_STATIC (1 << 1) /* retrieve info only once. */
164
#define HU_FLAG_ABSENT (1 << 2) /* data is absent in the device, */
222
#define HU_FLAG_OK 1 /* show element to upsd. */
223
#define HU_FLAG_STATIC 2 /* retrieve info only once. */
224
#define HU_FLAG_SEMI_STATIC 4 /* retrieve info smartly */
225
#define HU_FLAG_ABSENT 8 /* data is absent in the device, */
165
226
/* use default value. */
166
#define HU_FLAG_STALE (1 << 3) /* data stale, don't try too often. */
168
/* status string components */
169
#define HU_STATUS_PWR (0 << 8) /* indicates power status element */
170
#define HU_STATUS_BATT (1 << 8) /* indicates battery status element */
171
#define HU_STATUS_CAL (2 << 8) /* indicates calibration status element */
172
#define HU_STATUS_RB (3 << 8) /* indicates replace battery status element */
173
#define HU_STATUS_NUM_ELEM 4
174
#define HU_STATUS_INDEX(t) (((t) >> 8) & 7)
227
#define HU_FLAG_QUICK_POLL 16 /* Mandatory vars */
228
#define HU_FLAG_STALE 32 /* data stale, don't try too often. */
176
230
/* hints for su_ups_set, applicable only to rw vars */
177
#define HU_TYPE_INT (0 << 16) /* cast to int when setting value */
178
#define HU_TYPE_STRING (1 << 16) /* cast to string */
179
#define HU_TYPE_TIME (2 << 16) /* cast to int */
180
#define HU_TYPE_CMD (3 << 16) /* instant command */
181
#define HU_TYPE(t) ((t)->flags & 7 << 16)
231
#define HU_TYPE_CMD 64 /* instant command */
183
233
#define HU_CMD_MASK 0x2000
185
235
#define HU_INFOSIZE 128
237
#define MAX_TRY 2 /* max number of GetItem retry */
187
239
/* TODO: create an Mfr table (int VendorID, hid_info_t *hid_mfr, ...) */