1
/* upscommon.h - prototypes for upscommon.c
3
Copyright (C) 1999 Russell Kroll <rkroll@exploits.org>
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
#if defined(HAVE_SYS_TERMIOS_H)
23
# include <sys/termios.h> /* for speed_t */
25
# error "No <sys/termios.h> available. Unable to continue."
26
#endif /* HAVE_SYS_TERMIOS_H */
29
#include "upshandler.h"
31
/* useful values for new set/instcmd handlers */
33
#define STAT_INSTCMD_HANDLED 0x0001 /* all we do for now */
34
#define STAT_INSTCMD_UNKNOWN 0x0002
35
/* FUTURE: add details: pass/fail, etc */
37
#define STAT_SET_HANDLED 0x0010
38
#define STAT_SET_UNKNOWN 0x0011
41
/* called by alarm signal when the port open fails */
42
void openfail(int sig);
44
/* lock the serial port using flock or uu_lock */
45
void lockport(int upsfd, const char *port);
47
/* try to open the port at a given speed */
48
void open_serial_simple(const char *port, speed_t speed, int flags);
49
void open_serial(const char *port, speed_t speed);
51
/* function for erasing "timeout"-conditions */
52
void nolongertimeout(void);
54
/* alarm signal handler for when serial reads time out */
55
void timeout(int sig);
57
/* receive up to buflen bytes from the ups into buf until endchar is read */
58
/* any characters received that match members of ignchars are discarded */
59
int upsrecv(char *buf, int buflen, char endchar, const char *ignchars);
61
/* read buflen chars and store in buf */
62
int upsrecvchars(char *buf, int buflen);
64
/* send a byte to the ups */
65
int upssendchar(char data);
66
/* send a string to the ups */
67
int upssend(const char *fmt, ...);
69
/* flush any pending input from the ups, with reporting */
70
void upsflushin(int expected, int debugit, const char *ignchars);
72
/* --- old stuff starts here --- */
74
/* store data into the array */
75
void setinfo(int infotype, const char *fmt, ...);
77
/* set the flags on an existing member of the array */
78
void setflag(int infotype, int newflags);
80
/* return the data in the info array with type infotype */
81
const char *getdata(int infotype);
83
/* add another type to the info array */
84
void addinfo(int type, const char *value, int flags, int auxdata);
86
/* add a new ENUM info entry and do other related housekeeping */
87
void addenum(int basetype, const char *value);
89
/* --- old stuff ends here --- */
91
/* clean out the temp space for a new pass */
92
void status_init(void);
94
/* add a status element */
95
void status_set(char *buf);
97
/* write the temporary status_buf into ups.status */
98
void status_commit(void);
100
extern struct ups_handler upsh;
102
extern int flag_timeoutfailure;
103
extern unsigned int upssend_delay;
105
extern int experimental_driver;
107
void rtrim(char *in, char sep);
108
void unlockport(int upsfd, const char *port);
109
void exit_cleanup(void);
111
/* install handlers for TERM/QUIT/INT and HUP/PIPE */
112
void setup_signals(void);