Apollo 10.0
自动驾驶开放平台
park_command_104.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 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
20
21namespace apollo {
22namespace canbus {
23namespace demo {
24
25using ::apollo::drivers::canbus::Byte;
26
27const int32_t Parkcommand104::ID = 0x104;
28
29// public
31
32uint32_t Parkcommand104::GetPeriod() const {
33 // TODO(All) : modify every protocol's period manually
34 static const uint32_t PERIOD = 20 * 1000;
35 return PERIOD;
36}
37
38void Parkcommand104::Parse(const std::uint8_t* bytes, int32_t length,
39 Demo* chassis) const {
40 chassis->mutable_park_command_104()->set_heartbeat_104(
41 heartbeat_104(bytes, length));
42 chassis->mutable_park_command_104()->set_checksum_104(
43 checksum_104(bytes, length));
44 chassis->mutable_park_command_104()->set_park_target(
45 park_target(bytes, length));
46 chassis->mutable_park_command_104()->set_park_en_ctrl(
47 park_en_ctrl(bytes, length));
48}
49
51 // TODO(All) : you should add the heartbeat manually
52 ++heartbeat_104_;
53 heartbeat_104_ = (heartbeat_104_) % 16;
54 set_p_heartbeat_104(data, heartbeat_104_);
55 checksum_104_ =
56 data[0] ^ data[1] ^ data[2] ^ data[3] ^ data[4] ^ data[5] ^ data[6];
57 set_p_checksum_104(data, checksum_104_);
58}
59
60void Parkcommand104::UpdateData(uint8_t* data) {
61 set_p_park_target(data, park_target_);
62 set_p_park_en_ctrl(data, park_en_ctrl_);
63}
64
66 // TODO(All) : you should check this manually
67 heartbeat_104_ = 0;
68 checksum_104_ = 0;
71}
72
74 heartbeat_104_ = heartbeat_104;
75 return this;
76}
77
78// config detail: {'bit': 7, 'is_signed_var': False, 'len': 4, 'name':
79// 'Heartbeat_104', 'offset': 0.0, 'order': 'motorola', 'physical_range':
80// '[0|15]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
81void Parkcommand104::set_p_heartbeat_104(uint8_t* data, int heartbeat_104) {
82 heartbeat_104 = ProtocolData::BoundedValue(0, 15, heartbeat_104);
83 int x = heartbeat_104;
84
85 Byte to_set(data + 0);
86 to_set.set_value(x, 4, 4);
87}
88
90 checksum_104_ = checksum_104;
91 return this;
92}
93
94// config detail: {'bit': 63, 'is_signed_var': False, 'len': 8, 'name':
95// 'CheckSum_104', 'offset': 0.0, 'order': 'motorola', 'physical_range':
96// '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
97void Parkcommand104::set_p_checksum_104(uint8_t* data, int checksum_104) {
98 checksum_104 = ProtocolData::BoundedValue(0, 255, checksum_104);
99 int x = checksum_104;
100
101 Byte to_set(data + 7);
102 to_set.set_value(x, 0, 8);
103}
104
107 park_target_ = park_target;
108 return this;
109}
110
111// config detail: {'bit': 8, 'description': 'command', 'enum': {0:
112// 'PARK_TARGET_RELEASE', 1: 'PARK_TARGET_PARKING_TRIGGER'}, 'is_signed_var':
113// False, 'len': 1, 'name': 'Park_Target', 'offset': 0.0, 'order': 'motorola',
114// 'physical_range': '[0|1]', 'physical_unit': '', 'precision': 1.0,
115// 'signal_type': 'command', 'type': 'enum'}
116void Parkcommand104::set_p_park_target(
117 uint8_t* data, Park_command_104::Park_targetType park_target) {
118 int x = park_target;
119
120 Byte to_set(data + 1);
121 to_set.set_value(x, 0, 1);
122}
123
126 park_en_ctrl_ = park_en_ctrl;
127 return this;
128}
129
130// config detail: {'bit': 0, 'description': 'enable', 'enum': {0:
131// 'PARK_EN_CTRL_DISABLE', 1: 'PARK_EN_CTRL_ENABLE'}, 'is_signed_var': False,
132// 'len': 1, 'name': 'Park_EN_CTRL', 'offset': 0.0, 'order': 'motorola',
133// 'physical_range': '[0|1]', 'physical_unit': '', 'precision': 1.0,
134// 'signal_type': 'enable', 'type': 'enum'}
135void Parkcommand104::set_p_park_en_ctrl(
136 uint8_t* data, Park_command_104::Park_en_ctrlType park_en_ctrl) {
137 int x = park_en_ctrl;
138
139 Byte to_set(data + 0);
140 to_set.set_value(x, 0, 1);
141}
142
143int Parkcommand104::heartbeat_104(const std::uint8_t* bytes,
144 int32_t length) const {
145 Byte t0(bytes + 0);
146 int32_t x = t0.get_byte(4, 4);
147
148 int ret = x;
149 return ret;
150}
151
152int Parkcommand104::checksum_104(const std::uint8_t* bytes,
153 int32_t length) const {
154 Byte t0(bytes + 7);
155 int32_t x = t0.get_byte(0, 8);
156
157 int ret = x;
158 return ret;
159}
160
161Park_command_104::Park_targetType Parkcommand104::park_target(
162 const std::uint8_t* bytes, int32_t length) const {
163 Byte t0(bytes + 1);
164 int32_t x = t0.get_byte(0, 1);
165
167 static_cast<Park_command_104::Park_targetType>(x);
168 return ret;
169}
170
171Park_command_104::Park_en_ctrlType Parkcommand104::park_en_ctrl(
172 const std::uint8_t* bytes, int32_t length) const {
173 Byte t0(bytes + 0);
174 int32_t x = t0.get_byte(0, 1);
175
178 return ret;
179}
180} // namespace demo
181} // namespace canbus
182} // namespace apollo
Defines the Byte class.
void UpdateData_Heartbeat(uint8_t *data) override
void UpdateData(uint8_t *data) override
Parkcommand104 * set_heartbeat_104(int heartbeat_104)
Parkcommand104 * set_park_en_ctrl(Park_command_104::Park_en_ctrlType park_en_ctrl)
uint32_t GetPeriod() const override
Parkcommand104 * set_park_target(Park_command_104::Park_targetType park_target)
Parkcommand104 * set_checksum_104(int checksum_104)
void Parse(const std::uint8_t *bytes, int32_t length, Demo *chassis) const override
class register implement
Definition arena_queue.h:37