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

« back to all changes in this revision

Viewing changes to drivers/genericups.c

  • 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:
17
17
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
*/
19
19
 
20
 
#define DRV_VERSION "1.10"
 
20
#define DRV_VERSION "1.30"
21
21
 
22
22
#include <sys/ioctl.h>
23
23
#include <sys/termios.h>
24
24
 
25
25
#include "main.h"
 
26
#include "serial.h"
 
27
 
26
28
#include "genericups.h"
27
29
 
28
 
        int     upstype = -1;
 
30
        static  int     upstype = -1;
29
31
 
30
32
static void parse_output_signals(const char *value, int *line) 
31
33
73
75
        /* setup the basics */
74
76
 
75
77
        if (getval("mfr"))
76
 
                dstate_setinfo("ups.mfr", getval("mfr"));
 
78
                dstate_setinfo("ups.mfr", "%s", getval("mfr"));
77
79
        else
78
 
                dstate_setinfo("ups.mfr", upstab[upstype].mfr);
 
80
                dstate_setinfo("ups.mfr", "%s", upstab[upstype].mfr);
79
81
 
80
82
        if (getval("model"))
81
 
                dstate_setinfo("ups.model", getval("model"));
 
83
                dstate_setinfo("ups.model", "%s", getval("model"));
82
84
        else
83
 
                dstate_setinfo("ups.model", upstab[upstype].model);
 
85
                dstate_setinfo("ups.model", "%s", upstab[upstype].model);
84
86
 
85
87
        if (getval("serial"))
86
 
                dstate_setinfo("ups.serial", getval("serial"));
 
88
                dstate_setinfo("ups.serial", "%s", getval("serial"));
87
89
 
88
90
        dstate_setinfo("driver.version.internal", "%s", DRV_VERSION);
89
91
 
157
159
        
158
160
        upstype = atoi(getval("upstype"));
159
161
 
160
 
        for (i = 0; upstab[i].mfr != NULL; i++)
 
162
        for (i = 0; upstab[i].mfr != NULL; i++) {
161
163
                if (upstype == i) {
162
164
                        printf("UPS type: %s\n", upstab[i].desc);
163
165
                        return;
164
166
                }
 
167
        }
165
168
 
166
169
        printf("\nFatal error: unknown UPS type number\n");
167
170
        listtypes();
168
 
        exit(1);
 
171
 
 
172
        exit(EXIT_FAILURE);
169
173
}                       
170
174
 
171
175
/* power down the attached load immediately */
172
176
void upsdrv_shutdown(void)
173
177
{
174
 
        int     flags, ret;
 
178
        int     flags, ret;;
175
179
 
176
180
        if (upstype == -1)
177
 
                fatalx("No upstype set - see help text / man page!\n");
 
181
                fatalx("No upstype set - see help text / man page!");
178
182
 
179
183
        flags = upstab[upstype].line_sd;
180
184
 
181
185
        if (flags == -1)
182
 
                fatalx("No shutdown command defined for this model!\n");
 
186
                fatalx("No shutdown command defined for this model!");
183
187
 
184
188
        if (flags == TIOCM_ST) {
185
 
#ifdef HAVE_TCSENDBREAK
186
 
                tcsendbreak (upsfd, 4901);
187
 
#else
188
 
                fatalx("Need to send a BREAK, but don't have tcsendbreak!\n");
 
189
 
 
190
#ifndef HAVE_TCSENDBREAK
 
191
                fatalx("Need to send a BREAK, but don't have tcsendbreak!");
189
192
#endif
190
 
        } else {
191
 
                ret = ioctl(upsfd, TIOCMSET, &flags);
 
193
 
 
194
                ret = tcsendbreak(upsfd, 4901);
 
195
 
192
196
                if (ret != 0)
193
 
                        perror("ioctl");
 
197
                        fatal("tcsendbreak");
 
198
 
 
199
                return;
 
200
        }
 
201
 
 
202
        ret = ioctl(upsfd, TIOCMSET, &flags);
 
203
        if (ret != 0)
 
204
                fatal("ioctl TIOCMSET");
 
205
 
 
206
        if (getval("sdtime")) {
 
207
                int     sdtime;
 
208
 
 
209
                sdtime = strtol(getval("sdtime"), (char **) NULL, 10);
 
210
 
 
211
                upslogx(LOG_INFO, "Holding shutdown signal for %d seconds...\n",
 
212
                        sdtime);
 
213
 
 
214
                sleep(sdtime);
194
215
        }
195
216
}
196
217
 
201
222
 
202
223
void upsdrv_banner(void)
203
224
{
204
 
        printf("Network UPS Tools - Generic UPS driver %s (%s)\n", 
 
225
        printf("Network UPS Tools - Generic UPS driver %s (%s)\n", 
205
226
                DRV_VERSION, UPS_VERSION);
206
227
}
207
228
 
215
236
        addvar(VAR_VALUE, "OL", "Override on line signal"); 
216
237
        addvar(VAR_VALUE, "LB", "Override low battery signal"); 
217
238
        addvar(VAR_VALUE, "SD", "Override shutdown setting"); 
 
239
        addvar(VAR_VALUE, "sdtime", "Hold time for shutdown value (seconds)");
218
240
}
219
241
 
220
242
void upsdrv_initups(void)
221
243
{
222
244
        set_ups_type();
223
245
 
224
 
        open_serial_simple(device_path, 0, upstab[upstype].line_norm);
 
246
        upsfd = ser_open(device_path);
 
247
 
 
248
        if (ioctl(upsfd, TIOCMSET, &upstab[upstype].line_norm))
 
249
                fatal("ioctl TIOCMSET");
225
250
}
226
251
 
227
252
void upsdrv_cleanup(void)
228
253
{
 
254
        ser_close(upsfd, device_path);
229
255
}