serialIO.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #ifndef SERIALIO_H
19 #define SERIALIO_H
20 
21 // serial connection includes
22 #include <unistd.h>
23 #include <fcntl.h>
24 #include <errno.h>
25 #include <termios.h>
26 #include <time.h>
27 #include <sys/time.h>
28 
29 #include <string>
30 
31 #include <concurrentQueue.h>
32 #include <boost/thread.hpp>
33 
34 typedef struct ioData{
35  const char* buf;
36  size_t len;
37 } ioData_t;
38 
39 class SerialIO
40 {
41 public:
42  // Constructor
43  SerialIO();
44  // Destructor
45  ~SerialIO();
46 
47  // Open Serial Port
48  int openPort(std::string devicestring, int baudrate);
49 
50  // Send Data to Serial Port
51  int sendData(std::string value);
52 
53  // Send Data to Serial Port
54  int sendData(const char* data, size_t len);
55 
56  // Read Data from Serial Port
57  int readData(std::string &value, size_t nBytes);
58 
59  void enqueueData(std::vector<ioData_t> data);
60 
61  void enqueueData(const char* data, size_t len);
62 
63  // Check if Serial Port is opened
64  bool isOpen();
65 
66  // Close Serial Port
67  void closePort();
68 
69  bool recover();
70 
71  void start();
72  void stop();
73 
74 private:
75  //ioQueue
77 
79  boost::mutex _mutex;
80  boost::condition_variable _condition;
81 
82  // filedescriptor
83  int _fd;
84  // serial port settings
85  struct termios port_settings;
86  // device string
87  std::string _device_string;
88  // baudrate
89  int _baudrate;
90 
91  // resolve int to baudrate
92  speed_t getBaudFromInt(int baud);
93 
94  static const int maxUpdateRate = 50;
95 
96  void run();
97 };
98 
99 #endif
SerialIO::_device_string
std::string _device_string
Definition: serialIO.h:87
ConcurrentQueue
Definition: concurrentQueue.h:23
SerialIO::start
void start()
Definition: serialIO.cpp:101
boost::shared_ptr< boost::thread >
SerialIO::_mutex
boost::mutex _mutex
Definition: serialIO.h:79
SerialIO::recover
bool recover()
Definition: serialIO.cpp:161
time.h
SerialIO
Definition: serialIO.h:39
SerialIO::_oQueue
ConcurrentQueue< std::vector< struct ioData > > _oQueue
Definition: serialIO.h:76
SerialIO::_fd
int _fd
Definition: serialIO.h:83
SerialIO::SerialIO
SerialIO()
Definition: serialIO.cpp:25
SerialIO::getBaudFromInt
speed_t getBaudFromInt(int baud)
Definition: serialIO.cpp:175
SerialIO::~SerialIO
~SerialIO()
Definition: serialIO.cpp:30
SerialIO::sendData
int sendData(std::string value)
Definition: serialIO.cpp:63
SerialIO::_condition
boost::condition_variable _condition
Definition: serialIO.h:80
ioData::len
size_t len
Definition: serialIO.h:36
SerialIO::closePort
void closePort()
Definition: serialIO.cpp:152
ioData::buf
const char * buf
Definition: serialIO.h:35
SerialIO::port_settings
struct termios port_settings
Definition: serialIO.h:85
SerialIO::readData
int readData(std::string &value, size_t nBytes)
Definition: serialIO.cpp:83
SerialIO::_thread
boost::shared_ptr< boost::thread > _thread
Definition: serialIO.h:78
SerialIO::openPort
int openPort(std::string devicestring, int baudrate)
Definition: serialIO.cpp:37
SerialIO::run
void run()
Definition: serialIO.cpp:117
SerialIO::isOpen
bool isOpen()
Definition: serialIO.cpp:146
ioData_t
struct ioData ioData_t
SerialIO::enqueueData
void enqueueData(std::vector< ioData_t > data)
Definition: serialIO.cpp:130
SerialIO::maxUpdateRate
static const int maxUpdateRate
Definition: serialIO.h:94
SerialIO::stop
void stop()
Definition: serialIO.cpp:107
SerialIO::_baudrate
int _baudrate
Definition: serialIO.h:89
concurrentQueue.h
ioData
Definition: serialIO.h:34


cob_light
Author(s): Benjamin Maidel
autogenerated on Wed Nov 8 2023 03:47:37