-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerialPort.hpp
More file actions
113 lines (105 loc) · 3.44 KB
/
SerialPort.hpp
File metadata and controls
113 lines (105 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*******************************************************************************
* libunix++: C++ wrapper for Linux system calls
* Serial port interfaces
*
* © 2021—2024, Sauron <libunixpp@saur0n.science>
******************************************************************************/
#ifndef __UNIXPP_SERIALPORT_HPP
#define __UNIXPP_SERIALPORT_HPP
#include <linux/serial.h>
#include <sys/ioctl.h>
#include <termios.h>
#include "File.hpp"
namespace upp {
/**/
class SerialPortConfiguration {
friend class SerialPort;
public:
/** Set the input baud rate **/
void setInputBaudRate(speed_t speed);
/** Set the output baud rate **/
void setOutputBaudRate(speed_t speed);
/** Set both input and output baud rate **/
void setBaudRate(speed_t speed);
/** Set the specified control flags **/
void setFlags(unsigned flags);
/** Unset the specified control flags **/
void clearFlags(unsigned flags);
/** Set the specified local mode flags **/
void setLocalFlags(unsigned flags);
/** Unset the specified local mode flags **/
void clearLocalFlags(unsigned flags);
/** Set the specified input processing mode flags **/
void setInputFlags(unsigned flags);
/** Unset the specified input processing mode flags **/
void clearInputFlags(unsigned flags);
/** Set the specified output processing mode flags **/
void setOutputFlags(unsigned flags);
/** Unset the specified output processing mode flags **/
void clearOutputFlags(unsigned flags);
/** Set VMIN and VTIME **/
void setTimeouts(cc_t vmin, cc_t vtime);
private:
struct termios tty;
};
/**/
class SerialPort : public upp::File {
public:
/** Modem bits **/
enum {
/** DSR (data set ready/line enable) **/
LE=0x001,
/** DTR (data terminal ready) **/
DTR=0x002,
/** RTS (request to send) **/
RTS=0x004,
/** Secondary TXD (transmit) **/
ST=0x008,
/** Secondary RXD (receive) **/
SR=0x010,
/** CTS (clear to send)**/
CTS=0x020,
/** DCD (data carrier detect)**/
CAR=0x040,
/** see CAR **/
CD=CAR,
/** RNG (ring) **/
RNG=0x080,
/** see RNG **/
RI=RNG,
/** DSR (data set ready) **/
DSR=0x100,
/** ? **/
OUT1=0x2000,
/** ? **/
OUT2=0x4000,
};
/**/
SerialPort(const char * filename, int flags=O_RDWR|O_NOCTTY|O_NDELAY);
/** Get the serial port configuration **/
SerialPortConfiguration getConfiguration();
/** Set the serial port configuration **/
void setConfiguration(const SerialPortConfiguration &configuration);
/**/
void sendBreak(int duration);
/** Wait until all data previously written to the serial line **/
void drain();
/***/
void flush(int queueSelector);
/** Suspend or restart transmission on the serial port **/
void flow(int action);
/** Get the status of modem bits **/
int getModemStatus();
/** Set the status of modem bits **/
void setModemStatus(int status);
/** Clear the indicated modem bits **/
void clearModemBits(int bits);
/** Set the indicated modem bits **/
void setModemBits(int bits);
/** Wait for any of the 4 modem bits (DCD, RI, DSR, CTS) to change **/
void waitModemBits(int bits);
/** Get counts of input serial line interrupts (DCD, RI, DSR, CTS) **/
serial_icounter_struct getInterruptCount();
};
}
#endif