cola_transmitter.h
Go to the documentation of this file.
1 /*
2  * @brief sim_loc_cola_transmitter connects to the localization controller, sends cola command requests,
3  * and waits for the response with timeout.
4  *
5  * Copyright (C) 2019 Ing.-Buero Dr. Michael Lehning, Hildesheim
6  * Copyright (C) 2019 SICK AG, Waldkirch
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  * All rights reserved.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions are met:
24  *
25  * * Redistributions of source code must retain the above copyright
26  * notice, this list of conditions and the following disclaimer.
27  * * Redistributions in binary form must reproduce the above copyright
28  * notice, this list of conditions and the following disclaimer in the
29  * documentation and/or other materials provided with the distribution.
30  * * Neither the name of SICK AG nor the names of its
31  * contributors may be used to endorse or promote products derived from
32  * this software without specific prior written permission
33  * * Neither the name of Ing.-Buero Dr. Michael Lehning nor the names of its
34  * contributors may be used to endorse or promote products derived from
35  * this software without specific prior written permission
36  *
37  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
38  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
41  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
42  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
43  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
44  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
45  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
47  * POSSIBILITY OF SUCH DAMAGE.
48  *
49  * Authors:
50  * Michael Lehning <michael.lehning@lehning.de>
51  *
52  * Copyright 2019 SICK AG
53  * Copyright 2019 Ing.-Buero Dr. Michael Lehning
54  *
55  */
56 #ifndef __SIM_LOC_COLA_TRANSMITTER_H_INCLUDED
57 #define __SIM_LOC_COLA_TRANSMITTER_H_INCLUDED
58 
60 #include "sick_scan/fifo_buffer.h"
61 
62 namespace sick_scan
63 {
69  {
70  public:
71 
78  ColaTransmitter(const std::string & server_adress = "192.168.0.1", int tcp_port = 2111, double default_receive_timeout = 1);
79 
83  virtual ~ColaTransmitter();
84 
89  virtual bool connect(void);
90 
95  virtual bool close(void);
96 
103  virtual bool send(const std::vector<uint8_t> & data, ROS::Time & send_timestamp);
104 
112  static bool send(boost::asio::ip::tcp::socket & socket, const std::vector<uint8_t> & data, ROS::Time & send_timestamp);
113 
121  virtual bool receive(std::vector<uint8_t> & telegram, double timeout, ROS::Time & receive_timestamp);
122 
131  static bool receive(boost::asio::ip::tcp::socket & socket, std::vector<uint8_t> & telegram, double timeout,ROS::Time & receive_timestamp);
132 
138  virtual bool startReceiverThread(void);
139 
144  virtual bool stopReceiverThread(void);
145 
156  virtual bool waitPopResponse(std::vector<uint8_t> & telegram, double timeout, ROS::Time & receive_timestamp);
157 
158  protected:
159 
165  {
166  public:
167  ColaResponseContainer(const std::vector<uint8_t> & data = std::vector<uint8_t>(),const ROS::Time & timestamp = ROS::now())
168  : telegram_data(data), receive_timestamp(timestamp) {}
169  std::vector<uint8_t> telegram_data;
170  ROS::Time receive_timestamp;
171  };
172 
179  static bool dataEndWithETX(const std::vector<uint8_t> & data, const std::vector<uint8_t> & etx);
180 
184  void runReceiverThreadCb(void);
185 
186  /*
187  * member data
188  */
189 
190  std::string m_server_adress;
192  boost::asio::io_service m_ioservice;
196  boost::thread* m_receiver_thread;
198 
199  }; // class ColaTransmitter
200 
201 } // namespace sick_scan
202 #endif // __SIM_LOC_COLA_TRANSMITTER_H_INCLUDED
sick_scan::ColaTransmitter::m_tcp_socket
sick_scan::ClientSocket m_tcp_socket
tcp socket connected to the localization controller
Definition: cola_transmitter.h:193
sick_scan::ColaTransmitter::startReceiverThread
virtual bool startReceiverThread(void)
Definition: cola_transmitter.cpp:254
sick_scan::ColaTransmitter::connect
virtual bool connect(void)
Definition: cola_transmitter.cpp:95
sick_scan::ColaTransmitter
Definition: cola_transmitter.h:68
sick_scan::ColaTransmitter::~ColaTransmitter
virtual ~ColaTransmitter()
Definition: cola_transmitter.cpp:84
sick_scan::ColaTransmitter::close
virtual bool close(void)
Definition: cola_transmitter.cpp:104
sick_scan::ColaTransmitter::m_receive_timeout
double m_receive_timeout
default timeout in seconds for receive functions
Definition: cola_transmitter.h:194
sick_scan::ColaTransmitter::m_tcp_port
int m_tcp_port
tcp port of the localization controller, default: 2111 for command requests and 2112 for command resp...
Definition: cola_transmitter.h:191
sick_scan::ColaTransmitter::stopReceiverThread
virtual bool stopReceiverThread(void)
Definition: cola_transmitter.cpp:266
sick_scan::ColaTransmitter::m_ioservice
boost::asio::io_service m_ioservice
boost io service for tcp connections
Definition: cola_transmitter.h:192
data
data
sick_scan::ColaTransmitter::runReceiverThreadCb
void runReceiverThreadCb(void)
Definition: cola_transmitter.cpp:311
ROS::now
ROS::Time now(void)
Definition: ros_wrapper.cpp:116
sick_scan::ColaTransmitter::ColaResponseContainer::telegram_data
std::vector< uint8_t > telegram_data
received telegram_data (Cola-Ascii or Cola-Binary)
Definition: cola_transmitter.h:169
client_socket.h
sick_scan::ColaTransmitter::ColaResponseContainer::receive_timestamp
ROS::Time receive_timestamp
receive timestamp in seconds (ros timestamp immediately after first response byte received)
Definition: cola_transmitter.h:170
sick_scan::ColaTransmitter::send
virtual bool send(const std::vector< uint8_t > &data, ROS::Time &send_timestamp)
Definition: cola_transmitter.cpp:125
sick_scan::ColaTransmitter::ColaTransmitter
ColaTransmitter(const std::string &server_adress="192.168.0.1", int tcp_port=2111, double default_receive_timeout=1)
Definition: cola_transmitter.cpp:74
sick_scan
Definition: abstract_parser.cpp:50
sick_scan::ColaTransmitter::m_receiver_thread
boost::thread * m_receiver_thread
thread to receive responses from localization server
Definition: cola_transmitter.h:196
fifo_buffer.h
sick_scan::ColaTransmitter::dataEndWithETX
static bool dataEndWithETX(const std::vector< uint8_t > &data, const std::vector< uint8_t > &etx)
Definition: cola_transmitter.cpp:237
sick_scan::ColaTransmitter::waitPopResponse
virtual bool waitPopResponse(std::vector< uint8_t > &telegram, double timeout, ROS::Time &receive_timestamp)
Definition: cola_transmitter.cpp:288
sick_scan::ColaTransmitter::ColaResponseContainer
Definition: cola_transmitter.h:164
sick_scan::ClientSocket
Definition: client_socket.h:71
sick_generic_device_finder.timeout
timeout
Definition: sick_generic_device_finder.py:113
sick_scan::ColaTransmitter::receive
virtual bool receive(std::vector< uint8_t > &telegram, double timeout, ROS::Time &receive_timestamp)
Definition: cola_transmitter.cpp:166
sick_scan::ColaTransmitter::m_response_fifo
sick_scan::FifoBuffer< ColaResponseContainer, boost::mutex > m_response_fifo
fifo buffer for receiver thread for responses from localization server
Definition: cola_transmitter.h:197
sick_scan::ColaTransmitter::m_receiver_thread_running
bool m_receiver_thread_running
true: m_receiver_thread is running, otherwise false
Definition: cola_transmitter.h:195
sick_scan::FifoBuffer
Definition: fifo_buffer.h:66
sick_scan::ColaTransmitter::m_server_adress
std::string m_server_adress
ip adress of the localization controller, default: 192.168.0.1
Definition: cola_transmitter.h:190


sick_scan
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Thu Sep 8 2022 02:30:19