Raw File
1 #ifndef DCE_H
2 #define DCE_H 1
3
4 #define DCE_CL_DSR 1
5 #define DCE_CL_DCD 2
6 #define DCE_CL_CTS 4
7 #define DCE_CL_DTR 8
8 #define DCE_CL_LE 16
9 #define DCE_CL_RI 32
10
11 /* This is a cool piece of code found by Chris Osborn (fozztexx@fozztexx.com) from
12 * https://graphics.stanford.edu/~seander/bithacks.html#ParityWith64Bits that
13 * computes even parity for any 8 bit data value
14 */
15 #ifndef gen_parity
16 # define gen_parity(v) ((unsigned char)(((((v) * 0x0101010101010101ULL) & 0x8040201008040201ULL) % 0x1FF) & 1))
17 #endif
18
19 /* This is an impressive piece of code written by Chris Osborn (fozztexx@fozztexx.com)
20 * that given a value where SPACE=0,ODD=1,EVEN=2,MARK=3 parity is present in p,
21 * it will quickly add the correct parity to a 7 bit data value
22 */
23 #ifndef apply_parity
24 # define apply_parity(v, p) ((unsigned char)((v & 0x7f) | (((p >> gen_parity(v & 0x7f))) & 1) << 7))
25 #endif
26
27 enum {
28 PARITY_SPACE_NONE = 0,
29 PARITY_ODD,
30 PARITY_EVEN,
31 PARITY_MARK
32 };
33
34 typedef struct dce_config {
35 int port_speed;
36 int parity;
37 int is_ip232;
38 char tty[256];
39 int ifd;
40 int ofd;
41 int dp[2][2];
42 int sSocket;
43 int is_connected;
44 int ip232_dtr;
45 int ip232_dcd;
46 int ip232_iac;
47 int ip232_ri;
48 } dce_config;
49
50 void dce_init_config(dce_config *cfg);
51 int dce_connect(dce_config *cfg);
52 int dce_set_flow_control(dce_config *cfg, int opts);
53 int dce_set_control_lines(dce_config *cfg, int state);
54 int dce_get_control_lines(dce_config *cfg);
55 int dce_check_control_lines(dce_config *cfg);
56 int dce_write(dce_config *cfg, unsigned char *data, int len);
57 int dce_write_char_raw(dce_config *cfg, unsigned char data);
58 int dce_read(dce_config *cfg, unsigned char *data, int len);
59 int dce_read_char_raw(dce_config *cfg);
60 void dce_detect_parity(dce_config *cfg, unsigned char a, unsigned char t);
61 int dce_strip_parity(dce_config *cfg, unsigned char data);
62 int dce_get_parity(dce_config *cfg);
63 //int dce_check_for_break(dce_config *cfg, char ch, int chars_left);
64
65 #endif
66
Generated by GNU Enscript 1.6.6, and GophHub 1.3.