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

« back to all changes in this revision

Viewing changes to drivers/newhidups.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
 
/* newhidups.c - New prototype HID UPS driver for Network UPS Tools
 
1
/* newhidups.c - Driver for serial/USB HID UPS units
2
2
 *
3
 
 * Copyright (C) 2003-2004
4
 
 * Arnaud Quette <arnaud.quette@free.fr> && <arnaud.quette@mgeups.com>
 
3
 * Copyright (C) 2003 - 2005
 
4
 *   Arnaud Quette <arnaud.quette@free.fr> && <arnaud.quette@mgeups.com>
5
5
 *
6
6
 * This program is sponsored by MGE UPS SYSTEMS - opensource.mgeups.com
7
7
 *
27
27
#include <unistd.h>
28
28
#include "config.h"
29
29
 
30
 
#define DRIVER_VERSION          "0.11"
31
 
 
32
 
#define MGE_UPS_SYSTEMS         0x0463
33
 
#define APC                     0x051d
34
 
/* TODO: add other VendorID with HID compliant devices */
35
 
 
36
 
/* for formating finely model name */
37
 
typedef struct {
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) */
43
 
  int d2_offset; /* */
 
30
#define DRIVER_VERSION          "0.23"
 
31
 
 
32
/* --------------------------------------------------------------- */
 
33
/*      Supported Manufacturers IDs                                */
 
34
/* --------------------------------------------------------------- */
 
35
 
 
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... */
 
42
 
 
43
 
 
44
/* --------------------------------------------------------------- */
 
45
/*      Model Name formating entries                               */
 
46
/* --------------------------------------------------------------- */
 
47
 
 
48
typedef struct
 
49
{
 
50
        char    *iProduct;
 
51
        char    *iModel;
 
52
        int     comp_size;      /* size of the comparison, -1 for full */
 
53
        char    *finalname;
44
54
} models_name_t;
45
55
 
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 },
54
 
  
55
 
  /* TODO: add other MGE devices => ESPRIT, GALAXY (3000_10 => 3000 10), ?PwTrust2? */
56
 
 
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 },
61
 
 
62
 
  /* end of structure. */
63
 
  { 0, NULL, 0, NULL, NULL, 0 }
64
 
};
65
 
 
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"
 
60
 
 
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 */ 
70
 
 
71
 
 
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 */
 
69
 
 
70
#define MAX_STRING_SIZE         128
 
71
 
 
72
 
 
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   */
76
77
 
77
78
 
78
 
/* for lookup between HID values and NUT values*/
 
79
/* --------------------------------------------------------------- */
 
80
/* Struct & data for ups.status processing                         */
 
81
/* --------------------------------------------------------------- */
 
82
 
 
83
typedef struct {
 
84
        char    *status_str;    /* ups.status string */
 
85
        int     status_value;   /* ups.status value */
 
86
} status_lkp_t;
 
87
 
 
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 */
 
100
 
 
101
status_lkp_t status_info[] = {
 
102
  { "CAL", STATUS_CAL },
 
103
  { "TRIM", STATUS_TRIM },
 
104
  { "BOOST", STATUS_BOOST },
 
105
  { "OL", STATUS_OL },
 
106
  { "OB", STATUS_OB },
 
107
  { "OVER", STATUS_OVER },
 
108
  { "LB", STATUS_LB },
 
109
  { "RB", STATUS_RB },
 
110
  { "BYPASS", STATUS_BYPASS },
 
111
  { "OFF", STATUS_OFF },
 
112
  { "CHRG", STATUS_CHRG },
 
113
  { "DISCHRG", STATUS_DISCHRG },
 
114
  { "NULL", 0 },
 
115
};
 
116
 
 
117
 
 
118
/* --------------------------------------------------------------- */
 
119
/* Struct & data for lookup between HID and NUT values             */
 
120
/* (From USB/HID, Power Devices Class standard)                    */
 
121
/* --------------------------------------------------------------- */
 
122
 
79
123
typedef struct {
80
124
        long    hid_value;      /* HID value */
81
125
        char    *nut_value;     /* NUT value */
119
163
  { 1, "BOOST" },
120
164
  { 0, "NULL" }
121
165
};
122
 
/* TODO: add BYPASS, OFF, CAL */
 
166
/* FIXME: extend ups.status for BYPASS Manual/Automatic */
 
167
info_lkp_t bypass_info[] = {
 
168
  { 1, "BYPASS" },
 
169
  { 0, "NULL" }
 
170
};
 
171
info_lkp_t off_info[] = {
 
172
  { 0, "OFF" },
 
173
  { 0, "NULL" }
 
174
};
 
175
/* FIXME: add CAL */
123
176
 
124
177
info_lkp_t test_write_info[] = {
125
178
  { 0, "No test" },
138
191
  { 0, "NULL" }
139
192
};
140
193
 
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
146
 
*/
 
194
/* --------------------------------------------------------------- */
 
195
/* Structure containing information about how to get/set data      */
 
196
/* from/to the UPS and convert these to/from NUT standard          */
 
197
/* --------------------------------------------------------------- */
 
198
 
147
199
typedef struct {
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 */
 
209
 
 
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 */
159
213
} hid_info_t;
160
214
 
 
215
 
 
216
/* Data walk modes */
 
217
#define HU_WALKMODE_INIT                1
 
218
#define HU_WALKMODE_QUICK_UPDATE        2
 
219
#define HU_WALKMODE_FULL_UPDATE         3
 
220
 
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. */
167
 
 
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. */
175
229
 
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 */
182
232
 
183
233
#define HU_CMD_MASK             0x2000
184
234
 
185
235
#define HU_INFOSIZE             128
186
236
 
 
237
#define MAX_TRY         2               /* max number of GetItem retry */
 
238
 
187
239
/* TODO: create an Mfr table (int VendorID, hid_info_t *hid_mfr, ...) */