Livox SDK API  V2.0.0
protocol.h
Go to the documentation of this file.
1 //
2 // The MIT License (MIT)
3 //
4 // Copyright (c) 2019 Livox. All rights reserved.
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 //
24 
25 #ifndef COMM_PROTOCOL_H_
26 #define COMM_PROTOCOL_H_
27 
28 #include <stdint.h>
29 
30 namespace livox {
31 typedef struct CommPacket CommPacket;
32 
33 typedef int (*RequestPackCb)(CommPacket *packet);
34 
36 
38 
40 
42 
43 typedef struct CommPacket {
44  uint8_t packet_type;
45  uint8_t protocol;
47  uint8_t cmd_set;
48  uint32_t cmd_code;
49  uint32_t sender;
50  uint32_t sub_sender;
51  uint32_t receiver;
52  uint32_t sub_receiver;
53  uint32_t seq_num;
54  uint8_t *data;
55  uint16_t data_len;
56  uint32_t padding;
57  // RequestPackCb *ack_request_cb;
58  // uint32_t retry_times;
59  // uint32_t timeout;
60 } CommPacket;
61 
62 class Protocol {
63  public:
64  virtual ~Protocol(){};
65 
66  virtual int32_t ParsePacket(uint8_t *i_buf, uint32_t i_len, CommPacket *o_packet) = 0;
67 
68  virtual int32_t Pack(uint8_t *o_buf, uint32_t o_buf_size, uint32_t *o_len, const CommPacket &i_packet) = 0;
69 
70  virtual uint32_t GetPreambleLen() = 0;
71 
72  virtual uint32_t GetPacketWrapperLen() = 0;
73 
74  virtual uint32_t GetPacketLen(uint8_t *buf) = 0;
75 
76  virtual int32_t CheckPreamble(uint8_t *buf) = 0;
77 
78  virtual int32_t CheckPacket(uint8_t *buf) = 0;
79 };
80 
81 } // namespace livox
82 #endif // COMM_PROTOCOL_H_
livox::kMsgPack
Definition: protocol.h:35
livox::CommPacket::seq_num
uint32_t seq_num
Definition: protocol.h:53
livox::Protocol
Definition: protocol.h:62
livox::CommPacket::sub_receiver
uint32_t sub_receiver
Definition: protocol.h:52
livox::Protocol::CheckPreamble
virtual int32_t CheckPreamble(uint8_t *buf)=0
livox::CommPacket::cmd_set
uint8_t cmd_set
Definition: protocol.h:47
livox::CommPacket::data
uint8_t * data
Definition: protocol.h:54
livox::CommPacket::protocol_version
uint8_t protocol_version
Definition: protocol.h:46
livox::CommPacket::padding
uint32_t padding
Definition: protocol.h:56
livox::CommPacket::sender
uint32_t sender
Definition: protocol.h:49
livox::Protocol::CheckPacket
virtual int32_t CheckPacket(uint8_t *buf)=0
livox::kNoNeed
Definition: protocol.h:39
livox::kRsvd1
Definition: protocol.h:37
livox::CommPacket::packet_type
uint8_t packet_type
Definition: protocol.h:44
livox::kAckPack
Definition: protocol.h:35
livox::CommPacket::data_len
uint16_t data_len
Definition: protocol.h:55
livox::Protocol::GetPreambleLen
virtual uint32_t GetPreambleLen()=0
livox::RequestPackCb
int(* RequestPackCb)(CommPacket *packet)
Definition: protocol.h:33
livox::kDelayAck
Definition: protocol.h:39
livox::CommPacket::receiver
uint32_t receiver
Definition: protocol.h:51
livox::Protocol::~Protocol
virtual ~Protocol()
Definition: protocol.h:64
livox::Protocol::Pack
virtual int32_t Pack(uint8_t *o_buf, uint32_t o_buf_size, uint32_t *o_len, const CommPacket &i_packet)=0
livox::CommPacket::sub_sender
uint32_t sub_sender
Definition: protocol.h:50
livox::kNeedAck
Definition: protocol.h:39
livox::ParseResult
ParseResult
Definition: protocol.h:41
livox::Protocol::ParsePacket
virtual int32_t ParsePacket(uint8_t *i_buf, uint32_t i_len, CommPacket *o_packet)=0
livox::kLidarSdk
Definition: protocol.h:37
livox::ProtocolType
ProtocolType
Definition: protocol.h:37
livox::Protocol::GetPacketWrapperLen
virtual uint32_t GetPacketWrapperLen()=0
livox::CommPacket
struct CommPacket CommPacket
Definition: protocol.h:31
livox::CommPacket
Definition: protocol.h:43
livox
Definition: comm_port.h:31
livox::PacketType
PacketType
Definition: protocol.h:35
livox::Protocol::GetPacketLen
virtual uint32_t GetPacketLen(uint8_t *buf)=0
livox::CommPacket::cmd_code
uint32_t cmd_code
Definition: protocol.h:48
livox::kParseFail
Definition: protocol.h:41
livox::kRequestPack
Definition: protocol.h:35
livox::kProtocolUndef
Definition: protocol.h:37
livox::kParseSuccess
Definition: protocol.h:41
livox::NeedAckType
NeedAckType
Definition: protocol.h:39
livox::CommPacket::protocol
uint8_t protocol
Definition: protocol.h:45