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
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)
serial::parity_t
parity_t
Definition: serial.h:66
serial::Serial::SerialImpl::close
void close()
Definition: unix.cc:455
serial::Serial::SerialImpl::waitReadable
bool waitReadable(uint32_t timeout)
Definition: unix.cc:492
serial
Definition: unix.h:47
serial::Serial::SerialImpl::sendBreak
void sendBreak(int duration)
Definition: unix.cc:811
serial::Serial::SerialImpl::getPort
string getPort() const
Definition: unix.cc:696
serial::Serial::SerialImpl::getCTS
bool getCTS()
Definition: unix.cc:939
serial::Serial::SerialImpl::SerialImpl
SerialImpl(const string &port, unsigned long baudrate, bytesize_t bytesize, parity_t parity, stopbits_t stopbits, flowcontrol_t flowcontrol)
Definition: unix.cc:108
serial::Serial::SerialImpl::flushInput
void flushInput()
Definition: unix.cc:793
serial::Serial::SerialImpl::flush
void flush()
Definition: unix.cc:784
serial::Serial::SerialImpl::fd_
int fd_
Definition: unix.h:196
serial::Serial::SerialImpl::xonxoff_
bool xonxoff_
Definition: unix.h:199
serial::Serial::SerialImpl::getParity
parity_t getParity() const
Definition: unix.cc:750
serial::Serial::SerialImpl::getStopbits
stopbits_t getStopbits() const
Definition: unix.cc:764
serial::Serial::SerialImpl::writeLock
void writeLock()
Definition: unix.cc:1041
serial::Serial::SerialImpl::parity_
parity_t parity_
Definition: unix.h:206
serial::Serial::SerialImpl::setTimeout
void setTimeout(Timeout &timeout)
Definition: unix.cc:702
serial::MillisecondTimer::remaining
int64_t remaining()
Definition: unix.cc:73
serial::Serial::SerialImpl::timeout_
Timeout timeout_
Definition: unix.h:202
data
data
serial::Serial::SerialImpl::available
size_t available()
Definition: unix.cc:478
serial::Serial::SerialImpl::setBreak
void setBreak(bool level)
Definition: unix.cc:820
serial::Serial::SerialImpl::getRI
bool getRI()
Definition: unix.cc:981
serial::Serial::SerialImpl::~SerialImpl
virtual ~SerialImpl()
Definition: unix.cc:122
serial::Serial::SerialImpl::setParity
void setParity(parity_t parity)
Definition: unix.cc:742
serial::IOException
Definition: serial.h:688
serial::MillisecondTimer::MillisecondTimer
MillisecondTimer(const uint32_t millis)
Definition: unix.cc:59
serial::Serial::SerialImpl::write
size_t write(const uint8_t *data, size_t length)
Definition: unix.cc:607
serial::Serial::SerialImpl::getFlowcontrol
flowcontrol_t getFlowcontrol() const
Definition: unix.cc:778
serial::Serial::SerialImpl::setFlowcontrol
void setFlowcontrol(flowcontrol_t flowcontrol)
Definition: unix.cc:770
serial::bytesize_t
bytesize_t
Definition: serial.h:56
serial::Serial::SerialImpl::waitByteTimes
void waitByteTimes(size_t count)
Definition: unix.cc:523
serial::MillisecondTimer
Definition: unix.h:56
serial::MillisecondTimer::expiry
timespec expiry
Definition: unix.h:63
serial::Serial::SerialImpl::byte_time_ns_
uint32_t byte_time_ns_
Definition: unix.h:204
serial::Serial::SerialImpl::setPort
void setPort(const string &port)
Definition: unix.cc:690
python_serial_test.timeout
timeout
Definition: python_serial_test.py:10
serial::Serial::SerialImpl::getCD
bool getCD()
Definition: unix.cc:1002
serial::Serial::SerialImpl::readLock
void readLock()
Definition: unix.cc:1023
serial::Serial::SerialImpl::setStopbits
void setStopbits(stopbits_t stopbits)
Definition: unix.cc:756
serial::Serial::SerialImpl::setBaudrate
void setBaudrate(unsigned long baudrate)
Definition: unix.cc:714
serial::Serial::SerialImpl
Definition: unix.h:66
serial::Serial::SerialImpl::getDSR
bool getDSR()
Definition: unix.cc:960
serial::Serial::SerialImpl::readUnlock
void readUnlock()
Definition: unix.cc:1032
serial::Serial::SerialImpl::reconfigurePort
void reconfigurePort()
Definition: unix.cc:160
serial::MillisecondTimer::timespec_now
static timespec timespec_now()
Definition: unix.cc:82
serial::Serial::SerialImpl::open
void open()
Definition: unix.cc:130
serial.h
serial::Serial::SerialImpl::writeUnlock
void writeUnlock()
Definition: unix.cc:1050
serial::Serial::SerialImpl::flushOutput
void flushOutput()
Definition: unix.cc:802
serial::Serial::SerialImpl::setBytesize
void setBytesize(bytesize_t bytesize)
Definition: unix.cc:728
serial::Serial::SerialImpl::is_open_
bool is_open_
Definition: unix.h:198
serial::Serial::SerialImpl::read_mutex
pthread_mutex_t read_mutex
Definition: unix.h:212
serial::Serial::SerialImpl::bytesize_
bytesize_t bytesize_
Definition: unix.h:207
serial::flowcontrol_t
flowcontrol_t
Definition: serial.h:86
length
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
serial::Serial::SerialImpl::read
size_t read(uint8_t *buf, size_t size=1)
Definition: unix.cc:530
serial::stopbits_t
stopbits_t
Definition: serial.h:77
serial::Serial::SerialImpl::setRTS
void setRTS(bool level)
Definition: unix.cc:844
serial::Serial::SerialImpl::write_mutex
pthread_mutex_t write_mutex
Definition: unix.h:214
serial::Serial::SerialImpl::rtscts_
bool rtscts_
Definition: unix.h:200
serial::Serial::SerialImpl::flowcontrol_
flowcontrol_t flowcontrol_
Definition: unix.h:209
serial::Serial::SerialImpl::isOpen
bool isOpen() const
Definition: unix.cc:472
serial::Serial::SerialImpl::getTimeout
Timeout getTimeout() const
Definition: unix.cc:708
serial::Serial::SerialImpl::port_
string port_
Definition: unix.h:195
serial::Serial::SerialImpl::setDTR
void setDTR(bool level)
Definition: unix.cc:870
serial::Serial::SerialImpl::stopbits_
stopbits_t stopbits_
Definition: unix.h:208
serial::SerialException
Definition: serial.h:670
serial::Serial::SerialImpl::waitForChange
bool waitForChange()
Definition: unix.cc:896
serial::Serial::SerialImpl::getBytesize
bytesize_t getBytesize() const
Definition: unix.cc:736
serial::Serial::SerialImpl::getBaudrate
unsigned long getBaudrate() const
Definition: unix.cc:722
serial::Timeout
Definition: serial.h:98
serial::Serial::SerialImpl::baudrate_
unsigned long baudrate_
Definition: unix.h:203


ubiquity_motor
Author(s):
autogenerated on Thu Nov 16 2023 03:30:56