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::ClientSocket m_tcp_socket
tcp socket connected to the localization controller
int m_tcp_port
tcp port of the localization controller, default: 2111 for command requests and 2112 for command resp...
bool m_receiver_thread_running
true: m_receiver_thread is running, otherwise false
std::string m_server_adress
ip adress of the localization controller, default: 192.168.0.1
virtual bool startReceiverThread(void)
ROS::Time now(void)
virtual bool stopReceiverThread(void)
data
double m_receive_timeout
default timeout in seconds for receive functions
boost::asio::io_service m_ioservice
boost io service for tcp connections
static bool dataEndWithETX(const std::vector< uint8_t > &data, const std::vector< uint8_t > &etx)
ColaResponseContainer(const std::vector< uint8_t > &data=std::vector< uint8_t >(), const ROS::Time &timestamp=ROS::now())
Constructor.
boost::thread * m_receiver_thread
thread to receive responses from localization server
virtual bool send(const std::vector< uint8_t > &data, ROS::Time &send_timestamp)
ColaTransmitter(const std::string &server_adress="192.168.0.1", int tcp_port=2111, double default_receive_timeout=1)
ROS::Time receive_timestamp
receive timestamp in seconds (ros timestamp immediately after first response byte received) ...
sick_scan::FifoBuffer< ColaResponseContainer, boost::mutex > m_response_fifo
fifo buffer for receiver thread for responses from localization server
virtual bool receive(std::vector< uint8_t > &telegram, double timeout, ROS::Time &receive_timestamp)
std::vector< uint8_t > telegram_data
received telegram_data (Cola-Ascii or Cola-Binary)
virtual bool waitPopResponse(std::vector< uint8_t > &telegram, double timeout, ROS::Time &receive_timestamp)


sick_scan
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Wed Sep 7 2022 02:25:06