All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Pages
urg_serial.h
Go to the documentation of this file.
1 #ifndef URG_SERIAL_H
2 #define URG_SERIAL_H
3 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 #include "urg_detect_os.h"
18 
19 #if defined(URG_WINDOWS_OS)
20 #include <windows.h>
21 #else
22 #include <termios.h>
23 #endif
24 #include "urg_ring_buffer.h"
25 
26 
27 enum {
28  RING_BUFFER_SIZE_SHIFT = 7,
29  RING_BUFFER_SIZE = 1 << RING_BUFFER_SIZE_SHIFT,
30 
31  ERROR_MESSAGE_SIZE = 256,
32 };
33 
34 
36 typedef struct
37 {
38 #if defined(URG_WINDOWS_OS)
39  HANDLE hCom;
40  int current_timeout;
41 #else
42  int fd;
43  struct termios sio;
44 #endif
45 
47  char buffer[RING_BUFFER_SIZE];
48  char has_last_ch;
49  char last_ch;
50 } urg_serial_t;
51 
52 
54 extern int serial_open(urg_serial_t *serial, const char *device, long baudrate);
55 
56 
58 extern void serial_close(urg_serial_t *serial);
59 
60 
62 extern int serial_set_baudrate(urg_serial_t *serial, long baudrate);
63 
64 
66 extern int serial_write(urg_serial_t *serial, const char *data, int size);
67 
68 
70 extern int serial_read(urg_serial_t *serial,
71  char *data, int max_size, int timeout);
72 
73 
75 extern int serial_readline(urg_serial_t *serial,
76  char *data, int max_size, int timeout);
77 
78 
80 extern int serial_error(urg_serial_t *serial,
81  char *error_message, int max_size);
82 
83 #ifdef __cplusplus
84 }
85 #endif
86 
87 #endif /* !URG_SERIAL_H */