GitHub issues can also be used to report HCL updates
[networkupstools/kirr.git] / drivers / serial.h
blob5fb3a4512956f29ba08ca757172f77bd05b48da7
1 #ifndef SERIAL_H_SEEN
2 #define SERIAL_H_SEEN 1
4 #include "attribute.h"
6 #include "config.h"
8 #if defined(HAVE_SYS_TERMIOS_H)
9 # include <sys/termios.h> /* for speed_t */
10 #else
11 # include <termios.h>
12 #endif /* HAVE_SYS_TERMIOS_H */
14 /* limit the amount of spew that goes in the syslog when we lose the UPS */
15 #define SER_ERR_LIMIT 10 /* start limiting after 10 in a row */
16 #define SER_ERR_RATE 100 /* then only print every 100th error */
18 int ser_open_nf(const char *port);
19 int ser_open(const char *port);
21 int ser_set_speed_nf(int fd, const char *port, speed_t speed);
22 int ser_set_speed(int fd, const char *port, speed_t speed);
24 /* set the state of modem control lines */
25 int ser_set_dtr(int fd, int state);
26 int ser_set_rts(int fd, int state);
28 /* get the status of modem control lines */
29 int ser_get_dsr(int fd);
30 int ser_get_cts(int fd);
31 int ser_get_dcd(int fd);
33 int ser_flush_io(int fd);
35 int ser_close(int fd, const char *port);
37 int ser_send_char(int fd, unsigned char ch);
39 /* send the results of the format string with d_usec delay after each char */
40 int ser_send_pace(int fd, unsigned long d_usec, const char *fmt, ...)
41 __attribute__ ((__format__ (__printf__, 3, 4)));
43 /* send the results of the format string with no delay */
44 int ser_send(int fd, const char *fmt, ...)
45 __attribute__ ((__format__ (__printf__, 2, 3)));
47 /* send buflen bytes from buf with no delay */
48 int ser_send_buf(int fd, const void *buf, size_t buflen);
50 /* send buflen bytes from buf with d_usec delay after each char */
51 int ser_send_buf_pace(int fd, unsigned long d_usec, const void *buf,
52 size_t buflen);
54 int ser_get_char(int fd, void *ch, long d_sec, long d_usec);
56 int ser_get_buf(int fd, void *buf, size_t buflen, long d_sec, long d_usec);
58 /* keep reading until buflen bytes are received or a timeout occurs */
59 int ser_get_buf_len(int fd, void *buf, size_t buflen, long d_sec, long d_usec);
61 /* reads a line up to <endchar>, discarding anything else that may follow,
62 with callouts to the handler if anything matches the alertset */
63 int ser_get_line_alert(int fd, void *buf, size_t buflen, char endchar,
64 const char *ignset, const char *alertset, void handler (char ch),
65 long d_sec, long d_usec);
67 /* as above, only with no alertset handling (just a wrapper) */
68 int ser_get_line(int fd, void *buf, size_t buflen, char endchar,
69 const char *ignset, long d_sec, long d_usec);
71 int ser_flush_in(int fd, const char *ignset, int verbose);
73 /* unified failure reporting: call these often */
74 void ser_comm_fail(const char *fmt, ...)
75 __attribute__ ((__format__ (__printf__, 1, 2)));
76 void ser_comm_good(void);
79 #endif /* SERIAL_H_SEEN */