test_server_ldmrs_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_lidar_msg implements the ldmrs specific messages,
4  * i.e. message receiving and message creation to simulate ldmrs devices.
5  *
6  * Note: sick_scan2 test_server_lidar_msg does not implement the functions of lidar sensors,
7  * it just implements a simple message handling to test the sick_scan2 ros drivers.
8  *
9  * Copyright (C) 2020 Ing.-Buero Dr. Michael Lehning, Hildesheim
10  * Copyright (C) 2020 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 2020 SICK AG
57  * Copyright 2020 Ing.-Buero Dr. Michael Lehning
58  *
59  */
60 #ifndef __SICK_SCAN_TEST_SERVER_LDMRS_MESSAGE_H_INCLUDED
61 #define __SICK_SCAN_TEST_SERVER_LDMRS_MESSAGE_H_INCLUDED
62 
66 
67 namespace sick_scan_xd
68 {
69  namespace test
70  {
75  {
76  public:
77 
78  /*
79  * Constructor
80  * @param[in] send_scan_data_rate frequency to generate and send scan data (default: 20 Hz)
81  * @param[in] scan_data_payload scan data payload (without the message header)
82  */
83  TestServerLDMRSMsg(rosNodePtr nh, double send_scan_data_rate = 20.0, const std::vector<uint8_t> & scan_data_payload = std::vector<uint8_t>());
84 
85  /*
86  * @brief Receives a LDMRS message if data on a tcp socket are available.
87  * Non-blocking function (i.e. it returns immediately) if no data available.
88  * If data available, this function returns after a complete message has been received, or an error occured.
89  * @param[in] tcp_client_socket socket to read from
90  * @param[out] message message received from client
91  * @param[out] is_binary always true for LDMRS
92  * @return true, if a message has been received, false otherwise
93  */
94  virtual bool receiveMessage(sick_scan_xd::ServerSocket & tcp_client_socket, std::vector<uint8_t> & message, bool & is_binary);
95 
96  /*
97  * @brief Generate a response to a message received from client.
98  * @param[in] message_received message received from client
99  * @param[in] is_binary true for binary messages, false for ascii messages
100  * @param[out] response response to the client
101  * @return true, if a response has been created, false otherwise (no response required or invalid message received)
102  */
103  virtual bool createResponse(const std::vector<uint8_t> & message_received, bool is_binary, std::vector<uint8_t> & response);
104 
105  /*
106  * @brief Generate a scan data message.
107  * @param[out] scandata scan data message
108  * @return true, if a a scan data message has been created, false otherwise (f.e. if a sensor does not generate scan data)
109  */
110  virtual bool createScandata(std::vector<uint8_t> & scandata);
111 
112  protected:
113 
114  /*
115  * @brief Creates and returns the 24 byte message header containing the magic word 0xAFFEC0C2, the data type and payload length.
116  * @param[in] data_type data type identifier, f.e. 0x2010 for a command request or 0x2020 for a command response
117  * @param[in] payload_length length of payload in byte
118  * @return 24 byte message header
119  */
120  static std::vector<uint8_t> createMessageHeader(size_t data_type, size_t payload_length);
121 
123  double m_send_scan_data_rate; // frequency to generate and send scan data (default: 20 Hz)
124  bool m_send_scan_data; // true after command "start measure", false after command "stop measure"
125  std::vector<uint8_t> m_scan_data_payload; // scan data payload (without the message header)
126  size_t m_send_scan_data_cnt; // counts the number of scan data sent to client
127  std::chrono::system_clock::time_point m_last_scan_data; // timestamp of last scan data
128  int m_delta_range_cm; // simulate the scan of a moving object by increasing or decreasing the range of scan points by m_delta_range_cm
129  int m_delta_range_step; // step in cm to increase or decrease the range of scan points
130 
131  }; // class TestServerLDMRSMsg
132 
133  } // namespace test
134 } // namespace sick_scan_xd
135 #endif // __SICK_SCAN_TEST_SERVER_LDMRS_MESSAGE_H_INCLUDED
response
const std::string response
sick_scan_xd::test::TestServerLDMRSMsg::m_scan_data_payload
std::vector< uint8_t > m_scan_data_payload
Definition: test_server_ldmrs_msg.h:125
sick_scan_xd::test::TestServerLDMRSMsg::m_delta_range_cm
int m_delta_range_cm
Definition: test_server_ldmrs_msg.h:128
sick_scan_xd::test::TestServerLDMRSMsg::createResponse
virtual bool createResponse(const std::vector< uint8_t > &message_received, bool is_binary, std::vector< uint8_t > &response)
Definition: test_server_ldmrs_msg.cpp:163
sick_scan_xd::test::TestServerLDMRSMsg::createMessageHeader
static std::vector< uint8_t > createMessageHeader(size_t data_type, size_t payload_length)
Definition: test_server_ldmrs_msg.cpp:79
sick_scan_xd::test::TestServerLDMRSMsg::m_last_scan_data
std::chrono::system_clock::time_point m_last_scan_data
Definition: test_server_ldmrs_msg.h:127
sick_scan_xd
Definition: abstract_parser.cpp:65
sick_scan_xd::test::TestServerLDMRSMsg::m_send_scan_data_cnt
size_t m_send_scan_data_cnt
Definition: test_server_ldmrs_msg.h:126
test
sick_ros_wrapper.h
sick_scan_xd::test::TestServerLDMRSMsg
Definition: test_server_ldmrs_msg.h:74
message
def message(msg, *args, **kwargs)
sick_scan_xd::test::TestServerLDMRSMsg::receiveMessage
virtual bool receiveMessage(sick_scan_xd::ServerSocket &tcp_client_socket, std::vector< uint8_t > &message, bool &is_binary)
Definition: test_server_ldmrs_msg.cpp:105
server_socket.h
sick_scan_xd::test::TestServerLidarMsg
Definition: test_server_lidar_msg.h:79
sick_scan_xd::test::TestServerLDMRSMsg::createScandata
virtual bool createScandata(std::vector< uint8_t > &scandata)
Definition: test_server_ldmrs_msg.cpp:314
ros::NodeHandle
test_server_lidar_msg.h
sick_scan_xd::test::TestServerLDMRSMsg::TestServerLDMRSMsg
TestServerLDMRSMsg(rosNodePtr nh, double send_scan_data_rate=20.0, const std::vector< uint8_t > &scan_data_payload=std::vector< uint8_t >())
Definition: test_server_ldmrs_msg.cpp:67
sick_scan_xd::test::TestServerLDMRSMsg::m_send_scan_data
bool m_send_scan_data
Definition: test_server_ldmrs_msg.h:124
sick_scan_base.h
sick_scan_xd::test::TestServerLDMRSMsg::m_nh
rosNodePtr m_nh
Definition: test_server_ldmrs_msg.h:122
sick_scan_xd::test::TestServerLDMRSMsg::m_send_scan_data_rate
double m_send_scan_data_rate
Definition: test_server_ldmrs_msg.h:123
sick_scan_xd::test::TestServerLDMRSMsg::m_delta_range_step
int m_delta_range_step
Definition: test_server_ldmrs_msg.h:129
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