test_server.cpp
Go to the documentation of this file.
1 /*
2  * @brief test_server.cpp implements a simple tcp server,
3  * simulating a localization controller for unittests.
4  *
5  * Note: test_server.cpp does not implement the functions of localization controller,
6  * it just implements a simple tcp server, accepting tcp connections from clients
7  * and generating telegrams to test the ros driver for sim localization.
8  *
9  * Copyright (C) 2019 Ing.-Buero Dr. Michael Lehning, Hildesheim
10  * Copyright (C) 2019 SICK AG, Waldkirch
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  * http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  * All rights reserved.
25  *
26  * Redistribution and use in source and binary forms, with or without
27  * modification, are permitted provided that the following conditions are met:
28  *
29  * * Redistributions of source code must retain the above copyright
30  * notice, this list of conditions and the following disclaimer.
31  * * Redistributions in binary form must reproduce the above copyright
32  * notice, this list of conditions and the following disclaimer in the
33  * documentation and/or other materials provided with the distribution.
34  * * Neither the name of SICK AG nor the names of its
35  * contributors may be used to endorse or promote products derived from
36  * this software without specific prior written permission
37  * * Neither the name of Ing.-Buero Dr. Michael Lehning nor the names of its
38  * contributors may be used to endorse or promote products derived from
39  * this software without specific prior written permission
40  *
41  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
42  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
45  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
46  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
47  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
48  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
49  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
51  * POSSIBILITY OF SUCH DAMAGE.
52  *
53  * Authors:
54  * Michael Lehning <michael.lehning@lehning.de>
55  *
56  * Copyright 2019 SICK AG
57  * Copyright 2019 Ing.-Buero Dr. Michael Lehning
58  *
59  */
60 #include "sick_scan/ros_wrapper.h"
61 #include <string>
62 #include <vector>
63 
65 #include "sick_scan/utils.h"
66 
67 int main(int argc, char** argv)
68 {
69  // Ros configuration and initialization
70  ROS::init(argc, argv, "sick_scan_emulator");
71  ROS::NodePtr nh = ROS::createNode("sick_scan_emulator");
72  ROS_INFO_STREAM("sick_scan_emulator started.");
73 
74  // Create a server to simulate a localization controller, incl. a listener thread to accept tcp connections
75  int tcp_port_results = 2201; // Default: The localization controller uses IP port number 2201 to send localization results
76  int tcp_port_cola = 2111; // For requests and to transmit settings to the localization controller: IP port number 2111 and 2112 to send telegrams and to request data, SOPAS CoLa-A or CoLa-B protocols
77  ROS::param<int>(nh, "/sick_scan/test_server/result_telegrams_tcp_port", tcp_port_results, tcp_port_results);
78  ROS::param<int>(nh, "/sick_scan/test_server/cola_telegrams_tcp_port", tcp_port_cola, tcp_port_cola);
79  sick_scan::TestServerThread test_server_thread(nh, tcp_port_results, tcp_port_cola);
80 
81  // Subscribe to sim_loc_driver messages to monitor sim_loc_driver in error simulation mode
82  std::string result_telegrams_topic = "/sick_scan/driver/result_telegrams"; // default topic to publish result port telegram messages (type SickLocResultPortTelegramMsg)
83  ROS::param<std::string>(nh, "/sick_scan/driver/result_telegrams_topic", result_telegrams_topic, result_telegrams_topic);
84 #if defined __ROS_VERSION && __ROS_VERSION == 1
85  sick_scan::SickLocResultPortTelegramMsgSubscriber result_telegram_subscriber
86  = ROS_CREATE_SUBSCRIBER(nh, sick_scan::SickLocResultPortTelegramMsg, result_telegrams_topic, &sick_scan::TestServerThread::messageCbResultPortTelegrams, &test_server_thread);
87 #elif defined __ROS_VERSION && __ROS_VERSION == 2
88  sick_scan::SickLocResultPortTelegramMsgSubscriber result_telegram_subscriber
89  = ROS_CREATE_SUBSCRIBER(nh, sick_scan::SickLocResultPortTelegramMsg, result_telegrams_topic, &sick_scan::TestServerThread::messageCbResultPortTelegramsROS2, &test_server_thread);
90 #endif
91 
92  // Start simulation of a localization controller
93  test_server_thread.start();
94 
95  // Run ros event loop
96  ROS::spin(nh);
97 
98  // Cleanup and exit
99  std::cout << "sick_scan_emulator finished." << std::endl;
100  ROS_INFO_STREAM("sick_scan_emulator finished.");
101  test_server_thread.stop();
102  std::cout << "sick_scan_emulator exits." << std::endl;
103  ROS_INFO_STREAM("sick_scan_emulator exits.");
104  ROS::deleteNode(nh);
105  return 0;
106 }
int main(int argc, char **argv)
Definition: test_server.cpp:67
void deleteNode(ROS::NodePtr &node)
Definition: ros_wrapper.cpp:98
#define ROS_INFO_STREAM(args)
ROS::NodePtr createNode(const std::string &node_name="sick_scan")
Definition: ros_wrapper.cpp:65
virtual void messageCbResultPortTelegramsROS2(const std::shared_ptr< sick_scan::SickLocResultPortTelegramMsg > msg)
void messageCbResultPortTelegrams(const sick_scan::SickLocResultPortTelegramMsg &msg)


sick_scan
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Wed May 5 2021 03:05:48