Livox SDK API  V2.2.0
comm_port.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_PORT_H_
26 #define COMM_COMM_PORT_H_
27 
28 #include <stdint.h>
29 #include "protocol.h"
30 
31 namespace livox {
32 const uint32_t kCacheSize = 8192;
33 const uint32_t kMoveCacheLimit = 1536;
34 
35 typedef struct {
36  uint8_t buf[kCacheSize];
37  uint32_t rd_idx;
38  uint32_t wr_idx;
39  uint32_t size;
40 } PortCache;
41 
42 class CommPort {
43  public:
44  CommPort();
45 
46  ~CommPort();
47 
48  int32_t Pack(uint8_t *o_buf, uint32_t o_buf_size, uint32_t *o_len, const CommPacket &i_packet);
49 
50  int32_t ParseCommStream(CommPacket *o_pack);
51 
52  uint8_t *FetchCacheFreeSpace(uint32_t *o_len);
53 
54  int32_t UpdateCacheWrIdx(uint32_t used_size);
55 
56  uint16_t GetAndUpdateSeqNum();
57 
58  private:
59  uint32_t GetCacheTailSize();
60 
61  uint32_t GetValidDataSize();
62 
63  void UpdateCache(void);
64 
65  PortCache cache_;
66  Protocol *protocol_;
67  uint32_t parse_step_;
68  uint16_t seq_num_;
69 };
70 
71 } // namespace livox
72 #endif // COMM_COMM_PORT_H_
uint32_t wr_idx
Definition: comm_port.h:38
uint32_t size
Definition: comm_port.h:39
int32_t ParseCommStream(CommPacket *o_pack)
uint32_t rd_idx
Definition: comm_port.h:37
const uint32_t kMoveCacheLimit
Definition: comm_port.h:33
const uint32_t kCacheSize
Definition: comm_port.h:32
uint8_t * FetchCacheFreeSpace(uint32_t *o_len)
int32_t Pack(uint8_t *o_buf, uint32_t o_buf_size, uint32_t *o_len, const CommPacket &i_packet)
int32_t UpdateCacheWrIdx(uint32_t used_size)
uint16_t GetAndUpdateSeqNum()