| 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 | |
| 34 | #pragma once |
| 35 | |
| 36 | #include "sl_async_transceiver.h" |
| 37 | |
| 38 | namespace sl { namespace internal { |
| 39 | |
| 40 | |
| 41 | class IProtocolMessageListener { |
| 42 | public: |
| 43 | virtual void onProtocolMessageDecoded(const ProtocolMessage&) = 0; |
| 44 | }; |
| 45 | |
| 46 | |
| 47 | class RPLidarProtocolCodec : public IAsyncProtocolCodec |
| 48 | { |
| 49 | public: |
| 50 | |
| 51 | enum { |
| 52 | STATUS_WAIT_SYNC1 = 0x0, |
| 53 | STATUS_WAIT_SYNC2 = 0x1, |
| 54 | STATUS_WAIT_SIZE_FLAG = 0x2, |
| 55 | STATUS_WAIT_TYPE = 0x3, |
| 56 | STATUS_RECV_PAYLOAD = 0x4, |
| 57 | STATUS_LOOP_MODE_FLAG = 0x80000000, |
| 58 | }; |
| 59 | |
| 60 | RPLidarProtocolCodec(); |
| 61 | |
| 62 | void exitLoopMode(); |
| 63 | |
| 64 | |
| 65 | virtual size_t estimateLength(message_autoptr_t& message); |
| 66 | |
| 67 | |
| 68 | virtual void onEncodeData(message_autoptr_t& message, _u8* txbuffer, size_t* size); |
| 69 | |
| 70 | virtual void onDecodeReset(); |
| 71 | virtual void onDecodeData(const void* buffer, size_t size); |
| 72 | |
| 73 | void setMessageListener(IProtocolMessageListener* l); |
| 74 | |
| 75 | protected: |
| 76 | |
| 77 | IProtocolMessageListener* _listener; |
| 78 | ProtocolMessage _decodingMessage; |
| 79 | rp::hal::Locker _op_locker; |
| 80 | |
| 81 | _u32 _working_states; |
| 82 | int _rx_pos; |
| 83 | }; |
| 84 | |
| 85 | }} |
| 86 | |
| 87 | |
| 88 |