SerialFlags.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2014 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00025 //----------------------------------------------------------------------
00026 
00027 #include "icl_comm_serial/SerialFlags.h"
00028 
00029 // Terminal headers are included after all Debug headers, because the
00030 // Debug headers may include Eigen/Core from the Eigen matrix library.
00031 // For Eigen3 there is a name clash with B0 from termio.h, and Eigen3
00032 // silently #undefs it.  Therefore we make sure here that termio.h
00033 // gets re-included last.
00034 #ifdef _SYSTEM_POSIX_
00035 # include <termios.h>
00036 #ifdef _SYSTEM_DARWIN_
00037 #define B500000 500000
00038 #define B921600 921600
00039 #endif
00040 #endif
00041 
00042 namespace icl_comm  {
00043 namespace serial {
00044 
00045   //----------------------------------------------------------------------
00046   // SerialFlags
00047   //----------------------------------------------------------------------
00048 
00049   #ifdef _SYSTEM_POSIX_
00050 
00051   unsigned long SerialFlags::CFlags() const
00052   {
00053     unsigned long cflags = 0;
00054 
00055     switch (m_data_bits)
00056     {
00057       case eDB_5:
00058       {
00059         cflags |= CS5;
00060         break;
00061       }
00062       case eDB_6:
00063       {
00064         cflags |= CS6;
00065         break;
00066       }
00067       case eDB_7:
00068       {
00069         cflags |= CS7;
00070         break;
00071       }
00072       case eDB_8:
00073       {
00074         cflags |= CS8;
00075         break;
00076       }
00077     }
00078 
00079     if (m_stop_bits == eSB_2)
00080     {
00081       cflags |= CSTOPB;
00082     }
00083 
00084     if (m_parity != eP_NONE)
00085     {
00086       cflags |= PARENB;
00087     }
00088 
00089     if (m_parity == eP_ODD)
00090     {
00091       cflags |= PARODD;
00092     }
00093 
00094     cflags |= CFlags(m_baud_rate);
00095 
00096 
00097     if (m_flow_control == eFC_FLOW)
00098     {
00099       cflags |= CRTSCTS;
00100     }
00101 
00102     if (!m_use_modem_control)
00103     {
00104       cflags |= CLOCAL;
00105     }
00106 
00107     if (m_enable_receiver)
00108     {
00109       cflags |= CREAD;
00110     }
00111 
00112     if (m_enable_stop_on_receive)
00113     {
00114       cflags |= IXOFF;
00115     }
00116 
00117     return cflags;
00118   }
00119 
00120   unsigned long SerialFlags::CFlags(BaudRate baud_rate)
00121   {
00122     switch (baud_rate)
00123     {
00124       case SerialFlags::eBR_50:
00125         return B50;
00126       case SerialFlags::eBR_75:
00127         return B75;
00128       case SerialFlags::eBR_110:
00129         return B110;
00130       case SerialFlags::eBR_134:
00131         return B134;
00132       case SerialFlags::eBR_150:
00133         return B150;
00134       case SerialFlags::eBR_200:
00135         return B200;
00136       case SerialFlags::eBR_300:
00137         return B300;
00138       case SerialFlags::eBR_600:
00139         return B600;
00140       case SerialFlags::eBR_1200:
00141         return B1200;
00142       case SerialFlags::eBR_1800:
00143         return B1800;
00144       case SerialFlags::eBR_2400:
00145         return B2400;
00146       case SerialFlags::eBR_4800:
00147         return B4800;
00148       case SerialFlags::eBR_9600:
00149         return B9600;
00150       case SerialFlags::eBR_19200:
00151         return B19200;
00152       case SerialFlags::eBR_38400:
00153         return B38400;
00154       case SerialFlags::eBR_57600:
00155         return B57600;
00156       case SerialFlags::eBR_115200:
00157         return B115200;
00158       case SerialFlags::eBR_230400:
00159         return B230400;
00160       case SerialFlags::eBR_500000:
00161         return B500000;
00162       case SerialFlags::eBR_921600:
00163         return B921600;
00164       default:
00165         return B0;
00166     }
00167   }
00168 
00169   #endif
00170 
00171   #ifdef _SYSTEM_WIN32_
00172 
00173   BYTE parity_map[] = {
00174     NOPARITY,
00175     EVENPARITY,
00176     ODDPARITY,
00177     MARKPARITY,
00178     SPACEPARITY
00179   };
00180 
00181   BYTE stopbit_map[] =  {
00182     ONESTOPBIT,
00183     ONE5STOPBITS,
00184     TWOSTOPBITS
00185   };
00186 
00187   void SerialFlags::GetDCB(LPDCB dcb) const
00188   {
00189     dcb->DCBlength = sizeof(DCB);
00190     dcb->fBinary = TRUE;
00191     dcb->fOutxCtsFlow = FALSE;
00192     dcb->fOutxDsrFlow = FALSE;
00193     dcb->fDtrControl = DTR_CONTROL_DISABLE;
00194     dcb->fDsrSensitivity = FALSE;
00195     dcb->fTXContinueOnXoff = FALSE;
00196     dcb->fOutX = FALSE;
00197     dcb->fInX = FALSE;
00198     dcb->fErrorChar = FALSE;
00199     dcb->fNull = FALSE;
00200     dcb->fRtsControl = RTS_CONTROL_DISABLE;
00201     dcb->fAbortOnError = FALSE;
00202     dcb->wReserved = 0U;
00203 
00204     dcb->ByteSize = m_data_bits;
00205     dcb->StopBits = stopbit_map[m_stop_bits];
00206     dcb->fParity = (m_parity != eP_NONE);
00207     dcb->Parity = parity_map[m_parity];
00208     dcb->BaudRate = m_baud_rate;
00209 
00210     //if (m_flow_control == eFC_FLOW)
00211     //{
00212     //  cflags |= CRTSCTS;
00213     //}
00214     //
00215     //if (!m_use_modem_control)
00216     //{
00217     //  cflags |= CLOCAL;
00218     //}
00219     //
00220     //if (m_enable_receiver)
00221     //{
00222     //  cflags |= CREAD;
00223     //}
00224     //
00225     //if (m_enable_stop_on_receive)
00226     //{
00227     //  dcb->fOutX = TRUE;
00228     //}
00229   }
00230 
00231   #endif
00232 
00233 }
00234 }


fzi_icl_comm
Author(s):
autogenerated on Thu Jun 6 2019 21:31:31