unix.h
Go to the documentation of this file.
1 
38 #if !defined(_WIN32)
39 
40 #ifndef SERIAL_IMPL_UNIX_H
41 #define SERIAL_IMPL_UNIX_H
42 
43 #include "serial/serial.h"
44 
45 #include <pthread.h>
46 
47 namespace serial {
48 
49 using std::size_t;
50 using std::string;
51 using std::invalid_argument;
52 
55 
57 public:
58  MillisecondTimer(const uint32_t millis);
59  int64_t remaining();
60 
61 private:
62  static timespec timespec_now();
63  timespec expiry;
64 };
65 
67 public:
68  SerialImpl (const string &port,
69  unsigned long baudrate,
70  bytesize_t bytesize,
71  parity_t parity,
72  stopbits_t stopbits,
73  flowcontrol_t flowcontrol);
74 
75  virtual ~SerialImpl ();
76 
77  void
78  open ();
79 
80  void
81  close ();
82 
83  bool
84  isOpen () const;
85 
86  size_t
87  available ();
88 
89  bool
90  waitReadable (uint32_t timeout);
91 
92  void
93  waitByteTimes (size_t count);
94 
95  size_t
96  read (uint8_t *buf, size_t size = 1);
97 
98  size_t
99  write (const uint8_t *data, size_t length);
100 
101  void
102  flush ();
103 
104  void
105  flushInput ();
106 
107  void
108  flushOutput ();
109 
110  void
111  sendBreak (int duration);
112 
113  void
114  setBreak (bool level);
115 
116  void
117  setRTS (bool level);
118 
119  void
120  setDTR (bool level);
121 
122  bool
123  waitForChange ();
124 
125  bool
126  getCTS ();
127 
128  bool
129  getDSR ();
130 
131  bool
132  getRI ();
133 
134  bool
135  getCD ();
136 
137  void
138  setPort (const string &port);
139 
140  string
141  getPort () const;
142 
143  void
144  setTimeout (Timeout &timeout);
145 
146  Timeout
147  getTimeout () const;
148 
149  void
150  setBaudrate (unsigned long baudrate);
151 
152  unsigned long
153  getBaudrate () const;
154 
155  void
156  setBytesize (bytesize_t bytesize);
157 
158  bytesize_t
159  getBytesize () const;
160 
161  void
162  setParity (parity_t parity);
163 
164  parity_t
165  getParity () const;
166 
167  void
168  setStopbits (stopbits_t stopbits);
169 
170  stopbits_t
171  getStopbits () const;
172 
173  void
174  setFlowcontrol (flowcontrol_t flowcontrol);
175 
177  getFlowcontrol () const;
178 
179  void
180  readLock ();
181 
182  void
183  readUnlock ();
184 
185  void
186  writeLock ();
187 
188  void
189  writeUnlock ();
190 
191 protected:
192  void reconfigurePort ();
193 
194 private:
195  string port_; // Path to the file descriptor
196  int fd_; // The current file descriptor
197 
198  bool is_open_;
199  bool xonxoff_;
200  bool rtscts_;
201 
202  Timeout timeout_; // Timeout for read operations
203  unsigned long baudrate_; // Baudrate
204  uint32_t byte_time_ns_; // Nanoseconds to transmit/receive a single byte
205 
206  parity_t parity_; // Parity
207  bytesize_t bytesize_; // Size of the bytes
208  stopbits_t stopbits_; // Stop Bits
209  flowcontrol_t flowcontrol_; // Flow Control
210 
211  // Mutex used to lock the read functions
212  pthread_mutex_t read_mutex;
213  // Mutex used to lock the write functions
214  pthread_mutex_t write_mutex;
215 };
216 
217 }
218 
219 #endif // SERIAL_IMPL_UNIX_H
220 
221 #endif // !defined(_WIN32)
int64_t remaining()
Definition: unix.cc:73
pthread_mutex_t read_mutex
Definition: unix.h:212
uint32_t byte_time_ns_
Definition: unix.h:204
static timespec timespec_now()
Definition: unix.cc:82
bytesize_t bytesize_
Definition: unix.h:207
parity_t
Definition: serial.h:66
bytesize_t
Definition: serial.h:56
pthread_mutex_t write_mutex
Definition: unix.h:214
flowcontrol_t flowcontrol_
Definition: unix.h:209
Definition: unix.h:47
stopbits_t stopbits_
Definition: unix.h:208
unsigned long baudrate_
Definition: unix.h:203
stopbits_t
Definition: serial.h:77
MillisecondTimer(const uint32_t millis)
Definition: unix.cc:59
flowcontrol_t
Definition: serial.h:86


serial
Author(s): William Woodall , John Harrison
autogenerated on Thu Jan 9 2020 07:18:58