Apollo 10.0
自动驾驶开放平台
fuellevel_72.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 Fuellevel72::ID = 0x72;
28
29void Fuellevel72::Parse(const std::uint8_t *bytes, int32_t length,
30 Lincoln *chassis_detail) const {
31 chassis_detail->mutable_battery()->set_fuel_level(fuel_level(bytes, length));
32}
33
34double Fuellevel72::fuel_level(const std::uint8_t *bytes,
35 int32_t length) const {
36 Byte high_frame(bytes + 1);
37 int32_t high = high_frame.get_byte(0, 8);
38 Byte low_frame(bytes);
39 int32_t low = low_frame.get_byte(0, 8);
40 int32_t value = (high << 8) | low;
41 if (value > 0x7FFF) {
42 value -= 0x10000;
43 }
44 // should be in range of
45 // [0x0000, 0x0398]
46 // or [0xfc68, 0xffff]
47 const double fuel_level_coeff = 0.108696;
48 return value * fuel_level_coeff;
49}
50
51} // namespace lincoln
52} // namespace canbus
53} // namespace apollo
Defines the Byte class.
virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const
the class of (Fuellevel72) for lincoln vehicle)
class register implement
Definition arena_queue.h:37