test_server_cola_msg.h
Go to the documentation of this file.
1 #include "sick_scan/sick_scan_base.h" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */
2 /*
3  * @brief sick_scan2 test_server_cola_msg implements the lidar specific messages,
4  * i.e. message receiving and message creation to simulate lidar devices with
5  * cola communication over tcp.
6  *
7  * Note: sick_scan2 test_server_cola_msg does not implement the functions of lidar sensors,
8  * it just implements a simple message handling to test the sick_scan2 ros drivers.
9  *
10  * Copyright (C) 2020 Ing.-Buero Dr. Michael Lehning, Hildesheim
11  * Copyright (C) 2020 SICK AG, Waldkirch
12  *
13  * Licensed under the Apache License, Version 2.0 (the "License");
14  * you may not use this file except in compliance with the License.
15  * You may obtain a copy of the License at
16  *
17  * http://www.apache.org/licenses/LICENSE-2.0
18  *
19  * Unless required by applicable law or agreed to in writing, software
20  * distributed under the License is distributed on an "AS IS" BASIS,
21  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22  * See the License for the specific language governing permissions and
23  * limitations under the License.
24  *
25  * All rights reserved.
26  *
27  * Redistribution and use in source and binary forms, with or without
28  * modification, are permitted provided that the following conditions are met:
29  *
30  * * Redistributions of source code must retain the above copyright
31  * notice, this list of conditions and the following disclaimer.
32  * * Redistributions in binary form must reproduce the above copyright
33  * notice, this list of conditions and the following disclaimer in the
34  * documentation and/or other materials provided with the distribution.
35  * * Neither the name of SICK AG nor the names of its
36  * contributors may be used to endorse or promote products derived from
37  * this software without specific prior written permission
38  * * Neither the name of Ing.-Buero Dr. Michael Lehning nor the names of its
39  * contributors may be used to endorse or promote products derived from
40  * this software without specific prior written permission
41  *
42  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
46  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
47  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
48  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
49  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
50  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
52  * POSSIBILITY OF SUCH DAMAGE.
53  *
54  * Authors:
55  * Michael Lehning <michael.lehning@lehning.de>
56  *
57  * Copyright 2020 SICK AG
58  * Copyright 2020 Ing.-Buero Dr. Michael Lehning
59  *
60  */
61 #ifndef __SICK_SCAN_TEST_SERVER_COLA_MESSAGE_H_INCLUDED
62 #define __SICK_SCAN_TEST_SERVER_COLA_MESSAGE_H_INCLUDED
63 
67 
68 namespace sick_scan_xd
69 {
70  namespace test
71  {
76  {
77  public:
78 
79  /*
80  * Constructor
81  * @param[in] send_scan_data_rate frequency to generate and send scan data (default: 20 Hz)
82  * @param[in] scan_data_payload scan data payload (without the message header)
83  */
84  TestServerColaMsg(rosNodePtr nh, double send_scan_data_rate = 20.0, const std::vector<uint8_t> & scan_data_payload = std::vector<uint8_t>());
85 
86  /*
87  * @brief Receives a cola telegram if data on a tcp socket are available.
88  * Non-blocking function (i.e. it returns immediately) if no data available.
89  * If data available, this function returns after a complete message has been received, or an error occured.
90  * @param[in] tcp_client_socket socket to read from
91  * @param[out] message cola telegram received from client (without the leading <STX> or trailing <ETX> bytes)
92  * @param[out] is_binary always true for LDMRS
93  * @return true, if a cola telegram has been received, false otherwise
94  */
95  virtual bool receiveMessage(sick_scan_xd::ServerSocket & tcp_client_socket, std::vector<uint8_t> & message, bool & is_binary);
96 
97  /*
98  * @brief Generate a response to a message received from client.
99  * @param[in] message_received message received from client (without the leading <STX> or trailing <ETX> bytes)
100  * @param[in] is_binary true for binary messages, false for ascii messages
101  * @param[out] response response to the client
102  * @return true, if a response has been created, false otherwise (no response required or invalid message received)
103  */
104  virtual bool createResponse(const std::vector<uint8_t> & message_received, bool is_binary, std::vector<uint8_t> & response);
105 
106  /*
107  * @brief Generate a scan data message.
108  * @param[out] scandata scan data message
109  * @return true, if a a scan data message has been created, false otherwise (f.e. if a sensor does not generate scan data)
110  */
111  virtual bool createScandata(std::vector<uint8_t> & scandata);
112 
113  protected:
114 
116  std::map<std::string, std::vector<uint8_t>> m_colaRequestResponseMap[2]; // ascii and binary dictonaries to map a request (f.e. "sAN SetAccessMode") to the response payload
117  double m_send_scan_data_rate; // frequency to generate and send scan data (default: 20 Hz)
118  bool m_send_scan_data; // true after command "start scan data", false after command "stop scan data"
119  std::vector<uint8_t> m_scan_data_payload; // scan data payload (without the message header)
120  size_t m_send_scan_data_cnt; // counts the number of scan data sent to client
121  std::chrono::system_clock::time_point m_last_scan_data; // timestamp of last scan data
122 
123  }; // class TestServerColaMsg
124 
125  } // namespace test
126 } // namespace sick_scan_xd
127 #endif // __SICK_SCAN_TEST_SERVER_COLA_MESSAGE_H_INCLUDED
response
const std::string response
sick_scan_xd::test::TestServerColaMsg::m_send_scan_data_cnt
size_t m_send_scan_data_cnt
Definition: test_server_cola_msg.h:120
sick_scan_xd
Definition: abstract_parser.cpp:65
test
sick_ros_wrapper.h
sick_scan_xd::test::TestServerColaMsg
Definition: test_server_cola_msg.h:75
message
def message(msg, *args, **kwargs)
sick_scan_xd::test::TestServerColaMsg::m_last_scan_data
std::chrono::system_clock::time_point m_last_scan_data
Definition: test_server_cola_msg.h:121
sick_scan_xd::test::TestServerColaMsg::receiveMessage
virtual bool receiveMessage(sick_scan_xd::ServerSocket &tcp_client_socket, std::vector< uint8_t > &message, bool &is_binary)
Definition: test_server_cola_msg.cpp:317
server_socket.h
sick_scan_xd::test::TestServerLidarMsg
Definition: test_server_lidar_msg.h:79
sick_scan_xd::test::TestServerColaMsg::m_send_scan_data_rate
double m_send_scan_data_rate
Definition: test_server_cola_msg.h:117
sick_scan_xd::test::TestServerColaMsg::m_colaRequestResponseMap
std::map< std::string, std::vector< uint8_t > > m_colaRequestResponseMap[2]
Definition: test_server_cola_msg.h:116
ros::NodeHandle
sick_scan_xd::test::TestServerColaMsg::createScandata
virtual bool createScandata(std::vector< uint8_t > &scandata)
Definition: test_server_cola_msg.cpp:415
sick_scan_xd::test::TestServerColaMsg::m_nh
rosNodePtr m_nh
Definition: test_server_cola_msg.h:115
sick_scan_xd::test::TestServerColaMsg::createResponse
virtual bool createResponse(const std::vector< uint8_t > &message_received, bool is_binary, std::vector< uint8_t > &response)
Definition: test_server_cola_msg.cpp:369
test_server_lidar_msg.h
sick_scan_xd::test::TestServerColaMsg::TestServerColaMsg
TestServerColaMsg(rosNodePtr nh, double send_scan_data_rate=20.0, const std::vector< uint8_t > &scan_data_payload=std::vector< uint8_t >())
Definition: test_server_cola_msg.cpp:204
sick_scan_base.h
sick_scan_xd::test::TestServerColaMsg::m_scan_data_payload
std::vector< uint8_t > m_scan_data_payload
Definition: test_server_cola_msg.h:119
sick_scan_xd::test::TestServerColaMsg::m_send_scan_data
bool m_send_scan_data
Definition: test_server_cola_msg.h:118
sick_scan_xd::ServerSocket
Definition: server_socket.h:83


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:12