Main Page
Modules
Namespaces
Classes
Files
File List
File Members
common
comm
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_ros
{
31
typedef
struct
CommPacket
CommPacket
;
32
33
typedef
int (*
RequestPackCb
)(
CommPacket
*packet);
34
35
typedef
enum
{
kRequestPack
,
kAckPack
,
kMsgPack
}
PacketType
;
36
37
typedef
enum
{
kLidarSdk
,
kRsvd1
,
kGps
,
kProtocolUndef
}
ProtocolType
;
38
39
typedef
enum
{
kNoNeed
,
kNeedAck
,
kDelayAck
}
NeedAckType
;
40
41
typedef
enum
{
kParseSuccess
,
kParseFail
,
kParseNeedMoreData
}
ParseResult
;
42
43
typedef
enum
{
44
kFindLengthSuccess
,
45
kFindLengthContinue
,
46
kFindLengthError
47
}
FindLengthResult
;
48
49
typedef
struct
CommPacket
{
50
uint8_t
packet_type
;
51
uint8_t
protocol
;
52
uint8_t
protocol_version
;
53
uint8_t
cmd_set
;
54
uint32_t
cmd_code
;
55
uint32_t
sender
;
56
uint32_t
sub_sender
;
57
uint32_t
receiver
;
58
uint32_t
sub_receiver
;
59
uint32_t
seq_num
;
60
uint8_t
*
data
;
61
uint16_t
data_len
;
62
uint32_t
padding
;
63
}
CommPacket
;
64
66
typedef
struct
{
67
uint16_t
seed16
;
68
uint16_t
seed32
;
69
}
SdkProtocolConfig
;
70
72
typedef
struct
{
void
*
data
; }
GpsProtocolConfig
;
73
74
typedef
struct
{
75
uint8_t
type
;
76
union
{
77
SdkProtocolConfig
sdk
;
78
GpsProtocolConfig
gps
;
79
} config;
80
}
ProtocolConfig
;
81
82
class
Protocol
{
83
public
:
84
virtual
~
Protocol
() =
default
;
85
86
virtual
int32_t
ParsePacket(
const
uint8_t
*i_buf,
uint32_t
i_len,
87
CommPacket
*o_packet) = 0;
88
89
virtual
int32_t
Pack(
uint8_t
*o_buf,
uint32_t
o_buf_size,
uint32_t
*o_len,
90
const
CommPacket
&i_packet) = 0;
91
92
virtual
uint32_t
GetPreambleLen() = 0;
93
94
virtual
uint32_t
GetPacketWrapperLen() = 0;
95
96
virtual
uint32_t
FindPacketLen(
const
uint8_t
*buf,
uint32_t
buf_length) = 0;
97
98
virtual
uint32_t
GetPacketLen(
const
uint8_t
*buf) = 0;
99
100
virtual
int32_t
CheckPreamble(
const
uint8_t
*buf) = 0;
101
102
virtual
int32_t
CheckPacket(
const
uint8_t
*buf) = 0;
103
};
104
105
}
// namespace livox_ros
106
#endif // COMM_PROTOCOL_H_
livox_ros::kRsvd1
Definition:
protocol.h:37
livox_ros::SdkProtocolConfig::seed32
uint16_t seed32
Definition:
protocol.h:68
livox_ros::ProtocolType
ProtocolType
Definition:
protocol.h:37
livox_ros::kProtocolUndef
Definition:
protocol.h:37
livox_ros::GpsProtocolConfig
Definition:
protocol.h:72
livox_ros::GpsProtocolConfig::data
void * data
Definition:
protocol.h:72
livox_ros::kNeedAck
Definition:
protocol.h:39
uint16_t
unsigned short uint16_t
Definition:
stdint.h:126
livox_ros::CommPacket::sub_sender
uint32_t sub_sender
Definition:
protocol.h:56
livox_ros
Definition:
comm_device.h:30
livox_ros::kFindLengthSuccess
Definition:
protocol.h:44
livox_ros::ProtocolConfig
Definition:
protocol.h:74
livox_ros::SdkProtocolConfig
Definition:
protocol.h:66
livox_ros::ProtocolConfig::type
uint8_t type
Definition:
protocol.h:75
uint8_t
unsigned char uint8_t
Definition:
stdint.h:125
livox_ros::CommPacket::receiver
uint32_t receiver
Definition:
protocol.h:57
livox_ros::kParseNeedMoreData
Definition:
protocol.h:41
livox_ros::SdkProtocolConfig::seed16
uint16_t seed16
Definition:
protocol.h:67
livox_ros::ParseResult
ParseResult
Definition:
protocol.h:41
livox_ros::CommPacket::data_len
uint16_t data_len
Definition:
protocol.h:61
livox_ros::CommPacket::sender
uint32_t sender
Definition:
protocol.h:55
livox_ros::kAckPack
Definition:
protocol.h:35
livox_ros::CommPacket::packet_type
uint8_t packet_type
Definition:
protocol.h:50
livox_ros::CommPacket::sub_receiver
uint32_t sub_receiver
Definition:
protocol.h:58
livox_ros::RequestPackCb
int(* RequestPackCb)(CommPacket *packet)
Definition:
protocol.h:33
livox_ros::CommPacket::protocol_version
uint8_t protocol_version
Definition:
protocol.h:52
livox_ros::kParseSuccess
Definition:
protocol.h:41
uint32_t
unsigned int uint32_t
Definition:
stdint.h:127
livox_ros::kFindLengthContinue
Definition:
protocol.h:45
livox_ros::FindLengthResult
FindLengthResult
Definition:
protocol.h:43
livox_ros::CommPacket::cmd_set
uint8_t cmd_set
Definition:
protocol.h:53
livox_ros::ProtocolConfig::gps
GpsProtocolConfig gps
Definition:
protocol.h:78
livox_ros::kParseFail
Definition:
protocol.h:41
livox_ros::Protocol
Definition:
protocol.h:82
livox_ros::CommPacket::protocol
uint8_t protocol
Definition:
protocol.h:51
livox_ros::ProtocolConfig::sdk
SdkProtocolConfig sdk
Definition:
protocol.h:77
stdint.h
livox_ros::CommPacket::cmd_code
uint32_t cmd_code
Definition:
protocol.h:54
livox_ros::kMsgPack
Definition:
protocol.h:35
livox_ros::kLidarSdk
Definition:
protocol.h:37
livox_ros::CommPacket::seq_num
uint32_t seq_num
Definition:
protocol.h:59
livox_ros::CommPacket
Definition:
protocol.h:49
livox_ros::kFindLengthError
Definition:
protocol.h:46
livox_ros::kDelayAck
Definition:
protocol.h:39
livox_ros::kRequestPack
Definition:
protocol.h:35
livox_ros::NeedAckType
NeedAckType
Definition:
protocol.h:39
int32_t
signed int int32_t
Definition:
stdint.h:124
livox_ros::kGps
Definition:
protocol.h:37
livox_ros::CommPacket::padding
uint32_t padding
Definition:
protocol.h:62
livox_ros::CommPacket
struct CommPacket CommPacket
Definition:
protocol.h:31
livox_ros::PacketType
PacketType
Definition:
protocol.h:35
livox_ros::kNoNeed
Definition:
protocol.h:39
livox_ros::CommPacket::data
uint8_t * data
Definition:
protocol.h:60
livox_ros_driver
Author(s): Livox Dev Team
autogenerated on Mon Mar 15 2021 02:40:46