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
ROSCPP_DECL void start()
int _fd
Definition: serialIO.h:83
ConcurrentQueue< std::vector< struct ioData > > _oQueue
Definition: serialIO.h:76
boost::condition_variable _condition
Definition: serialIO.h:80
const char * buf
Definition: serialIO.h:35
boost::shared_ptr< boost::thread > _thread
Definition: serialIO.h:78
int _baudrate
Definition: serialIO.h:89
size_t len
Definition: serialIO.h:36
std::string _device_string
Definition: serialIO.h:87
struct ioData ioData_t
boost::mutex _mutex
Definition: serialIO.h:79


cob_light
Author(s): Benjamin Maidel
autogenerated on Wed Apr 7 2021 02:11:39