sick_scan_api_dump.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2022, Ing.-Buero Dr. Michael Lehning, Hildesheim
3 * Copyright (C) 2022, SICK AG, Waldkirch
4 * All rights reserved.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 *
19 * All rights reserved.
20 *
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions are met:
23 *
24 * * Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * * Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in the
28 * documentation and/or other materials provided with the distribution.
29 * * Neither the name of Osnabrueck University nor the names of its
30 * contributors may be used to endorse or promote products derived from
31 * this software without specific prior written permission.
32 * * Neither the name of SICK AG nor the names of its
33 * contributors may be used to endorse or promote products derived from
34 * this software without specific prior written permission
35 * * Neither the name of Ing.-Buero Dr. Michael Lehning 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 *
39 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
40 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
43 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
44 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
45 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 * POSSIBILITY OF SUCH DAMAGE.
50 *
51 * Authors:
52 * Michael Lehning <michael.lehning@lehning.de>
53 *
54 */
55 
56 #ifndef __SICK_SCAN_API_DUMP_H_INCLUDED
57 #define __SICK_SCAN_API_DUMP_H_INCLUDED
58 
59 #include <chrono>
60 #include <fstream>
61 #include <iomanip>
62 #include <sstream>
63 #include <string>
64 
65 /*
66 ** Optional message verification for test and development:
67 ** 0 = disabled (default),
68 ** 1 = dump all messages exported by sick_scan API
69 ** For verification of messages exported by the sick_scan API:
70 ** - Set VERIFY_API_MESSAGES 1
71 ** - Run sick_scan_api_test in ROS-1 against lidar or emulator
72 ** - Compare the dumped messages in the logfolder ("./log"):
73 ** * files api_*_impl.log are generated in api_impl,
74 ** * files api_*_test.log are received via sick_scan_api and converted back to ros messages
75 ** * files api_*_impl.log and api_*_test.log should be identical
76 */
77 #define VERIFY_API_MESSAGES 0 // Optional message verification for test and development only (default: 0)
78 
79 #if VERIFY_API_MESSAGES
80 
81 #define DUMP_API_POINTCLOUD_MESSAGE(postfix,msg) SickScanApiDump::dumpMessage("log", "api_cartesian_cloud", postfix, msg);
82 #define DUMP_API_IMU_MESSAGE(postfix,msg) SickScanApiDump::dumpMessage("log", "api_imu", postfix, msg);
83 #define DUMP_API_LFEREC_MESSAGE(postfix,msg) SickScanApiDump::dumpMessage("log", "api_lferec", postfix, msg);
84 #define DUMP_API_LIDOUTPUTSTATE_MESSAGE(postfix,msg) SickScanApiDump::dumpMessage("log", "api_lidoutputstate", postfix, msg);
85 #define DUMP_API_RADARSCAN_MESSAGE(postfix,msg) SickScanApiDump::dumpMessage("log", "api_radarscan", postfix, msg);
86 #define DUMP_API_LDMRSOBJECTARRAY_MESSAGE(postfix,msg) SickScanApiDump::dumpMessage("log", "api_ldmrsobjects", postfix, msg);
87 #define DUMP_API_VISUALIZATIONMARKER_MESSAGE(postfix,msg) SickScanApiDump::dumpMessage("log", "api_marker", postfix, msg);
88 
89 #else
90 
91 #define DUMP_API_POINTCLOUD_MESSAGE(postfix,msg)
92 #define DUMP_API_IMU_MESSAGE(postfix,msg)
93 #define DUMP_API_LFEREC_MESSAGE(postfix,msg)
94 #define DUMP_API_LIDOUTPUTSTATE_MESSAGE(postfix,msg)
95 #define DUMP_API_RADARSCAN_MESSAGE(postfix,msg)
96 #define DUMP_API_LDMRSOBJECTARRAY_MESSAGE(postfix,msg)
97 #define DUMP_API_VISUALIZATIONMARKER_MESSAGE(postfix,msg)
98 
99 #endif
100 
102 {
103 public:
105  template <class MsgType> static void dumpMessage(const std::string& logfolder, const std::string& prefix, const std::string& postfix, const MsgType& msg)
106  {
107  uint64_t timestamp_millisec = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
108  std::stringstream filepath;
109  filepath << logfolder << "/" << prefix << "_" << std::setfill('0') << std::setw(16) << timestamp_millisec << "_" << postfix << ".log";
110  std::ofstream fout(filepath.str(), std::fstream::out);
111  if (fout.is_open())
112  {
113  fout << msg << std::endl;
114  fout.close();
115  }
116  }
117 
118 }; // SickScanApiDump
119 
120 #endif // __SICK_SCAN_API_DUMP_H_INCLUDED
msg
msg
ROS::now
ROS::Time now(void)
Definition: ros_wrapper.cpp:116
SickScanApiDump::dumpMessage
static void dumpMessage(const std::string &logfolder, const std::string &prefix, const std::string &postfix, const MsgType &msg)
Definition: sick_scan_api_dump.h:105
SickScanApiDump
Definition: sick_scan_api_dump.h:101
time_since_epoch
double time_since_epoch()


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