Apollo  6.0
Open source self driving car software
tcp_cmd_client.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2020 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
17 #ifndef LIDAR_HESAI_SRC_TCP_CMD_CLIENT_H_
18 #define LIDAR_HESAI_SRC_TCP_CMD_CLIENT_H_
19 
20 #include <mutex>
21 #include <string>
22 
23 namespace apollo {
24 namespace drivers {
25 namespace hesai {
26 
27 typedef enum {
34 } PTC_COMMAND;
35 
36 typedef struct CommandHeader {
37  unsigned char cmd = '\0';
38  unsigned char ret_code = '\0';
39  uint32_t len = 0;
41 
42 typedef struct Command {
44  unsigned char* data = nullptr;
46  if (data != nullptr) {
47  free(data);
48  }
49  }
50 } Command;
51 
52 class TcpCmdClient {
53  public:
54  TcpCmdClient(const std::string& ip, uint32_t port) : ip_(ip), port_(port) {}
55  ~TcpCmdClient() { Close(); }
56  bool GetCalibration(std::string* content);
57 
58  private:
59  bool Open();
60  void Close();
61  bool ReadCmd(Command* feedBack);
62  int Read(unsigned char* buffer, int n);
63  bool WriteCmd(const Command& cmd);
64  int BuildCmdHeader(const Command& cmd, unsigned char* buffer);
65  void ParseHeader(const unsigned char* buffer, const int len,
66  CommandHeader* header);
67  std::string ip_;
68  uint32_t port_ = 0;
69  int socket_fd_ = -1;
70  std::mutex mutex_;
71 };
72 
73 } // namespace hesai
74 } // namespace drivers
75 } // namespace apollo
76 
77 #endif
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: tcp_cmd_client.h:52
~Command()
Definition: tcp_cmd_client.h:45
uint32_t len
Definition: tcp_cmd_client.h:39
Definition: tcp_cmd_client.h:30
Definition: tcp_cmd_client.h:32
unsigned char cmd
Definition: tcp_cmd_client.h:37
~TcpCmdClient()
Definition: tcp_cmd_client.h:55
TcpCmdClient(const std::string &ip, uint32_t port)
Definition: tcp_cmd_client.h:54
Definition: tcp_cmd_client.h:36
unsigned char ret_code
Definition: tcp_cmd_client.h:38
struct apollo::drivers::hesai::CommandHeader CommandHeader
CommandHeader header
Definition: tcp_cmd_client.h:43
struct apollo::drivers::hesai::Command Command
Definition: tcp_cmd_client.h:42
PTC_COMMAND
Definition: tcp_cmd_client.h:27