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_COMM_PROTOCOL_H_
26 #define COMM_COMM_PROTOCOL_H_
27 
28 #include <stdint.h>
29 #include "gps_protocol.h"
30 #include "protocol.h"
31 #include "sdk_protocol.h"
32 
33 namespace livox_ros {
34 const uint32_t kCacheSize = 8192;
36 
42 };
43 
45 typedef struct {
50 } CommCache;
51 
52 class CommProtocol {
53  public:
55  ~CommProtocol();
56 
57  int32_t Pack(uint8_t *o_buf, uint32_t o_buf_size, uint32_t *o_len,
58  const CommPacket &i_packet);
59 
61 
63 
65 
67 
68  void ResetParser();
69 
70  private:
73  void UpdateCache(void);
75  void ResetCache() {
76  cache_.wr_idx = 0;
77  cache_.rd_idx = 0;
79  }
80 
85 
87  bool IsLengthKnown() { return is_length_known; }
88 
95  void FsmParserStateTransfer(uint32_t new_state) {
96  if (new_state < kParseStepUndef) {
97  fsm_parse_step_ = new_state;
98  } else {
99  fsm_parse_step_ = kSearchPacketPreamble;
100  }
101  }
102 };
103 
104 } // namespace livox_ros
105 #endif // COMM_COMM_PROTOCOL_H_
uint8_t buf[kCacheSize]
Definition: comm_protocol.h:46
void FsmParserStateTransfer(uint32_t new_state)
Definition: comm_protocol.h:95
uint8_t * GetCacheReadPos()
Definition: comm_protocol.h:74
unsigned short uint16_t
Definition: stdint.h:126
CommProtocol(ProtocolConfig &config)
unsigned char uint8_t
Definition: stdint.h:125
const uint32_t kMoveCacheLimit
Definition: comm_protocol.h:35
uint8_t * FetchCacheFreeSpace(uint32_t *o_len)
unsigned int uint32_t
Definition: stdint.h:127
volatile uint32_t offset_to_read_index_
Definition: comm_protocol.h:89
int32_t UpdateCacheWrIdx(uint32_t used_size)
ProtocolConfig config_
Definition: comm_protocol.h:81
int32_t FsmGetPacketData(CommPacket *o_pack)
int32_t Pack(uint8_t *o_buf, uint32_t o_buf_size, uint32_t *o_len, const CommPacket &i_packet)
const uint32_t kCacheSize
Definition: comm_protocol.h:34
signed int int32_t
Definition: stdint.h:124
int32_t ParseCommStream(CommPacket *o_pack)
volatile uint32_t fsm_parse_step_
Definition: comm_protocol.h:91


livox_ros_driver
Author(s): Livox Dev Team
autogenerated on Mon Mar 15 2021 02:40:45