Apollo 10.0
自动驾驶开放平台
bms_report_512.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
19#include "glog/logging.h"
20
23
24namespace apollo {
25namespace canbus {
26namespace devkit {
27
28using ::apollo::drivers::canbus::Byte;
29
31const int32_t Bmsreport512::ID = 0x512;
32
33void Bmsreport512::Parse(const std::uint8_t* bytes, int32_t length,
34 Devkit* chassis) const {
35 chassis->mutable_bms_report_512()->set_battery_current(
36 battery_current(bytes, length));
37 chassis->mutable_bms_report_512()->set_battery_voltage(
38 battery_voltage(bytes, length));
39 chassis->mutable_bms_report_512()->set_battery_soc_percentage(
40 battery_soc_percentage(bytes, length));
41 chassis->mutable_bms_report_512()->set_is_battery_soc_low(
42 battery_soc_percentage(bytes, length) <= 15);
43 chassis->mutable_bms_report_512()->set_battery_inside_temperature(
44 battery_inside_temperature(bytes, length));
45 chassis->mutable_bms_report_512()->set_battery_flt_low_temp(
46 battery_flt_low_temp(bytes, length));
47 chassis->mutable_bms_report_512()->set_battery_flt_over_temp(
48 battery_flt_over_temp(bytes, length));
49}
50
51// config detail: {'bit': 23, 'description': 'Battery Total Current',
52// 'is_signed_var': False, 'len': 16, 'name': 'battery_current', 'offset':
53// -3200.0, 'order': 'motorola', 'physical_range': '[-3200|3200]',
54// 'physical_unit': 'A', 'precision': 0.1, 'type': 'double'}
55double Bmsreport512::battery_current(const std::uint8_t* bytes,
56 int32_t length) const {
57 Byte t0(bytes + 2);
58 int32_t x = t0.get_byte(0, 8);
59
60 Byte t1(bytes + 3);
61 int32_t t = t1.get_byte(0, 8);
62 x <<= 8;
63 x |= t;
64
65 double ret = x * 0.100000 + -3200.000000;
66 return ret;
67}
68
69// config detail: {'bit': 7, 'description': 'Battery Total Voltage',
70// 'is_signed_var': False, 'len': 16, 'name': 'battery_voltage', 'offset': 0.0,
71// 'order': 'motorola', 'physical_range': '[0|300]', 'physical_unit': 'V',
72// 'precision': 0.01, 'type': 'double'}
73double Bmsreport512::battery_voltage(const std::uint8_t* bytes,
74 int32_t length) const {
75 Byte t0(bytes + 0);
76 int32_t x = t0.get_byte(0, 8);
77
78 Byte t1(bytes + 1);
79 int32_t t = t1.get_byte(0, 8);
80 x <<= 8;
81 x |= t;
82
83 double ret = x * 0.010000;
84 return ret;
85}
86
87// config detail: {'bit': 39, 'description': 'Battery Soc percentage',
88// 'is_signed_var': False, 'len': 8, 'name': 'battery_soc_percentage', 'offset':
89// 0.0, 'order': 'motorola', 'physical_range': '[0|100]', 'physical_unit': '%',
90// 'precision': 1.0, 'type': 'int'}
91int Bmsreport512::battery_soc_percentage(const std::uint8_t* bytes,
92 int32_t length) const {
93 Byte t0(bytes + 4);
94 int32_t x = t0.get_byte(0, 8);
95
96 int ret = x;
97 return ret;
98}
99
100// config detail: {'bit': 40, 'description': 'Battery Inside temperature',
101// 'is_signed_var': False, 'len': 1, 'name': 'Battery_Inside_Temperature',
102// 'offset': -40, 'order': 'motorola', 'physical_range': '[-40|215]',
103// 'physical_unit': 'C', 'precision': 1.0, 'type': 'int'}
104int Bmsreport512::battery_inside_temperature(const std::uint8_t* bytes,
105 const int32_t length) const {
106 Byte t0(bytes + 5);
107 int32_t x = t0.get_byte(0, 8);
108
109 int ret = x - 40;
110 return ret;
111}
112
113// config detail: {'description': 'Battery Below Low temp fault', 'enum':
114// {0: 'BATTERY_FLT_LOW_TEMP_NO_FAULT', 1:
115// 'BATTERY_FLT_LOW_TEMP_FAULT'}, 'precision': 1.0, 'len': 1,
116// 'name': 'Brake_FLT2', 'is_signed_var': False, 'offset': 0.0,
117// 'physical_range': '[0|1]', 'bit': 48, 'type': 'enum', 'order': 'motorola',
118// 'physical_unit': ''}
119Bms_report_512::Battery_flt_lowtempType Bmsreport512::battery_flt_low_temp(
120 const std::uint8_t* bytes, const int32_t length) const {
121 Byte t0(bytes + 6);
122 int32_t x = t0.get_byte(0, 1);
123
126 return ret;
127}
128// config detail: {'description': 'Battery Over High Temp fault', 'enum':
129// {0: 'BATTERY_FLT_OVER_TEMP_NO_FAULT', 1:
130// 'BATTERY_FLT_OVER_TEMP_FAULT'}, 'precision': 1.0, 'len': 1,
131// 'name': 'Brake_FLT2', 'is_signed_var': False, 'offset': 0.0,
132// 'physical_range': '[0|1]', 'bit': 49, 'type': 'enum', 'order': 'motorola',
133// 'physical_unit': ''}
134Bms_report_512::Battery_flt_overtempType Bmsreport512::battery_flt_over_temp(
135 const std::uint8_t* bytes, const int32_t length) const {
136 Byte t0(bytes + 6);
137 int32_t x = t0.get_byte(1, 1);
138
141 return ret;
142}
143} // namespace devkit
144} // namespace canbus
145} // namespace apollo
Defines the Byte class.
void Parse(const std::uint8_t *bytes, int32_t length, Devkit *chassis) const override
class register implement
Definition arena_queue.h:37