Apollo 10.0
自动驾驶开放平台
attributes_filler.cc
浏览该文件的文档.
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
18
19#include <limits>
20
21#include "cyber/common/log.h"
23
24namespace apollo {
25namespace cyber {
26namespace transport {
27
30
32 const std::string& channel_name, const QosProfile& qos,
33 eprosima::fastrtps::PublisherAttributes* pub_attr) {
34 RETURN_VAL_IF_NULL(pub_attr, false);
35
36 pub_attr->topic.topicName = channel_name;
37 pub_attr->topic.topicDataType = "UnderlayMessage";
38 pub_attr->topic.topicKind = eprosima::fastrtps::rtps::NO_KEY;
39
40 switch (qos.history()) {
41 case QosHistoryPolicy::HISTORY_KEEP_LAST:
42 pub_attr->topic.historyQos.kind =
43 eprosima::fastrtps::KEEP_LAST_HISTORY_QOS;
44 break;
45 case QosHistoryPolicy::HISTORY_KEEP_ALL:
46 pub_attr->topic.historyQos.kind =
47 eprosima::fastrtps::KEEP_ALL_HISTORY_QOS;
48 break;
49 default:
50 break;
51 }
52
53 switch (qos.durability()) {
54 case QosDurabilityPolicy::DURABILITY_TRANSIENT_LOCAL:
55 pub_attr->qos.m_durability.kind =
56 eprosima::fastrtps::TRANSIENT_LOCAL_DURABILITY_QOS;
57 break;
58 case QosDurabilityPolicy::DURABILITY_VOLATILE:
59 pub_attr->qos.m_durability.kind =
60 eprosima::fastrtps::VOLATILE_DURABILITY_QOS;
61 break;
62 default:
63 break;
64 }
65
66 switch (qos.reliability()) {
67 case QosReliabilityPolicy::RELIABILITY_BEST_EFFORT:
68 pub_attr->qos.m_reliability.kind =
69 eprosima::fastrtps::BEST_EFFORT_RELIABILITY_QOS;
70 break;
71 case QosReliabilityPolicy::RELIABILITY_RELIABLE:
72 pub_attr->qos.m_reliability.kind =
73 eprosima::fastrtps::RELIABLE_RELIABILITY_QOS;
74 break;
75 default:
76 break;
77 }
78
80 pub_attr->topic.historyQos.depth = static_cast<int32_t>(qos.depth());
81 }
82
83 // ensure the history depth is at least the requested queue size
84 if (pub_attr->topic.historyQos.depth < 0) {
85 return false;
86 }
87
88 // transform messages per second to rtps heartbeat
89 // set default heartbeat period
90 pub_attr->times.heartbeatPeriod.seconds = 1;
91 pub_attr->times.heartbeatPeriod.fraction(0);
92 if (qos.mps() != 0) {
93 uint64_t mps = qos.mps();
94
95 // adapt heartbeat period
96 if (mps > 1024) {
97 mps = 1024;
98 } else if (mps < 64) {
99 mps = 64;
100 }
101
102 uint64_t fractions = (256ull << 32) / mps;
103 uint32_t fraction = fractions & 0xffffffff;
104 int32_t seconds = static_cast<int32_t>(fractions >> 32);
105
106 pub_attr->times.heartbeatPeriod.seconds = seconds;
107 pub_attr->times.heartbeatPeriod.fraction(fraction);
108 }
109
110 pub_attr->qos.m_publishMode.kind =
111 eprosima::fastrtps::ASYNCHRONOUS_PUBLISH_MODE;
112 pub_attr->historyMemoryPolicy =
113 eprosima::fastrtps::rtps::DYNAMIC_RESERVE_MEMORY_MODE;
114 pub_attr->topic.resourceLimitsQos.max_samples = 10000;
115
116 return true;
117}
118
120 const std::string& channel_name, const QosProfile& qos,
121 eprosima::fastrtps::SubscriberAttributes* sub_attr) {
122 RETURN_VAL_IF_NULL(sub_attr, false);
123 sub_attr->topic.topicName = channel_name;
124 sub_attr->topic.topicDataType = "UnderlayMessage";
125 sub_attr->topic.topicKind = eprosima::fastrtps::rtps::NO_KEY;
126
127 switch (qos.history()) {
128 case QosHistoryPolicy::HISTORY_KEEP_LAST:
129 sub_attr->topic.historyQos.kind =
130 eprosima::fastrtps::KEEP_LAST_HISTORY_QOS;
131 break;
132 case QosHistoryPolicy::HISTORY_KEEP_ALL:
133 sub_attr->topic.historyQos.kind =
134 eprosima::fastrtps::KEEP_ALL_HISTORY_QOS;
135 break;
136 default:
137 break;
138 }
139
140 switch (qos.durability()) {
141 case QosDurabilityPolicy::DURABILITY_TRANSIENT_LOCAL:
142 sub_attr->qos.m_durability.kind =
143 eprosima::fastrtps::TRANSIENT_LOCAL_DURABILITY_QOS;
144 break;
145 case QosDurabilityPolicy::DURABILITY_VOLATILE:
146 sub_attr->qos.m_durability.kind =
147 eprosima::fastrtps::VOLATILE_DURABILITY_QOS;
148 break;
149 default:
150 break;
151 }
152
153 switch (qos.reliability()) {
154 case QosReliabilityPolicy::RELIABILITY_BEST_EFFORT:
155 sub_attr->qos.m_reliability.kind =
156 eprosima::fastrtps::BEST_EFFORT_RELIABILITY_QOS;
157 break;
158 case QosReliabilityPolicy::RELIABILITY_RELIABLE:
159 sub_attr->qos.m_reliability.kind =
160 eprosima::fastrtps::RELIABLE_RELIABILITY_QOS;
161 break;
162 default:
163 break;
164 }
165
167 sub_attr->topic.historyQos.depth = static_cast<int32_t>(qos.depth());
168 }
169
170 // ensure the history depth is at least the requested queue size
171 if (sub_attr->topic.historyQos.depth < 0) {
172 return false;
173 }
174
175 sub_attr->historyMemoryPolicy =
176 eprosima::fastrtps::rtps::DYNAMIC_RESERVE_MEMORY_MODE;
177 sub_attr->topic.resourceLimitsQos.max_samples = 10000;
178
179 return true;
180}
181
182} // namespace transport
183} // namespace cyber
184} // namespace apollo
static bool FillInSubAttr(const std::string &channel_name, const QosProfile &qos, eprosima::fastrtps::SubscriberAttributes *sub_attr)
static bool FillInPubAttr(const std::string &channel_name, const QosProfile &qos, eprosima::fastrtps::PublisherAttributes *pub_attr)
static const uint32_t QOS_HISTORY_DEPTH_SYSTEM_DEFAULT
#define RETURN_VAL_IF_NULL(ptr, val)
Definition log.h:98
class register implement
Definition arena_queue.h:37
optional QosHistoryPolicy history
optional QosDurabilityPolicy durability
optional QosReliabilityPolicy reliability