blob: 6f77e73c48b25e47fee296a0054c8f7ba43bb29d
1 | #ifndef __CSERIAL_STREAM__ |
2 | #define __CSERIAL_STREAM__ |
3 | #include "CFile.h" |
4 | #include <stdio.h> |
5 | #include <unistd.h> |
6 | #include <stdlib.h> |
7 | #include <sys/types.h> |
8 | #include <sys/stat.h> |
9 | #include <fcntl.h> |
10 | #include <string.h> |
11 | #include <pthread.h> |
12 | #include <termios.h> |
13 | #include <errno.h> |
14 | |
15 | |
16 | static const int speed_arr[] = {B115200, B38400, B19200, B9600, B4800, B2400, B1200, B300, B38400, B19200, B9600, B4800, B2400, B1200, B300}; |
17 | static const int name_arr[] = { 115200, 38400, 19200, 9600, 4800, 2400, 1200, 300, 38400, 19200, 9600, 4800, 2400, 1200, 300}; |
18 | static const char *DEV_PATH_S0 = "/dev/ttyS0"; |
19 | static const char *DEV_PATH_S1 = "/dev/ttyS1"; |
20 | static const char *DEV_PATH_S2 = "/dev/ttyS2"; |
21 | |
22 | enum SerialDeviceID { |
23 | SERIAL_A = 0, |
24 | SERIAL_B, |
25 | SERIAL_C, |
26 | }; |
27 | |
28 | class CSerialPort: public CFile |
29 | { |
30 | public: |
31 | CSerialPort(); |
32 | ~CSerialPort(); |
33 | |
34 | int OpenDevice(int serial_dev_id); |
35 | int CloseDevice(); |
36 | |
37 | int writeFile(const unsigned char *pData, unsigned int uLen); |
38 | int readFile(unsigned char *pBuf, unsigned int uLen); |
39 | int set_opt(int speed, int db, int sb, char pb, int overtime, bool raw_mode); |
40 | int setup_serial(); |
41 | int getDevId() |
42 | { |
43 | return mDevId; |
44 | }; |
45 | |
46 | private: |
47 | int setdatabits(struct termios *s, int db); |
48 | int setstopbits(struct termios *s, int sb); |
49 | int setparity(struct termios *s, char pb); |
50 | int set_Parity (int fd, int databits, int stopbits, int parity); |
51 | void set_speed (int fd, int speed); |
52 | |
53 | int mDevId; |
54 | }; |
55 | #endif |
56 |