handler_hqnode.cpp
Go to the documentation of this file.
1 /*
2  * Slamtec LIDAR SDK
3  *
4  * Copyright (c) 2014 - 2023 Shanghai Slamtec Co., Ltd.
5  * http://www.slamtec.com
6  *
7  */
8 
9  /*
10  * Sample Data Unpacker System
11  * HQNode Sample Node Handler
12  */
13 
14  /*
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions are met:
17  *
18  * 1. Redistributions of source code must retain the above copyright notice,
19  * this list of conditions and the following disclaimer.
20  *
21  * 2. Redistributions in binary form must reproduce the above copyright notice,
22  * this list of conditions and the following disclaimer in the documentation
23  * and/or other materials provided with the distribution.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37  */
38 
39 #include "../dataunnpacker_commondef.h"
40 #include "../dataunpacker.h"
41 #include "../dataunnpacker_internal.h"
42 
43 #ifdef CONF_NO_BOOST_CRC_SUPPORT
44 #include "sl_crc.h"
45 #endif
46 
47 #include "handler_hqnode.h"
48 
50 
51 namespace unpacker{
52 
53 
54 static _u64 _getSampleDelayOffsetInHQMode(const SlamtecLidarTimingDesc& timing)
55 {
56  // FIXME: to eval
57  //
58  // guess channel baudrate by LIDAR model ....
59  const _u64 channelBaudRate = timing.native_baudrate? timing.native_baudrate:1000000;
60 
61  _u64 tranmissionDelay = 1000000ULL * sizeof(rplidar_response_measurement_node_hq_t) * 10 / channelBaudRate;
62 
63  if (timing.native_interface_type == LIDARInterfaceType::LIDAR_INTERFACE_ETHERNET)
64  {
65  tranmissionDelay = 100; //dummy value
66  }
67 
68  // center of the sample duration
69  const _u64 sampleDelay = (timing.sample_duration_uS >> 1);
70  const _u64 sampleFilterDelay = timing.sample_duration_uS;
71 
72  return sampleFilterDelay + sampleDelay + tranmissionDelay + timing.linkage_delay_uS;
73 }
74 
75 UnpackerHandler_HQNode::UnpackerHandler_HQNode()
76  : _cached_scan_node_buf_pos(0)
77 {
79  memset(&_cachedTimingDesc, 0, sizeof(_cachedTimingDesc));
80 }
81 
83 {
84 
85 }
86 
88 {
90 }
91 
93 {
94 
95  for (size_t pos = 0; pos < cnt; ++pos)
96  {
97  _u8 current_data = data[pos];
98 
100  {
101  case 0: // expect the sync byte
102  {
103  if (current_data == RPLIDAR_RESP_MEASUREMENT_HQ_SYNC) {
104  // pass
105  }
106  else {
107  continue;
108  }
109  }
110  break;
111 
112  case sizeof(rplidar_response_hq_capsule_measurement_nodes_t) - 1 - 4: // get bytes to calculate crc ready
113  {
114 
115  }
116  break;
117 
118  case sizeof(rplidar_response_hq_capsule_measurement_nodes_t) - 1: // new data ready
119  {
123 
124 #ifdef CONF_NO_BOOST_CRC_SUPPORT
125  _u32 crcCalc = crc32::getResult(&_cached_scan_node_buf[0], sizeof(sl_lidar_response_hq_capsule_measurement_nodes_t) - 4);
126 
127 
128 #else
129  // calculate crc with boost crc method
130  boost::crc_optimal<32, 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, true, true> mycrc;
131  std::vector<_u8> crcInputData;
132  crcInputData.resize(sizeof(rplidar_response_hq_capsule_measurement_nodes_t) - 4);
133  memcpy(&crcInputData[0], nodesData, sizeof(rplidar_response_hq_capsule_measurement_nodes_t) - 4);
134  //supplement crcInputData to mutiples of 4
135  int leftBytes = 4 - (crcInputData.size() & 3);
136  for (int i = 0; i < leftBytes; i++)
137  crcInputData.push_back(0);
138  mycrc.process_bytes(&crcInputData[0], crcInputData.size());
139  _u32 crcCalc = mycrc.checksum();
140 
141 #endif
142 
143  _u32 recvCRC = nodesData->crc32;
144 #ifdef _CPU_ENDIAN_BIG
145  recvCRC = le32_to_cpu(recvCRC);
146  nodesData->time_stamp = le64_to_cpu(nodesData->time_stamp);
147 #endif
148  if (recvCRC == crcCalc)
149  {
150  for (size_t pos = 0; pos < _countof(nodesData->node_hq); ++pos)
151  {
152  rplidar_response_measurement_node_hq_t hqNode = nodesData->node_hq[pos];
153 #ifdef _CPU_ENDIAN_BIG
154  hqNode.angle_z_q14 = le16_to_cpu(hqNode.angle_z_q14);
155  hqNode.dist_mm_q2 = le32_to_cpu(hqNode.dist_mm_q2);
156 #endif
158  }
159  }
160  else //crc check not passed
161  {
163  , RPLIDAR_ANS_TYPE_MEASUREMENT_HQ, nodesData, sizeof(*nodesData));
164  }
165  continue;
166  }
167  break;
168 
169 
170  }
172  }
173 
174 }
175 
176 
178 {
180  assert(size == sizeof(_cachedTimingDesc));
181  _cachedTimingDesc = *reinterpret_cast<const SlamtecLidarTimingDesc*>(data);
182  }
183 }
184 
186 {
188 }
189 }
190 
191 
LIDARSampleDataUnpackerInner
Definition: dataunnpacker_internal.h:44
sl_lidar_response_measurement_node_hq_t
Definition: sl_lidar_cmd.h:272
rplidar_response_hq_capsule_measurement_nodes_t
sl_lidar_response_hq_capsule_measurement_nodes_t rplidar_response_hq_capsule_measurement_nodes_t
Definition: rplidar_cmd.h:163
unpacker::UnpackerHandler_HQNode::getSampleAnswerType
virtual _u8 getSampleAnswerType() const
Definition: handler_hqnode.cpp:87
RPLIDAR_ANS_TYPE_MEASUREMENT_HQ
#define RPLIDAR_ANS_TYPE_MEASUREMENT_HQ
Definition: rplidar_cmd.h:107
BEGIN_DATAUNPACKER_NS
#define BEGIN_DATAUNPACKER_NS()
Definition: dataupacker_namespace.h:4
type
sl_u32 type
Definition: sl_lidar_cmd.h:2
unpacker::UnpackerHandler_HQNode::~UnpackerHandler_HQNode
virtual ~UnpackerHandler_HQNode()
Definition: handler_hqnode.cpp:82
LIDARSampleDataUnpackerInner::publishHQNode
virtual void publishHQNode(_u64 timestamp_uS, const rplidar_response_measurement_node_hq_t *node)=0
unpacker::_getSampleDelayOffsetInHQMode
static _u64 _getSampleDelayOffsetInHQMode(const SlamtecLidarTimingDesc &timing)
Definition: handler_hqnode.cpp:54
_u8
uint8_t _u8
Definition: rptypes.h:63
_countof
#define _countof(_Array)
Definition: util.h:42
LIDARSampleDataUnpackerInner::getCurrentTimestamp_uS
virtual _u64 getCurrentTimestamp_uS()=0
size
sl_u8 size
Definition: sl_lidar_protocol.h:4
sl_crc.h
LIDARSampleDataUnpacker::ERR_EVENT_ON_EXP_CHECKSUM_ERR
@ ERR_EVENT_ON_EXP_CHECKSUM_ERR
Definition: dataunpacker.h:64
LIDARSampleDataUnpacker::UNPACKER_CONTEXT_TYPE_LIDAR_TIMING
@ UNPACKER_CONTEXT_TYPE_LIDAR_TIMING
Definition: dataunpacker.h:69
sl::LIDAR_INTERFACE_ETHERNET
@ LIDAR_INTERFACE_ETHERNET
Definition: sl_lidar_driver.h:148
unpacker::UnpackerHandler_HQNode::onData
virtual void onData(LIDARSampleDataUnpackerInner *engine, const _u8 *data, size_t size)
Definition: handler_hqnode.cpp:92
sl_lidar_response_measurement_node_hq_t::dist_mm_q2
sl_u32 dist_mm_q2
Definition: sl_lidar_cmd.h:275
RPLIDAR_RESP_MEASUREMENT_HQ_SYNC
#define RPLIDAR_RESP_MEASUREMENT_HQ_SYNC
Definition: rplidar_cmd.h:147
unpacker::UnpackerHandler_HQNode::onUnpackerContextSet
virtual void onUnpackerContextSet(LIDARSampleDataUnpacker::UnpackerContextType type, const void *data, size_t size)
Definition: handler_hqnode.cpp:177
unpacker::UnpackerHandler_HQNode::_cached_scan_node_buf
std::vector< _u8 > _cached_scan_node_buf
Definition: handler_hqnode.h:56
unpacker::UnpackerHandler_HQNode::_cached_scan_node_buf_pos
int _cached_scan_node_buf_pos
Definition: handler_hqnode.h:57
rplidar_response_measurement_node_hq_t
sl_lidar_response_measurement_node_hq_t rplidar_response_measurement_node_hq_t
Definition: rplidar_cmd.h:162
LIDARSampleDataUnpacker::UnpackerContextType
UnpackerContextType
Definition: dataunpacker.h:67
sl_lidar_response_measurement_node_hq_t::angle_z_q14
sl_u16 angle_z_q14
Definition: sl_lidar_cmd.h:274
unpacker::UnpackerHandler_HQNode::_cachedTimingDesc
SlamtecLidarTimingDesc _cachedTimingDesc
Definition: handler_hqnode.h:58
unpacker
Definition: handler_capsules.cpp:49
le64_to_cpu
#define le64_to_cpu(x)
Definition: byteorder.h:42
unpacker::UnpackerHandler_HQNode::reset
virtual void reset()
Definition: handler_hqnode.cpp:185
_u64
uint64_t _u64
Definition: rptypes.h:72
sl::crc32::getResult
sl_result getResult(sl_u8 *ptr, sl_u32 len)
Definition: sl_crc.cpp:92
le32_to_cpu
#define le32_to_cpu(x)
Definition: byteorder.h:44
data
sl_u8 data[0]
Definition: sl_lidar_protocol.h:5
LIDARSampleDataUnpackerInner::publishDecodingErrorMsg
virtual void publishDecodingErrorMsg(int errorType, _u8 ansType, const void *payload, size_t size)=0
END_DATAUNPACKER_NS
#define END_DATAUNPACKER_NS()
Definition: dataupacker_namespace.h:5
_u32
uint32_t _u32
Definition: rptypes.h:69
le16_to_cpu
#define le16_to_cpu(x)
Definition: byteorder.h:46
handler_hqnode.h


rplidar_ros
Author(s):
autogenerated on Fri Aug 2 2024 08:42:14