blob: af52a3c0800965ff458af3fcc45f008a34cbb035
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 | public: |
30 | CSerialPort(); |
31 | ~CSerialPort(); |
32 | |
33 | int OpenDevice(int serial_dev_id); |
34 | int CloseDevice(); |
35 | |
36 | int writeFile(const unsigned char *pData, unsigned int uLen); |
37 | int readFile(unsigned char *pBuf, unsigned int uLen); |
38 | int set_opt(int speed, int db, int sb, char pb, int overtime, bool raw_mode); |
39 | int setup_serial(); |
40 | int getDevId() |
41 | { |
42 | return mDevId; |
43 | }; |
44 | |
45 | private: |
46 | int setdatabits(struct termios *s, int db); |
47 | int setstopbits(struct termios *s, int sb); |
48 | int setparity(struct termios *s, char pb); |
49 | int set_Parity (int fd, int databits, int stopbits, int parity); |
50 | void set_speed (int fd, int speed); |
51 | |
52 | int mDevId; |
53 | }; |
54 | #endif |
55 |