SerialFlags.cpp
Go to the documentation of this file.
1 //
3 // © Copyright 2022 SCHUNK Mobile Greifsysteme GmbH, Lauffen/Neckar Germany
4 // © Copyright 2022 FZI Forschungszentrum Informatik, Karlsruhe, Germany
5 //
6 // This file is part of the Schunk SVH Library.
7 //
8 // The Schunk SVH Library is free software: you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or (at your
11 // option) any later version.
12 //
13 // The Schunk SVH Library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16 // Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License along with
19 // the Schunk SVH Library. If not, see <https://www.gnu.org/licenses/>.
20 //
22 
23 //----------------------------------------------------------------------
33 //----------------------------------------------------------------------
34 
36 
37 // Terminal headers are included after all Debug headers, because the
38 // Debug headers may include Eigen/Core from the Eigen matrix library.
39 // For Eigen3 there is a name clash with B0 from termio.h, and Eigen3
40 // silently #undefs it. Therefore we make sure here that termio.h
41 // gets re-included last.
42 #ifdef _SYSTEM_POSIX_
43 # include <termios.h>
44 # ifdef _SYSTEM_DARWIN_
45 # define B500000 500000
46 # define B921600 921600
47 # endif
48 #endif
49 
50 namespace driver_svh {
51 namespace serial {
52 
53 //----------------------------------------------------------------------
54 // SerialFlags
55 //----------------------------------------------------------------------
56 
57 #ifdef _SYSTEM_POSIX_
58 
59 unsigned long SerialFlags::cFlags() const
60 {
61  unsigned long cflags = 0;
62 
63  switch (m_data_bits)
64  {
65  case DB_5: {
66  cflags |= CS5;
67  break;
68  }
69  case DB_6: {
70  cflags |= CS6;
71  break;
72  }
73  case DB_7: {
74  cflags |= CS7;
75  break;
76  }
77  case DB_8: {
78  cflags |= CS8;
79  break;
80  }
81  }
82 
83  if (m_stop_bits == SB_2)
84  {
85  cflags |= CSTOPB;
86  }
87 
88  if (m_parity != P_NONE)
89  {
90  cflags |= PARENB;
91  }
92 
93  if (m_parity == P_ODD)
94  {
95  cflags |= PARODD;
96  }
97 
98  cflags |= cFlags(m_baud_rate);
99 
100 
101  if (m_flow_control == FC_FLOW)
102  {
103  cflags |= CRTSCTS;
104  }
105 
106  if (!m_use_modem_control)
107  {
108  cflags |= CLOCAL;
109  }
110 
111  if (m_enable_receiver)
112  {
113  cflags |= CREAD;
114  }
115 
117  {
118  cflags |= IXOFF;
119  }
120 
121  return cflags;
122 }
123 
124 unsigned long SerialFlags::cFlags(BaudRate baud_rate)
125 {
126  switch (baud_rate)
127  {
128  case SerialFlags::BR_50:
129  return B50;
130  case SerialFlags::BR_75:
131  return B75;
132  case SerialFlags::BR_110:
133  return B110;
134  case SerialFlags::BR_134:
135  return B134;
136  case SerialFlags::BR_150:
137  return B150;
138  case SerialFlags::BR_200:
139  return B200;
140  case SerialFlags::BR_300:
141  return B300;
142  case SerialFlags::BR_600:
143  return B600;
145  return B1200;
147  return B1800;
149  return B2400;
151  return B4800;
153  return B9600;
155  return B19200;
157  return B38400;
159  return B57600;
161  return B115200;
163  return B230400;
165  return B500000;
167  return B921600;
168  default:
169  return B0;
170  }
171 }
172 
173 #endif
174 
175 #ifdef _SYSTEM_WIN32_
176 
177 BYTE parity_map[] = {NOPARITY, EVENPARITY, ODDPARITY, MARKPARITY, SPACEPARITY};
178 
179 BYTE stopbit_map[] = {ONESTOPBIT, ONE5STOPBITS, TWOSTOPBITS};
180 
181 void SerialFlags::GetDCB(LPDCB dcb) const
182 {
183  dcb->DCBlength = sizeof(DCB);
184  dcb->fBinary = TRUE;
185  dcb->fOutxCtsFlow = FALSE;
186  dcb->fOutxDsrFlow = FALSE;
187  dcb->fDtrControl = DTR_CONTROL_DISABLE;
188  dcb->fDsrSensitivity = FALSE;
189  dcb->fTXContinueOnXoff = FALSE;
190  dcb->fOutX = FALSE;
191  dcb->fInX = FALSE;
192  dcb->fErrorChar = FALSE;
193  dcb->fNull = FALSE;
194  dcb->fRtsControl = RTS_CONTROL_DISABLE;
195  dcb->fAbortOnError = FALSE;
196  dcb->wReserved = 0U;
197 
198  dcb->ByteSize = m_data_bits;
199  dcb->StopBits = stopbit_map[m_stop_bits];
200  dcb->fParity = (m_parity != eP_NONE);
201  dcb->Parity = parity_map[m_parity];
202  dcb->BaudRate = m_baud_rate;
203 
204  // if (m_flow_control == eFC_FLOW)
205  //{
206  // cflags |= CRTSCTS;
207  //}
208  //
209  // if (!m_use_modem_control)
210  //{
211  // cflags |= CLOCAL;
212  //}
213  //
214  // if (m_enable_receiver)
215  //{
216  // cflags |= CREAD;
217  //}
218  //
219  // if (m_enable_stop_on_receive)
220  //{
221  // dcb->fOutX = TRUE;
222  //}
223 }
224 
225 #endif
226 
227 } // namespace serial
228 } // namespace driver_svh
Contains tSerialFlags.


schunk_svh_library
Author(s): Georg Heppner, Lars Pfotzer, Felix Exner, Johannes Mangler, Stefan Scherzinger, Pascal Becker
autogenerated on Fri Apr 14 2023 02:26:23