urg_serial.h
Go to the documentation of this file.
00001 #ifndef URG_SERIAL_H
00002 #define URG_SERIAL_H
00003 
00013 #ifdef __cplusplus
00014 extern "C" {
00015 #endif
00016 
00017 #include "urg_c/urg_detect_os.h"
00018 
00019 #if defined(URG_WINDOWS_OS)
00020 #include <windows.h>
00021 #elif defined(ANDROID)
00022 #include <termios.h>
00023 #define tcdrain(fd) ioctl(fd, TCSBRK, 1) 
00024 #else
00025 #include <termios.h>
00026 #include <sys/select.h>
00027 #endif
00028 #include "urg_ring_buffer.h"
00029 
00030 
00031 enum {
00032     RING_BUFFER_SIZE_SHIFT = 7,
00033     RING_BUFFER_SIZE = 1 << RING_BUFFER_SIZE_SHIFT,
00034 
00035     ERROR_MESSAGE_SIZE = 256,
00036 };
00037 
00038 
00040 typedef struct
00041 {
00042 #if defined(URG_WINDOWS_OS)
00043     HANDLE hCom;                
00044     int current_timeout;        
00045 #else
00046     int fd;                     
00047     struct termios sio;         
00048 #endif
00049 
00050     ring_buffer_t ring;         
00051     char buffer[RING_BUFFER_SIZE]; 
00052     char has_last_ch;          
00053     char last_ch;              
00054 } urg_serial_t;
00055 
00056 
00058 extern int serial_open(urg_serial_t *serial, const char *device, long baudrate);
00059 
00060 
00062 extern void serial_close(urg_serial_t *serial);
00063 
00064 
00066 extern int serial_set_baudrate(urg_serial_t *serial, long baudrate);
00067 
00068 
00070 extern int serial_write(urg_serial_t *serial, const char *data, int size);
00071 
00072 
00074 extern int serial_read(urg_serial_t *serial,
00075                        char *data, int max_size, int timeout);
00076 
00077 
00079 extern int serial_readline(urg_serial_t *serial,
00080                            char *data, int max_size, int timeout);
00081 
00082 
00084 extern int serial_error(urg_serial_t *serial,
00085                         char *error_message, int max_size);
00086 
00087 #ifdef __cplusplus
00088 }
00089 #endif
00090 
00091 #endif /* !URG_SERIAL_H */


urg_c
Author(s): Satofumi Kamimura , Katsumi Kimoto, Adrian Boeing
autogenerated on Wed Aug 26 2015 16:38:27