Apollo 10.0
自动驾驶开放平台
gear_command_103.cc
浏览该文件的文档.
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
18
20
21namespace apollo {
22namespace canbus {
23namespace devkit {
24
25using ::apollo::drivers::canbus::Byte;
26
27const int32_t Gearcommand103::ID = 0x103;
28
29// public
31
32void Gearcommand103::Parse(const std::uint8_t* bytes, int32_t length,
33 Devkit* chassis) const {
34 chassis->mutable_gear_command_103()->set_gear_target(
35 gear_target(bytes, length));
36 chassis->mutable_gear_command_103()->set_gear_en_ctrl(
37 gear_en_ctrl(bytes, length));
38 chassis->mutable_gear_command_103()->set_checksum_103(
39 checksum_103(bytes, length));
40}
41
42uint32_t Gearcommand103::GetPeriod() const {
43 // TODO(All) : modify every protocol's period manually
44 static const uint32_t PERIOD = 20 * 1000;
45 return PERIOD;
46}
47
48void Gearcommand103::UpdateData(uint8_t* data) {
49 set_p_gear_target(data, gear_target_);
50 set_p_gear_en_ctrl(data, gear_en_ctrl_);
51 checksum_103_ =
52 data[0] ^ data[1] ^ data[2] ^ data[3] ^ data[4] ^ data[5] ^ data[6];
53 set_p_checksum_103(data, checksum_103_);
54}
55
57 // TODO(All) : you should check this manually
60 checksum_103_ = 0;
61}
62
65 gear_target_ = gear_target;
66 return this;
67}
68
69// config detail: {'name': 'Gear_Target', 'enum': {0: 'GEAR_TARGET_INVALID', 1:
70// 'GEAR_TARGET_PARK', 2: 'GEAR_TARGET_REVERSE', 3: 'GEAR_TARGET_NEUTRAL', 4:
71// 'GEAR_TARGET_DRIVE'}, 'precision': 1.0, 'len': 3, 'is_signed_var': False,
72// 'offset': 0.0, 'physical_range': '[0|4]', 'bit': 10, 'type': 'enum', 'order':
73// 'motorola', 'physical_unit': ''}
74void Gearcommand103::set_p_gear_target(
75 uint8_t* data, Gear_command_103::Gear_targetType gear_target) {
76 int x = gear_target;
77
78 Byte to_set(data + 1);
79 to_set.set_value(x, 0, 3);
80}
81
84 gear_en_ctrl_ = gear_en_ctrl;
85 return this;
86}
87
88// config detail: {'name': 'Gear_EN_CTRL', 'enum': {0: 'GEAR_EN_CTRL_DISABLE',
89// 1: 'GEAR_EN_CTRL_ENABLE'}, 'precision': 1.0, 'len': 1, 'is_signed_var':
90// False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 0, 'type': 'enum',
91// 'order': 'motorola', 'physical_unit': ''}
92void Gearcommand103::set_p_gear_en_ctrl(
93 uint8_t* data, Gear_command_103::Gear_en_ctrlType gear_en_ctrl) {
94 int x = gear_en_ctrl;
95
96 Byte to_set(data + 0);
97 to_set.set_value(x, 0, 1);
98}
99
101 checksum_103_ = checksum_103;
102 return this;
103}
104
105// config detail: {'name': 'CheckSum_103', 'offset': 0.0, 'precision': 1.0,
106// 'len': 8, 'is_signed_var': False, 'physical_range': '[0|255]', 'bit': 63,
107// 'type': 'int', 'order': 'motorola', 'physical_unit': ''}
108void Gearcommand103::set_p_checksum_103(uint8_t* data, int checksum_103) {
109 checksum_103 = ProtocolData::BoundedValue(0, 255, checksum_103);
110 int x = checksum_103;
111
112 Byte to_set(data + 7);
113 to_set.set_value(x, 0, 8);
114}
115
116Gear_command_103::Gear_targetType Gearcommand103::gear_target(
117 const std::uint8_t* bytes, int32_t length) const {
118 Byte t0(bytes + 1);
119 int32_t x = t0.get_byte(0, 3);
120
122 static_cast<Gear_command_103::Gear_targetType>(x);
123 return ret;
124}
125
126Gear_command_103::Gear_en_ctrlType Gearcommand103::gear_en_ctrl(
127 const std::uint8_t* bytes, int32_t length) const {
128 Byte t0(bytes + 0);
129 int32_t x = t0.get_byte(0, 1);
130
133 return ret;
134}
135
136int Gearcommand103::checksum_103(const std::uint8_t* bytes,
137 int32_t length) const {
138 Byte t0(bytes + 7);
139 int32_t x = t0.get_byte(0, 8);
140
141 int ret = x;
142 return ret;
143}
144
145} // namespace devkit
146} // namespace canbus
147} // namespace apollo
Defines the Byte class.
Gearcommand103 * set_gear_en_ctrl(Gear_command_103::Gear_en_ctrlType gear_en_ctrl)
Gearcommand103 * set_gear_target(Gear_command_103::Gear_targetType gear_target)
void UpdateData(uint8_t *data) override
Gearcommand103 * set_checksum_103(int checksum_103)
void Parse(const std::uint8_t *bytes, int32_t length, Devkit *chassis) const override
class register implement
Definition arena_queue.h:37