Apollo 10.0
自动驾驶开放平台
ecu_status_2_516.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 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#include "glog/logging.h"
21
22namespace apollo {
23namespace canbus {
24namespace ch {
25
26using ::apollo::drivers::canbus::Byte;
27
29const int32_t Ecustatus2516::ID = 0x516;
30
31void Ecustatus2516::Parse(const std::uint8_t* bytes, int32_t length,
32 Ch* chassis) const {
33 chassis->mutable_ecu_status_2_516()->set_battery_soc(
34 battery_soc(bytes, length));
35 chassis->mutable_ecu_status_2_516()->set_battery_capacity(
36 battery_capacity(bytes, length));
37 chassis->mutable_ecu_status_2_516()->set_battery_voltage(
38 battery_voltage(bytes, length));
39 chassis->mutable_ecu_status_2_516()->set_battery_current(
40 battery_current(bytes, length));
41 chassis->mutable_ecu_status_2_516()->set_battery_temperature(
42 battery_temperature(bytes, length));
43 chassis->mutable_ecu_status_2_516()->set_is_battery_soc_low(
44 battery_soc(bytes, length) <= 15);
45}
46
47// config detail: {'bit': 0, 'description': 'Percentage of battery remaining
48// (BMS status)', 'is_signed_var': False, 'len': 8, 'name': 'battery_soc',
49// 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|100]',
50// 'physical_unit': '%', 'precision': 1.0, 'type': 'int'}
51int Ecustatus2516::battery_soc(const std::uint8_t* bytes,
52 int32_t length) const {
53 Byte t0(bytes + 0);
54 int32_t x = t0.get_byte(0, 8);
55
56 int ret = x;
57 return ret;
58}
59
60// config detail: {'bit': 8, 'description': 'Battery full capacity (BMS
61// status)', 'is_signed_var': False, 'len': 8, 'name': 'battery_capacity',
62// 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|100]',
63// 'physical_unit': 'Ah', 'precision': 1.0, 'type': 'int'}
64int Ecustatus2516::battery_capacity(const std::uint8_t* bytes,
65 int32_t length) const {
66 Byte t0(bytes + 1);
67 int32_t x = t0.get_byte(0, 8);
68
69 int ret = x;
70 return ret;
71}
72
73// config detail: {'bit': 16, 'description': 'Current battery voltage (BMS
74// status)', 'is_signed_var': False, 'len': 16, 'name': 'battery_voltage',
75// 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|80]', 'physical_unit':
76// 'V', 'precision': 0.1, 'type': 'double'}
77double Ecustatus2516::battery_voltage(const std::uint8_t* bytes,
78 int32_t length) const {
79 Byte t0(bytes + 3);
80 int32_t x = t0.get_byte(0, 8);
81
82 Byte t1(bytes + 2);
83 int32_t t = t1.get_byte(0, 8);
84 x <<= 8;
85 x |= t;
86
87 double ret = x * 0.100000;
88 return ret;
89}
90
91// config detail: {'bit': 32, 'description': 'Current battery current (BMS
92// status)', 'is_signed_var': True, 'len': 16, 'name': 'battery_current',
93// 'offset': 0.0, 'order': 'intel', 'physical_range': '[-60|60]',
94// 'physical_unit': 'A', 'precision': 0.1, 'type': 'double'}
95double Ecustatus2516::battery_current(const std::uint8_t* bytes,
96 int32_t length) const {
97 Byte t0(bytes + 5);
98 int32_t x = t0.get_byte(0, 8);
99
100 Byte t1(bytes + 4);
101 int32_t t = t1.get_byte(0, 8);
102 x <<= 8;
103 x |= t;
104
105 x <<= 16;
106 x >>= 16;
107
108 double ret = x * 0.100000;
109 return ret;
110}
111
112// config detail: {'bit': 48, 'description': 'Current battery temperature (BMS
113// status)', 'is_signed_var': True, 'len': 16, 'name': 'battery_temperature',
114// 'offset': 0.0, 'order': 'intel', 'physical_range': '[-40|110]',
115// 'physical_unit': '℃', 'precision': 1.0, 'type': 'int'}
116int Ecustatus2516::battery_temperature(const std::uint8_t* bytes,
117 int32_t length) const {
118 Byte t0(bytes + 7);
119 int32_t x = t0.get_byte(0, 8);
120
121 Byte t1(bytes + 6);
122 int32_t t = t1.get_byte(0, 8);
123 x <<= 8;
124 x |= t;
125
126 x <<= 16;
127 x >>= 16;
128
129 int ret = x;
130 return ret;
131}
132} // namespace ch
133} // namespace canbus
134} // namespace apollo
Defines the Byte class.
void Parse(const std::uint8_t *bytes, int32_t length, Ch *chassis) const override
class register implement
Definition arena_queue.h:37