Apollo 10.0
自动驾驶开放平台
pc_bcs_202.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
19
20namespace apollo {
21namespace canbus {
22namespace ge3 {
23
24using ::apollo::drivers::canbus::Byte;
25
26const int32_t Pcbcs202::ID = 0x202;
27
28// public
30
31uint32_t Pcbcs202::GetPeriod() const {
32 // modify every protocol's period manually
33 static const uint32_t PERIOD = 20 * 1000;
34 return PERIOD;
35}
36
37void Pcbcs202::UpdateData(uint8_t* data) {
38 set_p_pc_brkpedreq(data, pc_brkpedreq_);
39 set_p_pc_brkpedenable(data, pc_brkpedenable_);
40}
41
43 // you should check this manually
44 pc_brkpedreq_ = 0.0;
45 pc_brkpedenable_ = Pc_bcs_202::PC_BRKPEDENABLE_DISABLE;
46}
47
48Pcbcs202* Pcbcs202::set_pc_brkpedreq(double pc_brkpedreq) {
49 pc_brkpedreq_ = pc_brkpedreq;
50 return this;
51}
52
53// config detail: {'description': 'Brake pedal request', 'offset': 0.0,
54// 'precision': 0.1, 'len': 10, 'name': 'PC_BrkPedReq', 'is_signed_var': False,
55// 'physical_range': '[0|100]', 'bit': 1, 'type': 'double', 'order': 'motorola',
56// 'physical_unit': '%'}
57void Pcbcs202::set_p_pc_brkpedreq(uint8_t* data, double pc_brkpedreq) {
58 pc_brkpedreq = ProtocolData::BoundedValue(0.0, 100.0, pc_brkpedreq);
59 int x = static_cast<int>(pc_brkpedreq / 0.100000);
60 uint8_t t = 0;
61
62 t = static_cast<uint8_t>(x & 0xFF);
63 Byte to_set0(data + 1);
64 to_set0.set_value(t, 0, 8);
65 x >>= 8;
66
67 t = x & 0x3;
68 Byte to_set1(data + 0);
69 to_set1.set_value(t, 0, 2);
70}
71
73 Pc_bcs_202::Pc_brkpedenableType pc_brkpedenable) {
74 pc_brkpedenable_ = pc_brkpedenable;
75 return this;
76}
77
78// config detail: {'description': 'Brake pedal control enable', 'enum': {0:
79// 'PC_BRKPEDENABLE_DISABLE', 1: 'PC_BRKPEDENABLE_ENABLE'}, 'precision': 1.0,
80// 'len': 1, 'name': 'PC_BrkPedEnable', 'is_signed_var': False, 'offset': 0.0,
81// 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': 'motorola',
82// 'physical_unit': ''}
83void Pcbcs202::set_p_pc_brkpedenable(
84 uint8_t* data, Pc_bcs_202::Pc_brkpedenableType pc_brkpedenable) {
85 int x = pc_brkpedenable;
86
87 Byte to_set(data + 0);
88 to_set.set_value(static_cast<uint8_t>(x), 7, 1);
89}
90
91} // namespace ge3
92} // namespace canbus
93} // namespace apollo
Defines the Byte class.
Pcbcs202 * set_pc_brkpedenable(Pc_bcs_202::Pc_brkpedenableType pc_brkpedenable)
Definition pc_bcs_202.cc:72
Pcbcs202 * set_pc_brkpedreq(double pc_brkpedreq)
Definition pc_bcs_202.cc:48
void UpdateData(uint8_t *data) override
Definition pc_bcs_202.cc:37
static const int32_t ID
Definition pc_bcs_202.h:29
uint32_t GetPeriod() const override
Definition pc_bcs_202.cc:31
class register implement
Definition arena_queue.h:37