Apollo 10.0
自动驾驶开放平台
gear_command_103.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 Gearcommand103::ID = 0x103;
28
29// public
31
32uint32_t Gearcommand103::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 Gearcommand103::Parse(const std::uint8_t* bytes, int32_t length,
39 Demo* chassis) const {
40 chassis->mutable_gear_command_103()->set_heartbeat_103(
41 heartbeat_103(bytes, length));
42 chassis->mutable_gear_command_103()->set_gear_target(
43 gear_target(bytes, length));
44 chassis->mutable_gear_command_103()->set_gear_en_ctrl(
45 gear_en_ctrl(bytes, length));
46 chassis->mutable_gear_command_103()->set_checksum_103(
47 checksum_103(bytes, length));
48}
49
51 // TODO(All) : you should add the heartbeat manually
52 ++heartbeat_103_;
53 heartbeat_103_ = (heartbeat_103_) % 16;
54 set_p_heartbeat_103(data, heartbeat_103_);
55 checksum_103_ =
56 data[0] ^ data[1] ^ data[2] ^ data[3] ^ data[4] ^ data[5] ^ data[6];
57 set_p_checksum_103(data, checksum_103_);
58}
59
60void Gearcommand103::UpdateData(uint8_t* data) {
61 set_p_gear_target(data, gear_target_);
62 set_p_gear_en_ctrl(data, gear_en_ctrl_);
63}
64
66 // TODO(All) : you should check this manually
67 heartbeat_103_ = 0;
70 checksum_103_ = 0;
71}
72
74 heartbeat_103_ = heartbeat_103;
75 return this;
76}
77
78// config detail: {'bit': 7, 'is_signed_var': False, 'len': 4, 'name':
79// 'Heartbeat_103', 'offset': 0.0, 'order': 'motorola', 'physical_range':
80// '[0|15]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
81void Gearcommand103::set_p_heartbeat_103(uint8_t* data, int heartbeat_103) {
82 heartbeat_103 = ProtocolData::BoundedValue(0, 15, heartbeat_103);
83 int x = heartbeat_103;
84
85 Byte to_set(data + 0);
86 to_set.set_value(x, 4, 4);
87}
88
91 gear_target_ = gear_target;
92 return this;
93}
94
95// config detail: {'bit': 10, 'description': 'command', 'enum': {0:
96// 'GEAR_TARGET_INVALID', 1: 'GEAR_TARGET_PARK', 2: 'GEAR_TARGET_REVERSE', 3:
97// 'GEAR_TARGET_NEUTRAL', 4: 'GEAR_TARGET_DRIVE'}, 'is_signed_var': False,
98// 'len': 3, 'name': 'Gear_Target', 'offset': 0.0, 'order': 'motorola',
99// 'physical_range': '[0|4]', 'physical_unit': '', 'precision': 1.0,
100// 'signal_type': 'command', 'type': 'enum'}
101void Gearcommand103::set_p_gear_target(
102 uint8_t* data, Gear_command_103::Gear_targetType gear_target) {
103 int x = gear_target;
104
105 Byte to_set(data + 1);
106 to_set.set_value(x, 0, 3);
107}
108
111 gear_en_ctrl_ = gear_en_ctrl;
112 return this;
113}
114
115// config detail: {'bit': 0, 'description': 'enable', 'enum': {0:
116// 'GEAR_EN_CTRL_DISABLE', 1: 'GEAR_EN_CTRL_ENABLE'}, 'is_signed_var': False,
117// 'len': 1, 'name': 'Gear_EN_CTRL', 'offset': 0.0, 'order': 'motorola',
118// 'physical_range':
119// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'signal_type': 'enable',
120// 'type': 'enum'}
121void Gearcommand103::set_p_gear_en_ctrl(
122 uint8_t* data, Gear_command_103::Gear_en_ctrlType gear_en_ctrl) {
123 int x = gear_en_ctrl;
124
125 Byte to_set(data + 0);
126 to_set.set_value(x, 0, 1);
127}
128
130 checksum_103_ = checksum_103;
131 return this;
132}
133
134// config detail: {'bit': 63, 'is_signed_var': False, 'len': 8, 'name':
135// 'CheckSum_103', 'offset': 0.0, 'order': 'motorola', 'physical_range':
136// '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
137void Gearcommand103::set_p_checksum_103(uint8_t* data, int checksum_103) {
138 checksum_103 = ProtocolData::BoundedValue(0, 255, checksum_103);
139 int x = checksum_103;
140
141 Byte to_set(data + 7);
142 to_set.set_value(x, 0, 8);
143}
144
145int Gearcommand103::heartbeat_103(const std::uint8_t* bytes,
146 int32_t length) const {
147 Byte t0(bytes + 0);
148 int32_t x = t0.get_byte(4, 4);
149
150 int ret = x;
151 return ret;
152}
153
154Gear_command_103::Gear_targetType Gearcommand103::gear_target(
155 const std::uint8_t* bytes, int32_t length) const {
156 Byte t0(bytes + 1);
157 int32_t x = t0.get_byte(0, 3);
158
160 static_cast<Gear_command_103::Gear_targetType>(x);
161 return ret;
162}
163
164Gear_command_103::Gear_en_ctrlType Gearcommand103::gear_en_ctrl(
165 const std::uint8_t* bytes, int32_t length) const {
166 Byte t0(bytes + 0);
167 int32_t x = t0.get_byte(0, 1);
168
171 return ret;
172}
173
174int Gearcommand103::checksum_103(const std::uint8_t* bytes,
175 int32_t length) const {
176 Byte t0(bytes + 7);
177 int32_t x = t0.get_byte(0, 8);
178
179 int ret = x;
180 return ret;
181}
182} // namespace demo
183} // namespace canbus
184} // namespace apollo
Defines the Byte class.
Gearcommand103 * set_heartbeat_103(int heartbeat_103)
void UpdateData_Heartbeat(uint8_t *data) override
uint32_t GetPeriod() const override
Gearcommand103 * set_checksum_103(int checksum_103)
Gearcommand103 * set_gear_en_ctrl(Gear_command_103::Gear_en_ctrlType gear_en_ctrl)
void Parse(const std::uint8_t *bytes, int32_t length, Demo *chassis) const override
void UpdateData(uint8_t *data) override
Gearcommand103 * set_gear_target(Gear_command_103::Gear_targetType gear_target)
class register implement
Definition arena_queue.h:37