sl_async_transceiver.h
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  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  */
32 
33 #pragma once
34 
35 #include <list>
36 #include <memory>
37 
38 namespace sl { namespace internal {
39 
40 
42 
43 public:
44  size_t len;
46 protected:
48  size_t _databufsize;
49 
50 public:
52  ProtocolMessage(_u8 cmd, const void* buffer, size_t size);
53  ProtocolMessage(const ProtocolMessage& srcMsg);
54  virtual ~ProtocolMessage();
55 
56  ProtocolMessage& operator=(const ProtocolMessage& srcMessage);
57 
58  // avoid use this method, pls. use fillData instead
59  void setDataBuf(_u8* buffer, size_t size);
60 
61  _u8* getDataBuf() { return data; }
62 
63  void fillData(const void* buffer, size_t size);
64  void cleanData();
65 
66  size_t getPayloadSize() const
67  {
68  return len;
69  }
70 
71 protected:
72 
73  // change the data buffer to fix the new payload size
74  // the existing buffer will be reused if possible.
75  // all the existing payload data will lose
76  void _changeBufSize(bool force_compact = false);
78 };
79 
80 
81 
82 typedef std::shared_ptr<ProtocolMessage> message_autoptr_t;
83 
84 
86 public:
88  virtual ~IAsyncProtocolCodec() {}
89 
90  virtual void onChannelError(u_result errCode) {}
91 
92  virtual void onDecodeReset() {}
93  virtual void onDecodeData(const void* buffer, size_t size) = 0;
94 
95 
96  virtual size_t estimateLength(message_autoptr_t& message) = 0;
97  virtual void onEncodeData(message_autoptr_t& message, _u8* txbuffer, size_t* size) = 0;
98 
99 };
100 
102 public:
103 
105  {
108 
109  WORKING_FLAG_ERROR = 0x1L << 31,
110  };
111 
112 
115 
116 
117 
119  void unbindAndClose();
120 
122  return _bindedChannel;
123  }
124 
126 
127 protected:
128 
131 
132 protected:
133 
134 
138 
141 
142 
145 
148 
149  struct Buffer {
150  size_t size;
152 
153 
154  Buffer() : size(0), data(NULL){}
155 
157  if (data) {
158  delete[] data;
159  data = NULL;
160  }
161  }
162  };
163  std::list< Buffer * > _rxQueue;
164 };
165 
166 
167 }}
u_result
uint32_t u_result
Definition: rptypes.h:100
sl::internal::AsyncTransceiver::openChannelAndBind
u_result openChannelAndBind(IChannel *channel)
Definition: sl_async_transceiver.cpp:193
sl::internal::IAsyncProtocolCodec::onChannelError
virtual void onChannelError(u_result errCode)
Definition: sl_async_transceiver.h:90
sl::internal::AsyncTransceiver::Buffer
Definition: sl_async_transceiver.h:149
sl::internal::ProtocolMessage::getPayloadSize
size_t getPayloadSize() const
Definition: sl_async_transceiver.h:66
sl::internal::IAsyncProtocolCodec::onDecodeReset
virtual void onDecodeReset()
Definition: sl_async_transceiver.h:92
sl::IChannel
Definition: sl_lidar_driver.h:171
sl::internal::AsyncTransceiver::_rxThread
rp::hal::Thread _rxThread
Definition: sl_async_transceiver.h:146
sl::internal::AsyncTransceiver::_isWorking
bool _isWorking
Definition: sl_async_transceiver.h:143
sl::internal::ProtocolMessage::len
size_t len
Definition: sl_async_transceiver.h:44
sl::internal::AsyncTransceiver::_rxQueue
std::list< Buffer * > _rxQueue
Definition: sl_async_transceiver.h:163
sl::internal::AsyncTransceiver::working_flag_t
working_flag_t
Definition: sl_async_transceiver.h:104
sl::internal::AsyncTransceiver::~AsyncTransceiver
~AsyncTransceiver()
Definition: sl_async_transceiver.cpp:188
sl::internal::IAsyncProtocolCodec::estimateLength
virtual size_t estimateLength(message_autoptr_t &message)=0
sl::internal::ProtocolMessage::data
_u8 * data
Definition: sl_async_transceiver.h:47
sl::internal::ProtocolMessage::getDataBuf
_u8 * getDataBuf()
Definition: sl_async_transceiver.h:61
_u8
uint8_t _u8
Definition: rptypes.h:63
sl::internal::AsyncTransceiver::Buffer::Buffer
Buffer()
Definition: sl_async_transceiver.h:154
sl::internal::AsyncTransceiver::_dataEvt
rp::hal::Event _dataEvt
Definition: sl_async_transceiver.h:137
sl::internal::IAsyncProtocolCodec::~IAsyncProtocolCodec
virtual ~IAsyncProtocolCodec()
Definition: sl_async_transceiver.h:88
size
sl_u8 size
Definition: sl_lidar_protocol.h:4
sl::internal::AsyncTransceiver::AsyncTransceiver
AsyncTransceiver(IAsyncProtocolCodec &codec)
Definition: sl_async_transceiver.cpp:179
sl::internal::AsyncTransceiver::_proc_rxThread
sl_result _proc_rxThread()
Definition: sl_async_transceiver.cpp:299
_single_thread
#define _single_thread
Definition: types.h:84
rp::hal::Event
Definition: event.h:38
sl::internal::ProtocolMessage
Definition: sl_async_transceiver.h:41
sl::internal::IAsyncProtocolCodec
Definition: sl_async_transceiver.h:85
sl::internal::AsyncTransceiver::WORKING_FLAG_ERROR
@ WORKING_FLAG_ERROR
Definition: sl_async_transceiver.h:109
rp::hal::Locker
Definition: locker.h:38
sl::internal::AsyncTransceiver::_opLocker
rp::hal::Locker _opLocker
Definition: sl_async_transceiver.h:135
sl::internal::IAsyncProtocolCodec::onDecodeData
virtual void onDecodeData(const void *buffer, size_t size)=0
rp::hal::Thread
Definition: thread.h:43
sl
Definition: sl_crc.h:38
sl::internal::AsyncTransceiver::_proc_decoderThread
sl_result _proc_decoderThread()
Definition: sl_async_transceiver.cpp:372
sl::internal::AsyncTransceiver::_bindedChannel
IChannel * _bindedChannel
Definition: sl_async_transceiver.h:139
sl::internal::IAsyncProtocolCodec::onEncodeData
virtual void onEncodeData(message_autoptr_t &message, _u8 *txbuffer, size_t *size)=0
sl::internal::AsyncTransceiver
Definition: sl_async_transceiver.h:101
sl::internal::message_autoptr_t
std::shared_ptr< ProtocolMessage > message_autoptr_t
Definition: sl_async_transceiver.h:82
sl::internal::IAsyncProtocolCodec::IAsyncProtocolCodec
IAsyncProtocolCodec()
Definition: sl_async_transceiver.h:87
sl::internal::ProtocolMessage::cmd
_u8 cmd
Definition: sl_async_transceiver.h:45
sl::internal::AsyncTransceiver::_decoderThread
rp::hal::Thread _decoderThread
Definition: sl_async_transceiver.h:147
sl::internal::AsyncTransceiver::_rxLocker
rp::hal::Locker _rxLocker
Definition: sl_async_transceiver.h:136
sl::internal::AsyncTransceiver::sendMessage
u_result sendMessage(message_autoptr_t &msg)
Definition: sl_async_transceiver.cpp:261
sl::internal::AsyncTransceiver::Buffer::size
size_t size
Definition: sl_async_transceiver.h:150
sl::internal::AsyncTransceiver::getBindedChannel
IChannel * getBindedChannel() const
Definition: sl_async_transceiver.h:121
sl::internal::AsyncTransceiver::Buffer::data
_u8 * data
Definition: sl_async_transceiver.h:151
sl::internal::ProtocolMessage::_databufsize
size_t _databufsize
Definition: sl_async_transceiver.h:48
sl::internal::AsyncTransceiver::_codec
IAsyncProtocolCodec & _codec
Definition: sl_async_transceiver.h:140
sl::internal::AsyncTransceiver::WORKING_FLAG_RX_DISABLED
@ WORKING_FLAG_RX_DISABLED
Definition: sl_async_transceiver.h:106
sl::internal::AsyncTransceiver::Buffer::~Buffer
~Buffer()
Definition: sl_async_transceiver.h:156
sl_result
uint32_t sl_result
Definition: sl_types.h:69
sl::internal::AsyncTransceiver::_workingFlag
_u32 _workingFlag
Definition: sl_async_transceiver.h:144
data
sl_u8 data[0]
Definition: sl_lidar_protocol.h:5
_u32
uint32_t _u32
Definition: rptypes.h:69
sl::internal::AsyncTransceiver::unbindAndClose
void unbindAndClose()
Definition: sl_async_transceiver.cpp:233
sl::internal::ProtocolMessage::_usingOutterData
bool _usingOutterData
Definition: sl_async_transceiver.h:77
sl::internal::AsyncTransceiver::WORKING_FLAG_TX_DISABLED
@ WORKING_FLAG_TX_DISABLED
Definition: sl_async_transceiver.h:107


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