Apollo 10.0
自动驾驶开放平台
gear_67.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 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 lincoln {
24
25using ::apollo::drivers::canbus::Byte;
26
27const int32_t Gear67::ID = 0x67;
28
29void Gear67::Parse(const std::uint8_t *bytes, int32_t length,
30 Lincoln *chassis_detail) const {
31 int32_t gear = gear_state(bytes, length);
32 switch (gear) {
33 case 0x01:
34 chassis_detail->mutable_gear()->set_gear_state(Chassis::GEAR_PARKING);
35 break;
36 case 0x02:
37 chassis_detail->mutable_gear()->set_gear_state(Chassis::GEAR_REVERSE);
38 break;
39 case 0x03:
40 chassis_detail->mutable_gear()->set_gear_state(Chassis::GEAR_NEUTRAL);
41 break;
42 case 0x04:
43 chassis_detail->mutable_gear()->set_gear_state(Chassis::GEAR_DRIVE);
44 break;
45 case 0x05:
46 chassis_detail->mutable_gear()->set_gear_state(Chassis::GEAR_LOW);
47 break;
48 case 0x00:
49 chassis_detail->mutable_gear()->set_gear_state(Chassis::GEAR_NONE);
50 break;
51 default:
52 chassis_detail->mutable_gear()->set_gear_state(Chassis::GEAR_INVALID);
53 break;
54 }
55
56 if (is_driver_override(bytes, length)) {
57 // last shift requested by driver
58 chassis_detail->mutable_gear()->set_is_shift_position_valid(false);
59 } else {
60 // last shift requested by-wire
61 chassis_detail->mutable_gear()->set_is_shift_position_valid(true);
62 }
63 chassis_detail->mutable_gear()->set_driver_override(
64 is_driver_override(bytes, length));
65
66 int32_t gear_cmd = reported_gear_cmd(bytes, length);
67 switch (gear_cmd) {
68 case 0x01:
69 chassis_detail->mutable_gear()->set_gear_cmd(Chassis::GEAR_PARKING);
70 break;
71 case 0x02:
72 chassis_detail->mutable_gear()->set_gear_cmd(Chassis::GEAR_REVERSE);
73 break;
74 case 0x03:
75 chassis_detail->mutable_gear()->set_gear_cmd(Chassis::GEAR_NEUTRAL);
76 break;
77 case 0x04:
78 chassis_detail->mutable_gear()->set_gear_cmd(Chassis::GEAR_DRIVE);
79 break;
80 case 0x05:
81 chassis_detail->mutable_gear()->set_gear_cmd(Chassis::GEAR_LOW);
82 break;
83 case 0x00:
84 chassis_detail->mutable_gear()->set_gear_cmd(Chassis::GEAR_NONE);
85 break;
86 default:
87 chassis_detail->mutable_gear()->set_gear_cmd(Chassis::GEAR_INVALID);
88 break;
89 }
90
91 chassis_detail->mutable_gear()->set_canbus_fault(
92 is_canbus_fault(bytes, length));
93}
94
95int32_t Gear67::gear_state(const std::uint8_t *bytes, int32_t length) const {
96 Byte frame(bytes + 0);
97 int32_t x = frame.get_byte(0, 3);
98 return x;
99}
100
101bool Gear67::is_driver_override(const std::uint8_t *bytes,
102 int32_t length) const {
103 Byte frame(bytes + 0);
104 return frame.is_bit_1(3);
105}
106
107int32_t Gear67::reported_gear_cmd(const std::uint8_t *bytes,
108 int32_t length) const {
109 Byte frame(bytes + 0);
110 int32_t x = frame.get_byte(4, 3);
111 return x;
112}
113
114bool Gear67::is_canbus_fault(const std::uint8_t *bytes, int32_t length) const {
115 Byte frame(bytes + 0);
116 return frame.is_bit_1(7);
117}
118
119} // namespace lincoln
120} // namespace canbus
121} // namespace apollo
Defines the Byte class.
virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const
Definition gear_67.cc:29
bool is_driver_override(const std::uint8_t *bytes, int32_t length) const
check driver override from byte array config detail: {'name': 'driver', 'offset': 0....
Definition gear_67.cc:101
int32_t gear_state(const std::uint8_t *bytes, int32_t length) const
get the gear state from byte array config detail: {'name': 'state', 'offset': 0.0,...
Definition gear_67.cc:95
int32_t reported_gear_cmd(const std::uint8_t *bytes, int32_t length) const
get reported gear command from byte array config detail: {'name': 'cmd', 'offset': 0....
Definition gear_67.cc:107
static const int32_t ID
Definition gear_67.h:43
bool is_canbus_fault(const std::uint8_t *bytes, int32_t length) const
check canbus fault from byte array config detail: {'name': 'fltbus', 'offset': 0.0,...
Definition gear_67.cc:114
the class of Gear67 (for lincoln vehicle)
class register implement
Definition arena_queue.h:37