Apollo  6.0
Open source self driving car software
udp_bridge_receiver_component.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 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 #pragma once
17 
18 #include <netinet/in.h>
19 #include <sys/socket.h>
20 
21 #include <cstdlib>
22 #include <iostream>
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 #include "modules/bridge/proto/udp_bridge_remote_info.pb.h"
28 #include "modules/canbus/proto/chassis.pb.h"
29 
32 #include "cyber/cyber.h"
33 #include "cyber/init.h"
40 
41 namespace apollo {
42 namespace bridge {
43 
44 #define RECEIVER_BRIDGE_COMPONENT_REGISTER(pb_msg) \
45  CYBER_REGISTER_COMPONENT(UDPBridgeReceiverComponent<pb_msg>)
46 
47 template <typename T>
49  public:
52 
53  bool Init() override;
54 
55  std::string Name() const { return FLAGS_bridge_module_name; }
56  bool MsgHandle(int fd);
57 
58  private:
59  bool InitSession(uint16_t port);
60  void MsgDispatcher();
61  bool IsProtoExist(const BridgeHeader &header);
62  BridgeProtoDiserializedBuf<T> *CreateBridgeProtoBuf(
63  const BridgeHeader &header);
64  bool IsTimeout(double time_stamp);
65  bool RemoveInvalidBuf(uint32_t msg_id);
66 
67  private:
68  common::monitor::MonitorLogBuffer monitor_logger_buffer_;
69  unsigned int bind_port_ = 0;
70  std::string proto_name_ = "";
71  std::string topic_name_ = "";
72  bool enable_timeout_ = true;
73  std::shared_ptr<cyber::Writer<T>> writer_;
74  std::mutex mutex_;
75 
76  std::shared_ptr<UDPListener<UDPBridgeReceiverComponent<T>>> listener_ =
77  std::make_shared<UDPListener<UDPBridgeReceiverComponent<T>>>();
78 
79  std::vector<BridgeProtoDiserializedBuf<T> *> proto_list_;
80 };
81 
83 } // namespace bridge
84 } // namespace apollo
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: bridge_header.h:33
#define RECEIVER_BRIDGE_COMPONENT_REGISTER(pb_msg)
Definition: udp_bridge_receiver_component.h:44
Definition: bridge_proto_diserialized_buf.h:50
std::string Name() const
Definition: udp_bridge_receiver_component.h:55
The class of MonitorLogBuffer.
Definition: udp_bridge_receiver_component.h:48
This class help collect MonitorMessage pb to monitor topic. The messages can be published automatical...
Definition: monitor_log_buffer.h:60
The Component can process up to four channels of messages. The message type is specified when the com...
Definition: component.h:58