repo_id
stringlengths
19
138
file_path
stringlengths
32
200
content
stringlengths
1
12.9M
__index_level_0__
int64
0
0
apollo_public_repos/apollo/modules/canbus_vehicle/devkit
apollo_public_repos/apollo/modules/canbus_vehicle/devkit/protocol/vcu_report_505.cc
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/devkit/protocol/vcu_report_505.h" #include "glog/logging.h" #include "modules/drivers/canbus/common/byte.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace devkit { using ::apollo::drivers::canbus::Byte; Vcureport505::Vcureport505() {} const int32_t Vcureport505::ID = 0x505; void Vcureport505::Parse(const std::uint8_t* bytes, int32_t length, Devkit* chassis) const { chassis->mutable_vcu_report_505()->set_steer_mode_sts( steer_mode_sts(bytes, length)); chassis->mutable_vcu_report_505()->set_brake_light_actual( brake_light_actual(bytes, length)); chassis->mutable_vcu_report_505()->set_acc( acc(bytes, length)); chassis->mutable_vcu_report_505()->set_speed( speed(bytes, length)); chassis->mutable_vcu_report_505()->set_aeb_brake_state( aeb_brake_state(bytes, length)); chassis->mutable_vcu_report_505()->set_frontcrash_state( frontcrash_state(bytes, length)); chassis->mutable_vcu_report_505()->set_backcrash_state( backcrash_state(bytes, length)); chassis->mutable_vcu_report_505()->set_vehicle_mode_state( vehicle_mode_state(bytes, length)); chassis->mutable_vcu_report_505()->set_drive_mode_sts( drive_mode_sts(bytes, length)); chassis->mutable_vcu_report_505()->set_chassis_errcode( chassis_errcode(bytes, length)); chassis->mutable_vcu_report_505()->set_turn_light_actual( turn_light_actual(bytes, length)); chassis->mutable_vcu_report_505()->set_aeb_mode( aeb_mode(bytes, length)); } // config detail: {'bit': 10, 'enum': {0: 'STEER_MODE_STS_STANDARD_STEER_MODE', // 1: 'STEER_MODE_STS_NON_DIRECTION_STEER_MODE', 2: // 'STEER_MODE_STS_SYNC_DIRECTION_STEER_MODE'}, 'is_signed_var': False, 'len': // 3, 'name': 'steer_mode_sts', 'offset': 0.0, 'order': 'motorola', // 'physical_range': '[0|7]', 'physical_unit': '', 'precision': 1.0, 'type': // 'enum'} Vcu_report_505::Steer_mode_stsType Vcureport505::steer_mode_sts( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(0, 3); Vcu_report_505::Steer_mode_stsType ret = static_cast<Vcu_report_505::Steer_mode_stsType>(x); return ret; } // config detail: {'bit': 11, 'enum': {0: 'BRAKE_LIGHT_ACTUAL_BRAKELIGHT_OFF', // 1: 'BRAKE_LIGHT_ACTUAL_BRAKELIGHT_ON'}, 'is_signed_var': False, 'len': 1, // 'name': 'brake_light_actual', 'offset': 0.0, 'order': 'motorola', // 'physical_range': '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': // 'enum'} Vcu_report_505::Brake_light_actualType Vcureport505::brake_light_actual( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(3, 1); Vcu_report_505::Brake_light_actualType ret = static_cast<Vcu_report_505::Brake_light_actualType>(x); return ret; } // config detail: {'bit': 7, 'is_signed_var': True, 'len': 12, 'name': 'acc', // 'offset': 0.0, 'order': 'motorola', 'physical_range': '[-10|10]', // 'physical_unit': 'm/s^2', 'precision': 0.01, 'type': 'double'} double Vcureport505::acc(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 1); int32_t t = t1.get_byte(4, 4); x <<= 4; x |= t; x <<= 20; x >>= 20; double ret = x * 0.010000; return ret; } // config detail: {'bit': 23, 'is_signed_var': True, 'len': 16, 'name': 'speed', // 'offset': 0.0, 'order': 'motorola', 'physical_range': '[-32.768|32.767]', // 'physical_unit': 'm/s', 'precision': 0.001, 'type': 'double'} double Vcureport505::speed(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 2); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 3); int32_t t = t1.get_byte(0, 8); x <<= 8; x |= t; x <<= 16; x >>= 16; double ret = x * 0.001000; return ret; } // config detail: {'bit': 32, 'description': 'describle the vehicle AEB mode // whether was set', 'enum': {0: 'AEB_BRAKE_STATE_INACTIVE', 1: // 'AEB_BRAKE_STATE_ACTIVE'}, 'is_signed_var': False, 'len': 1, 'name': // 'aeb_brake_state', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'} Vcu_report_505::Aeb_brake_stateType Vcureport505::aeb_brake_state( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(0, 1); Vcu_report_505::Aeb_brake_stateType ret = static_cast<Vcu_report_505::Aeb_brake_stateType>(x); return ret; } // config detail: {'bit': 33, 'enum': {0: 'FRONTCRASH_STATE_NO_EVENT', 1: // 'FRONTCRASH_STATE_CRASH_EVENT'}, 'is_signed_var': False, 'len': 1, 'name': // 'frontcrash_state', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'} Vcu_report_505::Frontcrash_stateType Vcureport505::frontcrash_state( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(1, 1); Vcu_report_505::Frontcrash_stateType ret = static_cast<Vcu_report_505::Frontcrash_stateType>(x); return ret; } // config detail: {'bit': 34, 'enum': {0: 'BACKCRASH_STATE_NO_EVENT', 1: // 'BACKCRASH_STATE_CRASH_EVENT'}, 'is_signed_var': False, 'len': 1, 'name': // 'backcrash_state', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'} Vcu_report_505::Backcrash_stateType Vcureport505::backcrash_state( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(2, 1); Vcu_report_505::Backcrash_stateType ret = static_cast<Vcu_report_505::Backcrash_stateType>(x); return ret; } // config detail: {'bit': 36, 'enum': {0: // 'VEHICLE_MODE_STATE_MANUAL_REMOTE_MODE', 1: 'VEHICLE_MODE_STATE_AUTO_MODE', // 2: 'VEHICLE_MODE_STATE_EMERGENCY_MODE', 3: // 'VEHICLE_MODE_STATE_STANDBY_MODE'}, 'is_signed_var': False, 'len': 2, 'name': // 'vehicle_mode_state', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'} Vcu_report_505::Vehicle_mode_stateType Vcureport505::vehicle_mode_state( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(3, 2); Vcu_report_505::Vehicle_mode_stateType ret = static_cast<Vcu_report_505::Vehicle_mode_stateType>(x); return ret; } // config detail: {'bit': 39, 'enum': {0: // 'DRIVE_MODE_STS_THROTTLE_PADDLE_DRIVE_MODE', 1: // 'DRIVE_MODE_STS_SPEED_DRIVE_MODE'}, 'is_signed_var': False, 'len': 3, 'name': // 'drive_mode_sts', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[0|7]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'} Vcu_report_505::Drive_mode_stsType Vcureport505::drive_mode_sts( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(5, 3); Vcu_report_505::Drive_mode_stsType ret = static_cast<Vcu_report_505::Drive_mode_stsType>(x); return ret; } // config detail: {'bit': 47, 'is_signed_var': False, 'len': 8, 'name': // 'chassis_errcode', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'} int Vcureport505::chassis_errcode(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 5); int32_t x = t0.get_byte(0, 8); int ret = x; return ret; } // config detail: {'bit': 57, 'enum': {0: 'TURN_LIGHT_ACTUAL_TURNLAMPSTS_OFF', // 1: 'TURN_LIGHT_ACTUAL_LEFT_TURNLAMPSTS_ON', 2: // 'TURN_LIGHT_ACTUAL_RIGHT_TURNLAMPSTS_ON', 3: // 'TURN_LIGHT_ACTUAL_HAZARD_WARNING_LAMPSTS_ON'}, 'is_signed_var': False, // 'len': 2, 'name': 'turn_light_actual', 'offset': 0.0, 'order': 'motorola', // 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': // 'enum'} Vcu_report_505::Turn_light_actualType Vcureport505::turn_light_actual( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 7); int32_t x = t0.get_byte(0, 2); Vcu_report_505::Turn_light_actualType ret = static_cast<Vcu_report_505::Turn_light_actualType>(x); return ret; } // config detail: {'bit': 58, 'description': 'describe the vehicle e-brake // command whether was triggered by AEB', 'enum': {0: 'AEB_MODE_DISABLE', 1: // 'AEB_MODE_ENABLE'}, 'is_signed_var': False, 'len': 1, 'name': 'aeb_mode', // 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|1]', // 'physical_unit': '', 'precision': 1.0, 'type': 'enum'} Vcu_report_505::Aeb_modeType Vcureport505::aeb_mode(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 7); int32_t x = t0.get_byte(2, 1); Vcu_report_505::Aeb_modeType ret = static_cast<Vcu_report_505::Aeb_modeType>(x); return ret; } } // namespace devkit } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/devkit
apollo_public_repos/apollo/modules/canbus_vehicle/devkit/protocol/ultr_sensor_2_508.cc
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/devkit/protocol/ultr_sensor_2_508.h" #include "glog/logging.h" #include "modules/drivers/canbus/common/byte.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace devkit { using ::apollo::drivers::canbus::Byte; Ultrsensor2508::Ultrsensor2508() {} const int32_t Ultrsensor2508::ID = 0x508; void Ultrsensor2508::Parse(const std::uint8_t* bytes, int32_t length, Devkit* chassis) const { chassis->mutable_ultr_sensor_2_508()->set_uiuss9_tof_indirect( uiuss9_tof_indirect(bytes, length)); chassis->mutable_ultr_sensor_2_508()->set_uiuss8_tof_indirect( uiuss8_tof_indirect(bytes, length)); chassis->mutable_ultr_sensor_2_508()->set_uiuss11_tof_indirect( uiuss11_tof_indirect(bytes, length)); chassis->mutable_ultr_sensor_2_508()->set_uiuss10_tof_indirect( uiuss10_tof_indirect(bytes, length)); } // config detail: {'name': 'uiuss9_tof_indirect', 'offset': 0.0, 'precision': // 0.01724, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|65535]', // 'bit': 23, 'type': 'double', 'order': 'motorola', 'physical_unit': 'cm'} double Ultrsensor2508::uiuss9_tof_indirect(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 2); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 3); int32_t t = t1.get_byte(0, 8); x <<= 8; x |= t; double ret = x / 58; return ret; } // config detail: {'name': 'uiuss8_tof_indirect', 'offset': 0.0, 'precision': // 0.01724, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|65535]', // 'bit': 7, 'type': 'double', 'order': 'motorola', 'physical_unit': 'cm'} double Ultrsensor2508::uiuss8_tof_indirect(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 1); int32_t t = t1.get_byte(0, 8); x <<= 8; x |= t; double ret = x / 58; return ret; } // config detail: {'name': 'uiuss11_tof_indirect', 'offset': 0.0, 'precision': // 0.01724, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|65535]', // 'bit': 55, 'type': 'double', 'order': 'motorola', 'physical_unit': 'cm'} double Ultrsensor2508::uiuss11_tof_indirect(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 6); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 7); int32_t t = t1.get_byte(0, 8); x <<= 8; x |= t; double ret = x / 58; return ret; } // config detail: {'name': 'uiuss10_tof_indirect', 'offset': 0.0, 'precision': // 0.01724, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|65535]', // 'bit': 39, 'type': 'double', 'order': 'motorola', 'physical_unit': 'cm'} double Ultrsensor2508::uiuss10_tof_indirect(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 5); int32_t t = t1.get_byte(0, 8); x <<= 8; x |= t; double ret = x / 58; return ret; } } // namespace devkit } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/devkit
apollo_public_repos/apollo/modules/canbus_vehicle/devkit/protocol/ultr_sensor_5_511.h
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/devkit/proto/devkit.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace devkit { class Ultrsensor5511 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Devkit> { public: static const int32_t ID; Ultrsensor5511(); void Parse(const std::uint8_t* bytes, int32_t length, Devkit* chassis) const override; private: // config detail: {'name': 'uiUSS7_ToF_Direct', 'offset': 0.0, 'precision': // 0.01724, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|65535]', // 'bit': 55, 'type': 'double', 'order': 'motorola', 'physical_unit': 'cm'} double uiuss7_tof_direct(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'uiUSS6_ToF_Direct', 'offset': 0.0, 'precision': // 0.01724, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|65535]', // 'bit': 39, 'type': 'double', 'order': 'motorola', 'physical_unit': 'cm'} double uiuss6_tof_direct(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'uiUSS1_ToF_Direct', 'offset': 0.0, 'precision': // 0.01724, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|65535]', // 'bit': 23, 'type': 'double', 'order': 'motorola', 'physical_unit': 'cm'} double uiuss1_tof_direct(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'uiUSS0_ToF_Direct', 'offset': 0.0, 'precision': // 0.01724, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|65535]', // 'bit': 7, 'type': 'double', 'order': 'motorola', 'physical_unit': 'cm'} double uiuss0_tof_direct(const std::uint8_t* bytes, const int32_t length) const; }; } // namespace devkit } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/devkit
apollo_public_repos/apollo/modules/canbus_vehicle/devkit/protocol/ultr_sensor_2_508.h
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/devkit/proto/devkit.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace devkit { class Ultrsensor2508 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Devkit> { public: static const int32_t ID; Ultrsensor2508(); void Parse(const std::uint8_t* bytes, int32_t length, Devkit* chassis) const override; private: // config detail: {'name': 'uiUSS9_ToF_Indirect', 'offset': 0.0, 'precision': // 0.01724, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|65535]', // 'bit': 23, 'type': 'double', 'order': 'motorola', 'physical_unit': 'cm'} double uiuss9_tof_indirect(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'uiUSS8_ToF_Indirect', 'offset': 0.0, 'precision': // 0.01724, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|65535]', // 'bit': 7, 'type': 'double', 'order': 'motorola', 'physical_unit': 'cm'} double uiuss8_tof_indirect(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'uiUSS11_ToF_Indirect', 'offset': 0.0, 'precision': // 0.01724, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|65535]', // 'bit': 55, 'type': 'double', 'order': 'motorola', 'physical_unit': 'cm'} double uiuss11_tof_indirect(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'uiUSS10_ToF_Indirect', 'offset': 0.0, 'precision': // 0.01724, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|65535]', // 'bit': 39, 'type': 'double', 'order': 'motorola', 'physical_unit': 'cm'} double uiuss10_tof_indirect(const std::uint8_t* bytes, const int32_t length) const; }; } // namespace devkit } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/devkit
apollo_public_repos/apollo/modules/canbus_vehicle/devkit/protocol/wheelspeed_report_506_test.cc
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/devkit/protocol/wheelspeed_report_506.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace devkit { class Wheelspeedreport506Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Wheelspeedreport506Test, General) { uint8_t data[8] = {0x07, 0x01, 0x01, 0x02, 0x8A, 0x03, 0x04, 0x05}; int32_t length = 8; Devkit cd; Wheelspeedreport506 wheelspeedreport; wheelspeedreport.Parse(data, length, &cd); EXPECT_EQ(data[0], 0b00000111); EXPECT_EQ(data[1], 0b00000001); EXPECT_EQ(data[2], 0b00000001); EXPECT_EQ(data[3], 0b00000010); EXPECT_EQ(data[4], 0b10001010); EXPECT_EQ(data[5], 0b00000011); EXPECT_EQ(data[6], 0b00000100); EXPECT_EQ(data[7], 0b00000101); EXPECT_EQ(cd.wheelspeed_report_506().rr(), 1.029); EXPECT_EQ(cd.wheelspeed_report_506().rl(), 35.331); EXPECT_EQ(cd.wheelspeed_report_506().fr(), 0.258); EXPECT_EQ(cd.wheelspeed_report_506().fl(), 1.793); } } // namespace devkit } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/devkit
apollo_public_repos/apollo/modules/canbus_vehicle/devkit/protocol/BUILD
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("//tools:cpplint.bzl", "cpplint") package(default_visibility = ["//visibility:public"]) CANBUS_COPTS = ["-DMODULE_NAME=\\\"canbus\\\""] cc_library( name = "canbus_devkit_protocol", deps = [ ":bms_report_512", ":brake_command_101", ":brake_report_501", ":gear_command_103", ":gear_report_503", ":park_command_104", ":park_report_504", ":steering_command_102", ":steering_report_502", ":throttle_command_100", ":throttle_report_500", ":ultr_sensor_1_507", ":ultr_sensor_2_508", ":ultr_sensor_3_509", ":ultr_sensor_4_510", ":ultr_sensor_5_511", ":vcu_report_505", ":vehicle_mode_command_105", ":vin_resp1_514", ":vin_resp2_515", ":vin_resp3_516", ":wheelspeed_report_506", ], ) cc_library( name = "bms_report_512", srcs = ["bms_report_512.cc"], hdrs = ["bms_report_512.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "bms_report_512_test", size = "small", srcs = ["bms_report_512_test.cc"], deps = [ "//modules/canbus_vehicle/devkit/protocol:canbus_devkit_protocol", "@com_google_googletest//:gtest_main", ], ) cc_library( name = "brake_command_101", srcs = ["brake_command_101.cc"], hdrs = ["brake_command_101.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "brake_command_101_test", size = "small", srcs = ["brake_command_101_test.cc"], deps = [ "//modules/canbus_vehicle/devkit/protocol:canbus_devkit_protocol", "@com_google_googletest//:gtest_main", ], ) cc_library( name = "brake_report_501", srcs = ["brake_report_501.cc"], hdrs = ["brake_report_501.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "brake_report_501_test", size = "small", srcs = ["brake_report_501_test.cc"], deps = [ "//modules/canbus_vehicle/devkit/protocol:canbus_devkit_protocol", "@com_google_googletest//:gtest_main", ], ) cc_library( name = "gear_command_103", srcs = ["gear_command_103.cc"], hdrs = ["gear_command_103.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "gear_command_103_test", size = "small", srcs = ["gear_command_103_test.cc"], deps = [ "//modules/canbus_vehicle/devkit/protocol:canbus_devkit_protocol", "@com_google_googletest//:gtest_main", ], ) cc_library( name = "gear_report_503", srcs = ["gear_report_503.cc"], hdrs = ["gear_report_503.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "gear_report_503_test", size = "small", srcs = ["gear_report_503_test.cc"], deps = [ "//modules/canbus_vehicle/devkit/protocol:canbus_devkit_protocol", "@com_google_googletest//:gtest_main", ], ) cc_library( name = "park_command_104", srcs = ["park_command_104.cc"], hdrs = ["park_command_104.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "park_command_104_test", size = "small", srcs = ["park_command_104_test.cc"], deps = [ "//modules/canbus_vehicle/devkit/protocol:canbus_devkit_protocol", "@com_google_googletest//:gtest_main", ], ) cc_library( name = "park_report_504", srcs = ["park_report_504.cc"], hdrs = ["park_report_504.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "park_report_504_test", size = "small", srcs = ["park_report_504_test.cc"], deps = [ "//modules/canbus_vehicle/devkit/protocol:canbus_devkit_protocol", "@com_google_googletest//:gtest_main", ], ) cc_library( name = "steering_command_102", srcs = ["steering_command_102.cc"], hdrs = ["steering_command_102.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "steering_command_102_test", size = "small", srcs = ["steering_command_102_test.cc"], deps = [ "//modules/canbus_vehicle/devkit/protocol:canbus_devkit_protocol", "@com_google_googletest//:gtest_main", ], ) cc_library( name = "steering_report_502", srcs = ["steering_report_502.cc"], hdrs = ["steering_report_502.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "steering_report_502_test", size = "small", srcs = ["steering_report_502_test.cc"], deps = [ "//modules/canbus_vehicle/devkit/protocol:canbus_devkit_protocol", "@com_google_googletest//:gtest_main", ], ) cc_library( name = "throttle_command_100", srcs = ["throttle_command_100.cc"], hdrs = ["throttle_command_100.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "throttle_command_100_test", size = "small", srcs = ["throttle_command_100_test.cc"], deps = [ "//modules/canbus_vehicle/devkit/protocol:canbus_devkit_protocol", "@com_google_googletest//:gtest_main", ], ) cc_library( name = "throttle_report_500", srcs = ["throttle_report_500.cc"], hdrs = ["throttle_report_500.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "throttle_report_500_test", size = "small", srcs = ["throttle_report_500_test.cc"], deps = [ "//modules/canbus_vehicle/devkit/protocol:canbus_devkit_protocol", "@com_google_googletest//:gtest_main", ], ) cc_library( name = "ultr_sensor_1_507", srcs = ["ultr_sensor_1_507.cc"], hdrs = ["ultr_sensor_1_507.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "ultr_sensor_1_507_test", size = "small", srcs = ["ultr_sensor_1_507_test.cc"], deps = [ "//modules/canbus_vehicle/devkit/protocol:canbus_devkit_protocol", "@com_google_googletest//:gtest_main", ], ) cc_library( name = "ultr_sensor_2_508", srcs = ["ultr_sensor_2_508.cc"], hdrs = ["ultr_sensor_2_508.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "ultr_sensor_2_508_test", size = "small", srcs = ["ultr_sensor_2_508_test.cc"], deps = [ "//modules/canbus_vehicle/devkit/protocol:canbus_devkit_protocol", "@com_google_googletest//:gtest_main", ], ) cc_library( name = "ultr_sensor_3_509", srcs = ["ultr_sensor_3_509.cc"], hdrs = ["ultr_sensor_3_509.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "ultr_sensor_3_509_test", size = "small", srcs = ["ultr_sensor_3_509_test.cc"], deps = [ "//modules/canbus_vehicle/devkit/protocol:canbus_devkit_protocol", "@com_google_googletest//:gtest_main", ], ) cc_library( name = "ultr_sensor_4_510", srcs = ["ultr_sensor_4_510.cc"], hdrs = ["ultr_sensor_4_510.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "ultr_sensor_4_510_test", size = "small", srcs = ["ultr_sensor_4_510_test.cc"], deps = [ "//modules/canbus_vehicle/devkit/protocol:canbus_devkit_protocol", "@com_google_googletest//:gtest_main", ], ) cc_library( name = "ultr_sensor_5_511", srcs = ["ultr_sensor_5_511.cc"], hdrs = ["ultr_sensor_5_511.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "ultr_sensor_5_511_test", size = "small", srcs = ["ultr_sensor_5_511_test.cc"], deps = [ "//modules/canbus_vehicle/devkit/protocol:canbus_devkit_protocol", "@com_google_googletest//:gtest_main", ], ) cc_library( name = "vcu_report_505", srcs = ["vcu_report_505.cc"], hdrs = ["vcu_report_505.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "vcu_report_505_test", size = "small", srcs = ["vcu_report_505_test.cc"], deps = [ "//modules/canbus_vehicle/devkit/protocol:canbus_devkit_protocol", "@com_google_googletest//:gtest_main", ], ) cc_library( name = "vehicle_mode_command_105", srcs = ["vehicle_mode_command_105.cc"], hdrs = ["vehicle_mode_command_105.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_library( name = "vin_resp1_514", srcs = ["vin_resp1_514.cc"], hdrs = ["vin_resp1_514.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_library( name = "vin_resp2_515", srcs = ["vin_resp2_515.cc"], hdrs = ["vin_resp2_515.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_library( name = "vin_resp3_516", srcs = ["vin_resp3_516.cc"], hdrs = ["vin_resp3_516.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_library( name = "wheelspeed_report_506", srcs = ["wheelspeed_report_506.cc"], hdrs = ["wheelspeed_report_506.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/devkit/proto:devkit_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "wheelspeed_report_506_test", size = "small", srcs = ["wheelspeed_report_506_test.cc"], deps = [ "//modules/canbus_vehicle/devkit/protocol:canbus_devkit_protocol", "@com_google_googletest//:gtest_main", ], ) cpplint()
0
apollo_public_repos/apollo/modules/canbus_vehicle/devkit
apollo_public_repos/apollo/modules/canbus_vehicle/devkit/protocol/brake_command_101_test.cc
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/devkit/protocol/brake_command_101.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace devkit { class Brakecommand101Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Brakecommand101Test, simple) { Brakecommand101 brake; EXPECT_EQ(brake.GetPeriod(), 20 * 1000); uint8_t data[8] = {0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78}; brake.UpdateData(data); EXPECT_EQ(data[0], 0b01110000); EXPECT_EQ(data[1], 0b00000000); EXPECT_EQ(data[2], 0b00110011); EXPECT_EQ(data[3], 0b00000000); EXPECT_EQ(data[4], 0b00000000); EXPECT_EQ(data[5], 0b01110110); EXPECT_EQ(data[6], 0b01110111); EXPECT_EQ(data[7], 0b01000010); } } // namespace devkit } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/devkit
apollo_public_repos/apollo/modules/canbus_vehicle/devkit/protocol/vcu_report_505.h
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/devkit/proto/devkit.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace devkit { class Vcureport505 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Devkit> { public: static const int32_t ID; Vcureport505(); void Parse(const std::uint8_t* bytes, int32_t length, Devkit* chassis) const override; private: // config detail: {'bit': 10, 'enum': {0: // 'STEER_MODE_STS_STANDARD_STEER_MODE', 1: // 'STEER_MODE_STS_NON_DIRECTION_STEER_MODE', 2: // 'STEER_MODE_STS_SYNC_DIRECTION_STEER_MODE'}, 'is_signed_var': False, 'len': // 3, 'name': 'Steer_Mode_STS', 'offset': 0.0, 'order': 'motorola', // 'physical_range': '[0|7]', 'physical_unit': '', 'precision': 1.0, 'type': // 'enum'} Vcu_report_505::Steer_mode_stsType steer_mode_sts(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'bit': 11, 'enum': {0: 'BRAKE_LIGHT_ACTUAL_BRAKELIGHT_OFF', // 1: 'BRAKE_LIGHT_ACTUAL_BRAKELIGHT_ON'}, 'is_signed_var': False, 'len': 1, // 'name': 'Brake_Light_Actual', 'offset': 0.0, 'order': 'motorola', // 'physical_range': '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': // 'enum'} Vcu_report_505::Brake_light_actualType brake_light_actual( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'bit': 7, 'is_signed_var': True, 'len': 12, 'name': 'ACC', // 'offset': 0.0, 'order': 'motorola', 'physical_range': '[-10|10]', // 'physical_unit': 'm/s^2', 'precision': 0.01, 'type': 'double'} double acc(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'bit': 23, 'is_signed_var': True, 'len': 16, 'name': // 'SPEED', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[-32.768|32.767]', 'physical_unit': 'm/s', 'precision': 0.001, 'type': // 'double'} double speed(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'bit': 32, 'description': 'describle the vehicle AEB mode // whether was set', 'enum': {0: 'AEB_BRAKE_STATE_INACTIVE', 1: // 'AEB_BRAKE_STATE_ACTIVE'}, 'is_signed_var': False, 'len': 1, 'name': // 'AEB_Brake_State', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'} Vcu_report_505::Aeb_brake_stateType aeb_brake_state( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'bit': 33, 'enum': {0: 'FRONTCRASH_STATE_NO_EVENT', 1: // 'FRONTCRASH_STATE_CRASH_EVENT'}, 'is_signed_var': False, 'len': 1, 'name': // 'FrontCrash_State', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'} Vcu_report_505::Frontcrash_stateType frontcrash_state( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'bit': 34, 'enum': {0: 'BACKCRASH_STATE_NO_EVENT', 1: // 'BACKCRASH_STATE_CRASH_EVENT'}, 'is_signed_var': False, 'len': 1, 'name': // 'BackCrash_State', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'} Vcu_report_505::Backcrash_stateType backcrash_state( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'bit': 36, 'enum': {0: // 'VEHICLE_MODE_STATE_MANUAL_REMOTE_MODE', 1: 'VEHICLE_MODE_STATE_AUTO_MODE', // 2: 'VEHICLE_MODE_STATE_EMERGENCY_MODE', 3: // 'VEHICLE_MODE_STATE_STANDBY_MODE'}, 'is_signed_var': False, 'len': 2, // 'name': 'Vehicle_Mode_State', 'offset': 0.0, 'order': 'motorola', // 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': // 'enum'} Vcu_report_505::Vehicle_mode_stateType vehicle_mode_state( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'bit': 39, 'enum': {0: // 'DRIVE_MODE_STS_THROTTLE_PADDLE_DRIVE_MODE', 1: // 'DRIVE_MODE_STS_SPEED_DRIVE_MODE'}, 'is_signed_var': False, 'len': 3, // 'name': 'Drive_Mode_STS', 'offset': 0.0, 'order': 'motorola', // 'physical_range': '[0|7]', 'physical_unit': '', 'precision': 1.0, 'type': // 'enum'} Vcu_report_505::Drive_mode_stsType drive_mode_sts(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'bit': 47, 'is_signed_var': False, 'len': 8, 'name': // 'Chassis_errcode', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'} int chassis_errcode(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'bit': 57, 'enum': {0: 'TURN_LIGHT_ACTUAL_TURNLAMPSTS_OFF', // 1: 'TURN_LIGHT_ACTUAL_LEFT_TURNLAMPSTS_ON', 2: // 'TURN_LIGHT_ACTUAL_RIGHT_TURNLAMPSTS_ON', 3: // 'TURN_LIGHT_ACTUAL_HAZARD_WARNING_LAMPSTS_ON'}, 'is_signed_var': False, // 'len': 2, 'name': 'Turn_Light_Actual', 'offset': 0.0, 'order': 'motorola', // 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': // 'enum'} Vcu_report_505::Turn_light_actualType turn_light_actual( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'bit': 58, 'description': 'describe the vehicle e-brake // command whether was triggered by AEB', 'enum': {0: 'AEB_MODE_DISABLE', 1: // 'AEB_MODE_ENABLE'}, 'is_signed_var': False, 'len': 1, 'name': 'AEB_Mode', // 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|1]', // 'physical_unit': '', 'precision': 1.0, 'type': 'enum'} Vcu_report_505::Aeb_modeType aeb_mode(const std::uint8_t* bytes, const int32_t length) const; }; } // namespace devkit } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/devkit
apollo_public_repos/apollo/modules/canbus_vehicle/devkit/protocol/ultr_sensor_5_511.cc
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/devkit/protocol/ultr_sensor_5_511.h" #include "glog/logging.h" #include "modules/drivers/canbus/common/byte.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace devkit { using ::apollo::drivers::canbus::Byte; Ultrsensor5511::Ultrsensor5511() {} const int32_t Ultrsensor5511::ID = 0x511; void Ultrsensor5511::Parse(const std::uint8_t* bytes, int32_t length, Devkit* chassis) const { chassis->mutable_ultr_sensor_5_511()->set_uiuss7_tof_direct( uiuss7_tof_direct(bytes, length)); chassis->mutable_ultr_sensor_5_511()->set_uiuss6_tof_direct( uiuss6_tof_direct(bytes, length)); chassis->mutable_ultr_sensor_5_511()->set_uiuss1_tof_direct( uiuss1_tof_direct(bytes, length)); chassis->mutable_ultr_sensor_5_511()->set_uiuss0_tof_direct( uiuss0_tof_direct(bytes, length)); } // config detail: {'name': 'uiuss7_tof_direct', 'offset': 0.0, 'precision': // 0.01724, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|65535]', // 'bit': 55, 'type': 'double', 'order': 'motorola', 'physical_unit': 'cm'} double Ultrsensor5511::uiuss7_tof_direct(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 6); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 7); int32_t t = t1.get_byte(0, 8); x <<= 8; x |= t; double ret = x / 58; return ret; } // config detail: {'name': 'uiuss6_tof_direct', 'offset': 0.0, 'precision': // 0.01724, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|65535]', // 'bit': 39, 'type': 'double', 'order': 'motorola', 'physical_unit': 'cm'} double Ultrsensor5511::uiuss6_tof_direct(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 5); int32_t t = t1.get_byte(0, 8); x <<= 8; x |= t; double ret = x / 58; return ret; } // config detail: {'name': 'uiuss1_tof_direct', 'offset': 0.0, 'precision': // 0.01724, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|65535]', // 'bit': 23, 'type': 'double', 'order': 'motorola', 'physical_unit': 'cm'} double Ultrsensor5511::uiuss1_tof_direct(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 2); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 3); int32_t t = t1.get_byte(0, 8); x <<= 8; x |= t; double ret = x / 58; return ret; } // config detail: {'name': 'uiuss0_tof_direct', 'offset': 0.0, 'precision': // 0.01724, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|65535]', // 'bit': 7, 'type': 'double', 'order': 'motorola', 'physical_unit': 'cm'} double Ultrsensor5511::uiuss0_tof_direct(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 1); int32_t t = t1.get_byte(0, 8); x <<= 8; x |= t; double ret = x / 58; return ret; } } // namespace devkit } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/devkit
apollo_public_repos/apollo/modules/canbus_vehicle/devkit/protocol/vin_resp3_516.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/devkit/protocol/vin_resp3_516.h" #include <string> #include "glog/logging.h" #include "modules/drivers/canbus/common/byte.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace devkit { using ::apollo::drivers::canbus::Byte; Vinresp3516::Vinresp3516() {} const int32_t Vinresp3516::ID = 0x516; void Vinresp3516::Parse(const std::uint8_t* bytes, int32_t length, Devkit* chassis) const { chassis->mutable_vin_resp3_516()->set_vin16( vin16(bytes, length)); } // config detail: {'bit': 7, 'is_signed_var': False, 'len': 8, 'name': 'vin16', // 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|255]', // 'physical_unit': '', 'precision': 1.0, 'type': 'int'} std::string Vinresp3516::vin16(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 8); std::string ret = ""; ret += x; return ret; } } // namespace devkit } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/devkit
apollo_public_repos/apollo/modules/canbus_vehicle/devkit/protocol/brake_command_101.h
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/devkit/proto/devkit.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace devkit { class Brakecommand101 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Devkit> { public: static const int32_t ID; Brakecommand101(); uint32_t GetPeriod() const override; void Parse(const std::uint8_t* bytes, int32_t length, Devkit* chassis) const override; void UpdateData(uint8_t* data) override; void Reset() override; // config detail: {'bit': 0, 'enum': {0: 'BRAKE_EN_CTRL_DISABLE', 1: // 'BRAKE_EN_CTRL_ENABLE'}, 'is_signed_var': False, 'len': 1, 'name': // 'Brake_EN_CTRL', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'} Brakecommand101* set_brake_en_ctrl( Brake_command_101::Brake_en_ctrlType brake_en_ctrl); // config detail: {'bit': 1, 'enum': {0: 'AEB_EN_CTRL_DISABLE_AEB', 1: // 'AEB_EN_CTRL_ENABLE_AEB'}, 'is_signed_var': False, 'len': 1, 'name': // 'AEB_EN_CTRL', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'} Brakecommand101* set_aeb_en_ctrl( Brake_command_101::Aeb_en_ctrlType aeb_en_ctrl); // config detail: {'bit': 15, 'is_signed_var': False, 'len': 10, 'name': // 'Brake_Dec', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[0|10]', 'physical_unit': 'm/s^2', 'precision': 0.01, 'type': 'double'} Brakecommand101* set_brake_dec(double brake_dec); // config detail: {'bit': 31, 'is_signed_var': False, 'len': 16, 'name': // 'Brake_Pedal_Target', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[0|100]', 'physical_unit': '%', 'precision': 0.1, 'type': 'double'} Brakecommand101* set_brake_pedal_target(double brake_pedal_target); // config detail: {'bit': 63, 'is_signed_var': False, 'len': 8, 'name': // 'CheckSum_101', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'} Brakecommand101* set_checksum_101(int checksum_101); private: // config detail: {'bit': 0, 'enum': {0: 'BRAKE_EN_CTRL_DISABLE', 1: // 'BRAKE_EN_CTRL_ENABLE'}, 'is_signed_var': False, 'len': 1, 'name': // 'Brake_EN_CTRL', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'} void set_p_brake_en_ctrl(uint8_t* data, Brake_command_101::Brake_en_ctrlType brake_en_ctrl); // config detail: {'bit': 1, 'enum': {0: 'AEB_EN_CTRL_DISABLE_AEB', 1: // 'AEB_EN_CTRL_ENABLE_AEB'}, 'is_signed_var': False, 'len': 1, 'name': // 'AEB_EN_CTRL', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'} void set_p_aeb_en_ctrl(uint8_t* data, Brake_command_101::Aeb_en_ctrlType aeb_en_ctrl); // config detail: {'bit': 15, 'is_signed_var': False, 'len': 10, 'name': // 'Brake_Dec', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[0|10]', 'physical_unit': 'm/s^2', 'precision': 0.01, 'type': 'double'} void set_p_brake_dec(uint8_t* data, double brake_dec); // config detail: {'bit': 31, 'is_signed_var': False, 'len': 16, 'name': // 'Brake_Pedal_Target', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[0|100]', 'physical_unit': '%', 'precision': 0.1, 'type': 'double'} void set_p_brake_pedal_target(uint8_t* data, double brake_pedal_target); // config detail: {'bit': 63, 'is_signed_var': False, 'len': 8, 'name': // 'CheckSum_101', 'offset': 0.0, 'order': 'motorola', 'physical_range': // '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'} void set_p_checksum_101(uint8_t* data, int checksum_101); // report the command Brake_command_101::Brake_en_ctrlType brake_en_ctrl( const std::uint8_t* bytes, const int32_t length) const; Brake_command_101::Aeb_en_ctrlType aeb_en_ctrl(const std::uint8_t* bytes, const int32_t length) const; double brake_dec(const std::uint8_t* bytes, const int32_t length) const; double brake_pedal_target(const std::uint8_t* bytes, const int32_t length) const; int checksum_101(const std::uint8_t* bytes, const int32_t length) const; private: Brake_command_101::Aeb_en_ctrlType aeb_en_ctrl_; double brake_dec_; int checksum_101_; double brake_pedal_target_; Brake_command_101::Brake_en_ctrlType brake_en_ctrl_; }; } // namespace devkit } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/devkit
apollo_public_repos/apollo/modules/canbus_vehicle/devkit/protocol/bms_report_512.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/devkit/protocol/bms_report_512.h" #include "glog/logging.h" #include "modules/drivers/canbus/common/byte.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace devkit { using ::apollo::drivers::canbus::Byte; Bmsreport512::Bmsreport512() {} const int32_t Bmsreport512::ID = 0x512; void Bmsreport512::Parse(const std::uint8_t* bytes, int32_t length, Devkit* chassis) const { chassis->mutable_bms_report_512()->set_battery_current( battery_current(bytes, length)); chassis->mutable_bms_report_512()->set_battery_voltage( battery_voltage(bytes, length)); chassis->mutable_bms_report_512()->set_battery_soc_percentage( battery_soc_percentage(bytes, length)); chassis->mutable_bms_report_512()->set_is_battery_soc_low( battery_soc_percentage(bytes, length) <= 15); chassis->mutable_bms_report_512()->set_battery_inside_temperature( battery_inside_temperature(bytes, length)); chassis->mutable_bms_report_512()->set_battery_flt_low_temp( battery_flt_low_temp(bytes, length)); chassis->mutable_bms_report_512()->set_battery_flt_over_temp( battery_flt_over_temp(bytes, length)); } // config detail: {'bit': 23, 'description': 'Battery Total Current', // 'is_signed_var': False, 'len': 16, 'name': 'battery_current', 'offset': // -3200.0, 'order': 'motorola', 'physical_range': '[-3200|3200]', // 'physical_unit': 'A', 'precision': 0.1, 'type': 'double'} double Bmsreport512::battery_current(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 2); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 3); int32_t t = t1.get_byte(0, 8); x <<= 8; x |= t; double ret = x * 0.100000 + -3200.000000; return ret; } // config detail: {'bit': 7, 'description': 'Battery Total Voltage', // 'is_signed_var': False, 'len': 16, 'name': 'battery_voltage', 'offset': 0.0, // 'order': 'motorola', 'physical_range': '[0|300]', 'physical_unit': 'V', // 'precision': 0.01, 'type': 'double'} double Bmsreport512::battery_voltage(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 1); int32_t t = t1.get_byte(0, 8); x <<= 8; x |= t; double ret = x * 0.010000; return ret; } // config detail: {'bit': 39, 'description': 'Battery Soc percentage', // 'is_signed_var': False, 'len': 8, 'name': 'battery_soc_percentage', 'offset': // 0.0, 'order': 'motorola', 'physical_range': '[0|100]', 'physical_unit': '%', // 'precision': 1.0, 'type': 'int'} int Bmsreport512::battery_soc_percentage(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(0, 8); int ret = x; return ret; } // config detail: {'bit': 40, 'description': 'Battery Inside temperature', // 'is_signed_var': False, 'len': 1, 'name': 'Battery_Inside_Temperature', // 'offset': -40, 'order': 'motorola', 'physical_range': '[-40|215]', // 'physical_unit': 'C', 'precision': 1.0, 'type': 'int'} int Bmsreport512::battery_inside_temperature(const std::uint8_t* bytes, const int32_t length) const { Byte t0(bytes + 5); int32_t x = t0.get_byte(0, 8); int ret = x - 40; return ret; } // config detail: {'description': 'Battery Below Low temp fault', 'enum': // {0: 'BATTERY_FLT_LOW_TEMP_NO_FAULT', 1: // 'BATTERY_FLT_LOW_TEMP_FAULT'}, 'precision': 1.0, 'len': 1, // 'name': 'Brake_FLT2', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 48, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Bms_report_512::Battery_flt_lowtempType Bmsreport512::battery_flt_low_temp( const std::uint8_t* bytes, const int32_t length) const { Byte t0(bytes + 6); int32_t x = t0.get_byte(0, 1); Bms_report_512::Battery_flt_lowtempType ret = static_cast<Bms_report_512::Battery_flt_lowtempType>(x); return ret; } // config detail: {'description': 'Battery Over High Temp fault', 'enum': // {0: 'BATTERY_FLT_OVER_TEMP_NO_FAULT', 1: // 'BATTERY_FLT_OVER_TEMP_FAULT'}, 'precision': 1.0, 'len': 1, // 'name': 'Brake_FLT2', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 49, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Bms_report_512::Battery_flt_overtempType Bmsreport512::battery_flt_over_temp( const std::uint8_t* bytes, const int32_t length) const { Byte t0(bytes + 6); int32_t x = t0.get_byte(1, 1); Bms_report_512::Battery_flt_overtempType ret = static_cast<Bms_report_512::Battery_flt_overtempType>(x); return ret; } } // namespace devkit } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/devkit
apollo_public_repos/apollo/modules/canbus_vehicle/devkit/protocol/steering_command_102_test.cc
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/devkit/protocol/steering_command_102.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace devkit { class Steeringcommand102Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Steeringcommand102Test, simple) { Steeringcommand102 steer; EXPECT_EQ(steer.GetPeriod(), 20 * 1000); uint8_t data[8] = {0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78}; steer.UpdateData(data); EXPECT_EQ(data[0], 0b01110000); EXPECT_EQ(data[1], 0b00000000); EXPECT_EQ(data[2], 0b01110011); EXPECT_EQ(data[3], 0b00000001); EXPECT_EQ(data[4], 0b11110100); EXPECT_EQ(data[5], 0b01110110); EXPECT_EQ(data[6], 0b01110111); EXPECT_EQ(data[7], 0b11110111); } } // namespace devkit } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/devkit
apollo_public_repos/apollo/modules/canbus_vehicle/devkit/protocol/vin_resp1_514.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include <string> #include "modules/canbus_vehicle/devkit/proto/devkit.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace devkit { class Vinresp1514 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Devkit> { public: static const int32_t ID; Vinresp1514(); void Parse(const std::uint8_t* bytes, int32_t length, Devkit* chassis) const override; private: // config detail: {'bit': 63, 'is_signed_var': False, 'len': 8, 'name': // 'VIN07', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|255]', // 'physical_unit': '', 'precision': 1.0, 'type': 'int'} std::string vin07(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'bit': 55, 'is_signed_var': False, 'len': 8, 'name': // 'VIN06', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|255]', // 'physical_unit': '', 'precision': 1.0, 'type': 'int'} std::string vin06(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'bit': 47, 'is_signed_var': False, 'len': 8, 'name': // 'VIN05', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|255]', // 'physical_unit': '', 'precision': 1.0, 'type': 'int'} std::string vin05(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'bit': 39, 'is_signed_var': False, 'len': 8, 'name': // 'VIN04', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|255]', // 'physical_unit': '', 'precision': 1.0, 'type': 'int'} std::string vin04(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'bit': 31, 'is_signed_var': False, 'len': 8, 'name': // 'VIN03', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|255]', // 'physical_unit': '', 'precision': 1.0, 'type': 'int'} std::string vin03(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'bit': 23, 'is_signed_var': False, 'len': 8, 'name': // 'VIN02', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|255]', // 'physical_unit': '', 'precision': 1.0, 'type': 'int'} std::string vin02(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'bit': 15, 'is_signed_var': False, 'len': 8, 'name': // 'VIN01', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|255]', // 'physical_unit': '', 'precision': 1.0, 'type': 'int'} std::string vin01(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'bit': 7, 'is_signed_var': False, 'len': 8, 'name': // 'VIN00', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|255]', // 'physical_unit': '', 'precision': 1.0, 'type': 'int'} std::string vin00(const std::uint8_t* bytes, const int32_t length) const; }; } // namespace devkit } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/devkit
apollo_public_repos/apollo/modules/canbus_vehicle/devkit/protocol/gear_report_503_test.cc
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/devkit/protocol/gear_report_503.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace devkit { class Gearreport503Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Gearreport503Test, General) { uint8_t data[8] = {0x04, 0x01, 0x01, 0x10, 0x90, 0x01, 0x00, 0x01}; int32_t length = 8; Devkit cd; Gearreport503 gearreport; gearreport.Parse(data, length, &cd); EXPECT_EQ(data[0], 0b00000100); EXPECT_EQ(data[1], 0b00000001); EXPECT_EQ(data[2], 0b00000001); EXPECT_EQ(data[3], 0b00010000); EXPECT_EQ(data[4], 0b10010000); EXPECT_EQ(data[5], 0b00000001); EXPECT_EQ(data[6], 0b00000000); EXPECT_EQ(data[7], 0b00000001); EXPECT_EQ(cd.gear_report_503().gear_flt(), 1); EXPECT_EQ(cd.gear_report_503().gear_actual(), 4); } } // namespace devkit } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/devkit
apollo_public_repos/apollo/modules/canbus_vehicle/devkit/protocol/gear_command_103.cc
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/devkit/protocol/gear_command_103.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace devkit { using ::apollo::drivers::canbus::Byte; const int32_t Gearcommand103::ID = 0x103; // public Gearcommand103::Gearcommand103() { Reset(); } void Gearcommand103::Parse(const std::uint8_t* bytes, int32_t length, Devkit* chassis) const { chassis->mutable_gear_command_103()->set_gear_target( gear_target(bytes, length)); chassis->mutable_gear_command_103()->set_gear_en_ctrl( gear_en_ctrl(bytes, length)); chassis->mutable_gear_command_103()->set_checksum_103( checksum_103(bytes, length)); } uint32_t Gearcommand103::GetPeriod() const { // TODO(All) : modify every protocol's period manually static const uint32_t PERIOD = 20 * 1000; return PERIOD; } void Gearcommand103::UpdateData(uint8_t* data) { set_p_gear_target(data, gear_target_); set_p_gear_en_ctrl(data, gear_en_ctrl_); checksum_103_ = data[0] ^ data[1] ^ data[2] ^ data[3] ^ data[4] ^ data[5] ^ data[6]; set_p_checksum_103(data, checksum_103_); } void Gearcommand103::Reset() { // TODO(All) : you should check this manually gear_target_ = Gear_command_103::GEAR_TARGET_NEUTRAL; gear_en_ctrl_ = Gear_command_103::GEAR_EN_CTRL_DISABLE; checksum_103_ = 0; } Gearcommand103* Gearcommand103::set_gear_target( Gear_command_103::Gear_targetType gear_target) { gear_target_ = gear_target; return this; } // config detail: {'name': 'Gear_Target', 'enum': {0: 'GEAR_TARGET_INVALID', 1: // 'GEAR_TARGET_PARK', 2: 'GEAR_TARGET_REVERSE', 3: 'GEAR_TARGET_NEUTRAL', 4: // 'GEAR_TARGET_DRIVE'}, 'precision': 1.0, 'len': 3, 'is_signed_var': False, // 'offset': 0.0, 'physical_range': '[0|4]', 'bit': 10, 'type': 'enum', 'order': // 'motorola', 'physical_unit': ''} void Gearcommand103::set_p_gear_target( uint8_t* data, Gear_command_103::Gear_targetType gear_target) { int x = gear_target; Byte to_set(data + 1); to_set.set_value(x, 0, 3); } Gearcommand103* Gearcommand103::set_gear_en_ctrl( Gear_command_103::Gear_en_ctrlType gear_en_ctrl) { gear_en_ctrl_ = gear_en_ctrl; return this; } // config detail: {'name': 'Gear_EN_CTRL', 'enum': {0: 'GEAR_EN_CTRL_DISABLE', // 1: 'GEAR_EN_CTRL_ENABLE'}, 'precision': 1.0, 'len': 1, 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 0, 'type': 'enum', // 'order': 'motorola', 'physical_unit': ''} void Gearcommand103::set_p_gear_en_ctrl( uint8_t* data, Gear_command_103::Gear_en_ctrlType gear_en_ctrl) { int x = gear_en_ctrl; Byte to_set(data + 0); to_set.set_value(x, 0, 1); } Gearcommand103* Gearcommand103::set_checksum_103(int checksum_103) { checksum_103_ = checksum_103; return this; } // config detail: {'name': 'CheckSum_103', 'offset': 0.0, 'precision': 1.0, // 'len': 8, 'is_signed_var': False, 'physical_range': '[0|255]', 'bit': 63, // 'type': 'int', 'order': 'motorola', 'physical_unit': ''} void Gearcommand103::set_p_checksum_103(uint8_t* data, int checksum_103) { checksum_103 = ProtocolData::BoundedValue(0, 255, checksum_103); int x = checksum_103; Byte to_set(data + 7); to_set.set_value(x, 0, 8); } Gear_command_103::Gear_targetType Gearcommand103::gear_target( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(0, 3); Gear_command_103::Gear_targetType ret = static_cast<Gear_command_103::Gear_targetType>(x); return ret; } Gear_command_103::Gear_en_ctrlType Gearcommand103::gear_en_ctrl( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 1); Gear_command_103::Gear_en_ctrlType ret = static_cast<Gear_command_103::Gear_en_ctrlType>(x); return ret; } int Gearcommand103::checksum_103(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 7); int32_t x = t0.get_byte(0, 8); int ret = x; return ret; } } // namespace devkit } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/devkit
apollo_public_repos/apollo/modules/canbus_vehicle/devkit/protocol/ultr_sensor_4_510_test.cc
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/devkit/protocol/ultr_sensor_4_510.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace devkit { class Ultrsensor4510Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Ultrsensor4510Test, General) { uint8_t data[8] = {0xE2, 0x95, 0x06, 0x58, 0x08, 0xD6, 0x02, 0x44}; int32_t length = 8; Devkit cd; Ultrsensor4510 ultrsensor4; ultrsensor4.Parse(data, length, &cd); EXPECT_EQ(data[0], 0b11100010); EXPECT_EQ(data[1], 0b10010101); EXPECT_EQ(data[2], 0b00000110); EXPECT_EQ(data[3], 0b01011000); EXPECT_EQ(data[4], 0b00001000); EXPECT_EQ(data[5], 0b11010110); EXPECT_EQ(data[6], 0b00000010); EXPECT_EQ(data[7], 0b01000100); EXPECT_EQ(cd.ultr_sensor_4_510().uiuss5_tof_indirect(), 10); EXPECT_EQ(cd.ultr_sensor_4_510().uiuss4_tof_indirect(), 39); EXPECT_EQ(cd.ultr_sensor_4_510().uiuss3_tof_indirect(), 28); EXPECT_EQ(cd.ultr_sensor_4_510().uiuss2_tof_indirect(), 1000); } } // namespace devkit } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/devkit
apollo_public_repos/apollo/modules/canbus_vehicle/devkit/protocol/park_command_104.h
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/devkit/proto/devkit.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace devkit { class Parkcommand104 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Devkit> { public: static const int32_t ID; Parkcommand104(); uint32_t GetPeriod() const override; void Parse(const std::uint8_t* bytes, int32_t length, Devkit* chassis) const override; void UpdateData(uint8_t* data) override; void Reset() override; // config detail: {'name': 'CheckSum_104', 'offset': 0.0, 'precision': 1.0, // 'len': 8, 'is_signed_var': False, 'physical_range': '[0|255]', 'bit': 63, // 'type': 'int', 'order': 'motorola', 'physical_unit': ''} Parkcommand104* set_checksum_104(int checksum_104); // config detail: {'name': 'Park_Target', 'enum': {0: 'PARK_TARGET_RELEASE', // 1: 'PARK_TARGET_PARKING_TRIGGER'}, 'precision': 1.0, 'len': 1, // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 8, // 'type': 'enum', 'order': 'motorola', 'physical_unit': ''} Parkcommand104* set_park_target( Park_command_104::Park_targetType park_target); // config detail: {'name': 'Park_EN_CTRL', 'enum': {0: 'PARK_EN_CTRL_DISABLE', // 1: 'PARK_EN_CTRL_ENABLE'}, 'precision': 1.0, 'len': 1, 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 0, 'type': 'enum', // 'order': 'motorola', 'physical_unit': ''} Parkcommand104* set_park_en_ctrl( Park_command_104::Park_en_ctrlType park_en_ctrl); private: // config detail: {'name': 'CheckSum_104', 'offset': 0.0, 'precision': 1.0, // 'len': 8, 'is_signed_var': False, 'physical_range': '[0|255]', 'bit': 63, // 'type': 'int', 'order': 'motorola', 'physical_unit': ''} void set_p_checksum_104(uint8_t* data, int checksum_104); // config detail: {'name': 'Park_Target', 'enum': {0: 'PARK_TARGET_RELEASE', // 1: 'PARK_TARGET_PARKING_TRIGGER'}, 'precision': 1.0, 'len': 1, // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 8, // 'type': 'enum', 'order': 'motorola', 'physical_unit': ''} void set_p_park_target(uint8_t* data, Park_command_104::Park_targetType park_target); // config detail: {'name': 'Park_EN_CTRL', 'enum': {0: 'PARK_EN_CTRL_DISABLE', // 1: 'PARK_EN_CTRL_ENABLE'}, 'precision': 1.0, 'len': 1, 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 0, 'type': 'enum', // 'order': 'motorola', 'physical_unit': ''} void set_p_park_en_ctrl(uint8_t* data, Park_command_104::Park_en_ctrlType park_en_ctrl); // report the command Park_command_104::Park_targetType park_target(const std::uint8_t* bytes, const int32_t length) const; Park_command_104::Park_en_ctrlType park_en_ctrl(const std::uint8_t* bytes, const int32_t length) const; int checksum_104(const std::uint8_t* bytes, const int32_t length) const; private: int checksum_104_; Park_command_104::Park_targetType park_target_; Park_command_104::Park_en_ctrlType park_en_ctrl_; }; } // namespace devkit } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/devkit
apollo_public_repos/apollo/modules/canbus_vehicle/devkit/protocol/vcu_report_505_test.cc
/****************************************************************************** * Copyright 2020 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/devkit/protocol/vcu_report_505.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace devkit { class Vcureport505Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Vcureport505Test, General) { uint8_t data[8] = {0x07, 0x01, 0x01, 0x02, 0x29, 0x03, 0x04, 0x05}; int32_t length = 8; Devkit cd; Vcureport505 vcureport; vcureport.Parse(data, length, &cd); EXPECT_EQ(data[0], 0b00000111); EXPECT_EQ(data[1], 0b00000001); EXPECT_EQ(data[2], 0b00000001); EXPECT_EQ(data[3], 0b00000010); EXPECT_EQ(data[4], 0b00101001); EXPECT_EQ(data[5], 0b00000011); EXPECT_EQ(data[6], 0b00000100); EXPECT_EQ(data[7], 0b00000101); EXPECT_EQ(cd.vcu_report_505().steer_mode_sts(), 1); EXPECT_EQ(cd.vcu_report_505().brake_light_actual(), 0); EXPECT_EQ(cd.vcu_report_505().acc(), 1.12); EXPECT_EQ(cd.vcu_report_505().speed(), 0.258); EXPECT_EQ(cd.vcu_report_505().aeb_brake_state(), 1); EXPECT_EQ(cd.vcu_report_505().frontcrash_state(), 0); EXPECT_EQ(cd.vcu_report_505().backcrash_state(), 0); EXPECT_EQ(cd.vcu_report_505().vehicle_mode_state(), 1); EXPECT_EQ(cd.vcu_report_505().drive_mode_sts(), 1); EXPECT_EQ(cd.vcu_report_505().chassis_errcode(), 3); EXPECT_EQ(cd.vcu_report_505().turn_light_actual(), 1); EXPECT_EQ(cd.vcu_report_505().aeb_mode(), 1); } } // namespace devkit } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/ge3_vehicle_factory_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/ge3_vehicle_factory.h" #include "gtest/gtest.h" #include "modules/canbus/proto/canbus_conf.pb.h" #include "modules/canbus/proto/vehicle_parameter.pb.h" #include "cyber/common/file.h" namespace apollo { namespace canbus { class Ge3VehicleFactoryTest : public ::testing::Test { public: virtual void SetUp() { std::string canbus_conf_file = "modules/canbus/testdata/conf/ge3_canbus_conf_test.pb.txt"; cyber::common::GetProtoFromFile(canbus_conf_file, &canbus_conf_); params_ = canbus_conf_.vehicle_parameter(); params_.set_brand(apollo::common::GE3); ge3_factory_.SetVehicleParameter(params_); } virtual void TearDown() {} protected: Ge3VehicleFactory ge3_factory_; CanbusConf canbus_conf_; VehicleParameter params_; }; TEST_F(Ge3VehicleFactoryTest, Init) { apollo::cyber::Init("vehicle_factory_test"); EXPECT_EQ(ge3_factory_.Init(&canbus_conf_), true); } } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/ge3_message_manager.h
/* Copyright 2019 The Apollo Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ #pragma once #include "modules/canbus_vehicle/ge3/proto/ge3.pb.h" #include "modules/drivers/canbus/can_comm/message_manager.h" namespace apollo { namespace canbus { namespace ge3 { using ::apollo::drivers::canbus::MessageManager; class Ge3MessageManager : public MessageManager<::apollo::canbus::Ge3> { public: Ge3MessageManager(); virtual ~Ge3MessageManager(); }; } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/ge3_message_manager.cc
/* Copyright 2019 The Apollo Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ #include "modules/canbus_vehicle/ge3/ge3_message_manager.h" #include "modules/canbus_vehicle/ge3/protocol/pc_bcm_201.h" #include "modules/canbus_vehicle/ge3/protocol/pc_bcs_202.h" #include "modules/canbus_vehicle/ge3/protocol/pc_epb_203.h" #include "modules/canbus_vehicle/ge3/protocol/pc_eps_204.h" #include "modules/canbus_vehicle/ge3/protocol/pc_vcu_205.h" #include "modules/canbus_vehicle/ge3/protocol/scu_1_301.h" #include "modules/canbus_vehicle/ge3/protocol/scu_2_302.h" #include "modules/canbus_vehicle/ge3/protocol/scu_3_303.h" #include "modules/canbus_vehicle/ge3/protocol/scu_bcm_304.h" #include "modules/canbus_vehicle/ge3/protocol/scu_bcs_1_306.h" #include "modules/canbus_vehicle/ge3/protocol/scu_bcs_2_307.h" #include "modules/canbus_vehicle/ge3/protocol/scu_bcs_3_308.h" #include "modules/canbus_vehicle/ge3/protocol/scu_epb_310.h" #include "modules/canbus_vehicle/ge3/protocol/scu_eps_311.h" #include "modules/canbus_vehicle/ge3/protocol/scu_vcu_1_312.h" #include "modules/canbus_vehicle/ge3/protocol/scu_vcu_2_313.h" namespace apollo { namespace canbus { namespace ge3 { Ge3MessageManager::Ge3MessageManager() { // Control Messages AddSendProtocolData<Pcbcm201, true>(); AddSendProtocolData<Pcbcs202, true>(); AddSendProtocolData<Pcepb203, true>(); AddSendProtocolData<Pceps204, true>(); AddSendProtocolData<Pcvcu205, true>(); // Report Messages AddRecvProtocolData<Scu1301, true>(); AddRecvProtocolData<Scu2302, true>(); AddRecvProtocolData<Scu3303, true>(); AddRecvProtocolData<Scubcm304, true>(); AddRecvProtocolData<Scubcs1306, true>(); AddRecvProtocolData<Scubcs2307, true>(); AddRecvProtocolData<Scubcs3308, true>(); AddRecvProtocolData<Scuepb310, true>(); AddRecvProtocolData<Scueps311, true>(); AddRecvProtocolData<Scuvcu1312, true>(); AddRecvProtocolData<Scuvcu2313, true>(); } Ge3MessageManager::~Ge3MessageManager() {} } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/cyberfile.xml
<package format="2"> <name>canbus-vehicle-ge3</name> <version>local</version> <description> Dynamic loading for canbus ge3 vehicle module </description> <maintainer email="apollo-support@baidu.com">Apollo</maintainer> <license>Apache License 2.0</license> <url type="website">https://www.apollo.auto/</url> <url type="repository">https://github.com/ApolloAuto/apollo</url> <url type="bugtracker">https://github.com/ApolloAuto/apollo/issues</url> <type>module</type> <src_path url="https://github.com/ApolloAuto/apollo">//modules/canbus_vehicle/ge3</src_path> <depend type="binary" repo_name="cyber">cyber-dev</depend> <depend type="binary" repo_name="common" lib_names="common">common-dev</depend> <depend type="binary" repo_name="canbus" lib_names="canbus">canbus-dev</depend> <depend repo_name="common-msgs" lib_names="common-msgs">common-msgs-dev</depend> <depend type="binary" repo_name="drivers">drivers-dev</depend> <depend repo_name="com_google_googletest" lib_names="gtest,gtest_main">3rd-gtest-dev</depend> </package>
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/ge3_vehicle_factory.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ /** * @file ge3_vehicle_factory.h */ #pragma once #include <memory> #include "modules/canbus/proto/canbus_conf.pb.h" #include "modules/canbus/proto/vehicle_parameter.pb.h" #include "modules/canbus_vehicle/ge3/proto/ge3.pb.h" #include "modules/common_msgs/control_msgs/control_cmd.pb.h" #include "cyber/cyber.h" #include "modules/canbus/vehicle/abstract_vehicle_factory.h" #include "modules/canbus/vehicle/vehicle_controller.h" #include "modules/common/status/status.h" #include "modules/drivers/canbus/can_client/can_client.h" #include "modules/drivers/canbus/can_comm/can_receiver.h" #include "modules/drivers/canbus/can_comm/can_sender.h" #include "modules/drivers/canbus/can_comm/message_manager.h" /** * @namespace apollo::canbus * @brief apollo::canbus */ namespace apollo { namespace canbus { /** * @class Ge3VehicleFactory * * @brief this class is inherited from AbstractVehicleFactory. It can be used to * create controller and message manager for ge3 vehicle. */ class Ge3VehicleFactory : public AbstractVehicleFactory { public: /** * @brief destructor */ virtual ~Ge3VehicleFactory() = default; /** * @brief init vehicle factory * @returns true if successfully initialized */ bool Init(const CanbusConf *canbus_conf) override; /** * @brief start canclient, cansender, canreceiver, vehicle controller * @returns true if successfully started */ bool Start() override; /** * @brief create ch vehicle controller * @returns a unique_ptr that points to the created controller */ void Stop() override; /** * @brief update control command */ void UpdateCommand( const apollo::control::ControlCommand *control_command) override; /** * @brief publish chassis messages */ Chassis publish_chassis() override; /** * @brief publish chassis for vehicle messages */ void PublishChassisDetail() override; private: /** * @brief create ge3 vehicle controller * @returns a unique_ptr that points to the created controller */ std::unique_ptr<VehicleController<::apollo::canbus::Ge3>> CreateVehicleController(); /** * @brief create ge3 message manager * @returns a unique_ptr that points to the created message manager */ std::unique_ptr<MessageManager<::apollo::canbus::Ge3>> CreateMessageManager(); std::unique_ptr<::apollo::cyber::Node> node_ = nullptr; std::unique_ptr<apollo::drivers::canbus::CanClient> can_client_; CanSender<::apollo::canbus::Ge3> can_sender_; apollo::drivers::canbus::CanReceiver<::apollo::canbus::Ge3> can_receiver_; std::unique_ptr<MessageManager<::apollo::canbus::Ge3>> message_manager_; std::unique_ptr<VehicleController<::apollo::canbus::Ge3>> vehicle_controller_; std::shared_ptr<::apollo::cyber::Writer<::apollo::canbus::Ge3>> chassis_detail_writer_; }; CYBER_REGISTER_VEHICLEFACTORY(Ge3VehicleFactory) } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/ge3_controller.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include <memory> #include <thread> #include "modules/canbus/proto/canbus_conf.pb.h" #include "modules/common_msgs/chassis_msgs/chassis.pb.h" #include "modules/canbus/proto/vehicle_parameter.pb.h" #include "modules/canbus_vehicle/ge3/protocol/pc_bcm_201.h" #include "modules/canbus_vehicle/ge3/protocol/pc_bcs_202.h" #include "modules/canbus_vehicle/ge3/protocol/pc_epb_203.h" #include "modules/canbus_vehicle/ge3/protocol/pc_eps_204.h" #include "modules/canbus_vehicle/ge3/protocol/pc_vcu_205.h" #include "modules/canbus/vehicle/vehicle_controller.h" #include "modules/common_msgs/basic_msgs/error_code.pb.h" #include "modules/common_msgs/control_msgs/control_cmd.pb.h" namespace apollo { namespace canbus { namespace ge3 { class Ge3Controller final : public VehicleController<::apollo::canbus::Ge3> { public: Ge3Controller() {} virtual ~Ge3Controller(); ::apollo::common::ErrorCode Init( const VehicleParameter& params, CanSender<::apollo::canbus::Ge3>* const can_sender, MessageManager<::apollo::canbus::Ge3>* const message_manager) override; bool Start() override; /** * @brief stop the vehicle controller. */ void Stop() override; /** * @brief calculate and return the chassis. * @returns a copy of chassis. Use copy here to avoid multi-thread issues. */ Chassis chassis() override; FRIEND_TEST(Ge3ControllerTest, SetDrivingMode); FRIEND_TEST(Ge3ControllerTest, Status); FRIEND_TEST(Ge3ControllerTest, UpdateDrivingMode); private: // main logical function for operation the car enter or exit the auto driving void Emergency() override; ::apollo::common::ErrorCode EnableAutoMode() override; ::apollo::common::ErrorCode DisableAutoMode() override; ::apollo::common::ErrorCode EnableSteeringOnlyMode() override; ::apollo::common::ErrorCode EnableSpeedOnlyMode() override; // NEUTRAL, REVERSE, DRIVE void Gear(Chassis::GearPosition state) override; // brake with new acceleration // acceleration:0.00~99.99, unit: // acceleration_spd: 60 ~ 100, suggest: 90 void Brake(double acceleration) override; // drive with old acceleration // gas:0.00~99.99 unit: void Throttle(double throttle) override; // drive with acceleration/deceleration // acc:-7.0~5.0 unit:m/s^2 void Acceleration(double acc) override; // steering with old angle speed // angle:-99.99~0.00~99.99, unit:, left:+, right:- void Steer(double angle) override; // steering with new angle speed // angle:-99.99~0.00~99.99, unit:, left:+, right:- // angle_spd:0.00~99.99, unit:deg/s void Steer(double angle, double angle_spd) override; // set Electrical Park Brake void SetEpbBreak(const ::apollo::control::ControlCommand& command) override; void SetBeam(const ::apollo::control::ControlCommand& command) override; void SetHorn(const ::apollo::control::ControlCommand& command) override; void SetTurningSignal( const ::apollo::control::ControlCommand& command) override; bool VerifyID() override; void ResetProtocol(); bool CheckChassisError(); bool CheckSafetyError(const canbus::Ge3& chassis); private: void SecurityDogThreadFunc(); virtual bool CheckResponse(const int32_t flags, bool need_wait); void set_chassis_error_mask(const int32_t mask); int32_t chassis_error_mask(); Chassis::ErrorCode chassis_error_code(); void set_chassis_error_code(const Chassis::ErrorCode& error_code); private: // control protocol Pcbcm201* pc_bcm_201_ = nullptr; Pcbcs202* pc_bcs_202_ = nullptr; Pcepb203* pc_epb_203_ = nullptr; Pceps204* pc_eps_204_ = nullptr; Pcvcu205* pc_vcu_205_ = nullptr; Chassis chassis_; std::unique_ptr<std::thread> thread_; bool is_chassis_error_ = false; bool received_vin_ = false; std::mutex chassis_error_code_mutex_; Chassis::ErrorCode chassis_error_code_ = Chassis::NO_ERROR; std::mutex chassis_mask_mutex_; int32_t chassis_error_mask_ = 0; }; } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/ge3_controller_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/ge3_controller.h" #include <string> #include "cyber/common/file.h" #include "gtest/gtest.h" #include "modules/canbus/proto/canbus_conf.pb.h" #include "modules/common_msgs/chassis_msgs/chassis.pb.h" #include "modules/canbus_vehicle/ge3/proto/ge3.pb.h" #include "modules/canbus_vehicle/ge3/ge3_message_manager.h" #include "modules/common_msgs/control_msgs/control_cmd.pb.h" #include "modules/drivers/canbus/can_comm/can_sender.h" namespace apollo { namespace canbus { namespace ge3 { using ::apollo::common::ErrorCode; using ::apollo::control::ControlCommand; class Ge3ControllerTest : public ::testing::Test { public: virtual void SetUp() { std::string canbus_conf_file = "modules/canbus/testdata/conf/ge3_canbus_conf_test.pb.txt"; cyber::common::GetProtoFromFile(canbus_conf_file, &canbus_conf_); params_ = canbus_conf_.vehicle_parameter(); } protected: Ge3Controller controller_; CanSender<::apollo::canbus::Ge3> sender_; CanbusConf canbus_conf_; VehicleParameter params_; Ge3MessageManager msg_manager_; ControlCommand control_cmd_; }; TEST_F(Ge3ControllerTest, Init) { ErrorCode ret = controller_.Init(params_, &sender_, &msg_manager_); EXPECT_EQ(ret, ErrorCode::OK); } TEST_F(Ge3ControllerTest, SetDrivingMode) { Chassis chassis; chassis.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE); controller_.Init(params_, &sender_, &msg_manager_); controller_.set_driving_mode(chassis.driving_mode()); EXPECT_EQ(controller_.driving_mode(), chassis.driving_mode()); EXPECT_EQ(controller_.SetDrivingMode(chassis.driving_mode()), ErrorCode::OK); } TEST_F(Ge3ControllerTest, Status) { controller_.Init(params_, &sender_, &msg_manager_); controller_.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE); EXPECT_EQ(controller_.Update(control_cmd_), ErrorCode::OK); controller_.SetHorn(control_cmd_); controller_.SetBeam(control_cmd_); controller_.SetTurningSignal(control_cmd_); EXPECT_FALSE(controller_.CheckChassisError()); } TEST_F(Ge3ControllerTest, UpdateDrivingMode) { controller_.Init(params_, &sender_, &msg_manager_); controller_.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE); EXPECT_EQ(controller_.SetDrivingMode(Chassis::COMPLETE_MANUAL), ErrorCode::OK); } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/ge3_vehicle_factory.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/ge3_vehicle_factory.h" #include "cyber/common/log.h" #include "modules/canbus/common/canbus_gflags.h" #include "modules/canbus_vehicle/ge3/ge3_controller.h" #include "modules/canbus_vehicle/ge3/ge3_message_manager.h" #include "modules/common/adapters/adapter_gflags.h" #include "modules/common/util/util.h" #include "modules/drivers/canbus/can_client/can_client_factory.h" using apollo::common::ErrorCode; using apollo::control::ControlCommand; using apollo::drivers::canbus::CanClientFactory; namespace apollo { namespace canbus { bool Ge3VehicleFactory::Init(const CanbusConf *canbus_conf) { // Init can client auto can_factory = CanClientFactory::Instance(); can_factory->RegisterCanClients(); can_client_ = can_factory->CreateCANClient(canbus_conf->can_card_parameter()); if (!can_client_) { AERROR << "Failed to create can client."; return false; } AINFO << "Can client is successfully created."; message_manager_ = this->CreateMessageManager(); if (message_manager_ == nullptr) { AERROR << "Failed to create message manager."; return false; } AINFO << "Message manager is successfully created."; if (can_receiver_.Init(can_client_.get(), message_manager_.get(), canbus_conf->enable_receiver_log()) != ErrorCode::OK) { AERROR << "Failed to init can receiver."; return false; } AINFO << "The can receiver is successfully initialized."; if (can_sender_.Init(can_client_.get(), message_manager_.get(), canbus_conf->enable_sender_log()) != ErrorCode::OK) { AERROR << "Failed to init can sender."; return false; } AINFO << "The can sender is successfully initialized."; vehicle_controller_ = CreateVehicleController(); if (vehicle_controller_ == nullptr) { AERROR << "Failed to create vehicle controller."; return false; } AINFO << "The vehicle controller is successfully created."; if (vehicle_controller_->Init(canbus_conf->vehicle_parameter(), &can_sender_, message_manager_.get()) != ErrorCode::OK) { AERROR << "Failed to init vehicle controller."; return false; } AINFO << "The vehicle controller is successfully" << " initialized with canbus conf as : " << canbus_conf->vehicle_parameter().ShortDebugString(); node_ = ::apollo::cyber::CreateNode("chassis_detail"); chassis_detail_writer_ = node_->CreateWriter<::apollo::canbus::Ge3>(FLAGS_chassis_detail_topic); return true; } bool Ge3VehicleFactory::Start() { // 1. init and start the can card hardware if (can_client_->Start() != ErrorCode::OK) { AERROR << "Failed to start can client"; return false; } AINFO << "Can client is started."; // 2. start receive first then send if (can_receiver_.Start() != ErrorCode::OK) { AERROR << "Failed to start can receiver."; return false; } AINFO << "Can receiver is started."; // 3. start send if (can_sender_.Start() != ErrorCode::OK) { AERROR << "Failed to start can sender."; return false; } // 4. start controller if (!vehicle_controller_->Start()) { AERROR << "Failed to start vehicle controller."; return false; } return true; } void Ge3VehicleFactory::Stop() { can_sender_.Stop(); can_receiver_.Stop(); can_client_->Stop(); vehicle_controller_->Stop(); AINFO << "Cleanup cansender, canreceiver, canclient, vehicle controller."; } void Ge3VehicleFactory::UpdateCommand( const apollo::control::ControlCommand *control_command) { if (vehicle_controller_->Update(*control_command) != ErrorCode::OK) { AERROR << "Failed to process callback function OnControlCommand because " "vehicle_controller_->Update error."; return; } can_sender_.Update(); } Chassis Ge3VehicleFactory::publish_chassis() { Chassis chassis = vehicle_controller_->chassis(); ADEBUG << chassis.ShortDebugString(); return chassis; } void Ge3VehicleFactory::PublishChassisDetail() { Ge3 chassis_detail; message_manager_->GetSensorData(&chassis_detail); ADEBUG << chassis_detail.ShortDebugString(); chassis_detail_writer_->Write(chassis_detail); } std::unique_ptr<VehicleController<::apollo::canbus::Ge3>> Ge3VehicleFactory::CreateVehicleController() { return std::unique_ptr<VehicleController<::apollo::canbus::Ge3>>( new ge3::Ge3Controller()); } std::unique_ptr<MessageManager<::apollo::canbus::Ge3>> Ge3VehicleFactory::CreateMessageManager() { return std::unique_ptr<MessageManager<::apollo::canbus::Ge3>>( new ge3::Ge3MessageManager()); } } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/BUILD
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("//tools/install:install.bzl", "install", "install_files", "install_src_files") load("//tools:cpplint.bzl", "cpplint") package(default_visibility = ["//visibility:public"]) CANBUS_COPTS = ["-DMODULE_NAME=\\\"canbus\\\""] cc_library( name = "ge3_vehicle_factory", srcs = ["ge3_vehicle_factory.cc"], hdrs = ["ge3_vehicle_factory.h"], copts = CANBUS_COPTS, alwayslink = True, deps = [ ":ge3_controller", ":ge3_message_manager", "//modules/canbus/common:canbus_gflags", "//modules/common/adapters:adapter_gflags", "//modules/common/status", "//modules/canbus/proto:vehicle_parameter_cc_proto", "//modules/canbus/vehicle:abstract_vehicle_factory", "//modules/drivers/canbus:sensor_canbus_lib", ], ) cc_binary( name = "libge3_vehicle_factory_lib.so", linkshared = True, linkstatic = True, deps = [":ge3_vehicle_factory"], ) cc_test( name = "ge3_vehicle_factory_test", size = "small", srcs = ["ge3_vehicle_factory_test.cc"], data = ["//modules/canbus:test_data"], linkstatic = True, deps = [ ":ge3_vehicle_factory", "@com_google_googletest//:gtest_main", ], ) cc_library( name = "ge3_message_manager", srcs = ["ge3_message_manager.cc"], hdrs = ["ge3_message_manager.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/ge3/proto:ge3_cc_proto", "//modules/canbus_vehicle/ge3/protocol:canbus_ge3_protocol_pc_bcm_201", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "ge3_message_manager_test", size = "small", srcs = ["ge3_message_manager_test.cc"], deps = [ ":ge3_message_manager", "@com_google_googletest//:gtest_main", ], ) cc_library( name = "ge3_controller", srcs = ["ge3_controller.cc"], hdrs = ["ge3_controller.h"], copts = CANBUS_COPTS, deps = [ ":ge3_message_manager", "//modules/common_msgs/chassis_msgs:chassis_cc_proto", "//modules/canbus/vehicle:vehicle_controller_base", "//modules/canbus_vehicle/ge3/protocol:canbus_ge3_protocol_pc_bcm_201", "//modules/drivers/canbus/can_comm:can_sender", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "ge3_controller_test", size = "small", srcs = ["ge3_controller_test.cc"], data = ["//modules/canbus:test_data"], deps = [ ":ge3_controller", "//modules/common/util", "@com_google_googletest//:gtest_main", ], ) install( name = "install", library_dest = "canbus-vehicle-ge3/lib", data_dest = "canbus-vehicle-ge3", data = [ ":runtime_data", ":cyberfile.xml", ":canbus-vehicle-ge3.BUILD", ], targets = [ ":libge3_vehicle_factory_lib.so", ], deps = [ ":pb_ge3", ":pb_hdrs", ], ) install( name = "pb_hdrs", data_dest = "canbus-vehicle-ge3/include", data = [ "//modules/canbus_vehicle/ge3/proto:ge3_cc_proto", ], ) install_files( name = "pb_ge3", dest = "canbus-vehicle-ge3", files = [ "//modules/canbus_vehicle/ge3/proto:ge3_py_pb2", ], ) filegroup( name = "runtime_data", srcs = glob([ "testdata/**", ]), ) install_src_files( name = "install_src", deps = [ ":install_ge3_src", ":install_ge3_hdrs" ], ) install_src_files( name = "install_ge3_src", src_dir = ["."], dest = "canbus-vehicle-ge3/src", filter = "*", ) install_src_files( name = "install_ge3_hdrs", src_dir = ["."], dest = "canbus-vehicle-ge3/include", filter = "*.h", ) cpplint()
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/ge3_controller.cc
/* Copyright 2019 The Apollo Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ #include "modules/canbus_vehicle/ge3/ge3_controller.h" #include "modules/common_msgs/basic_msgs/vehicle_signal.pb.h" #include "cyber/time/time.h" #include "modules/canbus_vehicle/ge3/ge3_message_manager.h" #include "modules/canbus/vehicle/vehicle_controller.h" #include "modules/drivers/canbus/can_comm/can_sender.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace ge3 { using ::apollo::common::ErrorCode; using ::apollo::control::ControlCommand; using ::apollo::drivers::canbus::ProtocolData; namespace { const int32_t kMaxFailAttempt = 10; const int32_t CHECK_RESPONSE_STEER_UNIT_FLAG = 1; const int32_t CHECK_RESPONSE_SPEED_UNIT_FLAG = 2; } // namespace ErrorCode Ge3Controller::Init( const VehicleParameter& params, CanSender<Ge3>* const can_sender, MessageManager<::apollo::canbus::Ge3>* const message_manager) { if (is_initialized_) { AINFO << "Ge3Controller has already been initiated."; return ErrorCode::CANBUS_ERROR; } vehicle_params_.CopyFrom( common::VehicleConfigHelper::Instance()->GetConfig().vehicle_param()); params_.CopyFrom(params); if (!params_.has_driving_mode()) { AERROR << "Vehicle conf pb not set driving_mode."; return ErrorCode::CANBUS_ERROR; } if (can_sender == nullptr) { AERROR << "Canbus sender is null."; return ErrorCode::CANBUS_ERROR; } can_sender_ = can_sender; if (message_manager == nullptr) { AERROR << "protocol manager is null."; return ErrorCode::CANBUS_ERROR; } message_manager_ = message_manager; // sender part pc_bcm_201_ = dynamic_cast<Pcbcm201*>( message_manager_->GetMutableProtocolDataById(Pcbcm201::ID)); if (pc_bcm_201_ == nullptr) { AERROR << "Pcbcm201 does not exist in the Ge3MessageManager!"; return ErrorCode::CANBUS_ERROR; } pc_bcs_202_ = dynamic_cast<Pcbcs202*>( message_manager_->GetMutableProtocolDataById(Pcbcs202::ID)); if (pc_bcs_202_ == nullptr) { AERROR << "Pcbcs202 does not exist in the Ge3MessageManager!"; return ErrorCode::CANBUS_ERROR; } pc_epb_203_ = dynamic_cast<Pcepb203*>( message_manager_->GetMutableProtocolDataById(Pcepb203::ID)); if (pc_epb_203_ == nullptr) { AERROR << "Pcepb203 does not exist in the Ge3MessageManager!"; return ErrorCode::CANBUS_ERROR; } pc_eps_204_ = dynamic_cast<Pceps204*>( message_manager_->GetMutableProtocolDataById(Pceps204::ID)); if (pc_eps_204_ == nullptr) { AERROR << "Pceps204 does not exist in the Ge3MessageManager!"; return ErrorCode::CANBUS_ERROR; } pc_vcu_205_ = dynamic_cast<Pcvcu205*>( message_manager_->GetMutableProtocolDataById(Pcvcu205::ID)); if (pc_vcu_205_ == nullptr) { AERROR << "Pcvcu205 does not exist in the Ge3MessageManager!"; return ErrorCode::CANBUS_ERROR; } can_sender_->AddMessage(Pcbcm201::ID, pc_bcm_201_, false); can_sender_->AddMessage(Pcbcs202::ID, pc_bcs_202_, false); can_sender_->AddMessage(Pcepb203::ID, pc_epb_203_, false); can_sender_->AddMessage(Pceps204::ID, pc_eps_204_, false); can_sender_->AddMessage(Pcvcu205::ID, pc_vcu_205_, false); // Need to sleep to ensure all messages received AINFO << "Ge3Controller is initialized."; is_initialized_ = true; return ErrorCode::OK; } Ge3Controller::~Ge3Controller() {} bool Ge3Controller::Start() { if (!is_initialized_) { AERROR << "Ge3Controller has NOT been initialized."; return false; } const auto& update_func = [this] { SecurityDogThreadFunc(); }; thread_.reset(new std::thread(update_func)); return true; } void Ge3Controller::Stop() { if (!is_initialized_) { AERROR << "Ge3Controller stops or starts improperly!"; return; } if (thread_ != nullptr && thread_->joinable()) { thread_->join(); thread_.reset(); AINFO << "Ge3Controller stopped."; } } Chassis Ge3Controller::chassis() { chassis_.Clear(); Ge3 chassis_detail; message_manager_->GetSensorData(&chassis_detail); // 21, 22, previously 1, 2 if (driving_mode() == Chassis::EMERGENCY_MODE) { set_chassis_error_code(Chassis::NO_ERROR); } chassis_.set_driving_mode(driving_mode()); chassis_.set_error_code(chassis_error_code()); // 3 chassis_.set_engine_started(true); // 5 if (chassis_detail.has_scu_bcs_3_308()) { Scu_bcs_3_308 scu_bcs_3_308 = chassis_detail.scu_bcs_3_308(); if (scu_bcs_3_308.has_bcs_rrwheelspd()) { if (chassis_.has_wheel_speed()) { chassis_.mutable_wheel_speed()->set_is_wheel_spd_rr_valid( scu_bcs_3_308.bcs_rrwheelspdvd()); chassis_.mutable_wheel_speed()->set_wheel_direction_rr( (WheelSpeed::WheelSpeedType)scu_bcs_3_308.bcs_rrwheeldirection()); chassis_.mutable_wheel_speed()->set_wheel_spd_rr( scu_bcs_3_308.bcs_rrwheelspd()); } } if (scu_bcs_3_308.has_bcs_rlwheelspd()) { if (chassis_.has_wheel_speed()) { chassis_.mutable_wheel_speed()->set_is_wheel_spd_rl_valid( scu_bcs_3_308.bcs_rlwheelspdvd()); chassis_.mutable_wheel_speed()->set_wheel_direction_rl( (WheelSpeed::WheelSpeedType)scu_bcs_3_308.bcs_rlwheeldirection()); chassis_.mutable_wheel_speed()->set_wheel_spd_rl( scu_bcs_3_308.bcs_rlwheelspd()); } } if (scu_bcs_3_308.has_bcs_frwheelspd()) { if (chassis_.has_wheel_speed()) { chassis_.mutable_wheel_speed()->set_is_wheel_spd_fr_valid( scu_bcs_3_308.bcs_frwheelspdvd()); chassis_.mutable_wheel_speed()->set_wheel_direction_fr( (WheelSpeed::WheelSpeedType)scu_bcs_3_308.bcs_frwheeldirection()); chassis_.mutable_wheel_speed()->set_wheel_spd_fr( scu_bcs_3_308.bcs_frwheelspd()); } } if (scu_bcs_3_308.has_bcs_flwheelspd()) { if (chassis_.has_wheel_speed()) { chassis_.mutable_wheel_speed()->set_is_wheel_spd_fl_valid( scu_bcs_3_308.bcs_flwheelspdvd()); chassis_.mutable_wheel_speed()->set_wheel_direction_fl( (WheelSpeed::WheelSpeedType)scu_bcs_3_308.bcs_flwheeldirection()); chassis_.mutable_wheel_speed()->set_wheel_spd_fl( scu_bcs_3_308.bcs_flwheelspd()); } } } if (chassis_detail.has_scu_bcs_2_307() && chassis_detail.scu_bcs_2_307().has_bcs_vehspd()) { chassis_.set_speed_mps( static_cast<float>(chassis_detail.scu_bcs_2_307().bcs_vehspd())); } else { chassis_.set_speed_mps(0); } // 7 // ge3 only has fuel percentage // to avoid confusing, just don't set chassis_.set_fuel_range_m(0); if (chassis_detail.has_scu_vcu_1_312() && chassis_detail.scu_vcu_1_312().has_vcu_accpedact()) { chassis_.set_throttle_percentage( static_cast<float>(chassis_detail.scu_vcu_1_312().vcu_accpedact())); } else { chassis_.set_throttle_percentage(0); } // 9 if (chassis_detail.has_scu_bcs_1_306() && chassis_detail.scu_bcs_1_306().has_bcs_brkpedact()) { chassis_.set_brake_percentage( static_cast<float>(chassis_detail.scu_bcs_1_306().bcs_brkpedact())); } else { chassis_.set_brake_percentage(0); } // 23, previously 10 if (chassis_detail.has_scu_vcu_1_312() && chassis_detail.scu_vcu_1_312().has_vcu_gearact()) { switch (chassis_detail.scu_vcu_1_312().vcu_gearact()) { case Scu_vcu_1_312::VCU_GEARACT_INVALID: { chassis_.set_gear_location(Chassis::GEAR_INVALID); } break; case Scu_vcu_1_312::VCU_GEARACT_DRIVE: { chassis_.set_gear_location(Chassis::GEAR_DRIVE); } break; case Scu_vcu_1_312::VCU_GEARACT_NEUTRAL: { chassis_.set_gear_location(Chassis::GEAR_NEUTRAL); } break; case Scu_vcu_1_312::VCU_GEARACT_REVERSE: { chassis_.set_gear_location(Chassis::GEAR_REVERSE); } break; case Scu_vcu_1_312::VCU_GEARACT_PARK: { chassis_.set_gear_location(Chassis::GEAR_PARKING); } break; default: chassis_.set_gear_location(Chassis::GEAR_INVALID); break; } } else { chassis_.set_gear_location(Chassis::GEAR_INVALID); } // 11 if (chassis_detail.has_scu_eps_311() && chassis_detail.scu_eps_311().has_eps_steerangle()) { chassis_.set_steering_percentage( static_cast<float>(chassis_detail.scu_eps_311().eps_steerangle() / vehicle_params_.max_steer_angle() * M_PI / 1.80)); } else { chassis_.set_steering_percentage(0); } // 13 if (chassis_detail.has_scu_epb_310() && chassis_detail.scu_epb_310().has_epb_sysst()) { chassis_.set_parking_brake(chassis_detail.scu_epb_310().epb_sysst() == Scu_epb_310::EPB_SYSST_APPLIED); } else { chassis_.set_parking_brake(false); } // 14, 15: ge3 light control if (chassis_detail.has_scu_bcm_304() && chassis_detail.scu_bcm_304().has_bcm_highbeamst() && Scu_bcm_304::BCM_HIGHBEAMST_ACTIVE == chassis_detail.scu_bcm_304().bcm_highbeamst()) { if (chassis_.has_signal()) { chassis_.mutable_signal()->set_high_beam(true); } } else { if (chassis_.has_signal()) { chassis_.mutable_signal()->set_high_beam(false); } } // 16, 17 if (chassis_detail.has_scu_bcm_304()) { Scu_bcm_304 scu_bcm_304 = chassis_detail.scu_bcm_304(); if (scu_bcm_304.has_bcm_leftturnlampst() && Scu_bcm_304::BCM_LEFTTURNLAMPST_ACTIVE == scu_bcm_304.bcm_leftturnlampst()) { chassis_.mutable_signal()->set_turn_signal( common::VehicleSignal::TURN_LEFT); } else if (scu_bcm_304.has_bcm_rightturnlampst() && Scu_bcm_304::BCM_RIGHTTURNLAMPST_ACTIVE == scu_bcm_304.bcm_rightturnlampst()) { chassis_.mutable_signal()->set_turn_signal( common::VehicleSignal::TURN_RIGHT); } else { chassis_.mutable_signal()->set_turn_signal( common::VehicleSignal::TURN_NONE); } } else { chassis_.mutable_signal()->set_turn_signal( common::VehicleSignal::TURN_NONE); } // 18 if (chassis_detail.has_scu_bcm_304() && chassis_detail.scu_bcm_304().has_bcm_hornst() && Scu_bcm_304::BCM_HORNST_ACTIVE == chassis_detail.scu_bcm_304().bcm_hornst()) { chassis_.mutable_signal()->set_horn(true); } else { chassis_.mutable_signal()->set_horn(false); } // vin number will be written into KVDB once. chassis_.mutable_vehicle_id()->set_vin(""); if (chassis_detail.has_scu_1_301() && chassis_detail.has_scu_2_302() && chassis_detail.has_scu_3_303()) { Scu_1_301 scu_1_301 = chassis_detail.scu_1_301(); Scu_2_302 scu_2_302 = chassis_detail.scu_2_302(); Scu_3_303 scu_3_303 = chassis_detail.scu_3_303(); if (scu_2_302.has_vin00() && scu_2_302.has_vin01() && scu_2_302.has_vin02() && scu_2_302.has_vin03() && scu_2_302.has_vin04() && scu_2_302.has_vin05() && scu_2_302.has_vin06() && scu_2_302.has_vin07() && scu_3_303.has_vin08() && scu_3_303.has_vin09() && scu_3_303.has_vin10() && scu_3_303.has_vin11() && scu_3_303.has_vin12() && scu_3_303.has_vin13() && scu_3_303.has_vin14() && scu_3_303.has_vin15() && scu_1_301.has_vin16()) { int n[17]; n[0] = scu_2_302.vin00(); n[1] = scu_2_302.vin01(); n[2] = scu_2_302.vin02(); n[3] = scu_2_302.vin03(); n[4] = scu_2_302.vin04(); n[5] = scu_2_302.vin05(); n[6] = scu_2_302.vin06(); n[7] = scu_2_302.vin07(); n[8] = scu_3_303.vin08(); n[9] = scu_3_303.vin09(); n[10] = scu_3_303.vin10(); n[11] = scu_3_303.vin11(); n[12] = scu_3_303.vin12(); n[13] = scu_3_303.vin13(); n[14] = scu_3_303.vin14(); n[15] = scu_3_303.vin15(); n[16] = scu_1_301.vin16(); char ch[17]; memset(&ch, '\0', sizeof(ch)); for (int i = 0; i < 17; i++) { ch[i] = static_cast<char>(n[i]); } if (chassis_.has_vehicle_id()) { chassis_.mutable_vehicle_id()->set_vin(ch); } } } // give engage_advice based on error_code and canbus feedback if (chassis_error_mask_) { if (chassis_.has_engage_advice()) { chassis_.mutable_engage_advice()->set_advice( apollo::common::EngageAdvice::DISALLOW_ENGAGE); chassis_.mutable_engage_advice()->set_reason("Chassis error!"); } } else if (chassis_.parking_brake() || CheckSafetyError(chassis_detail)) { if (chassis_.has_engage_advice()) { chassis_.mutable_engage_advice()->set_advice( apollo::common::EngageAdvice::DISALLOW_ENGAGE); chassis_.mutable_engage_advice()->set_reason( "Vehicle is not in a safe state to engage!"); } } else { if (chassis_.has_engage_advice()) { chassis_.mutable_engage_advice()->set_advice( apollo::common::EngageAdvice::READY_TO_ENGAGE); } } // 19 add checkresponse signal if (chassis_detail.has_scu_bcs_1_306() && chassis_detail.scu_bcs_1_306().has_bcs_drvmode()) { chassis_.mutable_check_response()->set_is_esp_online( chassis_detail.scu_bcs_1_306().bcs_drvmode() == 1); } if (chassis_detail.has_scu_eps_311() && chassis_detail.scu_eps_311().has_eps_drvmode()) { chassis_.mutable_check_response()->set_is_eps_online( chassis_detail.scu_eps_311().eps_drvmode() == 1); } if (chassis_detail.has_scu_vcu_1_312() && chassis_detail.scu_vcu_1_312().has_vcu_drvmode()) { chassis_.mutable_check_response()->set_is_vcu_online( chassis_detail.scu_vcu_1_312().vcu_drvmode() == 1); } return chassis_; } bool Ge3Controller::VerifyID() { return true; } void Ge3Controller::Emergency() { set_driving_mode(Chassis::EMERGENCY_MODE); ResetProtocol(); // In emergency case, the hazard lamp should be on pc_bcm_201_->set_pc_hazardlampreq(Pc_bcm_201::PC_HAZARDLAMPREQ_REQ); set_chassis_error_code(Chassis::CHASSIS_ERROR); } ErrorCode Ge3Controller::EnableAutoMode() { if (driving_mode() == Chassis::COMPLETE_AUTO_DRIVE) { AINFO << "already in COMPLETE_AUTO_DRIVE mode"; return ErrorCode::OK; } pc_bcs_202_->set_pc_brkpedenable(Pc_bcs_202::PC_BRKPEDENABLE_ENABLE); pc_vcu_205_->set_pc_accpedenable(Pc_vcu_205::PC_ACCPEDENABLE_ENABLE); pc_vcu_205_->set_pc_gearenable(Pc_vcu_205::PC_GEARENABLE_ENABLE); pc_epb_203_->set_pc_epbenable(Pc_epb_203::PC_EPBENABLE_ENABLE); pc_eps_204_->set_pc_steerenable(Pc_eps_204::PC_STEERENABLE_ENABLE); can_sender_->Update(); const int32_t flag = CHECK_RESPONSE_STEER_UNIT_FLAG | CHECK_RESPONSE_SPEED_UNIT_FLAG; if (!CheckResponse(flag, true)) { AERROR << "Failed to switch to COMPLETE_AUTO_DRIVE mode."; Emergency(); set_chassis_error_code(Chassis::CHASSIS_ERROR); return ErrorCode::CANBUS_ERROR; } set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE); // If the auto mode can be set normally, the harzad lamp should be off. pc_bcm_201_->set_pc_hazardlampreq(Pc_bcm_201::PC_HAZARDLAMPREQ_NOREQ); AINFO << "Switch to COMPLETE_AUTO_DRIVE mode ok."; return ErrorCode::OK; } ErrorCode Ge3Controller::DisableAutoMode() { ResetProtocol(); can_sender_->Update(); set_driving_mode(Chassis::COMPLETE_MANUAL); set_chassis_error_code(Chassis::NO_ERROR); AINFO << "Switch to COMPLETE_MANUAL OK."; return ErrorCode::OK; } ErrorCode Ge3Controller::EnableSteeringOnlyMode() { if (driving_mode() == Chassis::COMPLETE_AUTO_DRIVE || driving_mode() == Chassis::AUTO_STEER_ONLY) { set_driving_mode(Chassis::AUTO_STEER_ONLY); AINFO << "Already in AUTO_STEER_ONLY mode"; return ErrorCode::OK; } pc_bcs_202_->set_pc_brkpedenable(Pc_bcs_202::PC_BRKPEDENABLE_DISABLE); pc_vcu_205_->set_pc_accpedenable(Pc_vcu_205::PC_ACCPEDENABLE_DISABLE); pc_vcu_205_->set_pc_gearenable(Pc_vcu_205::PC_GEARENABLE_DISABLE); pc_epb_203_->set_pc_epbenable(Pc_epb_203::PC_EPBENABLE_DISABLE); pc_eps_204_->set_pc_steerenable(Pc_eps_204::PC_STEERENABLE_ENABLE); can_sender_->Update(); if (!CheckResponse(CHECK_RESPONSE_STEER_UNIT_FLAG, true)) { AERROR << "Failed to switch to AUTO_STEER_ONLY mode."; Emergency(); set_chassis_error_code(Chassis::CHASSIS_ERROR); return ErrorCode::CANBUS_ERROR; } set_driving_mode(Chassis::AUTO_STEER_ONLY); // If the auto mode can be set normally, the harzad lamp should be off. pc_bcm_201_->set_pc_hazardlampreq(Pc_bcm_201::PC_HAZARDLAMPREQ_NOREQ); AINFO << "Switch to AUTO_STEER_ONLY mode ok."; return ErrorCode::OK; } ErrorCode Ge3Controller::EnableSpeedOnlyMode() { if (driving_mode() == Chassis::COMPLETE_AUTO_DRIVE || driving_mode() == Chassis::AUTO_SPEED_ONLY) { set_driving_mode(Chassis::AUTO_SPEED_ONLY); AINFO << "Already in AUTO_SPEED_ONLY mode"; return ErrorCode::OK; } pc_bcs_202_->set_pc_brkpedenable(Pc_bcs_202::PC_BRKPEDENABLE_ENABLE); pc_vcu_205_->set_pc_accpedenable(Pc_vcu_205::PC_ACCPEDENABLE_ENABLE); pc_vcu_205_->set_pc_gearenable(Pc_vcu_205::PC_GEARENABLE_ENABLE); pc_epb_203_->set_pc_epbenable(Pc_epb_203::PC_EPBENABLE_ENABLE); pc_eps_204_->set_pc_steerenable(Pc_eps_204::PC_STEERENABLE_DISABLE); can_sender_->Update(); if (!CheckResponse(CHECK_RESPONSE_SPEED_UNIT_FLAG, true)) { AERROR << "Failed to switch to AUTO_SPEED_ONLY mode."; Emergency(); set_chassis_error_code(Chassis::CHASSIS_ERROR); return ErrorCode::CANBUS_ERROR; } set_driving_mode(Chassis::AUTO_SPEED_ONLY); // If the auto mode can be set normally, the harzad lamp should be off. pc_bcm_201_->set_pc_hazardlampreq(Pc_bcm_201::PC_HAZARDLAMPREQ_NOREQ); AINFO << "Switch to AUTO_SPEED_ONLY mode ok."; return ErrorCode::OK; } // NEUTRAL, REVERSE, DRIVE void Ge3Controller::Gear(Chassis::GearPosition gear_position) { if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE && driving_mode() != Chassis::AUTO_SPEED_ONLY) { AINFO << "This drive mode no need to set gear."; return; } switch (gear_position) { case Chassis::GEAR_NEUTRAL: { pc_vcu_205_->set_pc_gearreq(Pc_vcu_205::PC_GEARREQ_NEUTRAL); break; } case Chassis::GEAR_REVERSE: { pc_vcu_205_->set_pc_gearreq(Pc_vcu_205::PC_GEARREQ_REVERSE); break; } case Chassis::GEAR_DRIVE: { pc_vcu_205_->set_pc_gearreq(Pc_vcu_205::PC_GEARREQ_DRIVE); break; } case Chassis::GEAR_PARKING: { pc_vcu_205_->set_pc_gearreq(Pc_vcu_205::PC_GEARREQ_PARK); break; } case Chassis::GEAR_LOW: { pc_vcu_205_->set_pc_gearreq(Pc_vcu_205::PC_GEARREQ_INVALID); break; } case Chassis::GEAR_NONE: { pc_vcu_205_->set_pc_gearreq(Pc_vcu_205::PC_GEARREQ_INVALID); break; } case Chassis::GEAR_INVALID: { AERROR << "Gear command is invalid!"; pc_vcu_205_->set_pc_gearreq(Pc_vcu_205::PC_GEARREQ_INVALID); break; } default: { pc_vcu_205_->set_pc_gearreq(Pc_vcu_205::PC_GEARREQ_INVALID); break; } } } // brake with new acceleration // acceleration:0.00~99.99, unit: // acceleration:0.0 ~ 7.0, unit:m/s^2 // acceleration_spd:60 ~ 100, suggest: 90 // -> pedal void Ge3Controller::Brake(double pedal) { // Update brake value based on mode if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE && driving_mode() != Chassis::AUTO_SPEED_ONLY) { AINFO << "The current drive mode does not need to set acceleration."; return; } pc_bcs_202_->set_pc_brkpedreq(pedal); } // drive with old acceleration // gas:0.00~99.99 unit: void Ge3Controller::Throttle(double pedal) { if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE && driving_mode() != Chassis::AUTO_SPEED_ONLY) { AINFO << "The current drive mode does not need to set acceleration."; return; } pc_vcu_205_->set_pc_accpedreq(pedal); } // ge3 default, -470 ~ 470, left:+, right:- // need to be compatible with control module, so reverse // steering with old angle speed // angle:-99.99~0.00~99.99, unit:, left:-, right:+ void Ge3Controller::Steer(double angle) { if (!(driving_mode() == Chassis::COMPLETE_AUTO_DRIVE || driving_mode() == Chassis::AUTO_STEER_ONLY)) { AINFO << "The current driving mode does not need to set steer."; return; } const double real_angle = vehicle_params_.max_steer_angle() / M_PI * 180 * angle / 100.0; pc_eps_204_->set_pc_steerangreq(real_angle)->set_pc_steerspdreq(500); } // drive with acceleration/deceleration // acc:-7.0 ~ 5.0, unit:m/s^2 void Ge3Controller::Acceleration(double acc) { if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE && driving_mode() != Chassis::AUTO_SPEED_ONLY) { AINFO << "The current drive mode does not need to set acceleration."; return; } // None } // steering with new angle speed // angle:-99.99~0.00~99.99, unit:, left:-, right:+ // angle_spd:0.00~99.99, unit:deg/s void Ge3Controller::Steer(double angle, double angle_spd) { if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE && driving_mode() != Chassis::AUTO_STEER_ONLY) { AINFO << "The current driving mode does not need to set steer."; return; } const double real_angle = vehicle_params_.max_steer_angle() / M_PI * 180 * angle / 100.0; const double real_angle_spd = ProtocolData<::apollo::canbus::Ge3>::BoundedValue( vehicle_params_.min_steer_angle_rate() / M_PI * 180, vehicle_params_.max_steer_angle_rate() / M_PI * 180, vehicle_params_.max_steer_angle_rate() / M_PI * 180 * angle_spd / 100.0); pc_eps_204_->set_pc_steerangreq(real_angle) ->set_pc_steerspdreq(static_cast<int>(real_angle_spd)); } void Ge3Controller::SetEpbBreak(const ControlCommand& command) { if (command.parking_brake()) { pc_epb_203_->set_pc_epbreq(Pc_epb_203::PC_EPBREQ_APPLY); } else { pc_epb_203_->set_pc_epbreq(Pc_epb_203::PC_EPBREQ_RELEASE); } } void Ge3Controller::SetBeam(const ControlCommand& command) { if (command.signal().high_beam()) { pc_bcm_201_->set_pc_lowbeamreq(Pc_bcm_201::PC_LOWBEAMREQ_NOREQ); pc_bcm_201_->set_pc_highbeamreq(Pc_bcm_201::PC_HIGHBEAMREQ_REQ); } else if (command.signal().low_beam()) { pc_bcm_201_->set_pc_lowbeamreq(Pc_bcm_201::PC_LOWBEAMREQ_REQ); pc_bcm_201_->set_pc_highbeamreq(Pc_bcm_201::PC_HIGHBEAMREQ_NOREQ); } else { pc_bcm_201_->set_pc_lowbeamreq(Pc_bcm_201::PC_LOWBEAMREQ_NOREQ); pc_bcm_201_->set_pc_highbeamreq(Pc_bcm_201::PC_HIGHBEAMREQ_NOREQ); } } void Ge3Controller::SetHorn(const ControlCommand& command) { if (command.signal().horn()) { pc_bcm_201_->set_pc_hornreq(Pc_bcm_201::PC_HORNREQ_REQ); } else { pc_bcm_201_->set_pc_hornreq(Pc_bcm_201::PC_HORNREQ_NOREQ); } } void Ge3Controller::SetTurningSignal(const ControlCommand& command) { // Set Turn Signal auto signal = command.signal().turn_signal(); if (signal == common::VehicleSignal::TURN_LEFT) { pc_bcm_201_->set_pc_leftturnlampreq(Pc_bcm_201::PC_LEFTTURNLAMPREQ_REQ); pc_bcm_201_->set_pc_rightturnlampreq(Pc_bcm_201::PC_RIGHTTURNLAMPREQ_NOREQ); } else if (signal == common::VehicleSignal::TURN_RIGHT) { pc_bcm_201_->set_pc_leftturnlampreq(Pc_bcm_201::PC_LEFTTURNLAMPREQ_NOREQ); pc_bcm_201_->set_pc_rightturnlampreq(Pc_bcm_201::PC_RIGHTTURNLAMPREQ_REQ); } else { pc_bcm_201_->set_pc_leftturnlampreq(Pc_bcm_201::PC_LEFTTURNLAMPREQ_NOREQ); pc_bcm_201_->set_pc_rightturnlampreq(Pc_bcm_201::PC_RIGHTTURNLAMPREQ_NOREQ); } } void Ge3Controller::ResetProtocol() { message_manager_->ResetSendMessages(); } bool Ge3Controller::CheckChassisError() { Ge3 chassis_detail; message_manager_->GetSensorData(&chassis_detail); if (!chassis_detail.has_check_response()) { AERROR_EVERY(100) << "ChassisDetail has NO ge3 vehicle info." << chassis_detail.DebugString(); return false; } // check steer error if (chassis_detail.has_scu_eps_311()) { if (Scu_eps_311::EPS_FAULTST_FAULT == chassis_detail.scu_eps_311().eps_faultst()) { return true; } } // check vcu error if (chassis_detail.has_scu_vcu_1_312() && Scu_vcu_1_312::VCU_FAULTST_NORMAL != chassis_detail.scu_vcu_1_312().vcu_faultst()) { return true; } // check braking error if (chassis_detail.has_scu_bcs_1_306()) { if (Scu_bcs_1_306::BCS_FAULTST_FAULT == chassis_detail.scu_bcs_1_306().bcs_faultst()) { return true; } } // check gear error if (chassis_detail.has_scu_vcu_1_312()) { if (Scu_vcu_1_312::VCU_GEARFAULTST_FAULT == chassis_detail.scu_vcu_1_312().vcu_gearfaultst()) { return true; } } // check parking error if (chassis_detail.has_scu_epb_310()) { if (Scu_epb_310::EPB_FAULTST_FAULT == chassis_detail.scu_epb_310().epb_faultst()) { return true; } } // check the whole vehicle error if (chassis_detail.has_scu_1_301()) { if (Scu_1_301::SCU_FAULTST_NORMAL != chassis_detail.scu_1_301().scu_faultst()) { return true; } } return false; } void Ge3Controller::SecurityDogThreadFunc() { int32_t vertical_ctrl_fail = 0; int32_t horizontal_ctrl_fail = 0; if (can_sender_ == nullptr) { AERROR << "Failed to run SecurityDogThreadFunc() because can_sender_ is " "nullptr."; return; } while (!can_sender_->IsRunning()) { std::this_thread::yield(); } std::chrono::duration<double, std::micro> default_period{50000}; int64_t start = 0; int64_t end = 0; while (can_sender_->IsRunning()) { start = ::apollo::cyber::Time::Now().ToMicrosecond(); const Chassis::DrivingMode mode = driving_mode(); bool emergency_mode = false; // 1. horizontal control check if ((mode == Chassis::COMPLETE_AUTO_DRIVE || mode == Chassis::AUTO_STEER_ONLY) && !CheckResponse(CHECK_RESPONSE_STEER_UNIT_FLAG, false)) { ++horizontal_ctrl_fail; if (horizontal_ctrl_fail >= kMaxFailAttempt) { emergency_mode = true; set_chassis_error_code(Chassis::MANUAL_INTERVENTION); } } else { horizontal_ctrl_fail = 0; } // 2. vertical control check if ((mode == Chassis::COMPLETE_AUTO_DRIVE || mode == Chassis::AUTO_SPEED_ONLY) && !CheckResponse(CHECK_RESPONSE_SPEED_UNIT_FLAG, false)) { ++vertical_ctrl_fail; if (vertical_ctrl_fail >= kMaxFailAttempt) { emergency_mode = true; set_chassis_error_code(Chassis::MANUAL_INTERVENTION); } } else { vertical_ctrl_fail = 0; } if (CheckChassisError()) { set_chassis_error_code(Chassis::CHASSIS_ERROR); emergency_mode = true; } if (emergency_mode && mode != Chassis::EMERGENCY_MODE) { set_driving_mode(Chassis::EMERGENCY_MODE); message_manager_->ResetSendMessages(); } end = ::apollo::cyber::Time::Now().ToMicrosecond(); std::chrono::duration<double, std::micro> elapsed{end - start}; if (elapsed < default_period) { std::this_thread::sleep_for(default_period - elapsed); } else { AERROR << "Too much time consumption in Ge3Controller looping process:" << elapsed.count(); } } } bool Ge3Controller::CheckResponse(const int32_t flags, bool need_wait) { int32_t retry_num = 20; Ge3 chassis_detail; bool is_eps_online = false; bool is_vcu_online = false; bool is_esp_online = false; do { if (message_manager_->GetSensorData(&chassis_detail) != ErrorCode::OK) { AERROR_EVERY(100) << "get chassis detail failed."; return false; } bool check_ok = true; if (flags & CHECK_RESPONSE_STEER_UNIT_FLAG) { is_eps_online = chassis_detail.has_check_response() && chassis_detail.check_response().has_is_eps_online() && chassis_detail.check_response().is_eps_online(); check_ok = check_ok && is_eps_online; } if (flags & CHECK_RESPONSE_SPEED_UNIT_FLAG) { is_vcu_online = chassis_detail.has_check_response() && chassis_detail.check_response().has_is_vcu_online() && chassis_detail.check_response().is_vcu_online(); is_esp_online = chassis_detail.has_check_response() && chassis_detail.check_response().has_is_esp_online() && chassis_detail.check_response().is_esp_online(); check_ok = check_ok && is_vcu_online && is_esp_online; } if (check_ok) { return true; } AINFO << "Need to check response again."; if (need_wait) { --retry_num; std::this_thread::sleep_for( std::chrono::duration<double, std::milli>(20)); } } while (need_wait && retry_num); AINFO << "check_response fail: is_eps_online:" << is_eps_online << ", is_vcu_online:" << is_vcu_online << ", is_esp_online:" << is_esp_online; return false; } void Ge3Controller::set_chassis_error_mask(const int32_t mask) { std::lock_guard<std::mutex> lock(chassis_mask_mutex_); chassis_error_mask_ = mask; } int32_t Ge3Controller::chassis_error_mask() { std::lock_guard<std::mutex> lock(chassis_mask_mutex_); return chassis_error_mask_; } Chassis::ErrorCode Ge3Controller::chassis_error_code() { std::lock_guard<std::mutex> lock(chassis_error_code_mutex_); return chassis_error_code_; } void Ge3Controller::set_chassis_error_code( const Chassis::ErrorCode& error_code) { std::lock_guard<std::mutex> lock(chassis_error_code_mutex_); chassis_error_code_ = error_code; } bool Ge3Controller::CheckSafetyError( const ::apollo::canbus::Ge3& chassis_detail) { return false; } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/ge3_message_manager_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/ge3_message_manager.h" #include "gtest/gtest.h" #include "modules/canbus_vehicle/ge3/protocol/pc_bcm_201.h" #include "modules/canbus_vehicle/ge3/protocol/pc_bcs_202.h" #include "modules/canbus_vehicle/ge3/protocol/pc_epb_203.h" #include "modules/canbus_vehicle/ge3/protocol/pc_eps_204.h" #include "modules/canbus_vehicle/ge3/protocol/pc_vcu_205.h" #include "modules/canbus_vehicle/ge3/protocol/scu_1_301.h" #include "modules/canbus_vehicle/ge3/protocol/scu_2_302.h" #include "modules/canbus_vehicle/ge3/protocol/scu_3_303.h" #include "modules/canbus_vehicle/ge3/protocol/scu_bcm_304.h" #include "modules/canbus_vehicle/ge3/protocol/scu_bcs_1_306.h" #include "modules/canbus_vehicle/ge3/protocol/scu_bcs_2_307.h" #include "modules/canbus_vehicle/ge3/protocol/scu_bcs_3_308.h" #include "modules/canbus_vehicle/ge3/protocol/scu_epb_310.h" #include "modules/canbus_vehicle/ge3/protocol/scu_eps_311.h" #include "modules/canbus_vehicle/ge3/protocol/scu_vcu_1_312.h" #include "modules/canbus_vehicle/ge3/protocol/scu_vcu_2_313.h" namespace apollo { namespace canbus { namespace ge3 { class Ge3MessageManagerTest : public ::testing::Test { public: Ge3MessageManagerTest() : manager_() {} virtual void SetUp() {} protected: Ge3MessageManager manager_; }; TEST_F(Ge3MessageManagerTest, GetSendProtocols) { EXPECT_NE(manager_.GetMutableProtocolDataById(Pcbcm201::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Pcbcs202::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Pcepb203::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Pceps204::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Pcvcu205::ID), nullptr); } TEST_F(Ge3MessageManagerTest, GetRecvProtocols) { EXPECT_NE(manager_.GetMutableProtocolDataById(Scu1301::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Scu2302::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Scu3303::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Scubcm304::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Scubcs1306::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Scubcs2307::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Scubcs3308::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Scuepb310::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Scueps311::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Scuvcu1312::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Scuvcu2313::ID), nullptr); } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/testdata/ge3_canbus_conf_test.pb.txt
vehicle_parameter { brand: GE3 max_enable_fail_attempt: 5 driving_mode: COMPLETE_AUTO_DRIVE } can_card_parameter { brand:SOCKET_CAN_RAW type: PCI_CARD channel_id: CHANNEL_ID_ZERO } enable_debug_mode: false
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/proto/ge3.proto
syntax = "proto2"; package apollo.canbus; message Pc_bcm_201 { // Control Message enum Pc_reverselampreqType { PC_REVERSELAMPREQ_NOREQ = 0; PC_REVERSELAMPREQ_REQ = 1; } enum Pc_lowbeamreqType { PC_LOWBEAMREQ_NOREQ = 0; PC_LOWBEAMREQ_REQ = 1; } enum Pc_highbeamreqType { PC_HIGHBEAMREQ_NOREQ = 0; PC_HIGHBEAMREQ_REQ = 1; } enum Pc_rightturnlampreqType { PC_RIGHTTURNLAMPREQ_NOREQ = 0; PC_RIGHTTURNLAMPREQ_REQ = 1; } enum Pc_leftturnlampreqType { PC_LEFTTURNLAMPREQ_NOREQ = 0; PC_LEFTTURNLAMPREQ_REQ = 1; } enum Pc_hornreqType { PC_HORNREQ_NOREQ = 0; PC_HORNREQ_REQ = 1; } enum Pc_hazardlampreqType { PC_HAZARDLAMPREQ_NOREQ = 0; PC_HAZARDLAMPREQ_REQ = 1; } // Left turn lamp request [] [0|1] optional Pc_reverselampreqType pc_reverselampreq = 1; // Left turn lamp request [] [0|1] optional Pc_lowbeamreqType pc_lowbeamreq = 2; // Left turn lamp request [] [0|1] optional Pc_highbeamreqType pc_highbeamreq = 3; // Right turn lamp request [] [0|3] optional Pc_rightturnlampreqType pc_rightturnlampreq = 4; // Left turn lamp request [] [0|1] optional Pc_leftturnlampreqType pc_leftturnlampreq = 5; // Horn request [] [0|1] optional Pc_hornreqType pc_hornreq = 6; // Hazard lamp request [] [0|1] optional Pc_hazardlampreqType pc_hazardlampreq = 7; } message Scu_bcs_3_308 { // Report Message enum Bcs_rrwheelspdvdType { BCS_RRWHEELSPDVD_INVALID = 0; BCS_RRWHEELSPDVD_VALID = 1; } enum Bcs_rrwheeldirectionvdType { BCS_RRWHEELDIRECTIONVD_INVALID = 0; BCS_RRWHEELDIRECTIONVD_VALID = 1; } enum Bcs_rlwheelspdvdType { BCS_RLWHEELSPDVD_INVALID = 0; BCS_RLWHEELSPDVD_VALID = 1; } enum Bcs_rlwheeldirectionvdType { BCS_RLWHEELDIRECTIONVD_INVALID = 0; BCS_RLWHEELDIRECTIONVD_VALID = 1; } enum Bcs_frwheelspdvdType { BCS_FRWHEELSPDVD_INVALID = 0; BCS_FRWHEELSPDVD_VALID = 1; } enum Bcs_frwheeldirectionvdType { BCS_FRWHEELDIRECTIONVD_INVALID = 0; BCS_FRWHEELDIRECTIONVD_VALID = 1; } enum Bcs_flwheelspdvdType { BCS_FLWHEELSPDVD_INVALID = 0; BCS_FLWHEELSPDVD_VALID = 1; } enum Bcs_flwheeldirectionvdType { BCS_FLWHEELDIRECTIONVD_INVALID = 0; BCS_FLWHEELDIRECTIONVD_VALID = 1; } enum Bcs_rrwheeldirectionType { BCS_RRWHEELDIRECTION_FORWARD = 0; BCS_RRWHEELDIRECTION_BACKWARD = 1; } enum Bcs_rlwheeldirectionType { BCS_RLWHEELDIRECTION_FORWARD = 0; BCS_RLWHEELDIRECTION_BACKWARD = 1; } enum Bcs_frwheeldirectionType { BCS_FRWHEELDIRECTION_FORWARD = 0; BCS_FRWHEELDIRECTION_BACKWARD = 1; } enum Bcs_flwheeldirectionType { BCS_FLWHEELDIRECTION_FORWARD = 0; BCS_FLWHEELDIRECTION_BACKWARD = 1; } // Rear right wheel speed valid data [-] [0|1] optional Bcs_rrwheelspdvdType bcs_rrwheelspdvd = 1; // Rear right wheel speed direction valid data [-] [0|1] optional Bcs_rrwheeldirectionvdType bcs_rrwheeldirectionvd = 2; // Rear left wheel speed valid data [-] [0|1] optional Bcs_rlwheelspdvdType bcs_rlwheelspdvd = 3; // Rear left wheel speed direction valid data [-] [0|1] optional Bcs_rlwheeldirectionvdType bcs_rlwheeldirectionvd = 4; // Front right wheel speed valid data [-] [0|1] optional Bcs_frwheelspdvdType bcs_frwheelspdvd = 5; // Front right wheel speed direction valid data [-] [0|1] optional Bcs_frwheeldirectionvdType bcs_frwheeldirectionvd = 6; // Front left wheel speed valid data [-] [0|1] optional Bcs_flwheelspdvdType bcs_flwheelspdvd = 7; // Front left wheel speed direction valid data [-] [0|1] optional Bcs_flwheeldirectionvdType bcs_flwheeldirectionvd = 8; // Rear right wheel speed [km/h] [0|240] optional double bcs_rrwheelspd = 9; // Rear right wheel speed direction [-] [0|1] optional Bcs_rrwheeldirectionType bcs_rrwheeldirection = 10; // Rear left wheel speed [km/h] [0|240] optional double bcs_rlwheelspd = 11; // Rear left wheel speed direction [-] [0|1] optional Bcs_rlwheeldirectionType bcs_rlwheeldirection = 12; // Front right wheel speed [km/h] [0|240] optional double bcs_frwheelspd = 13; // Front right wheel speed direction [-] [0|1] optional Bcs_frwheeldirectionType bcs_frwheeldirection = 14; // Front left wheel speed [km/h] [0|240] optional double bcs_flwheelspd = 15; // Front left wheel speed direction [-] [0|1] optional Bcs_flwheeldirectionType bcs_flwheeldirection = 16; } message Pc_epb_203 { // Control Message enum Pc_epbreqType { PC_EPBREQ_INVALID = 0; PC_EPBREQ_RELEASE = 1; PC_EPBREQ_APPLY = 2; } enum Pc_epbenableType { PC_EPBENABLE_DISABLE = 0; PC_EPBENABLE_ENABLE = 1; } // EPB request [] [0|1] optional Pc_epbreqType pc_epbreq = 1; // EPB control enable [] [0|1] optional Pc_epbenableType pc_epbenable = 2; } message Pc_bcs_202 { // Control Message enum Pc_brkpedenableType { PC_BRKPEDENABLE_DISABLE = 0; PC_BRKPEDENABLE_ENABLE = 1; } // Brake pedal request [%] [0|100] optional double pc_brkpedreq = 1; // Brake pedal control enable [] [0|1] optional Pc_brkpedenableType pc_brkpedenable = 2; } message Pc_vcu_205 { // Control Message enum Pc_accpedenableType { PC_ACCPEDENABLE_DISABLE = 0; PC_ACCPEDENABLE_ENABLE = 1; } enum Pc_torqenableType { PC_TORQENABLE_DISABLE = 0; PC_TORQENABLE_ENABLE = 1; } enum Pc_gearreqType { PC_GEARREQ_INVALID = 0; PC_GEARREQ_DRIVE = 1; PC_GEARREQ_NEUTRAL = 2; PC_GEARREQ_REVERSE = 3; PC_GEARREQ_PARK = 4; } enum Pc_gearenableType { PC_GEARENABLE_DISABLE = 0; PC_GEARENABLE_ENABLE = 1; } // Acceleration pedal request [%] [0|100] optional double pc_accpedreq = 1; // Acceleration pedal control enable [] [0|1] optional Pc_accpedenableType pc_accpedenable = 2; // Torque request [Nm] [-3000|3000] optional double pc_torqreq = 3; // Torque control enable [] [0|1] optional Pc_torqenableType pc_torqenable = 4; // Gear request [] [0|7] optional Pc_gearreqType pc_gearreq = 5; // Gear control enable [] [0|1] optional Pc_gearenableType pc_gearenable = 6; } message Pc_eps_204 { // Control Message enum Pc_steerenableType { PC_STEERENABLE_DISABLE = 0; PC_STEERENABLE_ENABLE = 1; } // Steer speed request [deg/s] [0|500] optional int32 pc_steerspdreq = 1; // Steer control enable [] [0|1] optional Pc_steerenableType pc_steerenable = 2; // Steer angle request [deg] [-500|500] optional double pc_steerangreq = 3; } message Scu_vcu_2_313 { // Report Message // Max positive torque [Nm] [0|3000] optional double vcu_torqposmax = 1; // Max negative torque [Nm] [-3000|0] optional double vcu_torqnegmax = 2; // Actual torque [Nm] [-3000|3000] optional double vcu_torqact = 3; // Engine speed [rpm] [0|65535] optional int32 vcu_engspd = 4; } message Scu_1_301 { // Report Message enum Scu_stopbutstType { SCU_STOPBUTST_UNPRESSED = 0; SCU_STOPBUTST_PRESSED = 1; } enum Scu_drvmodeType { SCU_DRVMODE_INVALID = 0; SCU_DRVMODE_MANUAL = 1; SCU_DRVMODE_INTERRUPT = 2; SCU_DRVMODE_AUTO = 3; } enum Scu_faultstType { SCU_FAULTST_NORMAL = 0; SCU_FAULTST_FAULT = 1; } // VIN string character 16 [-] [0|255] optional int32 vin16 = 1; // Brake pedal position [] [0|1] optional Scu_stopbutstType scu_stopbutst = 2; // SCU drive mode [] [0|3] optional Scu_drvmodeType scu_drvmode = 3; // SCU fault status [] [0|15] optional Scu_faultstType scu_faultst = 4; } message Scu_2_302 { // Report Message // VIN string character 07 [-] [0|255] optional int32 vin07 = 1; // VIN string character 06 [-] [0|255] optional int32 vin06 = 2; // VIN string character 05 [-] [0|255] optional int32 vin05 = 3; // VIN string character 04 [-] [0|255] optional int32 vin04 = 4; // VIN string character 03 [-] [0|255] optional int32 vin03 = 5; // VIN string character 02 [-] [0|255] optional int32 vin02 = 6; // VIN string character 01 [-] [0|255] optional int32 vin01 = 7; // VIN string character 00 [-] [0|255] optional int32 vin00 = 8; } message Scu_3_303 { // Report Message // VIN string character 15 [-] [0|255] optional int32 vin15 = 1; // VIN string character 14 [-] [0|255] optional int32 vin14 = 2; // VIN string character 13 [-] [0|255] optional int32 vin13 = 3; // VIN string character 12 [-] [0|255] optional int32 vin12 = 4; // VIN string character 11 [-] [0|255] optional int32 vin11 = 5; // VIN string character 10 [-] [0|255] optional int32 vin10 = 6; // VIN string character 09 [-] [0|255] optional int32 vin09 = 7; // VIN string character 08 [-] [0|255] optional int32 vin08 = 8; } message Scu_bcm_304 { // Report Message enum Bcm_vehreversestType { BCM_VEHREVERSEST_NORMAL = 0; BCM_VEHREVERSEST_REVERSE = 1; } enum Bcm_rightturnlampstType { BCM_RIGHTTURNLAMPST_INACTIVE = 0; BCM_RIGHTTURNLAMPST_ACTIVE = 1; } enum Bcm_rearfoglampstType { BCM_REARFOGLAMPST_INACTIVE = 0; BCM_REARFOGLAMPST_ACTIVE = 1; } enum Bcm_parkinglampstType { BCM_PARKINGLAMPST_INACTIVE = 0; BCM_PARKINGLAMPST_ACTIVE = 1; } enum Bcm_lowbeamstType { BCM_LOWBEAMST_INACTIVE = 0; BCM_LOWBEAMST_ACTIVE = 1; } enum Bcm_leftturnlampstType { BCM_LEFTTURNLAMPST_INACTIVE = 0; BCM_LEFTTURNLAMPST_ACTIVE = 1; } enum Bcm_keystType { BCM_KEYST_OFF = 0; BCM_KEYST_ACC = 1; BCM_KEYST_ON = 2; BCM_KEYST_CRANK = 3; } enum Bcm_hornstType { BCM_HORNST_INACTIVE = 0; BCM_HORNST_ACTIVE = 1; } enum Bcm_highbeamstType { BCM_HIGHBEAMST_INACTIVE = 0; BCM_HIGHBEAMST_ACTIVE = 1; } enum Bcm_hazardlampstType { BCM_HAZARDLAMPST_INACTIVE = 0; BCM_HAZARDLAMPST_ACTIVE = 1; } enum Bcm_frontfoglampstType { BCM_FRONTFOGLAMPST_INACTIVE = 0; BCM_FRONTFOGLAMPST_ACTIVE = 1; } enum Bcm_brakelightswitchstType { BCM_BRAKELIGHTSWITCHST_INACTIVE = 0; BCM_BRAKELIGHTSWITCHST_ACTIVE = 1; } // Vehicle reverse status [-] [0|1] optional Bcm_vehreversestType bcm_vehreversest = 1; // Right turn lamp status [-] [0|1] optional Bcm_rightturnlampstType bcm_rightturnlampst = 2; // Rear fog lamp status [-] [0|1] optional Bcm_rearfoglampstType bcm_rearfoglampst = 3; // Parking lamp status [] [0|1] optional Bcm_parkinglampstType bcm_parkinglampst = 4; // Low beam status [-] [0|1] optional Bcm_lowbeamstType bcm_lowbeamst = 5; // Left turn lamp status [-] [0|1] optional Bcm_leftturnlampstType bcm_leftturnlampst = 6; // Key status [-] [0|3] optional Bcm_keystType bcm_keyst = 7; // Horn status [-] [0|1] optional Bcm_hornstType bcm_hornst = 8; // High beam status [-] [0|1] optional Bcm_highbeamstType bcm_highbeamst = 9; // Hazard lamp status [] [0|1] optional Bcm_hazardlampstType bcm_hazardlampst = 10; // Front fog lamp status [-] [0|1] optional Bcm_frontfoglampstType bcm_frontfoglampst = 11; // Brake light switch status [-] [0|1] optional Bcm_brakelightswitchstType bcm_brakelightswitchst = 12; } message Scu_bcs_1_306 { // Report Message enum Bcs_aebavailableType { BCS_AEBAVAILABLE_UNAVAILABLE = 0; BCS_AEBAVAILABLE_AVAILABLE = 1; } enum Bcs_cddavailableType { BCS_CDDAVAILABLE_UNAVAILABLE = 0; BCS_CDDAVAILABLE_AVAILABLE = 1; } enum Bcs_intidxType { BCS_INTIDX_NOINT = 0; BCS_INTIDX_OVERFLOW = 1; BCS_INTIDX_TIMEOUT = 2; BCS_INTIDX_ACCPEDINT = 3; BCS_INTIDX_BRKPEDINT = 4; BCS_INTIDX_GEARINT = 5; } enum Bcs_vdcfaultstType { BCS_VDCFAULTST_NORMAL = 0; BCS_VDCFAULTST_FAULT = 1; } enum Bcs_vdcactivestType { BCS_VDCACTIVEST_INACTIVE = 0; BCS_VDCACTIVEST_ACTIVE = 1; } enum Bcs_absfaultstType { BCS_ABSFAULTST_NORMAL = 0; BCS_ABSFAULTST_FAULT = 1; } enum Bcs_absactivestType { BCS_ABSACTIVEST_INACTIVE = 0; BCS_ABSACTIVEST_ACTIVE = 1; } enum Bcs_faultstType { BCS_FAULTST_NORMAL = 0; BCS_FAULTST_FAULT = 1; } enum Bcs_drvmodeType { BCS_DRVMODE_INVALID = 0; BCS_DRVMODE_MANUAL = 1; BCS_DRVMODE_INTERRUPT = 2; BCS_DRVMODE_AUTO = 3; } // VDC active status [] [0|1] optional Bcs_aebavailableType bcs_aebavailable = 1; // VDC active status [] [0|1] optional Bcs_cddavailableType bcs_cddavailable = 2; // Actual brake pedal position [%] [0|100] optional double bcs_brkpedact = 3; // BCS interrupt index [] [0|7] optional Bcs_intidxType bcs_intidx = 4; // VDC fault status [] [0|1] optional Bcs_vdcfaultstType bcs_vdcfaultst = 5; // VDC active status [] [0|1] optional Bcs_vdcactivestType bcs_vdcactivest = 6; // ABS fault status [] [0|1] optional Bcs_absfaultstType bcs_absfaultst = 7; // ABS active status [] [0|1] optional Bcs_absactivestType bcs_absactivest = 8; // BCS fault status [] [0|1] optional Bcs_faultstType bcs_faultst = 9; // BCS drive mode [] [0|3] optional Bcs_drvmodeType bcs_drvmode = 10; } message Scu_bcs_2_307 { // Report Message enum Bcs_vehspdvdType { BCS_VEHSPDVD_INVALID = 0; BCS_VEHSPDVD_VALID = 1; } // Vehicle speed valid data [-] [0|1] optional Bcs_vehspdvdType bcs_vehspdvd = 1; // Yaw rate [rad/s] [-2.2243|2.2243] optional double bcs_yawrate = 2; // Vehicle speed [km/h] [0|240] optional double bcs_vehspd = 3; // Vehicle longitudinal acceleration [m/s^2] [-21.593|21.593] optional double bcs_vehlongaccel = 4; // Vehicle lateral acceleration [m/s^2] [-21.593|21.593] optional double bcs_vehlataccel = 5; } message Scu_epb_310 { // Report Message enum Epb_intidxType { EPB_INTIDX_NOINT = 0; EPB_INTIDX_OVERFLOW = 1; EPB_INTIDX_TIMEOUT = 2; } enum Epb_drvmodeType { EPB_DRVMODE_INVALID = 0; EPB_DRVMODE_MANUAL = 1; EPB_DRVMODE_INTERRUPT = 2; EPB_DRVMODE_AUTO = 3; } enum Epb_sysstType { EPB_SYSST_RELEASED = 0; EPB_SYSST_APPLIED = 1; EPB_SYSST_RELEASING = 2; EPB_SYSST_FAULT = 3; EPB_SYSST_APPLYING = 4; EPB_SYSST_DISENGAGED = 5; } enum Epb_faultstType { EPB_FAULTST_NORMAL = 0; EPB_FAULTST_FAULT = 1; } // EPS interrupt index [] [0|7] optional Epb_intidxType epb_intidx = 1; // EPB drive mode [] [0|3] optional Epb_drvmodeType epb_drvmode = 2; // EPB system status [] [0|7] optional Epb_sysstType epb_sysst = 3; // EPB fault status [] [0|1] optional Epb_faultstType epb_faultst = 4; } message Scu_vcu_1_312 { // Report Message enum Vcu_elcsysfaultType { VCU_ELCSYSFAULT_NORMAL = 0; VCU_ELCSYSFAULT_FAULT = 1; } enum Vcu_brkpedstType { VCU_BRKPEDST_UNPRESSED = 0; VCU_BRKPEDST_PRESSED = 1; } enum Vcu_intidxType { VCU_INTIDX_NOINT = 0; VCU_INTIDX_OVERFLOW = 1; VCU_INTIDX_TIMEOUT = 2; VCU_INTIDX_ACCPEDINT = 3; VCU_INTIDX_BRKPEDINT = 4; VCU_INTIDX_GEARINT = 5; } enum Vcu_gearintidxType { VCU_GEARINTIDX_NOINT = 0; VCU_GEARINTIDX_OVERFLOW = 1; VCU_GEARINTIDX_TIMEOUT = 2; } enum Vcu_geardrvmodeType { VCU_GEARDRVMODE_INVALID = 0; VCU_GEARDRVMODE_MANUAL = 1; VCU_GEARDRVMODE_INTERRUPT = 2; VCU_GEARDRVMODE_AUTO = 3; } enum Vcu_vehrdystType { VCU_VEHRDYST_NOTREADY = 0; VCU_VEHRDYST_READY = 1; } enum Vcu_faultstType { VCU_FAULTST_NORMAL = 0; VCU_FAULTST_DERATE = 1; VCU_FAULTST_RSV1 = 2; VCU_FAULTST_RSV2 = 3; VCU_FAULTST_RSV3 = 4; VCU_FAULTST_FAULT = 5; } enum Vcu_drvmodeType { VCU_DRVMODE_INVALID = 0; VCU_DRVMODE_MANUAL = 1; VCU_DRVMODE_INTERRUPT = 2; VCU_DRVMODE_AUTO = 3; } enum Vcu_gearpstType { VCU_GEARPST_INVALID = 0; VCU_GEARPST_DRIVE = 1; VCU_GEARPST_NEUTRAL = 2; VCU_GEARPST_REVERSE = 3; VCU_GEARPST_PARK = 4; } enum Vcu_gearfaultstType { VCU_GEARFAULTST_NORMAL = 0; VCU_GEARFAULTST_FAULT = 1; } enum Vcu_gearactType { VCU_GEARACT_INVALID = 0; VCU_GEARACT_DRIVE = 1; VCU_GEARACT_NEUTRAL = 2; VCU_GEARACT_REVERSE = 3; VCU_GEARACT_PARK = 4; } // Gear fault status [] [0|0] optional Vcu_elcsysfaultType vcu_elcsysfault = 1; // Brake pedal position [] [0|1] optional Vcu_brkpedstType vcu_brkpedst = 2; // VCU interrupt index [] [0|7] optional Vcu_intidxType vcu_intidx = 3; // Gear interrupt index [] [0|7] optional Vcu_gearintidxType vcu_gearintidx = 4; // VCU Gear drive mode [] [0|3] optional Vcu_geardrvmodeType vcu_geardrvmode = 5; // Actual acceleration pedal position [%] [0|100] optional double vcu_accpedact = 6; // Brake pedal position [%] [0|99.96] optional double vcu_brkpedpst = 7; // Veh range [km] [0|1000] optional int32 vcu_vehrng = 8; // Actual acceleration pedal position [%] [0|99.96] optional double vcu_accpedpst = 9; // HEV system ready status [] [0|1] optional Vcu_vehrdystType vcu_vehrdyst = 10; // VCU fault status [] [0|0] optional Vcu_faultstType vcu_faultst = 11; // VCU drive mode [] [0|3] optional Vcu_drvmodeType vcu_drvmode = 12; // Gear lever position [] [0|7] optional Vcu_gearpstType vcu_gearpst = 13; // Gear fault status [] [0|0] optional Vcu_gearfaultstType vcu_gearfaultst = 14; // Actual gear [] [0|7] optional Vcu_gearactType vcu_gearact = 15; } message Scu_eps_311 { // Report Message enum Eps_intidxType { EPS_INTIDX_NOINT = 0; EPS_INTIDX_OVERFLOW = 1; EPS_INTIDX_TIMEOUT = 2; EPS_INTIDX_STEERINT = 3; } enum Eps_faultstType { EPS_FAULTST_NORMAL = 0; EPS_FAULTST_FAULT = 1; } enum Eps_drvmodeType { EPS_DRVMODE_INVALID = 0; EPS_DRVMODE_MANUAL = 1; EPS_DRVMODE_INTERRUPT = 2; EPS_DRVMODE_AUTO = 3; } // EPS interrupt index [] [0|7] optional Eps_intidxType eps_intidx = 1; // Steer angle speed [deg/s] [0|1016] optional double eps_steeranglespd = 2; // Steer angle Left + right - [deg] [-780|779.9] optional double eps_steerangle = 3; // EPS fault status [] [0|1] optional Eps_faultstType eps_faultst = 4; // EPS drive mode [] [0|3] optional Eps_drvmodeType eps_drvmode = 5; } // CheckResponseSignal message CheckResponseSignal { optional bool is_eps_online = 1 [default = false]; optional bool is_epb_online = 2 [default = false]; optional bool is_esp_online = 3 [default = false]; optional bool is_vtog_online = 4 [default = false]; optional bool is_scu_online = 5 [default = false]; optional bool is_switch_online = 6 [default = false]; optional bool is_vcu_online = 7 [default = false]; } message Ge3 { optional Pc_bcm_201 pc_bcm_201 = 1; // control message optional Scu_bcs_3_308 scu_bcs_3_308 = 2; // report message optional Pc_epb_203 pc_epb_203 = 3; // control message optional Pc_bcs_202 pc_bcs_202 = 4; // control message optional Pc_vcu_205 pc_vcu_205 = 5; // control message optional Pc_eps_204 pc_eps_204 = 6; // control message optional Scu_vcu_2_313 scu_vcu_2_313 = 7; // report message optional Scu_1_301 scu_1_301 = 8; // report message optional Scu_2_302 scu_2_302 = 9; // report message optional Scu_3_303 scu_3_303 = 10; // report message optional Scu_bcm_304 scu_bcm_304 = 11; // report message optional Scu_bcs_1_306 scu_bcs_1_306 = 12; // report message optional Scu_bcs_2_307 scu_bcs_2_307 = 13; // report message optional Scu_epb_310 scu_epb_310 = 14; // report message optional Scu_vcu_1_312 scu_vcu_1_312 = 15; // report message optional Scu_eps_311 scu_eps_311 = 16; // report message optional CheckResponseSignal check_response = 100; }
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/proto/BUILD
## Auto generated by `proto_build_generator.py` load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_cc//cc:defs.bzl", "cc_proto_library") load("//tools:python_rules.bzl", "py_proto_library") package(default_visibility = ["//visibility:public"]) cc_proto_library( name = "ge3_cc_proto", deps = [ ":ge3_proto", ], ) proto_library( name = "ge3_proto", srcs = ["ge3.proto"], ) py_proto_library( name = "ge3_py_pb2", deps = [ ":ge3_proto", ], )
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_3_303.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/ge3/proto/ge3.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace ge3 { class Scu3303 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Ge3> { public: static const int32_t ID; Scu3303(); void Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const override; private: // config detail: {'description': 'VIN string character 15', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'VIN15', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 63, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int vin15(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VIN string character 14', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'VIN14', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 55, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int vin14(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VIN string character 13', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'VIN13', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 47, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int vin13(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VIN string character 12', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'VIN12', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 39, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int vin12(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VIN string character 11', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'VIN11', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 31, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int vin11(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VIN string character 10', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'VIN10', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 23, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int vin10(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VIN string character 09', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'VIN09', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 15, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int vin09(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VIN string character 08', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'VIN08', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 7, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int vin08(const std::uint8_t* bytes, const int32_t length) const; }; } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_bcs_1_306_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_bcs_1_306.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace ge3 { class Scubcs1306Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Scubcs1306Test, reset) { Scubcs1306 scubcs1306; int32_t length = 8; Ge3 chassis_detail; uint8_t bytes[8] = {0x01, 0x02, 0x03, 0x04, 0x11, 0x12, 0x13, 0x14}; scubcs1306.Parse(bytes, length, &chassis_detail); EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_1_306().bcs_aebavailable(), 1); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_1_306().bcs_cddavailable(), 1); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_1_306().bcs_brkpedact(), 0.8); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_1_306().bcs_intidx(), 0); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_1_306().bcs_vdcfaultst(), 0); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_1_306().bcs_vdcactivest(), 0); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_1_306().bcs_absfaultst(), 0); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_1_306().bcs_absactivest(), 0); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_1_306().bcs_faultst(), 0); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_1_306().bcs_drvmode(), 0); // } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/pc_eps_204_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/pc_eps_204.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace ge3 { class Pceps204Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Pceps204Test, reset) { uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; Pceps204 pceps204; EXPECT_EQ(pceps204.GetPeriod(), 20 * 1000); pceps204.UpdateData(data); EXPECT_EQ(data[0], 0b01100111); EXPECT_EQ(data[1], 0b00010011); EXPECT_EQ(data[2], 0b10001000); EXPECT_EQ(data[3], 0b00000000); EXPECT_EQ(data[4], 0b00000000); EXPECT_EQ(data[5], 0b01010010); EXPECT_EQ(data[6], 0b01010011); EXPECT_EQ(data[7], 0b01010100); } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_bcm_304.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_bcm_304.h" #include "glog/logging.h" #include "modules/drivers/canbus/common/byte.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace ge3 { using ::apollo::drivers::canbus::Byte; Scubcm304::Scubcm304() {} const int32_t Scubcm304::ID = 0x304; void Scubcm304::Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const { chassis->mutable_scu_bcm_304()->set_bcm_vehreversest( bcm_vehreversest(bytes, length)); chassis->mutable_scu_bcm_304()->set_bcm_rightturnlampst( bcm_rightturnlampst(bytes, length)); chassis->mutable_scu_bcm_304()->set_bcm_rearfoglampst( bcm_rearfoglampst(bytes, length)); chassis->mutable_scu_bcm_304()->set_bcm_parkinglampst( bcm_parkinglampst(bytes, length)); chassis->mutable_scu_bcm_304()->set_bcm_lowbeamst( bcm_lowbeamst(bytes, length)); chassis->mutable_scu_bcm_304()->set_bcm_leftturnlampst( bcm_leftturnlampst(bytes, length)); chassis->mutable_scu_bcm_304()->set_bcm_keyst( bcm_keyst(bytes, length)); chassis->mutable_scu_bcm_304()->set_bcm_hornst( bcm_hornst(bytes, length)); chassis->mutable_scu_bcm_304()->set_bcm_highbeamst( bcm_highbeamst(bytes, length)); chassis->mutable_scu_bcm_304()->set_bcm_hazardlampst( bcm_hazardlampst(bytes, length)); chassis->mutable_scu_bcm_304()->set_bcm_frontfoglampst( bcm_frontfoglampst(bytes, length)); chassis->mutable_scu_bcm_304()->set_bcm_brakelightswitchst( bcm_brakelightswitchst(bytes, length)); } // config detail: {'description': 'Vehicle reverse status', 'enum': {0: // 'BCM_VEHREVERSEST_NORMAL', 1: 'BCM_VEHREVERSEST_REVERSE'}, 'precision': 1.0, // 'len': 1, 'name': 'bcm_vehreversest', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 11, 'type': 'enum', 'order': 'motorola', // 'physical_unit': '-'} Scu_bcm_304::Bcm_vehreversestType Scubcm304::bcm_vehreversest( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(3, 1); Scu_bcm_304::Bcm_vehreversestType ret = static_cast<Scu_bcm_304::Bcm_vehreversestType>(x); return ret; } // config detail: {'description': 'Right turn lamp status', 'enum': {0: // 'BCM_RIGHTTURNLAMPST_INACTIVE', 1: 'BCM_RIGHTTURNLAMPST_ACTIVE'}, // 'precision': 1.0, 'len': 1, 'name': 'bcm_rightturnlampst', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 4, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcm_304::Bcm_rightturnlampstType Scubcm304::bcm_rightturnlampst( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(4, 1); Scu_bcm_304::Bcm_rightturnlampstType ret = static_cast<Scu_bcm_304::Bcm_rightturnlampstType>(x); return ret; } // config detail: {'description': 'Rear fog lamp status', 'enum': {0: // 'BCM_REARFOGLAMPST_INACTIVE', 1: 'BCM_REARFOGLAMPST_ACTIVE'}, // 'precision': 1.0, 'len': 1, 'name': 'bcm_rearfoglampst', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 0, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcm_304::Bcm_rearfoglampstType Scubcm304::bcm_rearfoglampst( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 1); Scu_bcm_304::Bcm_rearfoglampstType ret = static_cast<Scu_bcm_304::Bcm_rearfoglampstType>(x); return ret; } // config detail: {'description': 'Parking lamp status', 'enum': {0: // 'BCM_PARKINGLAMPST_INACTIVE', 1: 'BCM_PARKINGLAMPST_ACTIVE'}, // 'precision': 1.0, 'len': 1, 'name': 'bcm_parkinglampst', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 12, 'type': 'enum', // 'order': 'motorola', 'physical_unit': ''} Scu_bcm_304::Bcm_parkinglampstType Scubcm304::bcm_parkinglampst( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(4, 1); Scu_bcm_304::Bcm_parkinglampstType ret = static_cast<Scu_bcm_304::Bcm_parkinglampstType>(x); return ret; } // config detail: {'description': 'Low beam status', 'enum': {0: // 'BCM_LOWBEAMST_INACTIVE', 1: 'BCM_LOWBEAMST_ACTIVE'}, 'precision': 1.0, // 'len': 1, 'name': 'bcm_lowbeamst', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 2, 'type': 'enum', 'order': 'motorola', // 'physical_unit': '-'} Scu_bcm_304::Bcm_lowbeamstType Scubcm304::bcm_lowbeamst( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(2, 1); Scu_bcm_304::Bcm_lowbeamstType ret = static_cast<Scu_bcm_304::Bcm_lowbeamstType>(x); return ret; } // config detail: {'description': 'Left turn lamp status', 'enum': {0: // 'BCM_LEFTTURNLAMPST_INACTIVE', 1: 'BCM_LEFTTURNLAMPST_ACTIVE'}, // 'precision': 1.0, 'len': 1, 'name': 'bcm_leftturnlampst', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 5, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcm_304::Bcm_leftturnlampstType Scubcm304::bcm_leftturnlampst( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(5, 1); Scu_bcm_304::Bcm_leftturnlampstType ret = static_cast<Scu_bcm_304::Bcm_leftturnlampstType>(x); return ret; } // config detail: {'description': 'Key status', 'enum': {0: 'BCM_KEYST_OFF', 1: // 'BCM_KEYST_ACC', 2: 'BCM_KEYST_ON', 3: 'BCM_KEYST_CRANK'}, 'precision': 1.0, // 'len': 2, 'name': 'bcm_keyst', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|3]', 'bit': 7, 'type': 'enum', 'order': 'motorola', // 'physical_unit': '-'} Scu_bcm_304::Bcm_keystType Scubcm304::bcm_keyst(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(6, 2); Scu_bcm_304::Bcm_keystType ret = static_cast<Scu_bcm_304::Bcm_keystType>(x); return ret; } // config detail: {'description': 'Horn status', 'enum': {0: // 'BCM_HORNST_INACTIVE', 1: 'BCM_HORNST_ACTIVE'}, 'precision': 1.0, 'len': 1, // 'name': 'bcm_hornst', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 15, 'type': 'enum', 'order': 'motorola', // 'physical_unit': '-'} Scu_bcm_304::Bcm_hornstType Scubcm304::bcm_hornst(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(7, 1); Scu_bcm_304::Bcm_hornstType ret = static_cast<Scu_bcm_304::Bcm_hornstType>(x); return ret; } // config detail: {'description': 'High beam status', 'enum': {0: // 'BCM_HIGHBEAMST_INACTIVE', 1: 'BCM_HIGHBEAMST_ACTIVE'}, 'precision': 1.0, // 'len': 1, 'name': 'bcm_highbeamst', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 3, 'type': 'enum', 'order': 'motorola', // 'physical_unit': '-'} Scu_bcm_304::Bcm_highbeamstType Scubcm304::bcm_highbeamst( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(3, 1); Scu_bcm_304::Bcm_highbeamstType ret = static_cast<Scu_bcm_304::Bcm_highbeamstType>(x); return ret; } // config detail: {'description': 'Hazard lamp status', 'enum': {0: // 'BCM_HAZARDLAMPST_INACTIVE', 1: 'BCM_HAZARDLAMPST_ACTIVE'}, 'precision': 1.0, // 'len': 1, 'name': 'bcm_hazardlampst', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 13, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_bcm_304::Bcm_hazardlampstType Scubcm304::bcm_hazardlampst( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(5, 1); Scu_bcm_304::Bcm_hazardlampstType ret = static_cast<Scu_bcm_304::Bcm_hazardlampstType>(x); return ret; } // config detail: {'description': 'Front fog lamp status', 'enum': {0: // 'BCM_FRONTFOGLAMPST_INACTIVE', 1: 'BCM_FRONTFOGLAMPST_ACTIVE'}, // 'precision': 1.0, 'len': 1, 'name': 'bcm_frontfoglampst', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 1, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcm_304::Bcm_frontfoglampstType Scubcm304::bcm_frontfoglampst( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(1, 1); Scu_bcm_304::Bcm_frontfoglampstType ret = static_cast<Scu_bcm_304::Bcm_frontfoglampstType>(x); return ret; } // config detail: {'description': 'Brake light switch status', 'enum': {0: // 'BCM_BRAKELIGHTSWITCHST_INACTIVE', 1: 'BCM_BRAKELIGHTSWITCHST_ACTIVE'}, // 'precision': 1.0, 'len': 1, 'name': 'bcm_brakelightswitchst', // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 14, // 'type': 'enum', 'order': 'motorola', 'physical_unit': '-'} Scu_bcm_304::Bcm_brakelightswitchstType Scubcm304::bcm_brakelightswitchst( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(6, 1); Scu_bcm_304::Bcm_brakelightswitchstType ret = static_cast<Scu_bcm_304::Bcm_brakelightswitchstType>(x); return ret; } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/pc_epb_203.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/pc_epb_203.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace ge3 { using ::apollo::drivers::canbus::Byte; const int32_t Pcepb203::ID = 0x203; // public Pcepb203::Pcepb203() { Reset(); } uint32_t Pcepb203::GetPeriod() const { // modify every protocol's period manually static const uint32_t PERIOD = 20 * 1000; return PERIOD; } void Pcepb203::UpdateData(uint8_t* data) { set_p_pc_epbreq(data, pc_epbreq_); set_p_pc_epbenable(data, pc_epbenable_); } void Pcepb203::Reset() { // you should check this manually pc_epbreq_ = Pc_epb_203::PC_EPBREQ_INVALID; pc_epbenable_ = Pc_epb_203::PC_EPBENABLE_DISABLE; } Pcepb203* Pcepb203::set_pc_epbreq(Pc_epb_203::Pc_epbreqType pc_epbreq) { pc_epbreq_ = pc_epbreq; return this; } // config detail: {'description': 'EPB request', 'enum': {0: // 'PC_EPBREQ_INVALID', 1: 'PC_EPBREQ_RELEASE', 2: 'PC_EPBREQ_APPLY'}, // 'precision': 1.0, 'len': 2, 'name': 'PC_EpbReq', 'is_signed_var': False, // 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 1, 'type': 'enum', 'order': // 'motorola', 'physical_unit': ''} void Pcepb203::set_p_pc_epbreq(uint8_t* data, Pc_epb_203::Pc_epbreqType pc_epbreq) { int x = pc_epbreq; Byte to_set(data + 0); to_set.set_value(static_cast<uint8_t>(x), 0, 2); } Pcepb203* Pcepb203::set_pc_epbenable( Pc_epb_203::Pc_epbenableType pc_epbenable) { pc_epbenable_ = pc_epbenable; return this; } // config detail: {'description': 'EPB control enable', 'enum': {0: // 'PC_EPBENABLE_DISABLE', 1: 'PC_EPBENABLE_ENABLE'}, 'precision': 1.0, 'len': // 1, 'name': 'PC_EpbEnable', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} void Pcepb203::set_p_pc_epbenable(uint8_t* data, Pc_epb_203::Pc_epbenableType pc_epbenable) { int x = pc_epbenable; Byte to_set(data + 0); to_set.set_value(static_cast<uint8_t>(x), 7, 1); } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/pc_bcs_202.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/pc_bcs_202.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace ge3 { using ::apollo::drivers::canbus::Byte; const int32_t Pcbcs202::ID = 0x202; // public Pcbcs202::Pcbcs202() { Reset(); } uint32_t Pcbcs202::GetPeriod() const { // modify every protocol's period manually static const uint32_t PERIOD = 20 * 1000; return PERIOD; } void Pcbcs202::UpdateData(uint8_t* data) { set_p_pc_brkpedreq(data, pc_brkpedreq_); set_p_pc_brkpedenable(data, pc_brkpedenable_); } void Pcbcs202::Reset() { // you should check this manually pc_brkpedreq_ = 0.0; pc_brkpedenable_ = Pc_bcs_202::PC_BRKPEDENABLE_DISABLE; } Pcbcs202* Pcbcs202::set_pc_brkpedreq(double pc_brkpedreq) { pc_brkpedreq_ = pc_brkpedreq; return this; } // config detail: {'description': 'Brake pedal request', 'offset': 0.0, // 'precision': 0.1, 'len': 10, 'name': 'PC_BrkPedReq', 'is_signed_var': False, // 'physical_range': '[0|100]', 'bit': 1, 'type': 'double', 'order': 'motorola', // 'physical_unit': '%'} void Pcbcs202::set_p_pc_brkpedreq(uint8_t* data, double pc_brkpedreq) { pc_brkpedreq = ProtocolData::BoundedValue(0.0, 100.0, pc_brkpedreq); int x = static_cast<int>(pc_brkpedreq / 0.100000); uint8_t t = 0; t = static_cast<uint8_t>(x & 0xFF); Byte to_set0(data + 1); to_set0.set_value(t, 0, 8); x >>= 8; t = x & 0x3; Byte to_set1(data + 0); to_set1.set_value(t, 0, 2); } Pcbcs202* Pcbcs202::set_pc_brkpedenable( Pc_bcs_202::Pc_brkpedenableType pc_brkpedenable) { pc_brkpedenable_ = pc_brkpedenable; return this; } // config detail: {'description': 'Brake pedal control enable', 'enum': {0: // 'PC_BRKPEDENABLE_DISABLE', 1: 'PC_BRKPEDENABLE_ENABLE'}, 'precision': 1.0, // 'len': 1, 'name': 'PC_BrkPedEnable', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} void Pcbcs202::set_p_pc_brkpedenable( uint8_t* data, Pc_bcs_202::Pc_brkpedenableType pc_brkpedenable) { int x = pc_brkpedenable; Byte to_set(data + 0); to_set.set_value(static_cast<uint8_t>(x), 7, 1); } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_vcu_2_313_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_vcu_2_313.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace ge3 { class Scuvcu2313Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Scuvcu2313Test, reset) { Scuvcu2313 scuvcu2313; int32_t length = 8; Ge3 chassis_detail; uint8_t bytes[8] = {0x01, 0x02, 0x03, 0x04, 0x11, 0x12, 0x13, 0x14}; scuvcu2313.Parse(bytes, length, &chassis_detail); EXPECT_DOUBLE_EQ(chassis_detail.scu_vcu_2_313().vcu_torqposmax(), 228); EXPECT_DOUBLE_EQ(chassis_detail.scu_vcu_2_313().vcu_torqnegmax(), -2796); EXPECT_DOUBLE_EQ(chassis_detail.scu_vcu_2_313().vcu_torqact(), -2928); EXPECT_DOUBLE_EQ(chassis_detail.scu_vcu_2_313().vcu_engspd(), 258); } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_3_303.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_3_303.h" #include "glog/logging.h" #include "modules/drivers/canbus/common/byte.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace ge3 { using ::apollo::drivers::canbus::Byte; Scu3303::Scu3303() {} const int32_t Scu3303::ID = 0x303; void Scu3303::Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const { chassis->mutable_scu_3_303()->set_vin15(vin15(bytes, length)); chassis->mutable_scu_3_303()->set_vin14(vin14(bytes, length)); chassis->mutable_scu_3_303()->set_vin13(vin13(bytes, length)); chassis->mutable_scu_3_303()->set_vin12(vin12(bytes, length)); chassis->mutable_scu_3_303()->set_vin11(vin11(bytes, length)); chassis->mutable_scu_3_303()->set_vin10(vin10(bytes, length)); chassis->mutable_scu_3_303()->set_vin09(vin09(bytes, length)); chassis->mutable_scu_3_303()->set_vin08(vin08(bytes, length)); } // config detail: {'description': 'VIN string character 15', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'vin15', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 63, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int Scu3303::vin15(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 7); int32_t x = t0.get_byte(0, 8); int ret = x; return ret; } // config detail: {'description': 'VIN string character 14', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'vin14', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 55, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int Scu3303::vin14(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 6); int32_t x = t0.get_byte(0, 8); int ret = x; return ret; } // config detail: {'description': 'VIN string character 13', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'vin13', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 47, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int Scu3303::vin13(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 5); int32_t x = t0.get_byte(0, 8); int ret = x; return ret; } // config detail: {'description': 'VIN string character 12', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'vin12', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 39, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int Scu3303::vin12(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(0, 8); int ret = x; return ret; } // config detail: {'description': 'VIN string character 11', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'vin11', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 31, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int Scu3303::vin11(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 3); int32_t x = t0.get_byte(0, 8); int ret = x; return ret; } // config detail: {'description': 'VIN string character 10', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'vin10', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 23, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int Scu3303::vin10(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 2); int32_t x = t0.get_byte(0, 8); int ret = x; return ret; } // config detail: {'description': 'VIN string character 09', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'vin09', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 15, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int Scu3303::vin09(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(0, 8); int ret = x; return ret; } // config detail: {'description': 'VIN string character 08', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'vin08', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 7, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int Scu3303::vin08(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 8); int ret = x; return ret; } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/pc_bcm_201_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/pc_bcm_201.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace ge3 { class Pcbcm201Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Pcbcm201Test, reset) { uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; Pcbcm201 pcbcm201; EXPECT_EQ(pcbcm201.GetPeriod(), 20 * 1000); pcbcm201.UpdateData(data); EXPECT_EQ(data[0], 0b00000001); EXPECT_EQ(data[1], 0b01100010); EXPECT_EQ(data[2], 0b01100011); EXPECT_EQ(data[3], 0b01100100); EXPECT_EQ(data[4], 0b01010001); EXPECT_EQ(data[5], 0b01010010); EXPECT_EQ(data[6], 0b01010011); EXPECT_EQ(data[7], 0b01010100); } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/pc_eps_204.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/pc_eps_204.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace ge3 { using ::apollo::drivers::canbus::Byte; const int32_t Pceps204::ID = 0x204; // public Pceps204::Pceps204() { Reset(); } uint32_t Pceps204::GetPeriod() const { // modify every protocol's period manually static const uint32_t PERIOD = 20 * 1000; return PERIOD; } void Pceps204::UpdateData(uint8_t* data) { set_p_pc_steerspdreq(data, pc_steerspdreq_); set_p_pc_steerenable(data, pc_steerenable_); set_p_pc_steerangreq(data, pc_steerangreq_); } void Pceps204::Reset() { // you should check this manually pc_steerspdreq_ = 0; pc_steerenable_ = Pc_eps_204::PC_STEERENABLE_DISABLE; pc_steerangreq_ = 0.0; } Pceps204* Pceps204::set_pc_steerspdreq(int pc_steerspdreq) { pc_steerspdreq_ = pc_steerspdreq; return this; } // config detail: {'description': 'Steer speed request', 'offset': 0.0, // 'precision': 1.0, 'len': 16, 'name': 'PC_SteerSpdReq', 'is_signed_var': // False, 'physical_range': '[0|500]', 'bit': 31, 'type': 'int', 'order': // 'motorola', 'physical_unit': 'deg/s'} void Pceps204::set_p_pc_steerspdreq(uint8_t* data, int pc_steerspdreq) { pc_steerspdreq = ProtocolData::BoundedValue(0, 500, pc_steerspdreq); int x = pc_steerspdreq; uint8_t t = 0; t = static_cast<uint8_t>(x & 0xFF); Byte to_set0(data + 4); to_set0.set_value(t, 0, 8); x >>= 8; t = static_cast<uint8_t>(x & 0xFF); Byte to_set1(data + 3); to_set1.set_value(t, 0, 8); } Pceps204* Pceps204::set_pc_steerenable( Pc_eps_204::Pc_steerenableType pc_steerenable) { pc_steerenable_ = pc_steerenable; return this; } // config detail: {'description': 'Steer control enable', 'enum': {0: // 'PC_STEERENABLE_DISABLE', 1: 'PC_STEERENABLE_ENABLE'}, 'precision': 1.0, // 'len': 1, 'name': 'PC_SteerEnable', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} void Pceps204::set_p_pc_steerenable( uint8_t* data, Pc_eps_204::Pc_steerenableType pc_steerenable) { int x = pc_steerenable; Byte to_set(data + 0); to_set.set_value(static_cast<uint8_t>(x), 7, 1); } Pceps204* Pceps204::set_pc_steerangreq(double pc_steerangreq) { pc_steerangreq_ = pc_steerangreq; return this; } // config detail: {'description': 'Steer angle request', 'offset': -500.0, // 'precision': 0.1, 'len': 16, 'name': 'PC_SteerAngReq', 'is_signed_var': // False, 'physical_range': '[-500|500]', 'bit': 15, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'deg'} void Pceps204::set_p_pc_steerangreq(uint8_t* data, double pc_steerangreq) { pc_steerangreq = ProtocolData::BoundedValue(-500.0, 500.0, pc_steerangreq); int x = static_cast<int>((pc_steerangreq - -500.000000) / 0.100000); uint8_t t = 0; t = static_cast<uint8_t>(x & 0xFF); Byte to_set0(data + 2); to_set0.set_value(t, 0, 8); x >>= 8; t = static_cast<uint8_t>(x & 0xFF); Byte to_set1(data + 1); to_set1.set_value(t, 0, 8); } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_epb_310_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_epb_310.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace ge3 { class Scuepb310Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Scuepb310Test, reset) { Scuepb310 scuepb310; int32_t length = 8; Ge3 chassis_detail; uint8_t bytes[8] = {0x01, 0x02, 0x03, 0x04, 0x11, 0x12, 0x13, 0x14}; scuepb310.Parse(bytes, length, &chassis_detail); EXPECT_DOUBLE_EQ(chassis_detail.scu_epb_310().epb_intidx(), 2); EXPECT_DOUBLE_EQ(chassis_detail.scu_epb_310().epb_drvmode(), 0); EXPECT_DOUBLE_EQ(chassis_detail.scu_epb_310().epb_sysst(), 1); EXPECT_DOUBLE_EQ(chassis_detail.scu_epb_310().epb_faultst(), 0); } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_bcs_3_308.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/ge3/proto/ge3.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace ge3 { class Scubcs3308 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Ge3> { public: static const int32_t ID; Scubcs3308(); void Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const override; private: // config detail: {'description': 'Rear right wheel speed valid data', 'enum': // {0: 'BCS_RRWHEELSPDVD_INVALID', 1: 'BCS_RRWHEELSPDVD_VALID'}, // 'precision': 1.0, 'len': 1, 'name': 'BCS_RRWheelSpdVD', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 57, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcs_3_308::Bcs_rrwheelspdvdType bcs_rrwheelspdvd( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Rear right wheel speed direction valid // data', 'enum': {0: 'BCS_RRWHEELDIRECTIONVD_INVALID', 1: // 'BCS_RRWHEELDIRECTIONVD_VALID'}, 'precision': 1.0, 'len': 1, 'name': // 'BCS_RRWheelDirectionVD', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 58, 'type': 'enum', 'order': 'motorola', // 'physical_unit': '-'} Scu_bcs_3_308::Bcs_rrwheeldirectionvdType bcs_rrwheeldirectionvd( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Rear left wheel speed valid data', 'enum': // {0: 'BCS_RLWHEELSPDVD_INVALID', 1: 'BCS_RLWHEELSPDVD_VALID'}, // 'precision': 1.0, 'len': 1, 'name': 'BCS_RLWheelSpdVD', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 41, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcs_3_308::Bcs_rlwheelspdvdType bcs_rlwheelspdvd( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Rear left wheel speed direction valid // data', 'enum': {0: 'BCS_RLWHEELDIRECTIONVD_INVALID', 1: // 'BCS_RLWHEELDIRECTIONVD_VALID'}, 'precision': 1.0, 'len': 1, 'name': // 'BCS_RLWheelDirectionVD', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 42, 'type': 'enum', 'order': 'motorola', // 'physical_unit': '-'} Scu_bcs_3_308::Bcs_rlwheeldirectionvdType bcs_rlwheeldirectionvd( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Front right wheel speed valid data', // 'enum': {0: 'BCS_FRWHEELSPDVD_INVALID', 1: 'BCS_FRWHEELSPDVD_VALID'}, // 'precision': 1.0, 'len': 1, 'name': 'BCS_FRWheelSpdVD', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 25, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcs_3_308::Bcs_frwheelspdvdType bcs_frwheelspdvd( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Front right wheel speed direction valid // data', 'enum': {0: 'BCS_FRWHEELDIRECTIONVD_INVALID', 1: // 'BCS_FRWHEELDIRECTIONVD_VALID'}, 'precision': 1.0, 'len': 1, 'name': // 'BCS_FRWheelDirectionVD', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 26, 'type': 'enum', 'order': 'motorola', // 'physical_unit': '-'} Scu_bcs_3_308::Bcs_frwheeldirectionvdType bcs_frwheeldirectionvd( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Front left wheel speed valid data', 'enum': // {0: 'BCS_FLWHEELSPDVD_INVALID', 1: 'BCS_FLWHEELSPDVD_VALID'}, // 'precision': 1.0, 'len': 1, 'name': 'BCS_FLWheelSpdVD', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 9, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcs_3_308::Bcs_flwheelspdvdType bcs_flwheelspdvd( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Front left wheel speed direction valid // data', 'enum': {0: 'BCS_FLWHEELDIRECTIONVD_INVALID', 1: // 'BCS_FLWHEELDIRECTIONVD_VALID'}, 'precision': 1.0, 'len': 1, 'name': // 'BCS_FLWheelDirectionVD', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 10, 'type': 'enum', 'order': 'motorola', // 'physical_unit': '-'} Scu_bcs_3_308::Bcs_flwheeldirectionvdType bcs_flwheeldirectionvd( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Rear right wheel speed', 'offset': 0.0, // 'precision': 0.05625, 'len': 13, 'name': 'BCS_RRWheelSpd', 'is_signed_var': // False, 'physical_range': '[0|240]', 'bit': 55, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'km/h'} double bcs_rrwheelspd(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Rear right wheel speed direction', 'enum': // {0: 'BCS_RRWHEELDIRECTION_FORWARD', 1: 'BCS_RRWHEELDIRECTION_BACKWARD'}, // 'precision': 1.0, 'len': 1, 'name': 'BCS_RRWheelDirection', // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': // 56, 'type': 'enum', 'order': 'motorola', 'physical_unit': '-'} Scu_bcs_3_308::Bcs_rrwheeldirectionType bcs_rrwheeldirection( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Rear left wheel speed', 'offset': 0.0, // 'precision': 0.05625, 'len': 13, 'name': 'BCS_RLWheelSpd', 'is_signed_var': // False, 'physical_range': '[0|240]', 'bit': 39, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'km/h'} double bcs_rlwheelspd(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Rear left wheel speed direction', 'enum': // {0: 'BCS_RLWHEELDIRECTION_FORWARD', 1: 'BCS_RLWHEELDIRECTION_BACKWARD'}, // 'precision': 1.0, 'len': 1, 'name': 'BCS_RLWheelDirection', // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': // 40, 'type': 'enum', 'order': 'motorola', 'physical_unit': '-'} Scu_bcs_3_308::Bcs_rlwheeldirectionType bcs_rlwheeldirection( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Front right wheel speed', 'offset': 0.0, // 'precision': 0.05625, 'len': 13, 'name': 'BCS_FRWheelSpd', 'is_signed_var': // False, 'physical_range': '[0|240]', 'bit': 23, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'km/h'} double bcs_frwheelspd(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Front right wheel speed direction', 'enum': // {0: 'BCS_FRWHEELDIRECTION_FORWARD', 1: 'BCS_FRWHEELDIRECTION_BACKWARD'}, // 'precision': 1.0, 'len': 1, 'name': 'BCS_FRWheelDirection', // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': // 24, 'type': 'enum', 'order': 'motorola', 'physical_unit': '-'} Scu_bcs_3_308::Bcs_frwheeldirectionType bcs_frwheeldirection( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Front left wheel speed', 'offset': 0.0, // 'precision': 0.05625, 'len': 13, 'name': 'BCS_FLWheelSpd', 'is_signed_var': // False, 'physical_range': '[0|240]', 'bit': 7, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'km/h'} double bcs_flwheelspd(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Front left wheel speed direction', 'enum': // {0: 'BCS_FLWHEELDIRECTION_FORWARD', 1: 'BCS_FLWHEELDIRECTION_BACKWARD'}, // 'precision': 1.0, 'len': 1, 'name': 'BCS_FLWheelDirection', // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 8, // 'type': 'enum', 'order': 'motorola', 'physical_unit': '-'} Scu_bcs_3_308::Bcs_flwheeldirectionType bcs_flwheeldirection( const std::uint8_t* bytes, const int32_t length) const; }; } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_bcs_1_306.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/ge3/proto/ge3.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace ge3 { class Scubcs1306 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Ge3> { public: static const int32_t ID; Scubcs1306(); void Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const override; private: // config detail: {'description': 'VDC active status', 'enum': {0: // 'BCS_AEBAVAILABLE_UNAVAILABLE', 1: 'BCS_AEBAVAILABLE_AVAILABLE'}, // 'precision': 1.0, 'len': 1, 'name': 'BCS_AEBAvailable', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 17, 'type': 'enum', // 'order': 'motorola', 'physical_unit': ''} Scu_bcs_1_306::Bcs_aebavailableType bcs_aebavailable( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VDC active status', 'enum': {0: // 'BCS_CDDAVAILABLE_UNAVAILABLE', 1: 'BCS_CDDAVAILABLE_AVAILABLE'}, // 'precision': 1.0, 'len': 1, 'name': 'BCS_CDDAvailable', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 16, 'type': 'enum', // 'order': 'motorola', 'physical_unit': ''} Scu_bcs_1_306::Bcs_cddavailableType bcs_cddavailable( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Actual brake pedal position', 'offset': // 0.0, 'precision': 0.1, 'len': 10, 'name': 'BCS_BrkPedAct', 'is_signed_var': // False, 'physical_range': '[0|100]', 'bit': 15, 'type': 'double', 'order': // 'motorola', 'physical_unit': '%'} double bcs_brkpedact(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'BCS interrupt index', 'enum': {0: // 'BCS_INTIDX_NOINT', 1: 'BCS_INTIDX_OVERFLOW', 2: 'BCS_INTIDX_TIMEOUT', 3: // 'BCS_INTIDX_ACCPEDINT', 4: 'BCS_INTIDX_BRKPEDINT', 5: // 'BCS_INTIDX_GEARINT'}, 'precision': 1.0, 'len': 3, 'name': 'BCS_IntIdx', // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|7]', 'bit': // 21, 'type': 'enum', 'order': 'motorola', 'physical_unit': ''} Scu_bcs_1_306::Bcs_intidxType bcs_intidx(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VDC fault status', 'enum': {0: // 'BCS_VDCFAULTST_NORMAL', 1: 'BCS_VDCFAULTST_FAULT'}, 'precision': 1.0, // 'len': 1, 'name': 'BCS_VDCFaultSt', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 1, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_bcs_1_306::Bcs_vdcfaultstType bcs_vdcfaultst(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VDC active status', 'enum': {0: // 'BCS_VDCACTIVEST_INACTIVE', 1: 'BCS_VDCACTIVEST_ACTIVE'}, 'precision': 1.0, // 'len': 1, 'name': 'BCS_VDCActiveSt', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 2, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_bcs_1_306::Bcs_vdcactivestType bcs_vdcactivest( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'ABS fault status', 'enum': {0: // 'BCS_ABSFAULTST_NORMAL', 1: 'BCS_ABSFAULTST_FAULT'}, 'precision': 1.0, // 'len': 1, 'name': 'BCS_ABSFaultSt', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 3, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_bcs_1_306::Bcs_absfaultstType bcs_absfaultst(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'ABS active status', 'enum': {0: // 'BCS_ABSACTIVEST_INACTIVE', 1: 'BCS_ABSACTIVEST_ACTIVE'}, 'precision': 1.0, // 'len': 1, 'name': 'BCS_ABSActiveSt', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 4, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_bcs_1_306::Bcs_absactivestType bcs_absactivest( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'BCS fault status', 'enum': {0: // 'BCS_FAULTST_NORMAL', 1: 'BCS_FAULTST_FAULT'}, 'precision': 1.0, 'len': 1, // 'name': 'BCS_FaultSt', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 5, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_bcs_1_306::Bcs_faultstType bcs_faultst(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'BCS drive mode', 'enum': {0: // 'BCS_DRVMODE_INVALID', 1: 'BCS_DRVMODE_MANUAL', 2: 'BCS_DRVMODE_INTERRUPT', // 3: 'BCS_DRVMODE_AUTO'}, 'precision': 1.0, 'len': 2, 'name': 'BCS_DrvMode', // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|3]', 'bit': 7, // 'type': 'enum', 'order': 'motorola', 'physical_unit': ''} Scu_bcs_1_306::Bcs_drvmodeType bcs_drvmode(const std::uint8_t* bytes, const int32_t length) const; }; } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/pc_eps_204.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/ge3/proto/ge3.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace ge3 { class Pceps204 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Ge3> { public: static const int32_t ID; Pceps204(); uint32_t GetPeriod() const override; void UpdateData(uint8_t* data) override; void Reset() override; // config detail: {'description': 'Steer speed request', 'offset': 0.0, // 'precision': 1.0, 'len': 16, 'name': 'PC_SteerSpdReq', 'is_signed_var': // False, 'physical_range': '[0|500]', 'bit': 31, 'type': 'int', 'order': // 'motorola', 'physical_unit': 'deg/s'} Pceps204* set_pc_steerspdreq(int pc_steerspdreq); // config detail: {'description': 'Steer control enable', 'enum': {0: // 'PC_STEERENABLE_DISABLE', 1: 'PC_STEERENABLE_ENABLE'}, 'precision': 1.0, // 'len': 1, 'name': 'PC_SteerEnable', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Pceps204* set_pc_steerenable(Pc_eps_204::Pc_steerenableType pc_steerenable); // config detail: {'description': 'Steer angle request', 'offset': -500.0, // 'precision': 0.1, 'len': 16, 'name': 'PC_SteerAngReq', 'is_signed_var': // False, 'physical_range': '[-500|500]', 'bit': 15, 'type': 'double', // 'order': 'motorola', 'physical_unit': 'deg'} Pceps204* set_pc_steerangreq(double pc_steerangreq); private: // config detail: {'description': 'Steer speed request', 'offset': 0.0, // 'precision': 1.0, 'len': 16, 'name': 'PC_SteerSpdReq', 'is_signed_var': // False, 'physical_range': '[0|500]', 'bit': 31, 'type': 'int', 'order': // 'motorola', 'physical_unit': 'deg/s'} void set_p_pc_steerspdreq(uint8_t* data, int pc_steerspdreq); // config detail: {'description': 'Steer control enable', 'enum': {0: // 'PC_STEERENABLE_DISABLE', 1: 'PC_STEERENABLE_ENABLE'}, 'precision': 1.0, // 'len': 1, 'name': 'PC_SteerEnable', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} void set_p_pc_steerenable(uint8_t* data, Pc_eps_204::Pc_steerenableType pc_steerenable); // config detail: {'description': 'Steer angle request', 'offset': -500.0, // 'precision': 0.1, 'len': 16, 'name': 'PC_SteerAngReq', 'is_signed_var': // False, 'physical_range': '[-500|500]', 'bit': 15, 'type': 'double', // 'order': 'motorola', 'physical_unit': 'deg'} void set_p_pc_steerangreq(uint8_t* data, double pc_steerangreq); private: int pc_steerspdreq_; Pc_eps_204::Pc_steerenableType pc_steerenable_; double pc_steerangreq_; }; } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_bcs_2_307_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_bcs_2_307.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace ge3 { class Scubcs2307Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Scubcs2307Test, reset) { Scubcs2307 scubcs2307; int32_t length = 8; Ge3 chassis_detail; uint8_t bytes[8] = {0x01, 0x02, 0x03, 0x04, 0x11, 0x12, 0x13, 0x14}; scubcs2307.Parse(bytes, length, &chassis_detail); EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_2_307().bcs_vehspdvd(), 0); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_2_307().bcs_yawrate(), -1.573735); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_2_307().bcs_vehspd(), 8.53125); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_2_307().bcs_vehlongaccel(), -20.290904); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_2_307().bcs_vehlataccel(), -21.158968); // } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_bcs_3_308_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_bcs_3_308.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace ge3 { class Scubcs3308Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Scubcs3308Test, reset) { Scubcs3308 scubcs3308; int32_t length = 8; Ge3 chassis_detail; uint8_t bytes[8] = {0x01, 0x02, 0x03, 0x04, 0x11, 0x12, 0x13, 0x14}; scubcs3308.Parse(bytes, length, &chassis_detail); EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_3_308().bcs_rrwheelspdvd(), 0); // EXPECT_DOUBLE_EQ( chassis_detail.scu_bcs_3_308().bcs_rrwheeldirectionvd(), 1); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_3_308().bcs_rlwheelspdvd(), 1); // EXPECT_DOUBLE_EQ( chassis_detail.scu_bcs_3_308().bcs_rlwheeldirectionvd(), 0); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_3_308().bcs_frwheelspdvd(), 0); // EXPECT_DOUBLE_EQ( chassis_detail.scu_bcs_3_308().bcs_frwheeldirectionvd(), 1); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_3_308().bcs_flwheelspdvd(), 1); // EXPECT_DOUBLE_EQ( chassis_detail.scu_bcs_3_308().bcs_flwheeldirectionvd(), 0); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_3_308().bcs_rrwheelspd(), 34.3125); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_3_308().bcs_rrwheeldirection(), 0); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_3_308().bcs_rlwheelspd(), 30.7125); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_3_308().bcs_rlwheeldirection(), 0); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_3_308().bcs_frwheelspd(), 5.4); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_3_308().bcs_frwheeldirection(), 0); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_3_308().bcs_flwheelspd(), 1.8); // EXPECT_DOUBLE_EQ(chassis_detail.scu_bcs_3_308().bcs_flwheeldirection(), 0); // } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_vcu_2_313.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_vcu_2_313.h" #include "glog/logging.h" #include "modules/drivers/canbus/common/byte.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace ge3 { using ::apollo::drivers::canbus::Byte; Scuvcu2313::Scuvcu2313() {} const int32_t Scuvcu2313::ID = 0x313; void Scuvcu2313::Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const { chassis->mutable_scu_vcu_2_313()->set_vcu_torqposmax( vcu_torqposmax(bytes, length)); chassis->mutable_scu_vcu_2_313()->set_vcu_torqnegmax( vcu_torqnegmax(bytes, length)); chassis->mutable_scu_vcu_2_313()->set_vcu_torqact( vcu_torqact(bytes, length)); chassis->mutable_scu_vcu_2_313()->set_vcu_engspd( vcu_engspd(bytes, length)); } // config detail: {'description': 'Max positive torque', 'offset': 0.0, // 'precision': 1.5, 'len': 11, 'name': 'vcu_torqposmax', 'is_signed_var': // False, 'physical_range': '[0|3000]', 'bit': 55, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'Nm'} double Scuvcu2313::vcu_torqposmax(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 6); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 7); int32_t t = t1.get_byte(5, 3); x <<= 3; x |= t; double ret = x * 1.500000; return ret; } // config detail: {'description': 'Max negative torque', 'offset': -3000.0, // 'precision': 1.5, 'len': 11, 'name': 'vcu_torqnegmax', 'is_signed_var': // False, 'physical_range': '[-3000|0]', 'bit': 39, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'Nm'} double Scuvcu2313::vcu_torqnegmax(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 5); int32_t t = t1.get_byte(5, 3); x <<= 3; x |= t; double ret = x * 1.500000 + -3000.000000; return ret; } // config detail: {'description': 'Actual torque', 'offset': -3000.0, // 'precision': 1.5, 'len': 12, 'name': 'vcu_torqact', 'is_signed_var': False, // 'physical_range': '[-3000|3000]', 'bit': 23, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'Nm'} double Scuvcu2313::vcu_torqact(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 2); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 3); int32_t t = t1.get_byte(4, 4); x <<= 4; x |= t; double ret = x * 1.500000 + -3000.000000; return ret; } // config detail: {'description': 'Engine speed', 'offset': 0.0, // 'precision': 1.0, 'len': 16, 'name': 'vcu_engspd', 'is_signed_var': False, // 'physical_range': '[0|65535]', 'bit': 7, 'type': 'int', 'order': 'motorola', // 'physical_unit': 'rpm'} int Scuvcu2313::vcu_engspd(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 1); int32_t t = t1.get_byte(0, 8); x <<= 8; x |= t; int ret = x; return ret; } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_bcm_304.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/ge3/proto/ge3.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace ge3 { class Scubcm304 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Ge3> { public: static const int32_t ID; Scubcm304(); void Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const override; private: // config detail: {'description': 'Vehicle reverse status', 'enum': {0: // 'BCM_VEHREVERSEST_NORMAL', 1: 'BCM_VEHREVERSEST_REVERSE'}, // 'precision': 1.0, 'len': 1, 'name': 'BCM_VehReverseSt', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 11, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcm_304::Bcm_vehreversestType bcm_vehreversest( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Right turn lamp status', 'enum': {0: // 'BCM_RIGHTTURNLAMPST_INACTIVE', 1: 'BCM_RIGHTTURNLAMPST_ACTIVE'}, // 'precision': 1.0, 'len': 1, 'name': 'BCM_RightTurnLampSt', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 4, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcm_304::Bcm_rightturnlampstType bcm_rightturnlampst( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Rear fog lamp status', 'enum': {0: // 'BCM_REARFOGLAMPST_INACTIVE', 1: 'BCM_REARFOGLAMPST_ACTIVE'}, // 'precision': 1.0, 'len': 1, 'name': 'BCM_RearFogLampSt', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 0, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcm_304::Bcm_rearfoglampstType bcm_rearfoglampst( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Parking lamp status', 'enum': {0: // 'BCM_PARKINGLAMPST_INACTIVE', 1: 'BCM_PARKINGLAMPST_ACTIVE'}, // 'precision': 1.0, 'len': 1, 'name': 'BCM_ParkingLampSt', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 12, 'type': 'enum', // 'order': 'motorola', 'physical_unit': ''} Scu_bcm_304::Bcm_parkinglampstType bcm_parkinglampst( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Low beam status', 'enum': {0: // 'BCM_LOWBEAMST_INACTIVE', 1: 'BCM_LOWBEAMST_ACTIVE'}, 'precision': 1.0, // 'len': 1, 'name': 'BCM_LowBeamSt', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 2, 'type': 'enum', 'order': 'motorola', // 'physical_unit': '-'} Scu_bcm_304::Bcm_lowbeamstType bcm_lowbeamst(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Left turn lamp status', 'enum': {0: // 'BCM_LEFTTURNLAMPST_INACTIVE', 1: 'BCM_LEFTTURNLAMPST_ACTIVE'}, // 'precision': 1.0, 'len': 1, 'name': 'BCM_LeftTurnLampSt', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 5, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcm_304::Bcm_leftturnlampstType bcm_leftturnlampst( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Key status', 'enum': {0: 'BCM_KEYST_OFF', // 1: 'BCM_KEYST_ACC', 2: 'BCM_KEYST_ON', 3: 'BCM_KEYST_CRANK'}, // 'precision': 1.0, 'len': 2, 'name': 'BCM_KeySt', 'is_signed_var': False, // 'offset': 0.0, 'physical_range': '[0|3]', 'bit': 7, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcm_304::Bcm_keystType bcm_keyst(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Horn status', 'enum': {0: // 'BCM_HORNST_INACTIVE', 1: 'BCM_HORNST_ACTIVE'}, 'precision': 1.0, 'len': 1, // 'name': 'BCM_HornSt', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 15, 'type': 'enum', 'order': 'motorola', // 'physical_unit': '-'} Scu_bcm_304::Bcm_hornstType bcm_hornst(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'High beam status', 'enum': {0: // 'BCM_HIGHBEAMST_INACTIVE', 1: 'BCM_HIGHBEAMST_ACTIVE'}, 'precision': 1.0, // 'len': 1, 'name': 'BCM_HighBeamSt', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 3, 'type': 'enum', 'order': 'motorola', // 'physical_unit': '-'} Scu_bcm_304::Bcm_highbeamstType bcm_highbeamst(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Hazard lamp status', 'enum': {0: // 'BCM_HAZARDLAMPST_INACTIVE', 1: 'BCM_HAZARDLAMPST_ACTIVE'}, // 'precision': 1.0, 'len': 1, 'name': 'BCM_HazardLampSt', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 13, 'type': 'enum', // 'order': 'motorola', 'physical_unit': ''} Scu_bcm_304::Bcm_hazardlampstType bcm_hazardlampst( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Front fog lamp status', 'enum': {0: // 'BCM_FRONTFOGLAMPST_INACTIVE', 1: 'BCM_FRONTFOGLAMPST_ACTIVE'}, // 'precision': 1.0, 'len': 1, 'name': 'BCM_FrontFogLampSt', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 1, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcm_304::Bcm_frontfoglampstType bcm_frontfoglampst( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Brake light switch status', 'enum': {0: // 'BCM_BRAKELIGHTSWITCHST_INACTIVE', 1: 'BCM_BRAKELIGHTSWITCHST_ACTIVE'}, // 'precision': 1.0, 'len': 1, 'name': 'BCM_BrakeLightSwitchSt', // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': // 14, 'type': 'enum', 'order': 'motorola', 'physical_unit': '-'} Scu_bcm_304::Bcm_brakelightswitchstType bcm_brakelightswitchst( const std::uint8_t* bytes, const int32_t length) const; }; } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_epb_310.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_epb_310.h" #include "glog/logging.h" #include "modules/drivers/canbus/common/byte.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace ge3 { using ::apollo::drivers::canbus::Byte; Scuepb310::Scuepb310() {} const int32_t Scuepb310::ID = 0x310; void Scuepb310::Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const { chassis->mutable_scu_epb_310()->set_epb_intidx( epb_intidx(bytes, length)); chassis->mutable_scu_epb_310()->set_epb_drvmode( epb_drvmode(bytes, length)); chassis->mutable_scu_epb_310()->set_epb_sysst( epb_sysst(bytes, length)); chassis->mutable_scu_epb_310()->set_epb_faultst( epb_faultst(bytes, length)); } // config detail: {'description': 'EPS interrupt index', 'enum': {0: // 'EPB_INTIDX_NOINT', 1: 'EPB_INTIDX_OVERFLOW', 2: 'EPB_INTIDX_TIMEOUT'}, // 'precision': 1.0, 'len': 3, 'name': 'epb_intidx', 'is_signed_var': False, // 'offset': 0.0, 'physical_range': '[0|7]', 'bit': 10, 'type': 'enum', 'order': // 'motorola', 'physical_unit': ''} Scu_epb_310::Epb_intidxType Scuepb310::epb_intidx(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(0, 3); Scu_epb_310::Epb_intidxType ret = static_cast<Scu_epb_310::Epb_intidxType>(x); return ret; } // config detail: {'description': 'EPB drive mode', 'enum': {0: // 'EPB_DRVMODE_INVALID', 1: 'EPB_DRVMODE_MANUAL', 2: 'EPB_DRVMODE_INTERRUPT', // 3: 'EPB_DRVMODE_AUTO'}, 'precision': 1.0, 'len': 2, 'name': 'epb_drvmode', // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|3]', 'bit': 6, // 'type': 'enum', 'order': 'motorola', 'physical_unit': ''} Scu_epb_310::Epb_drvmodeType Scuepb310::epb_drvmode(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(5, 2); Scu_epb_310::Epb_drvmodeType ret = static_cast<Scu_epb_310::Epb_drvmodeType>(x); return ret; } // config detail: {'description': 'EPB system status', 'enum': {0: // 'EPB_SYSST_RELEASED', 1: 'EPB_SYSST_APPLIED', 2: 'EPB_SYSST_RELEASING', 3: // 'EPB_SYSST_FAULT', 4: 'EPB_SYSST_APPLYING', 5: 'EPB_SYSST_DISENGAGED'}, // 'precision': 1.0, 'len': 3, 'name': 'epb_sysst', 'is_signed_var': False, // 'offset': 0.0, 'physical_range': '[0|7]', 'bit': 2, 'type': 'enum', 'order': // 'motorola', 'physical_unit': ''} Scu_epb_310::Epb_sysstType Scuepb310::epb_sysst(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 3); Scu_epb_310::Epb_sysstType ret = static_cast<Scu_epb_310::Epb_sysstType>(x); return ret; } // config detail: {'description': 'EPB fault status', 'enum': {0: // 'EPB_FAULTST_NORMAL', 1: 'EPB_FAULTST_FAULT'}, 'precision': 1.0, 'len': 1, // 'name': 'epb_faultst', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_epb_310::Epb_faultstType Scuepb310::epb_faultst(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(7, 1); Scu_epb_310::Epb_faultstType ret = static_cast<Scu_epb_310::Epb_faultstType>(x); return ret; } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_vcu_1_312_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_vcu_1_312.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace ge3 { class Scuvcu1312Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Scuvcu1312Test, reset) { Scuvcu1312 scuvcu1312; int32_t length = 8; Ge3 chassis_detail; uint8_t bytes[8] = {0x01, 0x02, 0x03, 0x04, 0x11, 0x12, 0x13, 0x14}; scuvcu1312.Parse(bytes, length, &chassis_detail); EXPECT_DOUBLE_EQ(chassis_detail.scu_vcu_1_312().vcu_elcsysfault(), 1); EXPECT_DOUBLE_EQ(chassis_detail.scu_vcu_1_312().vcu_brkpedst(), 1); EXPECT_DOUBLE_EQ(chassis_detail.scu_vcu_1_312().vcu_intidx(), 4); EXPECT_DOUBLE_EQ(chassis_detail.scu_vcu_1_312().vcu_gearintidx(), 2); EXPECT_DOUBLE_EQ(chassis_detail.scu_vcu_1_312().vcu_geardrvmode(), 0); EXPECT_DOUBLE_EQ(chassis_detail.scu_vcu_1_312().vcu_accpedact(), 14.45); EXPECT_DOUBLE_EQ(chassis_detail.scu_vcu_1_312().vcu_brkpedpst(), 6.664); EXPECT_DOUBLE_EQ(chassis_detail.scu_vcu_1_312().vcu_vehrng(), 515); EXPECT_DOUBLE_EQ(chassis_detail.scu_vcu_1_312().vcu_accpedpst(), 1.568); EXPECT_DOUBLE_EQ(chassis_detail.scu_vcu_1_312().vcu_vehrdyst(), 1); EXPECT_DOUBLE_EQ(chassis_detail.scu_vcu_1_312().vcu_faultst(), 0); EXPECT_DOUBLE_EQ(chassis_detail.scu_vcu_1_312().vcu_drvmode(), 0); EXPECT_DOUBLE_EQ(chassis_detail.scu_vcu_1_312().vcu_gearpst(), 0); EXPECT_DOUBLE_EQ(chassis_detail.scu_vcu_1_312().vcu_gearfaultst(), 0); EXPECT_DOUBLE_EQ(chassis_detail.scu_vcu_1_312().vcu_gearact(), 0); } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/pc_epb_203_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/pc_epb_203.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace ge3 { class Pcepb203Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Pcepb203Test, reset) { uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; Pcepb203 pcepb203; EXPECT_EQ(pcepb203.GetPeriod(), 20 * 1000); pcepb203.UpdateData(data); EXPECT_EQ(data[0], 0b01100100); EXPECT_EQ(data[1], 0b01100010); EXPECT_EQ(data[2], 0b01100011); EXPECT_EQ(data[3], 0b01100100); EXPECT_EQ(data[4], 0b01010001); EXPECT_EQ(data[5], 0b01010010); EXPECT_EQ(data[6], 0b01010011); EXPECT_EQ(data[7], 0b01010100); } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_bcs_2_307.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_bcs_2_307.h" #include "glog/logging.h" #include "modules/drivers/canbus/common/byte.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace ge3 { using ::apollo::drivers::canbus::Byte; Scubcs2307::Scubcs2307() {} const int32_t Scubcs2307::ID = 0x307; void Scubcs2307::Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const { chassis->mutable_scu_bcs_2_307()->set_bcs_vehspdvd( bcs_vehspdvd(bytes, length)); chassis->mutable_scu_bcs_2_307()->set_bcs_yawrate( bcs_yawrate(bytes, length)); chassis->mutable_scu_bcs_2_307()->set_bcs_vehspd( bcs_vehspd(bytes, length)); chassis->mutable_scu_bcs_2_307()->set_bcs_vehlongaccel( bcs_vehlongaccel(bytes, length)); chassis->mutable_scu_bcs_2_307()->set_bcs_vehlataccel( bcs_vehlataccel(bytes, length)); } // config detail: {'description': 'Vehicle speed valid data', 'enum': {0: // 'BCS_VEHSPDVD_INVALID', 1: 'BCS_VEHSPDVD_VALID'}, 'precision': 1.0, 'len': 1, // 'name': 'bcs_vehspdvd', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 40, 'type': 'enum', 'order': 'motorola', // 'physical_unit': '-'} Scu_bcs_2_307::Bcs_vehspdvdType Scubcs2307::bcs_vehspdvd( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 5); int32_t x = t0.get_byte(0, 1); Scu_bcs_2_307::Bcs_vehspdvdType ret = static_cast<Scu_bcs_2_307::Bcs_vehspdvdType>(x); return ret; } // config detail: {'description': 'Yaw rate', 'offset': -2.2243, 'precision': // 0.0021326, 'len': 12, 'name': 'bcs_yawrate', 'is_signed_var': False, // 'physical_range': '[-2.2243|2.2243]', 'bit': 55, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'rad/s'} double Scubcs2307::bcs_yawrate(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 6); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 7); int32_t t = t1.get_byte(4, 4); x <<= 4; x |= t; double ret = x * 0.002133 + -2.224300; return ret; } // config detail: {'description': 'Vehicle speed', 'offset': 0.0, 'precision': // 0.05625, 'len': 13, 'name': 'bcs_vehspd', 'is_signed_var': False, // 'physical_range': '[0|240]', 'bit': 39, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'km/h'} double Scubcs2307::bcs_vehspd(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 5); int32_t t = t1.get_byte(3, 5); x <<= 5; x |= t; double ret = x * 0.056250 / 3.6; // modified by 20181211 , change km/h to m/s return ret; } // config detail: {'description': 'Vehicle longitudinal acceleration', 'offset': // -21.593, 'precision': 0.027126736, 'len': 12, 'name': 'bcs_vehlongaccel', // 'is_signed_var': False, 'physical_range': '[-21.593|21.593]', 'bit': 23, // 'type': 'double', 'order': 'motorola', 'physical_unit': 'm/s^2'} double Scubcs2307::bcs_vehlongaccel(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 2); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 3); int32_t t = t1.get_byte(4, 4); x <<= 4; x |= t; double ret = x * 0.027127 + -21.593000; return ret; } // config detail: {'description': 'Vehicle lateral acceleration', 'offset': // -21.593, 'precision': 0.027126736, 'len': 12, 'name': 'bcs_vehlataccel', // 'is_signed_var': False, 'physical_range': '[-21.593|21.593]', 'bit': 7, // 'type': 'double', 'order': 'motorola', 'physical_unit': 'm/s^2'} double Scubcs2307::bcs_vehlataccel(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 1); int32_t t = t1.get_byte(4, 4); x <<= 4; x |= t; double ret = x * 0.027127 + -21.593000; return ret; } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_3_303_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_3_303.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace ge3 { class Scu3303Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Scu3303Test, reset) { Scu3303 scu3303; int32_t length = 8; Ge3 chassis_detail; uint8_t bytes[8] = {0x41, 0x42, 0x43, 0x61, 0x62, 0x30, 0x31, 0x32}; scu3303.Parse(bytes, length, &chassis_detail); EXPECT_DOUBLE_EQ(chassis_detail.scu_3_303().vin08(), 'A'); // 65 EXPECT_DOUBLE_EQ(chassis_detail.scu_3_303().vin09(), 'B'); // 66 EXPECT_DOUBLE_EQ(chassis_detail.scu_3_303().vin10(), 67); // 'C' EXPECT_DOUBLE_EQ(chassis_detail.scu_3_303().vin11(), 97); // 'a' EXPECT_DOUBLE_EQ(chassis_detail.scu_3_303().vin12(), 'b'); // 98 EXPECT_DOUBLE_EQ(chassis_detail.scu_3_303().vin13(), 48); // '0' EXPECT_DOUBLE_EQ(chassis_detail.scu_3_303().vin14(), '1'); // 49 EXPECT_DOUBLE_EQ(chassis_detail.scu_3_303().vin15(), '2'); // 50 } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_vcu_2_313.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/ge3/proto/ge3.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace ge3 { class Scuvcu2313 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Ge3> { public: static const int32_t ID; Scuvcu2313(); void Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const override; private: // config detail: {'description': 'Max positive torque', 'offset': 0.0, // 'precision': 1.5, 'len': 11, 'name': 'VCU_TorqPosMax', 'is_signed_var': // False, 'physical_range': '[0|3000]', 'bit': 55, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'Nm'} double vcu_torqposmax(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Max negative torque', 'offset': -3000.0, // 'precision': 1.5, 'len': 11, 'name': 'VCU_TorqNegMax', 'is_signed_var': // False, 'physical_range': '[-3000|0]', 'bit': 39, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'Nm'} double vcu_torqnegmax(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Actual torque', 'offset': -3000.0, // 'precision': 1.5, 'len': 12, 'name': 'VCU_TorqAct', 'is_signed_var': False, // 'physical_range': '[-3000|3000]', 'bit': 23, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'Nm'} double vcu_torqact(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Engine speed', 'offset': 0.0, // 'precision': 1.0, 'len': 16, 'name': 'VCU_EngSpd', 'is_signed_var': False, // 'physical_range': '[0|65535]', 'bit': 7, 'type': 'int', 'order': // 'motorola', 'physical_unit': 'rpm'} int vcu_engspd(const std::uint8_t* bytes, const int32_t length) const; }; } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_2_302.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_2_302.h" #include "glog/logging.h" #include "modules/drivers/canbus/common/byte.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace ge3 { using ::apollo::drivers::canbus::Byte; Scu2302::Scu2302() {} const int32_t Scu2302::ID = 0x302; void Scu2302::Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const { chassis->mutable_scu_2_302()->set_vin07(vin07(bytes, length)); chassis->mutable_scu_2_302()->set_vin06(vin06(bytes, length)); chassis->mutable_scu_2_302()->set_vin05(vin05(bytes, length)); chassis->mutable_scu_2_302()->set_vin04(vin04(bytes, length)); chassis->mutable_scu_2_302()->set_vin03(vin03(bytes, length)); chassis->mutable_scu_2_302()->set_vin02(vin02(bytes, length)); chassis->mutable_scu_2_302()->set_vin01(vin01(bytes, length)); chassis->mutable_scu_2_302()->set_vin00(vin00(bytes, length)); } // config detail: {'description': 'VIN string character 07', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'vin07', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 63, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int Scu2302::vin07(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 7); int32_t x = t0.get_byte(0, 8); int ret = x; return ret; } // config detail: {'description': 'VIN string character 06', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'vin06', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 55, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int Scu2302::vin06(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 6); int32_t x = t0.get_byte(0, 8); int ret = x; return ret; } // config detail: {'description': 'VIN string character 05', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'vin05', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 47, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int Scu2302::vin05(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 5); int32_t x = t0.get_byte(0, 8); int ret = x; return ret; } // config detail: {'description': 'VIN string character 04', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'vin04', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 39, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int Scu2302::vin04(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(0, 8); int ret = x; return ret; } // config detail: {'description': 'VIN string character 03', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'vin03', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 31, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int Scu2302::vin03(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 3); int32_t x = t0.get_byte(0, 8); int ret = x; return ret; } // config detail: {'description': 'VIN string character 02', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'vin02', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 23, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int Scu2302::vin02(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 2); int32_t x = t0.get_byte(0, 8); int ret = x; return ret; } // config detail: {'description': 'VIN string character 01', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'vin01', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 15, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int Scu2302::vin01(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(0, 8); int ret = x; return ret; } // config detail: {'description': 'VIN string character 00', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'vin00', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 7, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int Scu2302::vin00(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 8); int ret = x; return ret; } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_bcs_3_308.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_bcs_3_308.h" #include "glog/logging.h" #include "modules/drivers/canbus/common/byte.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace ge3 { using ::apollo::drivers::canbus::Byte; Scubcs3308::Scubcs3308() {} const int32_t Scubcs3308::ID = 0x308; void Scubcs3308::Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const { chassis->mutable_scu_bcs_3_308()->set_bcs_rrwheelspdvd( bcs_rrwheelspdvd(bytes, length)); chassis->mutable_scu_bcs_3_308()->set_bcs_rrwheeldirectionvd( bcs_rrwheeldirectionvd(bytes, length)); chassis->mutable_scu_bcs_3_308()->set_bcs_rlwheelspdvd( bcs_rlwheelspdvd(bytes, length)); chassis->mutable_scu_bcs_3_308()->set_bcs_rlwheeldirectionvd( bcs_rlwheeldirectionvd(bytes, length)); chassis->mutable_scu_bcs_3_308()->set_bcs_frwheelspdvd( bcs_frwheelspdvd(bytes, length)); chassis->mutable_scu_bcs_3_308()->set_bcs_frwheeldirectionvd( bcs_frwheeldirectionvd(bytes, length)); chassis->mutable_scu_bcs_3_308()->set_bcs_flwheelspdvd( bcs_flwheelspdvd(bytes, length)); chassis->mutable_scu_bcs_3_308()->set_bcs_flwheeldirectionvd( bcs_flwheeldirectionvd(bytes, length)); chassis->mutable_scu_bcs_3_308()->set_bcs_rrwheelspd( bcs_rrwheelspd(bytes, length)); chassis->mutable_scu_bcs_3_308()->set_bcs_rrwheeldirection( bcs_rrwheeldirection(bytes, length)); chassis->mutable_scu_bcs_3_308()->set_bcs_rlwheelspd( bcs_rlwheelspd(bytes, length)); chassis->mutable_scu_bcs_3_308()->set_bcs_rlwheeldirection( bcs_rlwheeldirection(bytes, length)); chassis->mutable_scu_bcs_3_308()->set_bcs_frwheelspd( bcs_frwheelspd(bytes, length)); chassis->mutable_scu_bcs_3_308()->set_bcs_frwheeldirection( bcs_frwheeldirection(bytes, length)); chassis->mutable_scu_bcs_3_308()->set_bcs_flwheelspd( bcs_flwheelspd(bytes, length)); chassis->mutable_scu_bcs_3_308()->set_bcs_flwheeldirection( bcs_flwheeldirection(bytes, length)); } // config detail: {'description': 'Rear right wheel speed valid data', 'enum': // {0: 'BCS_RRWHEELSPDVD_INVALID', 1: 'BCS_RRWHEELSPDVD_VALID'}, // 'precision': 1.0, 'len': 1, 'name': 'bcs_rrwheelspdvd', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 57, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcs_3_308::Bcs_rrwheelspdvdType Scubcs3308::bcs_rrwheelspdvd( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 7); int32_t x = t0.get_byte(1, 1); Scu_bcs_3_308::Bcs_rrwheelspdvdType ret = static_cast<Scu_bcs_3_308::Bcs_rrwheelspdvdType>(x); return ret; } // config detail: {'description': 'Rear right wheel speed direction valid data', // 'enum': {0: 'BCS_RRWHEELDIRECTIONVD_INVALID', 1: // 'BCS_RRWHEELDIRECTIONVD_VALID'}, 'precision': 1.0, 'len': 1, 'name': // 'bcs_rrwheeldirectionvd', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 58, 'type': 'enum', 'order': 'motorola', // 'physical_unit': '-'} Scu_bcs_3_308::Bcs_rrwheeldirectionvdType Scubcs3308::bcs_rrwheeldirectionvd( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 7); int32_t x = t0.get_byte(2, 1); Scu_bcs_3_308::Bcs_rrwheeldirectionvdType ret = static_cast<Scu_bcs_3_308::Bcs_rrwheeldirectionvdType>(x); return ret; } // config detail: {'description': 'Rear left wheel speed valid data', 'enum': // {0: 'BCS_RLWHEELSPDVD_INVALID', 1: 'BCS_RLWHEELSPDVD_VALID'}, // 'precision': 1.0, 'len': 1, 'name': 'bcs_rlwheelspdvd', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 41, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcs_3_308::Bcs_rlwheelspdvdType Scubcs3308::bcs_rlwheelspdvd( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 5); int32_t x = t0.get_byte(1, 1); Scu_bcs_3_308::Bcs_rlwheelspdvdType ret = static_cast<Scu_bcs_3_308::Bcs_rlwheelspdvdType>(x); return ret; } // config detail: {'description': 'Rear left wheel speed direction valid data', // 'enum': {0: 'BCS_RLWHEELDIRECTIONVD_INVALID', 1: // 'BCS_RLWHEELDIRECTIONVD_VALID'}, 'precision': 1.0, 'len': 1, 'name': // 'bcs_rlwheeldirectionvd', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 42, 'type': 'enum', 'order': 'motorola', // 'physical_unit': '-'} Scu_bcs_3_308::Bcs_rlwheeldirectionvdType Scubcs3308::bcs_rlwheeldirectionvd( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 5); int32_t x = t0.get_byte(2, 1); Scu_bcs_3_308::Bcs_rlwheeldirectionvdType ret = static_cast<Scu_bcs_3_308::Bcs_rlwheeldirectionvdType>(x); return ret; } // config detail: {'description': 'Front right wheel speed valid data', 'enum': // {0: 'BCS_FRWHEELSPDVD_INVALID', 1: 'BCS_FRWHEELSPDVD_VALID'}, // 'precision': 1.0, 'len': 1, 'name': 'bcs_frwheelspdvd', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 25, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcs_3_308::Bcs_frwheelspdvdType Scubcs3308::bcs_frwheelspdvd( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 3); int32_t x = t0.get_byte(1, 1); Scu_bcs_3_308::Bcs_frwheelspdvdType ret = static_cast<Scu_bcs_3_308::Bcs_frwheelspdvdType>(x); return ret; } // config detail: {'description': 'Front right wheel speed direction valid // data', 'enum': {0: 'BCS_FRWHEELDIRECTIONVD_INVALID', 1: // 'BCS_FRWHEELDIRECTIONVD_VALID'}, 'precision': 1.0, 'len': 1, 'name': // 'bcs_frwheeldirectionvd', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 26, 'type': 'enum', 'order': 'motorola', // 'physical_unit': '-'} Scu_bcs_3_308::Bcs_frwheeldirectionvdType Scubcs3308::bcs_frwheeldirectionvd( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 3); int32_t x = t0.get_byte(2, 1); Scu_bcs_3_308::Bcs_frwheeldirectionvdType ret = static_cast<Scu_bcs_3_308::Bcs_frwheeldirectionvdType>(x); return ret; } // config detail: {'description': 'Front left wheel speed valid data', 'enum': // {0: 'BCS_FLWHEELSPDVD_INVALID', 1: 'BCS_FLWHEELSPDVD_VALID'}, // 'precision': 1.0, 'len': 1, 'name': 'bcs_flwheelspdvd', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 9, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcs_3_308::Bcs_flwheelspdvdType Scubcs3308::bcs_flwheelspdvd( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(1, 1); Scu_bcs_3_308::Bcs_flwheelspdvdType ret = static_cast<Scu_bcs_3_308::Bcs_flwheelspdvdType>(x); return ret; } // config detail: {'description': 'Front left wheel speed direction valid data', // 'enum': {0: 'BCS_FLWHEELDIRECTIONVD_INVALID', 1: // 'BCS_FLWHEELDIRECTIONVD_VALID'}, 'precision': 1.0, 'len': 1, 'name': // 'bcs_flwheeldirectionvd', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 10, 'type': 'enum', 'order': 'motorola', // 'physical_unit': '-'} Scu_bcs_3_308::Bcs_flwheeldirectionvdType Scubcs3308::bcs_flwheeldirectionvd( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(2, 1); Scu_bcs_3_308::Bcs_flwheeldirectionvdType ret = static_cast<Scu_bcs_3_308::Bcs_flwheeldirectionvdType>(x); return ret; } // config detail: {'description': 'Rear right wheel speed', 'offset': 0.0, // 'precision': 0.05625, 'len': 13, 'name': 'bcs_rrwheelspd', 'is_signed_var': // False, 'physical_range': '[0|240]', 'bit': 55, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'km/h'} double Scubcs3308::bcs_rrwheelspd(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 6); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 7); int32_t t = t1.get_byte(3, 5); x <<= 5; x |= t; double ret = x * 0.056250; return ret; } // config detail: {'description': 'Rear right wheel speed direction', 'enum': // {0: 'BCS_RRWHEELDIRECTION_FORWARD', 1: 'BCS_RRWHEELDIRECTION_BACKWARD'}, // 'precision': 1.0, 'len': 1, 'name': 'bcs_rrwheeldirection', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 56, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcs_3_308::Bcs_rrwheeldirectionType Scubcs3308::bcs_rrwheeldirection( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 7); int32_t x = t0.get_byte(0, 1); Scu_bcs_3_308::Bcs_rrwheeldirectionType ret = static_cast<Scu_bcs_3_308::Bcs_rrwheeldirectionType>(x); return ret; } // config detail: {'description': 'Rear left wheel speed', 'offset': 0.0, // 'precision': 0.05625, 'len': 13, 'name': 'bcs_rlwheelspd', 'is_signed_var': // False, 'physical_range': '[0|240]', 'bit': 39, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'km/h'} double Scubcs3308::bcs_rlwheelspd(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 5); int32_t t = t1.get_byte(3, 5); x <<= 5; x |= t; double ret = x * 0.056250; return ret; } // config detail: {'description': 'Rear left wheel speed direction', 'enum': {0: // 'BCS_RLWHEELDIRECTION_FORWARD', 1: 'BCS_RLWHEELDIRECTION_BACKWARD'}, // 'precision': 1.0, 'len': 1, 'name': 'bcs_rlwheeldirection', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 40, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcs_3_308::Bcs_rlwheeldirectionType Scubcs3308::bcs_rlwheeldirection( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 5); int32_t x = t0.get_byte(0, 1); Scu_bcs_3_308::Bcs_rlwheeldirectionType ret = static_cast<Scu_bcs_3_308::Bcs_rlwheeldirectionType>(x); return ret; } // config detail: {'description': 'Front right wheel speed', 'offset': 0.0, // 'precision': 0.05625, 'len': 13, 'name': 'bcs_frwheelspd', 'is_signed_var': // False, 'physical_range': '[0|240]', 'bit': 23, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'km/h'} double Scubcs3308::bcs_frwheelspd(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 2); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 3); int32_t t = t1.get_byte(3, 5); x <<= 5; x |= t; double ret = x * 0.056250; return ret; } // config detail: {'description': 'Front right wheel speed direction', 'enum': // {0: 'BCS_FRWHEELDIRECTION_FORWARD', 1: 'BCS_FRWHEELDIRECTION_BACKWARD'}, // 'precision': 1.0, 'len': 1, 'name': 'bcs_frwheeldirection', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 24, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcs_3_308::Bcs_frwheeldirectionType Scubcs3308::bcs_frwheeldirection( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 3); int32_t x = t0.get_byte(0, 1); Scu_bcs_3_308::Bcs_frwheeldirectionType ret = static_cast<Scu_bcs_3_308::Bcs_frwheeldirectionType>(x); return ret; } // config detail: {'description': 'Front left wheel speed', 'offset': 0.0, // 'precision': 0.05625, 'len': 13, 'name': 'bcs_flwheelspd', 'is_signed_var': // False, 'physical_range': '[0|240]', 'bit': 7, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'km/h'} double Scubcs3308::bcs_flwheelspd(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 1); int32_t t = t1.get_byte(3, 5); x <<= 5; x |= t; double ret = x * 0.056250; return ret; } // config detail: {'description': 'Front left wheel speed direction', 'enum': // {0: 'BCS_FLWHEELDIRECTION_FORWARD', 1: 'BCS_FLWHEELDIRECTION_BACKWARD'}, // 'precision': 1.0, 'len': 1, 'name': 'bcs_flwheeldirection', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 8, 'type': 'enum', // 'order': 'motorola', 'physical_unit': '-'} Scu_bcs_3_308::Bcs_flwheeldirectionType Scubcs3308::bcs_flwheeldirection( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(0, 1); Scu_bcs_3_308::Bcs_flwheeldirectionType ret = static_cast<Scu_bcs_3_308::Bcs_flwheeldirectionType>(x); return ret; } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/pc_bcm_201.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/pc_bcm_201.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace ge3 { using ::apollo::drivers::canbus::Byte; const int32_t Pcbcm201::ID = 0x201; // public Pcbcm201::Pcbcm201() { Reset(); } uint32_t Pcbcm201::GetPeriod() const { // modify every protocol's period manually static const uint32_t PERIOD = 20 * 1000; return PERIOD; } void Pcbcm201::UpdateData(uint8_t* data) { set_p_pc_reverselampreq(data, pc_reverselampreq_); set_p_pc_lowbeamreq(data, pc_lowbeamreq_); set_p_pc_highbeamreq(data, pc_highbeamreq_); set_p_pc_rightturnlampreq(data, pc_rightturnlampreq_); set_p_pc_leftturnlampreq(data, pc_leftturnlampreq_); set_p_pc_hornreq(data, pc_hornreq_); set_p_pc_hazardlampreq(data, pc_hazardlampreq_); } void Pcbcm201::Reset() { // you should check this manually pc_reverselampreq_ = Pc_bcm_201::PC_REVERSELAMPREQ_NOREQ; pc_lowbeamreq_ = Pc_bcm_201::PC_LOWBEAMREQ_NOREQ; pc_highbeamreq_ = Pc_bcm_201::PC_HIGHBEAMREQ_NOREQ; pc_rightturnlampreq_ = Pc_bcm_201::PC_RIGHTTURNLAMPREQ_NOREQ; pc_leftturnlampreq_ = Pc_bcm_201::PC_LEFTTURNLAMPREQ_NOREQ; pc_hornreq_ = Pc_bcm_201::PC_HORNREQ_NOREQ; pc_hazardlampreq_ = Pc_bcm_201::PC_HAZARDLAMPREQ_NOREQ; } Pcbcm201* Pcbcm201::set_pc_reverselampreq( Pc_bcm_201::Pc_reverselampreqType pc_reverselampreq) { pc_reverselampreq_ = pc_reverselampreq; return this; } // config detail: {'description': 'Left turn lamp request', 'enum': {0: // 'PC_REVERSELAMPREQ_NOREQ', 1: 'PC_REVERSELAMPREQ_REQ'}, 'precision': 1.0, // 'len': 1, 'name': 'PC_ReverseLampReq', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 1, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} void Pcbcm201::set_p_pc_reverselampreq( uint8_t* data, Pc_bcm_201::Pc_reverselampreqType pc_reverselampreq) { int x = pc_reverselampreq; Byte to_set(data + 0); to_set.set_value(static_cast<uint8_t>(x), 1, 1); } Pcbcm201* Pcbcm201::set_pc_lowbeamreq( Pc_bcm_201::Pc_lowbeamreqType pc_lowbeamreq) { pc_lowbeamreq_ = pc_lowbeamreq; return this; } // config detail: {'description': 'Left turn lamp request', 'enum': {0: // 'PC_LOWBEAMREQ_NOREQ', 1: 'PC_LOWBEAMREQ_REQ'}, 'precision': 1.0, 'len': 1, // 'name': 'PC_LowBeamReq', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 2, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} void Pcbcm201::set_p_pc_lowbeamreq( uint8_t* data, Pc_bcm_201::Pc_lowbeamreqType pc_lowbeamreq) { int x = pc_lowbeamreq; Byte to_set(data + 0); to_set.set_value(static_cast<uint8_t>(x), 2, 1); } Pcbcm201* Pcbcm201::set_pc_highbeamreq( Pc_bcm_201::Pc_highbeamreqType pc_highbeamreq) { pc_highbeamreq_ = pc_highbeamreq; return this; } // config detail: {'description': 'Left turn lamp request', 'enum': {0: // 'PC_HIGHBEAMREQ_NOREQ', 1: 'PC_HIGHBEAMREQ_REQ'}, 'precision': 1.0, 'len': 1, // 'name': 'PC_HighBeamReq', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 3, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} void Pcbcm201::set_p_pc_highbeamreq( uint8_t* data, Pc_bcm_201::Pc_highbeamreqType pc_highbeamreq) { int x = pc_highbeamreq; Byte to_set(data + 0); to_set.set_value(static_cast<uint8_t>(x), 3, 1); } Pcbcm201* Pcbcm201::set_pc_rightturnlampreq( Pc_bcm_201::Pc_rightturnlampreqType pc_rightturnlampreq) { pc_rightturnlampreq_ = pc_rightturnlampreq; return this; } // config detail: {'description': 'Right turn lamp request', 'enum': {0: // 'PC_RIGHTTURNLAMPREQ_NOREQ', 1: 'PC_RIGHTTURNLAMPREQ_REQ'}, 'precision': 1.0, // 'len': 1, 'name': 'PC_RightTurnLampReq', 'is_signed_var': False, 'offset': // 0.0, 'physical_range': '[0|3]', 'bit': 4, 'type': 'enum', 'order': // 'motorola', 'physical_unit': ''} void Pcbcm201::set_p_pc_rightturnlampreq( uint8_t* data, Pc_bcm_201::Pc_rightturnlampreqType pc_rightturnlampreq) { int x = pc_rightturnlampreq; Byte to_set(data + 0); to_set.set_value(static_cast<uint8_t>(x), 4, 1); } Pcbcm201* Pcbcm201::set_pc_leftturnlampreq( Pc_bcm_201::Pc_leftturnlampreqType pc_leftturnlampreq) { pc_leftturnlampreq_ = pc_leftturnlampreq; return this; } // config detail: {'description': 'Left turn lamp request', 'enum': {0: // 'PC_LEFTTURNLAMPREQ_NOREQ', 1: 'PC_LEFTTURNLAMPREQ_REQ'}, 'precision': 1.0, // 'len': 1, 'name': 'PC_LeftTurnLampReq', 'is_signed_var': False, 'offset': // 0.0, 'physical_range': '[0|1]', 'bit': 5, 'type': 'enum', 'order': // 'motorola', 'physical_unit': ''} void Pcbcm201::set_p_pc_leftturnlampreq( uint8_t* data, Pc_bcm_201::Pc_leftturnlampreqType pc_leftturnlampreq) { int x = pc_leftturnlampreq; Byte to_set(data + 0); to_set.set_value(static_cast<uint8_t>(x), 5, 1); } Pcbcm201* Pcbcm201::set_pc_hornreq(Pc_bcm_201::Pc_hornreqType pc_hornreq) { pc_hornreq_ = pc_hornreq; return this; } // config detail: {'description': 'Horn request', 'enum': {0: // 'PC_HORNREQ_NOREQ', 1: 'PC_HORNREQ_REQ'}, 'precision': 1.0, 'len': 1, 'name': // 'PC_HornReq', 'is_signed_var': False, 'offset': 0.0, 'physical_range': // '[0|1]', 'bit': 6, 'type': 'enum', 'order': 'motorola', 'physical_unit': ''} void Pcbcm201::set_p_pc_hornreq(uint8_t* data, Pc_bcm_201::Pc_hornreqType pc_hornreq) { int x = pc_hornreq; Byte to_set(data + 0); to_set.set_value(static_cast<uint8_t>(x), 6, 1); } Pcbcm201* Pcbcm201::set_pc_hazardlampreq( Pc_bcm_201::Pc_hazardlampreqType pc_hazardlampreq) { pc_hazardlampreq_ = pc_hazardlampreq; return this; } // config detail: {'description': 'Hazard lamp request', 'enum': {0: // 'PC_HAZARDLAMPREQ_NOREQ', 1: 'PC_HAZARDLAMPREQ_REQ'}, 'precision': 1.0, // 'len': 1, 'name': 'PC_HazardLampReq', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} void Pcbcm201::set_p_pc_hazardlampreq( uint8_t* data, Pc_bcm_201::Pc_hazardlampreqType pc_hazardlampreq) { int x = pc_hazardlampreq; Byte to_set(data + 0); to_set.set_value(static_cast<uint8_t>(x), 7, 1); } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_1_301.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/ge3/proto/ge3.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace ge3 { class Scu1301 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Ge3> { public: static const int32_t ID; Scu1301(); void Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const override; private: // config detail: {'description': 'VIN string character 16', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'VIN16', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 15, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int vin16(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Brake pedal position', 'enum': {0: // 'SCU_STOPBUTST_UNPRESSED', 1: 'SCU_STOPBUTST_PRESSED'}, 'precision': 1.0, // 'len': 1, 'name': 'SCU_StopButSt', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 0, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_1_301::Scu_stopbutstType scu_stopbutst(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'SCU drive mode', 'enum': {0: // 'SCU_DRVMODE_INVALID', 1: 'SCU_DRVMODE_MANUAL', 2: 'SCU_DRVMODE_INTERRUPT', // 3: 'SCU_DRVMODE_AUTO'}, 'precision': 1.0, 'len': 2, 'name': 'SCU_DrvMode', // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|3]', 'bit': 3, // 'type': 'enum', 'order': 'motorola', 'physical_unit': ''} Scu_1_301::Scu_drvmodeType scu_drvmode(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'SCU fault status', 'enum': {0: // 'SCU_FAULTST_NORMAL', 1: 'SCU_FAULTST_FAULT'}, 'precision': 1.0, 'len': 4, // 'name': 'SCU_FaultSt', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|15]', 'bit': 7, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_1_301::Scu_faultstType scu_faultst(const std::uint8_t* bytes, const int32_t length) const; }; } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_2_302.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/ge3/proto/ge3.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace ge3 { class Scu2302 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Ge3> { public: static const int32_t ID; Scu2302(); void Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const override; private: // config detail: {'description': 'VIN string character 07', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'VIN07', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 63, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int vin07(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VIN string character 06', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'VIN06', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 55, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int vin06(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VIN string character 05', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'VIN05', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 47, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int vin05(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VIN string character 04', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'VIN04', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 39, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int vin04(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VIN string character 03', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'VIN03', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 31, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int vin03(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VIN string character 02', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'VIN02', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 23, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int vin02(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VIN string character 01', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'VIN01', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 15, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int vin01(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VIN string character 00', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'VIN00', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 7, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int vin00(const std::uint8_t* bytes, const int32_t length) const; }; } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/pc_bcs_202.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/ge3/proto/ge3.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace ge3 { class Pcbcs202 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Ge3> { public: static const int32_t ID; Pcbcs202(); uint32_t GetPeriod() const override; void UpdateData(uint8_t* data) override; void Reset() override; // config detail: {'description': 'Brake pedal request', 'offset': 0.0, // 'precision': 0.1, 'len': 10, 'name': 'PC_BrkPedReq', 'is_signed_var': // False, 'physical_range': '[0|100]', 'bit': 1, 'type': 'double', 'order': // 'motorola', 'physical_unit': '%'} Pcbcs202* set_pc_brkpedreq(double pc_brkpedreq); // config detail: {'description': 'Brake pedal control enable', 'enum': {0: // 'PC_BRKPEDENABLE_DISABLE', 1: 'PC_BRKPEDENABLE_ENABLE'}, 'precision': 1.0, // 'len': 1, 'name': 'PC_BrkPedEnable', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Pcbcs202* set_pc_brkpedenable( Pc_bcs_202::Pc_brkpedenableType pc_brkpedenable); private: // config detail: {'description': 'Brake pedal request', 'offset': 0.0, // 'precision': 0.1, 'len': 10, 'name': 'PC_BrkPedReq', 'is_signed_var': // False, 'physical_range': '[0|100]', 'bit': 1, 'type': 'double', 'order': // 'motorola', 'physical_unit': '%'} void set_p_pc_brkpedreq(uint8_t* data, double pc_brkpedreq); // config detail: {'description': 'Brake pedal control enable', 'enum': {0: // 'PC_BRKPEDENABLE_DISABLE', 1: 'PC_BRKPEDENABLE_ENABLE'}, 'precision': 1.0, // 'len': 1, 'name': 'PC_BrkPedEnable', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} void set_p_pc_brkpedenable(uint8_t* data, Pc_bcs_202::Pc_brkpedenableType pc_brkpedenable); private: double pc_brkpedreq_; Pc_bcs_202::Pc_brkpedenableType pc_brkpedenable_; }; } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/pc_vcu_205.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/pc_vcu_205.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace ge3 { using ::apollo::drivers::canbus::Byte; const int32_t Pcvcu205::ID = 0x205; // public Pcvcu205::Pcvcu205() { Reset(); } uint32_t Pcvcu205::GetPeriod() const { // modify every protocol's period manually static const uint32_t PERIOD = 20 * 1000; return PERIOD; } void Pcvcu205::UpdateData(uint8_t* data) { set_p_pc_accpedreq(data, pc_accpedreq_); set_p_pc_accpedenable(data, pc_accpedenable_); set_p_pc_torqreq(data, pc_torqreq_); set_p_pc_torqenable(data, pc_torqenable_); set_p_pc_gearreq(data, pc_gearreq_); set_p_pc_gearenable(data, pc_gearenable_); } void Pcvcu205::Reset() { // you should check this manually pc_accpedreq_ = 0.0; pc_accpedenable_ = Pc_vcu_205::PC_ACCPEDENABLE_DISABLE; pc_torqreq_ = 0.0; pc_torqenable_ = Pc_vcu_205::PC_TORQENABLE_DISABLE; pc_gearreq_ = Pc_vcu_205::PC_GEARREQ_INVALID; pc_gearenable_ = Pc_vcu_205::PC_GEARENABLE_DISABLE; } Pcvcu205* Pcvcu205::set_pc_accpedreq(double pc_accpedreq) { pc_accpedreq_ = pc_accpedreq; return this; } // config detail: {'description': 'Acceleration pedal request', 'offset': 0.0, // 'precision': 0.05, 'len': 12, 'name': 'PC_AccPedReq', 'is_signed_var': False, // 'physical_range': '[0|100]', 'bit': 15, 'type': 'double', 'order': // 'motorola', 'physical_unit': '%'} void Pcvcu205::set_p_pc_accpedreq(uint8_t* data, double pc_accpedreq) { pc_accpedreq = ProtocolData::BoundedValue(0.0, 100.0, pc_accpedreq); int x = static_cast<int>(pc_accpedreq / 0.050000); uint8_t t = 0; t = x & 0xF; Byte to_set0(data + 2); to_set0.set_value(t, 4, 4); x >>= 4; t = static_cast<uint8_t>(x & 0xFF); Byte to_set1(data + 1); to_set1.set_value(t, 0, 8); } Pcvcu205* Pcvcu205::set_pc_accpedenable( Pc_vcu_205::Pc_accpedenableType pc_accpedenable) { pc_accpedenable_ = pc_accpedenable; return this; } // config detail: {'description': 'Acceleration pedal control enable', 'enum': // {0: 'PC_ACCPEDENABLE_DISABLE', 1: 'PC_ACCPEDENABLE_ENABLE'}, // 'precision': 1.0, 'len': 1, 'name': 'PC_AccPedEnable', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 6, 'type': 'enum', // 'order': 'motorola', 'physical_unit': ''} void Pcvcu205::set_p_pc_accpedenable( uint8_t* data, Pc_vcu_205::Pc_accpedenableType pc_accpedenable) { int x = pc_accpedenable; Byte to_set(data + 0); to_set.set_value(static_cast<uint8_t>(x), 6, 1); } Pcvcu205* Pcvcu205::set_pc_torqreq(double pc_torqreq) { pc_torqreq_ = pc_torqreq; return this; } // config detail: {'description': 'Torque request', 'offset': -3000.0, // 'precision': 1.5, 'len': 12, 'name': 'PC_TorqReq', 'is_signed_var': False, // 'physical_range': '[-3000|3000]', 'bit': 19, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'Nm'} void Pcvcu205::set_p_pc_torqreq(uint8_t* data, double pc_torqreq) { pc_torqreq = ProtocolData::BoundedValue(-3000.0, 3000.0, pc_torqreq); int x = static_cast<int>((pc_torqreq - -3000.000000) / 1.500000); uint8_t t = 0; t = static_cast<uint8_t>(x & 0xFF); Byte to_set0(data + 3); to_set0.set_value(t, 0, 8); x >>= 8; t = x & 0xF; Byte to_set1(data + 2); to_set1.set_value(t, 0, 4); } Pcvcu205* Pcvcu205::set_pc_torqenable( Pc_vcu_205::Pc_torqenableType pc_torqenable) { pc_torqenable_ = pc_torqenable; return this; } // config detail: {'description': 'Torque control enable', 'enum': {0: // 'PC_TORQENABLE_DISABLE', 1: 'PC_TORQENABLE_ENABLE'}, 'precision': 1.0, 'len': // 1, 'name': 'PC_TorqEnable', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 5, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} void Pcvcu205::set_p_pc_torqenable( uint8_t* data, Pc_vcu_205::Pc_torqenableType pc_torqenable) { int x = pc_torqenable; Byte to_set(data + 0); to_set.set_value(static_cast<uint8_t>(x), 5, 1); } Pcvcu205* Pcvcu205::set_pc_gearreq(Pc_vcu_205::Pc_gearreqType pc_gearreq) { pc_gearreq_ = pc_gearreq; return this; } // config detail: {'description': 'Gear request', 'enum': {0: // 'PC_GEARREQ_INVALID', 1: 'PC_GEARREQ_DRIVE', 2: 'PC_GEARREQ_NEUTRAL', 3: // 'PC_GEARREQ_REVERSE', 4: 'PC_GEARREQ_PARK'}, 'precision': 1.0, 'len': 3, // 'name': 'PC_GearReq', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|7]', 'bit': 2, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} void Pcvcu205::set_p_pc_gearreq(uint8_t* data, Pc_vcu_205::Pc_gearreqType pc_gearreq) { int x = pc_gearreq; Byte to_set(data + 0); to_set.set_value(static_cast<uint8_t>(x), 0, 3); } Pcvcu205* Pcvcu205::set_pc_gearenable( Pc_vcu_205::Pc_gearenableType pc_gearenable) { pc_gearenable_ = pc_gearenable; return this; } // config detail: {'description': 'Gear control enable', 'enum': {0: // 'PC_GEARENABLE_DISABLE', 1: 'PC_GEARENABLE_ENABLE'}, 'precision': 1.0, 'len': // 1, 'name': 'PC_GearEnable', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} void Pcvcu205::set_p_pc_gearenable( uint8_t* data, Pc_vcu_205::Pc_gearenableType pc_gearenable) { int x = pc_gearenable; Byte to_set(data + 0); to_set.set_value(static_cast<uint8_t>(x), 7, 1); } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_epb_310.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/ge3/proto/ge3.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace ge3 { class Scuepb310 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Ge3> { public: static const int32_t ID; Scuepb310(); void Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const override; private: // config detail: {'description': 'EPS interrupt index', 'enum': {0: // 'EPB_INTIDX_NOINT', 1: 'EPB_INTIDX_OVERFLOW', 2: 'EPB_INTIDX_TIMEOUT'}, // 'precision': 1.0, 'len': 3, 'name': 'EPB_IntIdx', 'is_signed_var': False, // 'offset': 0.0, 'physical_range': '[0|7]', 'bit': 10, 'type': 'enum', // 'order': 'motorola', 'physical_unit': ''} Scu_epb_310::Epb_intidxType epb_intidx(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'EPB drive mode', 'enum': {0: // 'EPB_DRVMODE_INVALID', 1: 'EPB_DRVMODE_MANUAL', 2: 'EPB_DRVMODE_INTERRUPT', // 3: 'EPB_DRVMODE_AUTO'}, 'precision': 1.0, 'len': 2, 'name': 'EPB_DrvMode', // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|3]', 'bit': 6, // 'type': 'enum', 'order': 'motorola', 'physical_unit': ''} Scu_epb_310::Epb_drvmodeType epb_drvmode(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'EPB system status', 'enum': {0: // 'EPB_SYSST_RELEASED', 1: 'EPB_SYSST_APPLIED', 2: 'EPB_SYSST_RELEASING', 3: // 'EPB_SYSST_FAULT', 4: 'EPB_SYSST_APPLYING', 5: 'EPB_SYSST_DISENGAGED'}, // 'precision': 1.0, 'len': 3, 'name': 'EPB_SysSt', 'is_signed_var': False, // 'offset': 0.0, 'physical_range': '[0|7]', 'bit': 2, 'type': 'enum', // 'order': 'motorola', 'physical_unit': ''} Scu_epb_310::Epb_sysstType epb_sysst(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'EPB fault status', 'enum': {0: // 'EPB_FAULTST_NORMAL', 1: 'EPB_FAULTST_FAULT'}, 'precision': 1.0, 'len': 1, // 'name': 'EPB_FaultSt', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_epb_310::Epb_faultstType epb_faultst(const std::uint8_t* bytes, const int32_t length) const; }; } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_eps_311.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_eps_311.h" #include "glog/logging.h" #include "modules/drivers/canbus/common/byte.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace ge3 { using ::apollo::drivers::canbus::Byte; Scueps311::Scueps311() {} const int32_t Scueps311::ID = 0x311; void Scueps311::Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const { chassis->mutable_scu_eps_311()->set_eps_intidx( eps_intidx(bytes, length)); chassis->mutable_scu_eps_311()->set_eps_steeranglespd( eps_steeranglespd(bytes, length)); chassis->mutable_scu_eps_311()->set_eps_steerangle( eps_steerangle(bytes, length)); chassis->mutable_scu_eps_311()->set_eps_faultst( eps_faultst(bytes, length)); chassis->mutable_scu_eps_311()->set_eps_drvmode( eps_drvmode(bytes, length)); // newcode chassis->mutable_check_response()->set_is_eps_online( eps_drvmode(bytes, length) == 3); } // config detail: {'description': 'EPS interrupt index', 'enum': {0: // 'EPS_INTIDX_NOINT', 1: 'EPS_INTIDX_OVERFLOW', 2: 'EPS_INTIDX_TIMEOUT', 3: // 'EPS_INTIDX_STEERINT'}, 'precision': 1.0, 'len': 3, 'name': 'eps_intidx', // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|7]', 'bit': 6, // 'type': 'enum', 'order': 'motorola', 'physical_unit': ''} Scu_eps_311::Eps_intidxType Scueps311::eps_intidx(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(4, 3); Scu_eps_311::Eps_intidxType ret = static_cast<Scu_eps_311::Eps_intidxType>(x); return ret; } // config detail: {'description': 'Steer angle speed', 'offset': 0.0, // 'precision': 4.0, 'len': 8, 'name': 'eps_steeranglespd', 'is_signed_var': // False, 'physical_range': '[0|1016]', 'bit': 15, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'deg/s'} double Scueps311::eps_steeranglespd(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(0, 8); double ret = x * 4.000000; return ret; } // config detail: {'description': 'Steer angle Left + right -', 'offset': // -780.0, 'precision': 0.1, 'len': 16, 'name': 'eps_steerangle', // 'is_signed_var': False, 'physical_range': '[-780|779.9]', 'bit': 23, 'type': // 'double', 'order': 'motorola', 'physical_unit': 'deg'} double Scueps311::eps_steerangle(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 2); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 3); int32_t t = t1.get_byte(0, 8); x <<= 8; x |= t; double ret = x * 0.100000 + -780.000000; return ret; } // config detail: {'description': 'EPS fault status', 'enum': {0: // 'EPS_FAULTST_NORMAL', 1: 'EPS_FAULTST_FAULT'}, 'precision': 1.0, 'len': 1, // 'name': 'eps_faultst', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_eps_311::Eps_faultstType Scueps311::eps_faultst(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(7, 1); Scu_eps_311::Eps_faultstType ret = static_cast<Scu_eps_311::Eps_faultstType>(x); return ret; } // config detail: {'description': 'EPS drive mode', 'enum': {0: // 'EPS_DRVMODE_INVALID', 1: 'EPS_DRVMODE_MANUAL', 2: 'EPS_DRVMODE_INTERRUPT', // 3: 'EPS_DRVMODE_AUTO'}, 'precision': 1.0, 'len': 2, 'name': 'eps_drvmode', // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|3]', 'bit': 1, // 'type': 'enum', 'order': 'motorola', 'physical_unit': ''} Scu_eps_311::Eps_drvmodeType Scueps311::eps_drvmode(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 2); Scu_eps_311::Eps_drvmodeType ret = static_cast<Scu_eps_311::Eps_drvmodeType>(x); return ret; } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_bcs_2_307.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/ge3/proto/ge3.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace ge3 { class Scubcs2307 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Ge3> { public: static const int32_t ID; Scubcs2307(); void Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const override; private: // config detail: {'description': 'Vehicle speed valid data', 'enum': {0: // 'BCS_VEHSPDVD_INVALID', 1: 'BCS_VEHSPDVD_VALID'}, 'precision': 1.0, 'len': // 1, 'name': 'BCS_VehSpdVD', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 40, 'type': 'enum', 'order': 'motorola', // 'physical_unit': '-'} Scu_bcs_2_307::Bcs_vehspdvdType bcs_vehspdvd(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Yaw rate', 'offset': -2.2243, 'precision': // 0.0021326, 'len': 12, 'name': 'BCS_YawRate', 'is_signed_var': False, // 'physical_range': '[-2.2243|2.2243]', 'bit': 55, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'rad/s'} double bcs_yawrate(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Vehicle speed', 'offset': 0.0, 'precision': // 0.05625, 'len': 13, 'name': 'BCS_VehSpd', 'is_signed_var': False, // 'physical_range': '[0|240]', 'bit': 39, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'km/h'} double bcs_vehspd(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Vehicle longitudinal acceleration', // 'offset': -21.593, 'precision': 0.027126736, 'len': 12, 'name': // 'BCS_VehLongAccel', 'is_signed_var': False, 'physical_range': // '[-21.593|21.593]', 'bit': 23, 'type': 'double', 'order': 'motorola', // 'physical_unit': 'm/s^2'} double bcs_vehlongaccel(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Vehicle lateral acceleration', 'offset': // -21.593, 'precision': 0.027126736, 'len': 12, 'name': 'BCS_VehLatAccel', // 'is_signed_var': False, 'physical_range': '[-21.593|21.593]', 'bit': 7, // 'type': 'double', 'order': 'motorola', 'physical_unit': 'm/s^2'} double bcs_vehlataccel(const std::uint8_t* bytes, const int32_t length) const; }; } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_eps_311.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/ge3/proto/ge3.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace ge3 { class Scueps311 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Ge3> { public: static const int32_t ID; Scueps311(); void Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const override; private: // config detail: {'description': 'EPS interrupt index', 'enum': {0: // 'EPS_INTIDX_NOINT', 1: 'EPS_INTIDX_OVERFLOW', 2: 'EPS_INTIDX_TIMEOUT', 3: // 'EPS_INTIDX_STEERINT'}, 'precision': 1.0, 'len': 3, 'name': 'EPS_IntIdx', // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|7]', 'bit': 6, // 'type': 'enum', 'order': 'motorola', 'physical_unit': ''} Scu_eps_311::Eps_intidxType eps_intidx(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Steer angle speed', 'offset': 0.0, // 'precision': 4.0, 'len': 8, 'name': 'EPS_SteerAngleSpd', 'is_signed_var': // False, 'physical_range': '[0|1016]', 'bit': 15, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'deg/s'} double eps_steeranglespd(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Steer angle Left + right -', 'offset': // -780.0, 'precision': 0.1, 'len': 16, 'name': 'EPS_SteerAngle', // 'is_signed_var': False, 'physical_range': '[-780|779.9]', 'bit': 23, // 'type': 'double', 'order': 'motorola', 'physical_unit': 'deg'} double eps_steerangle(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'EPS fault status', 'enum': {0: // 'EPS_FAULTST_NORMAL', 1: 'EPS_FAULTST_FAULT'}, 'precision': 1.0, 'len': 1, // 'name': 'EPS_FaultSt', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_eps_311::Eps_faultstType eps_faultst(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'EPS drive mode', 'enum': {0: // 'EPS_DRVMODE_INVALID', 1: 'EPS_DRVMODE_MANUAL', 2: 'EPS_DRVMODE_INTERRUPT', // 3: 'EPS_DRVMODE_AUTO'}, 'precision': 1.0, 'len': 2, 'name': 'EPS_DrvMode', // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|3]', 'bit': 1, // 'type': 'enum', 'order': 'motorola', 'physical_unit': ''} Scu_eps_311::Eps_drvmodeType eps_drvmode(const std::uint8_t* bytes, const int32_t length) const; }; } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/pc_bcm_201.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/ge3/proto/ge3.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace ge3 { class Pcbcm201 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Ge3> { public: static const int32_t ID; Pcbcm201(); uint32_t GetPeriod() const override; void UpdateData(uint8_t* data) override; void Reset() override; // config detail: {'description': 'Left turn lamp request', 'enum': {0: // 'PC_REVERSELAMPREQ_NOREQ', 1: 'PC_REVERSELAMPREQ_REQ'}, 'precision': 1.0, // 'len': 1, 'name': 'PC_ReverseLampReq', 'is_signed_var': False, 'offset': // 0.0, 'physical_range': '[0|1]', 'bit': 1, 'type': 'enum', 'order': // 'motorola', 'physical_unit': ''} Pcbcm201* set_pc_reverselampreq( Pc_bcm_201::Pc_reverselampreqType pc_reverselampreq); // config detail: {'description': 'Left turn lamp request', 'enum': {0: // 'PC_LOWBEAMREQ_NOREQ', 1: 'PC_LOWBEAMREQ_REQ'}, 'precision': 1.0, 'len': 1, // 'name': 'PC_LowBeamReq', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 2, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Pcbcm201* set_pc_lowbeamreq(Pc_bcm_201::Pc_lowbeamreqType pc_lowbeamreq); // config detail: {'description': 'Left turn lamp request', 'enum': {0: // 'PC_HIGHBEAMREQ_NOREQ', 1: 'PC_HIGHBEAMREQ_REQ'}, 'precision': 1.0, 'len': // 1, 'name': 'PC_HighBeamReq', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 3, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Pcbcm201* set_pc_highbeamreq(Pc_bcm_201::Pc_highbeamreqType pc_highbeamreq); // config detail: {'description': 'Right turn lamp request', 'enum': {0: // 'PC_RIGHTTURNLAMPREQ_NOREQ', 1: 'PC_RIGHTTURNLAMPREQ_REQ'}, // 'precision': 1.0, 'len': 1, 'name': 'PC_RightTurnLampReq', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|3]', 'bit': 4, 'type': 'enum', // 'order': 'motorola', 'physical_unit': ''} Pcbcm201* set_pc_rightturnlampreq( Pc_bcm_201::Pc_rightturnlampreqType pc_rightturnlampreq); // config detail: {'description': 'Left turn lamp request', 'enum': {0: // 'PC_LEFTTURNLAMPREQ_NOREQ', 1: 'PC_LEFTTURNLAMPREQ_REQ'}, 'precision': 1.0, // 'len': 1, 'name': 'PC_LeftTurnLampReq', 'is_signed_var': False, 'offset': // 0.0, 'physical_range': '[0|1]', 'bit': 5, 'type': 'enum', 'order': // 'motorola', 'physical_unit': ''} Pcbcm201* set_pc_leftturnlampreq( Pc_bcm_201::Pc_leftturnlampreqType pc_leftturnlampreq); // config detail: {'description': 'Horn request', 'enum': {0: // 'PC_HORNREQ_NOREQ', 1: 'PC_HORNREQ_REQ'}, 'precision': 1.0, 'len': 1, // 'name': 'PC_HornReq', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 6, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Pcbcm201* set_pc_hornreq(Pc_bcm_201::Pc_hornreqType pc_hornreq); // config detail: {'description': 'Hazard lamp request', 'enum': {0: // 'PC_HAZARDLAMPREQ_NOREQ', 1: 'PC_HAZARDLAMPREQ_REQ'}, 'precision': 1.0, // 'len': 1, 'name': 'PC_HazardLampReq', 'is_signed_var': False, 'offset': // 0.0, 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': // 'motorola', 'physical_unit': ''} Pcbcm201* set_pc_hazardlampreq( Pc_bcm_201::Pc_hazardlampreqType pc_hazardlampreq); private: // config detail: {'description': 'Left turn lamp request', 'enum': {0: // 'PC_REVERSELAMPREQ_NOREQ', 1: 'PC_REVERSELAMPREQ_REQ'}, 'precision': 1.0, // 'len': 1, 'name': 'PC_ReverseLampReq', 'is_signed_var': False, 'offset': // 0.0, 'physical_range': '[0|1]', 'bit': 1, 'type': 'enum', 'order': // 'motorola', 'physical_unit': ''} void set_p_pc_reverselampreq( uint8_t* data, Pc_bcm_201::Pc_reverselampreqType pc_reverselampreq); // config detail: {'description': 'Left turn lamp request', 'enum': {0: // 'PC_LOWBEAMREQ_NOREQ', 1: 'PC_LOWBEAMREQ_REQ'}, 'precision': 1.0, 'len': 1, // 'name': 'PC_LowBeamReq', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 2, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} void set_p_pc_lowbeamreq(uint8_t* data, Pc_bcm_201::Pc_lowbeamreqType pc_lowbeamreq); // config detail: {'description': 'Left turn lamp request', 'enum': {0: // 'PC_HIGHBEAMREQ_NOREQ', 1: 'PC_HIGHBEAMREQ_REQ'}, 'precision': 1.0, 'len': // 1, 'name': 'PC_HighBeamReq', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 3, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} void set_p_pc_highbeamreq(uint8_t* data, Pc_bcm_201::Pc_highbeamreqType pc_highbeamreq); // config detail: {'description': 'Right turn lamp request', 'enum': {0: // 'PC_RIGHTTURNLAMPREQ_NOREQ', 1: 'PC_RIGHTTURNLAMPREQ_REQ'}, // 'precision': 1.0, 'len': 1, 'name': 'PC_RightTurnLampReq', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|3]', 'bit': 4, 'type': 'enum', // 'order': 'motorola', 'physical_unit': ''} void set_p_pc_rightturnlampreq( uint8_t* data, Pc_bcm_201::Pc_rightturnlampreqType pc_rightturnlampreq); // config detail: {'description': 'Left turn lamp request', 'enum': {0: // 'PC_LEFTTURNLAMPREQ_NOREQ', 1: 'PC_LEFTTURNLAMPREQ_REQ'}, 'precision': 1.0, // 'len': 1, 'name': 'PC_LeftTurnLampReq', 'is_signed_var': False, 'offset': // 0.0, 'physical_range': '[0|1]', 'bit': 5, 'type': 'enum', 'order': // 'motorola', 'physical_unit': ''} void set_p_pc_leftturnlampreq( uint8_t* data, Pc_bcm_201::Pc_leftturnlampreqType pc_leftturnlampreq); // config detail: {'description': 'Horn request', 'enum': {0: // 'PC_HORNREQ_NOREQ', 1: 'PC_HORNREQ_REQ'}, 'precision': 1.0, 'len': 1, // 'name': 'PC_HornReq', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 6, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} void set_p_pc_hornreq(uint8_t* data, Pc_bcm_201::Pc_hornreqType pc_hornreq); // config detail: {'description': 'Hazard lamp request', 'enum': {0: // 'PC_HAZARDLAMPREQ_NOREQ', 1: 'PC_HAZARDLAMPREQ_REQ'}, 'precision': 1.0, // 'len': 1, 'name': 'PC_HazardLampReq', 'is_signed_var': False, 'offset': // 0.0, 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': // 'motorola', 'physical_unit': ''} void set_p_pc_hazardlampreq( uint8_t* data, Pc_bcm_201::Pc_hazardlampreqType pc_hazardlampreq); private: Pc_bcm_201::Pc_reverselampreqType pc_reverselampreq_; Pc_bcm_201::Pc_lowbeamreqType pc_lowbeamreq_; Pc_bcm_201::Pc_highbeamreqType pc_highbeamreq_; Pc_bcm_201::Pc_rightturnlampreqType pc_rightturnlampreq_; Pc_bcm_201::Pc_leftturnlampreqType pc_leftturnlampreq_; Pc_bcm_201::Pc_hornreqType pc_hornreq_; Pc_bcm_201::Pc_hazardlampreqType pc_hazardlampreq_; }; } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/pc_bcs_202_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/pc_bcs_202.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace ge3 { class Pcbcs202Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Pcbcs202Test, reset) { uint8_t data[8] = {0x01, 0x02, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; Pcbcs202 pcbcs202; EXPECT_EQ(pcbcs202.GetPeriod(), 20 * 1000); pcbcs202.UpdateData(data); EXPECT_EQ(data[0], 0b00000000); EXPECT_EQ(data[1], 0b00000000); EXPECT_EQ(data[2], 0b01100011); EXPECT_EQ(data[3], 0b01100100); EXPECT_EQ(data[4], 0b01010001); EXPECT_EQ(data[5], 0b01010010); EXPECT_EQ(data[6], 0b01010011); EXPECT_EQ(data[7], 0b01010100); } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_1_301.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_1_301.h" #include "glog/logging.h" #include "modules/drivers/canbus/common/byte.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace ge3 { using ::apollo::drivers::canbus::Byte; Scu1301::Scu1301() {} const int32_t Scu1301::ID = 0x301; void Scu1301::Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const { chassis->mutable_scu_1_301()->set_vin16(vin16(bytes, length)); chassis->mutable_scu_1_301()->set_scu_stopbutst( scu_stopbutst(bytes, length)); chassis->mutable_scu_1_301()->set_scu_drvmode( scu_drvmode(bytes, length)); chassis->mutable_scu_1_301()->set_scu_faultst( scu_faultst(bytes, length)); } // config detail: {'description': 'VIN string character 16', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'name': 'vin16', 'is_signed_var': False, // 'physical_range': '[0|255]', 'bit': 15, 'type': 'int', 'order': 'motorola', // 'physical_unit': '-'} int Scu1301::vin16(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(0, 8); int ret = x; return ret; } // config detail: {'description': 'Brake pedal position', 'enum': {0: // 'SCU_STOPBUTST_UNPRESSED', 1: 'SCU_STOPBUTST_PRESSED'}, 'precision': 1.0, // 'len': 1, 'name': 'scu_stopbutst', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 0, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_1_301::Scu_stopbutstType Scu1301::scu_stopbutst(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 1); Scu_1_301::Scu_stopbutstType ret = static_cast<Scu_1_301::Scu_stopbutstType>(x); return ret; } // config detail: {'description': 'SCU drive mode', 'enum': {0: // 'SCU_DRVMODE_INVALID', 1: 'SCU_DRVMODE_MANUAL', 2: 'SCU_DRVMODE_INTERRUPT', // 3: 'SCU_DRVMODE_AUTO'}, 'precision': 1.0, 'len': 2, 'name': 'scu_drvmode', // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|3]', 'bit': 3, // 'type': 'enum', 'order': 'motorola', 'physical_unit': ''} Scu_1_301::Scu_drvmodeType Scu1301::scu_drvmode(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(2, 2); Scu_1_301::Scu_drvmodeType ret = static_cast<Scu_1_301::Scu_drvmodeType>(x); return ret; } // config detail: {'description': 'SCU fault status', 'enum': {0: // 'SCU_FAULTST_NORMAL', 1: 'SCU_FAULTST_FAULT'}, 'precision': 1.0, 'len': 4, // 'name': 'scu_faultst', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|15]', 'bit': 7, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_1_301::Scu_faultstType Scu1301::scu_faultst(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(4, 4); Scu_1_301::Scu_faultstType ret = static_cast<Scu_1_301::Scu_faultstType>(x); return ret; } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/BUILD
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("//tools:cpplint.bzl", "cpplint") package(default_visibility = ["//visibility:public"]) cc_library( name = "canbus_ge3_protocol_pc_bcm_201", srcs = [ "pc_bcm_201.cc", "pc_bcs_202.cc", "pc_epb_203.cc", "pc_eps_204.cc", "pc_vcu_205.cc", "scu_1_301.cc", "scu_2_302.cc", "scu_3_303.cc", "scu_bcm_304.cc", "scu_bcs_1_306.cc", "scu_bcs_2_307.cc", "scu_bcs_3_308.cc", "scu_epb_310.cc", "scu_eps_311.cc", "scu_vcu_1_312.cc", "scu_vcu_2_313.cc", ], hdrs = [ "pc_bcm_201.h", "pc_bcs_202.h", "pc_epb_203.h", "pc_eps_204.h", "pc_vcu_205.h", "scu_1_301.h", "scu_2_302.h", "scu_3_303.h", "scu_bcm_304.h", "scu_bcs_1_306.h", "scu_bcs_2_307.h", "scu_bcs_3_308.h", "scu_epb_310.h", "scu_eps_311.h", "scu_vcu_1_312.h", "scu_vcu_2_313.h", ], deps = [ "//modules/canbus_vehicle/ge3/proto:ge3_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "pc_bcm_201_test", size = "small", srcs = ["pc_bcm_201_test.cc"], deps = [ "//modules/canbus_vehicle/ge3/protocol:canbus_ge3_protocol_pc_bcm_201", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "pc_bcs_202_test", size = "small", srcs = ["pc_bcs_202_test.cc"], deps = [ "//modules/canbus_vehicle/ge3/protocol:canbus_ge3_protocol_pc_bcm_201", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "pc_epb_203_test", size = "small", srcs = ["pc_epb_203_test.cc"], deps = [ "//modules/canbus_vehicle/ge3/protocol:canbus_ge3_protocol_pc_bcm_201", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "pc_eps_204_test", size = "small", srcs = ["pc_eps_204_test.cc"], deps = [ "//modules/canbus_vehicle/ge3/protocol:canbus_ge3_protocol_pc_bcm_201", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "pc_vcu_205_test", size = "small", srcs = ["pc_vcu_205_test.cc"], deps = [ "//modules/canbus_vehicle/ge3/protocol:canbus_ge3_protocol_pc_bcm_201", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "scu_1_301_test", size = "small", srcs = ["scu_1_301_test.cc"], deps = [ "//modules/canbus_vehicle/ge3/protocol:canbus_ge3_protocol_pc_bcm_201", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "scu_2_302_test", size = "small", srcs = ["scu_2_302_test.cc"], deps = [ "//modules/canbus_vehicle/ge3/protocol:canbus_ge3_protocol_pc_bcm_201", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "scu_3_303_test", size = "small", srcs = ["scu_3_303_test.cc"], deps = [ "//modules/canbus_vehicle/ge3/protocol:canbus_ge3_protocol_pc_bcm_201", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "scu_bcm_304_test", size = "small", srcs = ["scu_bcm_304_test.cc"], deps = [ "//modules/canbus_vehicle/ge3/protocol:canbus_ge3_protocol_pc_bcm_201", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "scu_bcs_1_306_test", size = "small", srcs = ["scu_bcs_1_306_test.cc"], deps = [ "//modules/canbus_vehicle/ge3/protocol:canbus_ge3_protocol_pc_bcm_201", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "scu_bcs_2_307_test", size = "small", srcs = ["scu_bcs_2_307_test.cc"], deps = [ "//modules/canbus_vehicle/ge3/protocol:canbus_ge3_protocol_pc_bcm_201", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "scu_bcs_3_308_test", size = "small", srcs = ["scu_bcs_3_308_test.cc"], deps = [ "//modules/canbus_vehicle/ge3/protocol:canbus_ge3_protocol_pc_bcm_201", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "scu_epb_310_test", size = "small", srcs = ["scu_epb_310_test.cc"], deps = [ "//modules/canbus_vehicle/ge3/protocol:canbus_ge3_protocol_pc_bcm_201", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "scu_eps_311_test", size = "small", srcs = ["scu_eps_311_test.cc"], deps = [ "//modules/canbus_vehicle/ge3/protocol:canbus_ge3_protocol_pc_bcm_201", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "scu_vcu_1_312_test", size = "small", srcs = ["scu_vcu_1_312_test.cc"], deps = [ "//modules/canbus_vehicle/ge3/protocol:canbus_ge3_protocol_pc_bcm_201", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "scu_vcu_2_313_test", size = "small", srcs = ["scu_vcu_2_313_test.cc"], deps = [ "//modules/canbus_vehicle/ge3/protocol:canbus_ge3_protocol_pc_bcm_201", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cpplint()
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/pc_epb_203.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/ge3/proto/ge3.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace ge3 { class Pcepb203 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Ge3> { public: static const int32_t ID; Pcepb203(); uint32_t GetPeriod() const override; void UpdateData(uint8_t* data) override; void Reset() override; // config detail: {'description': 'EPB request', 'enum': {0: // 'PC_EPBREQ_INVALID', 1: 'PC_EPBREQ_RELEASE', 2: 'PC_EPBREQ_APPLY'}, // 'precision': 1.0, 'len': 2, 'name': 'PC_EpbReq', 'is_signed_var': False, // 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 1, 'type': 'enum', // 'order': 'motorola', 'physical_unit': ''} Pcepb203* set_pc_epbreq(Pc_epb_203::Pc_epbreqType pc_epbreq); // config detail: {'description': 'EPB control enable', 'enum': {0: // 'PC_EPBENABLE_DISABLE', 1: 'PC_EPBENABLE_ENABLE'}, 'precision': 1.0, 'len': // 1, 'name': 'PC_EpbEnable', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Pcepb203* set_pc_epbenable(Pc_epb_203::Pc_epbenableType pc_epbenable); private: // config detail: {'description': 'EPB request', 'enum': {0: // 'PC_EPBREQ_INVALID', 1: 'PC_EPBREQ_RELEASE', 2: 'PC_EPBREQ_APPLY'}, // 'precision': 1.0, 'len': 2, 'name': 'PC_EpbReq', 'is_signed_var': False, // 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 1, 'type': 'enum', // 'order': 'motorola', 'physical_unit': ''} void set_p_pc_epbreq(uint8_t* data, Pc_epb_203::Pc_epbreqType pc_epbreq); // config detail: {'description': 'EPB control enable', 'enum': {0: // 'PC_EPBENABLE_DISABLE', 1: 'PC_EPBENABLE_ENABLE'}, 'precision': 1.0, 'len': // 1, 'name': 'PC_EpbEnable', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} void set_p_pc_epbenable(uint8_t* data, Pc_epb_203::Pc_epbenableType pc_epbenable); private: Pc_epb_203::Pc_epbreqType pc_epbreq_; Pc_epb_203::Pc_epbenableType pc_epbenable_; }; } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/pc_vcu_205.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/ge3/proto/ge3.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace ge3 { class Pcvcu205 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Ge3> { public: static const int32_t ID; Pcvcu205(); uint32_t GetPeriod() const override; void UpdateData(uint8_t* data) override; void Reset() override; // config detail: {'description': 'Acceleration pedal request', 'offset': 0.0, // 'precision': 0.05, 'len': 12, 'name': 'PC_AccPedReq', 'is_signed_var': // False, 'physical_range': '[0|100]', 'bit': 15, 'type': 'double', 'order': // 'motorola', 'physical_unit': '%'} Pcvcu205* set_pc_accpedreq(double pc_accpedreq); // config detail: {'description': 'Acceleration pedal control enable', 'enum': // {0: 'PC_ACCPEDENABLE_DISABLE', 1: 'PC_ACCPEDENABLE_ENABLE'}, // 'precision': 1.0, 'len': 1, 'name': 'PC_AccPedEnable', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 6, 'type': 'enum', // 'order': 'motorola', 'physical_unit': ''} Pcvcu205* set_pc_accpedenable( Pc_vcu_205::Pc_accpedenableType pc_accpedenable); // config detail: {'description': 'Torque request', 'offset': -3000.0, // 'precision': 1.5, 'len': 12, 'name': 'PC_TorqReq', 'is_signed_var': False, // 'physical_range': '[-3000|3000]', 'bit': 19, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'Nm'} Pcvcu205* set_pc_torqreq(double pc_torqreq); // config detail: {'description': 'Torque control enable', 'enum': {0: // 'PC_TORQENABLE_DISABLE', 1: 'PC_TORQENABLE_ENABLE'}, 'precision': 1.0, // 'len': 1, 'name': 'PC_TorqEnable', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 5, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Pcvcu205* set_pc_torqenable(Pc_vcu_205::Pc_torqenableType pc_torqenable); // config detail: {'description': 'Gear request', 'enum': {0: // 'PC_GEARREQ_INVALID', 1: 'PC_GEARREQ_DRIVE', 2: 'PC_GEARREQ_NEUTRAL', 3: // 'PC_GEARREQ_REVERSE', 4: 'PC_GEARREQ_PARK'}, 'precision': 1.0, 'len': 3, // 'name': 'PC_GearReq', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|7]', 'bit': 2, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Pcvcu205* set_pc_gearreq(Pc_vcu_205::Pc_gearreqType pc_gearreq); // config detail: {'description': 'Gear control enable', 'enum': {0: // 'PC_GEARENABLE_DISABLE', 1: 'PC_GEARENABLE_ENABLE'}, 'precision': 1.0, // 'len': 1, 'name': 'PC_GearEnable', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Pcvcu205* set_pc_gearenable(Pc_vcu_205::Pc_gearenableType pc_gearenable); private: // config detail: {'description': 'Acceleration pedal request', 'offset': 0.0, // 'precision': 0.05, 'len': 12, 'name': 'PC_AccPedReq', 'is_signed_var': // False, 'physical_range': '[0|100]', 'bit': 15, 'type': 'double', 'order': // 'motorola', 'physical_unit': '%'} void set_p_pc_accpedreq(uint8_t* data, double pc_accpedreq); // config detail: {'description': 'Acceleration pedal control enable', 'enum': // {0: 'PC_ACCPEDENABLE_DISABLE', 1: 'PC_ACCPEDENABLE_ENABLE'}, // 'precision': 1.0, 'len': 1, 'name': 'PC_AccPedEnable', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 6, 'type': 'enum', // 'order': 'motorola', 'physical_unit': ''} void set_p_pc_accpedenable(uint8_t* data, Pc_vcu_205::Pc_accpedenableType pc_accpedenable); // config detail: {'description': 'Torque request', 'offset': -3000.0, // 'precision': 1.5, 'len': 12, 'name': 'PC_TorqReq', 'is_signed_var': False, // 'physical_range': '[-3000|3000]', 'bit': 19, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'Nm'} void set_p_pc_torqreq(uint8_t* data, double pc_torqreq); // config detail: {'description': 'Torque control enable', 'enum': {0: // 'PC_TORQENABLE_DISABLE', 1: 'PC_TORQENABLE_ENABLE'}, 'precision': 1.0, // 'len': 1, 'name': 'PC_TorqEnable', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 5, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} void set_p_pc_torqenable(uint8_t* data, Pc_vcu_205::Pc_torqenableType pc_torqenable); // config detail: {'description': 'Gear request', 'enum': {0: // 'PC_GEARREQ_INVALID', 1: 'PC_GEARREQ_DRIVE', 2: 'PC_GEARREQ_NEUTRAL', 3: // 'PC_GEARREQ_REVERSE', 4: 'PC_GEARREQ_PARK'}, 'precision': 1.0, 'len': 3, // 'name': 'PC_GearReq', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|7]', 'bit': 2, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} void set_p_pc_gearreq(uint8_t* data, Pc_vcu_205::Pc_gearreqType pc_gearreq); // config detail: {'description': 'Gear control enable', 'enum': {0: // 'PC_GEARENABLE_DISABLE', 1: 'PC_GEARENABLE_ENABLE'}, 'precision': 1.0, // 'len': 1, 'name': 'PC_GearEnable', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 7, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} void set_p_pc_gearenable(uint8_t* data, Pc_vcu_205::Pc_gearenableType pc_gearenable); private: double pc_accpedreq_; Pc_vcu_205::Pc_accpedenableType pc_accpedenable_; double pc_torqreq_; Pc_vcu_205::Pc_torqenableType pc_torqenable_; Pc_vcu_205::Pc_gearreqType pc_gearreq_; Pc_vcu_205::Pc_gearenableType pc_gearenable_; }; } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_1_301_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_1_301.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace ge3 { class Scu1301Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Scu1301Test, reset) { Scu1301 scu1301; int32_t length = 8; Ge3 chassis_detail; uint8_t bytes[8] = {0x01, 0x02, 0x03, 0x04, 0x11, 0x12, 0x13, 0x14}; scu1301.Parse(bytes, length, &chassis_detail); EXPECT_DOUBLE_EQ(chassis_detail.scu_1_301().vin16(), 2); EXPECT_DOUBLE_EQ(chassis_detail.scu_1_301().scu_stopbutst(), 1); EXPECT_DOUBLE_EQ(chassis_detail.scu_1_301().scu_drvmode(), 0); EXPECT_DOUBLE_EQ(chassis_detail.scu_1_301().scu_faultst(), 0); } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_bcm_304_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_bcm_304.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace ge3 { class Scubcm304Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Scubcm304Test, reset) { Scubcm304 scubcm304; int32_t length = 8; Ge3 chassis_detail; uint8_t bytes[8] = {0x01, 0x02, 0x03, 0x04, 0x11, 0x12, 0x13, 0x14}; scubcm304.Parse(bytes, length, &chassis_detail); EXPECT_DOUBLE_EQ(chassis_detail.scu_bcm_304().bcm_vehreversest(), 0); EXPECT_DOUBLE_EQ(chassis_detail.scu_bcm_304().bcm_rightturnlampst(), 0); EXPECT_DOUBLE_EQ(chassis_detail.scu_bcm_304().bcm_rearfoglampst(), 1); EXPECT_DOUBLE_EQ(chassis_detail.scu_bcm_304().bcm_parkinglampst(), 0); EXPECT_DOUBLE_EQ(chassis_detail.scu_bcm_304().bcm_lowbeamst(), 0); EXPECT_DOUBLE_EQ(chassis_detail.scu_bcm_304().bcm_leftturnlampst(), 0); EXPECT_DOUBLE_EQ(chassis_detail.scu_bcm_304().bcm_keyst(), 0); EXPECT_DOUBLE_EQ(chassis_detail.scu_bcm_304().bcm_hornst(), 0); EXPECT_DOUBLE_EQ(chassis_detail.scu_bcm_304().bcm_highbeamst(), 0); EXPECT_DOUBLE_EQ(chassis_detail.scu_bcm_304().bcm_hazardlampst(), 0); EXPECT_DOUBLE_EQ(chassis_detail.scu_bcm_304().bcm_frontfoglampst(), 0); EXPECT_DOUBLE_EQ(chassis_detail.scu_bcm_304().bcm_brakelightswitchst(), 0); } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_bcs_1_306.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_bcs_1_306.h" #include "glog/logging.h" #include "modules/drivers/canbus/common/byte.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace ge3 { using ::apollo::drivers::canbus::Byte; Scubcs1306::Scubcs1306() {} const int32_t Scubcs1306::ID = 0x306; void Scubcs1306::Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const { chassis->mutable_scu_bcs_1_306()->set_bcs_aebavailable( bcs_aebavailable(bytes, length)); chassis->mutable_scu_bcs_1_306()->set_bcs_cddavailable( bcs_cddavailable(bytes, length)); chassis->mutable_scu_bcs_1_306()->set_bcs_brkpedact( bcs_brkpedact(bytes, length)); chassis->mutable_scu_bcs_1_306()->set_bcs_intidx( bcs_intidx(bytes, length)); chassis->mutable_scu_bcs_1_306()->set_bcs_vdcfaultst( bcs_vdcfaultst(bytes, length)); chassis->mutable_scu_bcs_1_306()->set_bcs_vdcactivest( bcs_vdcactivest(bytes, length)); chassis->mutable_scu_bcs_1_306()->set_bcs_absfaultst( bcs_absfaultst(bytes, length)); chassis->mutable_scu_bcs_1_306()->set_bcs_absactivest( bcs_absactivest(bytes, length)); chassis->mutable_scu_bcs_1_306()->set_bcs_faultst( bcs_faultst(bytes, length)); chassis->mutable_scu_bcs_1_306()->set_bcs_drvmode( bcs_drvmode(bytes, length)); // newcode chassis->mutable_check_response()->set_is_esp_online( bcs_drvmode(bytes, length) == 3); } // config detail: {'description': 'VDC active status', 'enum': {0: // 'BCS_AEBAVAILABLE_UNAVAILABLE', 1: 'BCS_AEBAVAILABLE_AVAILABLE'}, // 'precision': 1.0, 'len': 1, 'name': 'bcs_aebavailable', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 17, 'type': 'enum', // 'order': 'motorola', 'physical_unit': ''} Scu_bcs_1_306::Bcs_aebavailableType Scubcs1306::bcs_aebavailable( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 2); int32_t x = t0.get_byte(1, 1); Scu_bcs_1_306::Bcs_aebavailableType ret = static_cast<Scu_bcs_1_306::Bcs_aebavailableType>(x); return ret; } // config detail: {'description': 'VDC active status', 'enum': {0: // 'BCS_CDDAVAILABLE_UNAVAILABLE', 1: 'BCS_CDDAVAILABLE_AVAILABLE'}, // 'precision': 1.0, 'len': 1, 'name': 'bcs_cddavailable', 'is_signed_var': // False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 16, 'type': 'enum', // 'order': 'motorola', 'physical_unit': ''} Scu_bcs_1_306::Bcs_cddavailableType Scubcs1306::bcs_cddavailable( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 2); int32_t x = t0.get_byte(0, 1); Scu_bcs_1_306::Bcs_cddavailableType ret = static_cast<Scu_bcs_1_306::Bcs_cddavailableType>(x); return ret; } // config detail: {'description': 'Actual brake pedal position', 'offset': 0.0, // 'precision': 0.1, 'len': 10, 'name': 'bcs_brkpedact', 'is_signed_var': False, // 'physical_range': '[0|100]', 'bit': 15, 'type': 'double', 'order': // 'motorola', 'physical_unit': '%'} double Scubcs1306::bcs_brkpedact(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 2); int32_t t = t1.get_byte(6, 2); x <<= 2; x |= t; double ret = x * 0.100000; return ret; } // config detail: {'description': 'BCS interrupt index', 'enum': {0: // 'BCS_INTIDX_NOINT', 1: 'BCS_INTIDX_OVERFLOW', 2: 'BCS_INTIDX_TIMEOUT', 3: // 'BCS_INTIDX_ACCPEDINT', 4: 'BCS_INTIDX_BRKPEDINT', 5: 'BCS_INTIDX_GEARINT'}, // 'precision': 1.0, 'len': 3, 'name': 'bcs_intidx', 'is_signed_var': False, // 'offset': 0.0, 'physical_range': '[0|7]', 'bit': 21, 'type': 'enum', 'order': // 'motorola', 'physical_unit': ''} Scu_bcs_1_306::Bcs_intidxType Scubcs1306::bcs_intidx(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 2); int32_t x = t0.get_byte(3, 3); Scu_bcs_1_306::Bcs_intidxType ret = static_cast<Scu_bcs_1_306::Bcs_intidxType>(x); return ret; } // config detail: {'description': 'VDC fault status', 'enum': {0: // 'BCS_VDCFAULTST_NORMAL', 1: 'BCS_VDCFAULTST_FAULT'}, 'precision': 1.0, 'len': // 1, 'name': 'bcs_vdcfaultst', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 1, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_bcs_1_306::Bcs_vdcfaultstType Scubcs1306::bcs_vdcfaultst( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(1, 1); Scu_bcs_1_306::Bcs_vdcfaultstType ret = static_cast<Scu_bcs_1_306::Bcs_vdcfaultstType>(x); return ret; } // config detail: {'description': 'VDC active status', 'enum': {0: // 'BCS_VDCACTIVEST_INACTIVE', 1: 'BCS_VDCACTIVEST_ACTIVE'}, 'precision': 1.0, // 'len': 1, 'name': 'bcs_vdcactivest', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 2, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_bcs_1_306::Bcs_vdcactivestType Scubcs1306::bcs_vdcactivest( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(2, 1); Scu_bcs_1_306::Bcs_vdcactivestType ret = static_cast<Scu_bcs_1_306::Bcs_vdcactivestType>(x); return ret; } // config detail: {'description': 'ABS fault status', 'enum': {0: // 'BCS_ABSFAULTST_NORMAL', 1: 'BCS_ABSFAULTST_FAULT'}, 'precision': 1.0, 'len': // 1, 'name': 'bcs_absfaultst', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 3, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_bcs_1_306::Bcs_absfaultstType Scubcs1306::bcs_absfaultst( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(3, 1); Scu_bcs_1_306::Bcs_absfaultstType ret = static_cast<Scu_bcs_1_306::Bcs_absfaultstType>(x); return ret; } // config detail: {'description': 'ABS active status', 'enum': {0: // 'BCS_ABSACTIVEST_INACTIVE', 1: 'BCS_ABSACTIVEST_ACTIVE'}, 'precision': 1.0, // 'len': 1, 'name': 'bcs_absactivest', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 4, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_bcs_1_306::Bcs_absactivestType Scubcs1306::bcs_absactivest( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(4, 1); Scu_bcs_1_306::Bcs_absactivestType ret = static_cast<Scu_bcs_1_306::Bcs_absactivestType>(x); return ret; } // config detail: {'description': 'BCS fault status', 'enum': {0: // 'BCS_FAULTST_NORMAL', 1: 'BCS_FAULTST_FAULT'}, 'precision': 1.0, 'len': 1, // 'name': 'bcs_faultst', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 5, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_bcs_1_306::Bcs_faultstType Scubcs1306::bcs_faultst( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(5, 1); Scu_bcs_1_306::Bcs_faultstType ret = static_cast<Scu_bcs_1_306::Bcs_faultstType>(x); return ret; } // config detail: {'description': 'BCS drive mode', 'enum': {0: // 'BCS_DRVMODE_INVALID', 1: 'BCS_DRVMODE_MANUAL', 2: 'BCS_DRVMODE_INTERRUPT', // 3: 'BCS_DRVMODE_AUTO'}, 'precision': 1.0, 'len': 2, 'name': 'bcs_drvmode', // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|3]', 'bit': 7, // 'type': 'enum', 'order': 'motorola', 'physical_unit': ''} Scu_bcs_1_306::Bcs_drvmodeType Scubcs1306::bcs_drvmode( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(6, 2); Scu_bcs_1_306::Bcs_drvmodeType ret = static_cast<Scu_bcs_1_306::Bcs_drvmodeType>(x); return ret; } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_eps_311_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_eps_311.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace ge3 { class Scueps311Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Scueps311Test, reset) { Scueps311 scueps311; int32_t length = 8; Ge3 chassis_detail; uint8_t bytes[8] = {0x01, 0x02, 0x03, 0x04, 0x11, 0x12, 0x13, 0x14}; scueps311.Parse(bytes, length, &chassis_detail); EXPECT_DOUBLE_EQ(chassis_detail.scu_eps_311().eps_intidx(), 0); EXPECT_DOUBLE_EQ(chassis_detail.scu_eps_311().eps_steeranglespd(), 8); EXPECT_DOUBLE_EQ(chassis_detail.scu_eps_311().eps_steerangle(), -702.8); EXPECT_DOUBLE_EQ(chassis_detail.scu_eps_311().eps_faultst(), 0); EXPECT_DOUBLE_EQ(chassis_detail.scu_eps_311().eps_drvmode(), 1); } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/pc_vcu_205_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/pc_vcu_205.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace ge3 { class Pcvcu205Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Pcvcu205Test, reset) { uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; Pcvcu205 pcvcu205; EXPECT_EQ(pcvcu205.GetPeriod(), 20 * 1000); pcvcu205.UpdateData(data); EXPECT_EQ(data[0], 0b00000000); EXPECT_EQ(data[1], 0b00000000); EXPECT_EQ(data[2], 0b00000111); EXPECT_EQ(data[3], 0b11010000); EXPECT_EQ(data[4], 0b01010001); EXPECT_EQ(data[5], 0b01010010); EXPECT_EQ(data[6], 0b01010011); EXPECT_EQ(data[7], 0b01010100); } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_vcu_1_312.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/ge3/proto/ge3.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace ge3 { class Scuvcu1312 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Ge3> { public: static const int32_t ID; Scuvcu1312(); void Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const override; private: // config detail: {'description': 'Gear fault status', 'enum': {0: // 'VCU_ELCSYSFAULT_NORMAL', 1: 'VCU_ELCSYSFAULT_FAULT'}, 'precision': 1.0, // 'len': 1, 'name': 'VCU_ElcSysFault', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|0]', 'bit': 49, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_vcu_1_312::Vcu_elcsysfaultType vcu_elcsysfault( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Brake pedal position', 'enum': {0: // 'VCU_BRKPEDST_UNPRESSED', 1: 'VCU_BRKPEDST_PRESSED'}, 'precision': 1.0, // 'len': 1, 'name': 'VCU_BrkPedSt', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 48, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_vcu_1_312::Vcu_brkpedstType vcu_brkpedst(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VCU interrupt index', 'enum': {0: // 'VCU_INTIDX_NOINT', 1: 'VCU_INTIDX_OVERFLOW', 2: 'VCU_INTIDX_TIMEOUT', 3: // 'VCU_INTIDX_ACCPEDINT', 4: 'VCU_INTIDX_BRKPEDINT', 5: // 'VCU_INTIDX_GEARINT'}, 'precision': 1.0, 'len': 3, 'name': 'VCU_IntIdx', // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|7]', 'bit': // 58, 'type': 'enum', 'order': 'motorola', 'physical_unit': ''} Scu_vcu_1_312::Vcu_intidxType vcu_intidx(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Gear interrupt index', 'enum': {0: // 'VCU_GEARINTIDX_NOINT', 1: 'VCU_GEARINTIDX_OVERFLOW', 2: // 'VCU_GEARINTIDX_TIMEOUT'}, 'precision': 1.0, 'len': 3, 'name': // 'VCU_GearIntIdx', 'is_signed_var': False, 'offset': 0.0, 'physical_range': // '[0|7]', 'bit': 61, 'type': 'enum', 'order': 'motorola', 'physical_unit': // ''} Scu_vcu_1_312::Vcu_gearintidxType vcu_gearintidx(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VCU Gear drive mode', 'enum': {0: // 'VCU_GEARDRVMODE_INVALID', 1: 'VCU_GEARDRVMODE_MANUAL', 2: // 'VCU_GEARDRVMODE_INTERRUPT', 3: 'VCU_GEARDRVMODE_AUTO'}, 'precision': 1.0, // 'len': 2, 'name': 'VCU_GearDrvMode', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|3]', 'bit': 63, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_vcu_1_312::Vcu_geardrvmodeType vcu_geardrvmode( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Actual acceleration pedal position', // 'offset': 0.0, 'precision': 0.05, 'len': 12, 'name': 'VCU_AccPedAct', // 'is_signed_var': False, 'physical_range': '[0|100]', 'bit': 47, 'type': // 'double', 'order': 'motorola', 'physical_unit': '%'} double vcu_accpedact(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Brake pedal position', 'offset': 0.0, // 'precision': 0.392, 'len': 8, 'name': 'VCU_BrkPedPst', 'is_signed_var': // False, 'physical_range': '[0|99.96]', 'bit': 39, 'type': 'double', 'order': // 'motorola', 'physical_unit': '%'} double vcu_brkpedpst(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Veh range', 'offset': 0.0, // 'precision': 1.0, 'len': 10, 'name': 'VCU_VehRng', 'is_signed_var': False, // 'physical_range': '[0|1000]', 'bit': 9, 'type': 'int', 'order': 'motorola', // 'physical_unit': 'km'} int vcu_vehrng(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Actual acceleration pedal position', // 'offset': 0.0, 'precision': 0.392, 'len': 8, 'name': 'VCU_AccPedPst', // 'is_signed_var': False, 'physical_range': '[0|99.96]', 'bit': 31, 'type': // 'double', 'order': 'motorola', 'physical_unit': '%'} double vcu_accpedpst(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'HEV system ready status', 'enum': {0: // 'VCU_VEHRDYST_NOTREADY', 1: 'VCU_VEHRDYST_READY'}, 'precision': 1.0, 'len': // 1, 'name': 'VCU_VehRdySt', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 0, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_vcu_1_312::Vcu_vehrdystType vcu_vehrdyst(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VCU fault status', 'enum': {0: // 'VCU_FAULTST_NORMAL', 1: 'VCU_FAULTST_DERATE', 2: 'VCU_FAULTST_RSV1', 3: // 'VCU_FAULTST_RSV2', 4: 'VCU_FAULTST_RSV3', 5: 'VCU_FAULTST_FAULT'}, // 'precision': 1.0, 'len': 4, 'name': 'VCU_FaultSt', 'is_signed_var': False, // 'offset': 0.0, 'physical_range': '[0|0]', 'bit': 5, 'type': 'enum', // 'order': 'motorola', 'physical_unit': ''} Scu_vcu_1_312::Vcu_faultstType vcu_faultst(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'VCU drive mode', 'enum': {0: // 'VCU_DRVMODE_INVALID', 1: 'VCU_DRVMODE_MANUAL', 2: 'VCU_DRVMODE_INTERRUPT', // 3: 'VCU_DRVMODE_AUTO'}, 'precision': 1.0, 'len': 2, 'name': 'VCU_DrvMode', // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|3]', 'bit': 7, // 'type': 'enum', 'order': 'motorola', 'physical_unit': ''} Scu_vcu_1_312::Vcu_drvmodeType vcu_drvmode(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Gear lever position', 'enum': {0: // 'VCU_GEARPST_INVALID', 1: 'VCU_GEARPST_DRIVE', 2: 'VCU_GEARPST_NEUTRAL', 3: // 'VCU_GEARPST_REVERSE', 4: 'VCU_GEARPST_PARK'}, 'precision': 1.0, 'len': 3, // 'name': 'VCU_GearPst', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|7]', 'bit': 12, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_vcu_1_312::Vcu_gearpstType vcu_gearpst(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Gear fault status', 'enum': {0: // 'VCU_GEARFAULTST_NORMAL', 1: 'VCU_GEARFAULTST_FAULT'}, 'precision': 1.0, // 'len': 1, 'name': 'VCU_GearFaultSt', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|0]', 'bit': 1, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_vcu_1_312::Vcu_gearfaultstType vcu_gearfaultst( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'Actual gear', 'enum': {0: // 'VCU_GEARACT_INVALID', 1: 'VCU_GEARACT_DRIVE', 2: 'VCU_GEARACT_NEUTRAL', 3: // 'VCU_GEARACT_REVERSE', 4: 'VCU_GEARACT_PARK'}, 'precision': 1.0, 'len': 3, // 'name': 'VCU_GearAct', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|7]', 'bit': 15, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_vcu_1_312::Vcu_gearactType vcu_gearact(const std::uint8_t* bytes, const int32_t length) const; }; } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_2_302_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_2_302.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace ge3 { class Scu2302Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Scu2302Test, reset) { Scu2302 scu2302; int32_t length = 8; Ge3 chassis_detail; uint8_t bytes[8] = {0x4D, 0x47, 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA}; scu2302.Parse(bytes, length, &chassis_detail); EXPECT_DOUBLE_EQ(chassis_detail.scu_2_302().vin00(), 'M'); // 77 EXPECT_DOUBLE_EQ(chassis_detail.scu_2_302().vin01(), 71); EXPECT_DOUBLE_EQ(chassis_detail.scu_2_302().vin02(), 255); EXPECT_DOUBLE_EQ(chassis_detail.scu_2_302().vin03(), 238); EXPECT_DOUBLE_EQ(chassis_detail.scu_2_302().vin04(), 221); EXPECT_DOUBLE_EQ(chassis_detail.scu_2_302().vin05(), 204); EXPECT_DOUBLE_EQ(chassis_detail.scu_2_302().vin06(), 187); EXPECT_DOUBLE_EQ(chassis_detail.scu_2_302().vin07(), 170); } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/ge3
apollo_public_repos/apollo/modules/canbus_vehicle/ge3/protocol/scu_vcu_1_312.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/ge3/protocol/scu_vcu_1_312.h" #include "glog/logging.h" #include "modules/drivers/canbus/common/byte.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace ge3 { using ::apollo::drivers::canbus::Byte; Scuvcu1312::Scuvcu1312() {} const int32_t Scuvcu1312::ID = 0x312; void Scuvcu1312::Parse(const std::uint8_t* bytes, int32_t length, Ge3* chassis) const { chassis->mutable_scu_vcu_1_312()->set_vcu_elcsysfault( vcu_elcsysfault(bytes, length)); chassis->mutable_scu_vcu_1_312()->set_vcu_brkpedst( vcu_brkpedst(bytes, length)); chassis->mutable_scu_vcu_1_312()->set_vcu_intidx( vcu_intidx(bytes, length)); chassis->mutable_scu_vcu_1_312()->set_vcu_gearintidx( vcu_gearintidx(bytes, length)); chassis->mutable_scu_vcu_1_312()->set_vcu_geardrvmode( vcu_geardrvmode(bytes, length)); chassis->mutable_scu_vcu_1_312()->set_vcu_accpedact( vcu_accpedact(bytes, length)); chassis->mutable_scu_vcu_1_312()->set_vcu_brkpedpst( vcu_brkpedpst(bytes, length)); chassis->mutable_scu_vcu_1_312()->set_vcu_vehrng( vcu_vehrng(bytes, length)); chassis->mutable_scu_vcu_1_312()->set_vcu_accpedpst( vcu_accpedpst(bytes, length)); chassis->mutable_scu_vcu_1_312()->set_vcu_vehrdyst( vcu_vehrdyst(bytes, length)); chassis->mutable_scu_vcu_1_312()->set_vcu_faultst( vcu_faultst(bytes, length)); chassis->mutable_scu_vcu_1_312()->set_vcu_drvmode( vcu_drvmode(bytes, length)); chassis->mutable_scu_vcu_1_312()->set_vcu_gearpst( vcu_gearpst(bytes, length)); chassis->mutable_scu_vcu_1_312()->set_vcu_gearfaultst( vcu_gearfaultst(bytes, length)); chassis->mutable_scu_vcu_1_312()->set_vcu_gearact( vcu_gearact(bytes, length)); // newcode chassis->mutable_check_response()->set_is_vcu_online( vcu_drvmode(bytes, length) == 3); } // config detail: {'description': 'Gear fault status', 'enum': {0: // 'VCU_ELCSYSFAULT_NORMAL', 1: 'VCU_ELCSYSFAULT_FAULT'}, 'precision': 1.0, // 'len': 1, 'name': 'vcu_elcsysfault', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|0]', 'bit': 49, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_vcu_1_312::Vcu_elcsysfaultType Scuvcu1312::vcu_elcsysfault( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 6); int32_t x = t0.get_byte(1, 1); Scu_vcu_1_312::Vcu_elcsysfaultType ret = static_cast<Scu_vcu_1_312::Vcu_elcsysfaultType>(x); return ret; } // config detail: {'description': 'Brake pedal position', 'enum': {0: // 'VCU_BRKPEDST_UNPRESSED', 1: 'VCU_BRKPEDST_PRESSED'}, 'precision': 1.0, // 'len': 1, 'name': 'vcu_brkpedst', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 48, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_vcu_1_312::Vcu_brkpedstType Scuvcu1312::vcu_brkpedst( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 6); int32_t x = t0.get_byte(0, 1); Scu_vcu_1_312::Vcu_brkpedstType ret = static_cast<Scu_vcu_1_312::Vcu_brkpedstType>(x); return ret; } // config detail: {'description': 'VCU interrupt index', 'enum': {0: // 'VCU_INTIDX_NOINT', 1: 'VCU_INTIDX_OVERFLOW', 2: 'VCU_INTIDX_TIMEOUT', 3: // 'VCU_INTIDX_ACCPEDINT', 4: 'VCU_INTIDX_BRKPEDINT', 5: 'VCU_INTIDX_GEARINT'}, // 'precision': 1.0, 'len': 3, 'name': 'vcu_intidx', 'is_signed_var': False, // 'offset': 0.0, 'physical_range': '[0|7]', 'bit': 58, 'type': 'enum', 'order': // 'motorola', 'physical_unit': ''} Scu_vcu_1_312::Vcu_intidxType Scuvcu1312::vcu_intidx(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 7); int32_t x = t0.get_byte(0, 3); Scu_vcu_1_312::Vcu_intidxType ret = static_cast<Scu_vcu_1_312::Vcu_intidxType>(x); return ret; } // config detail: {'description': 'Gear interrupt index', 'enum': {0: // 'VCU_GEARINTIDX_NOINT', 1: 'VCU_GEARINTIDX_OVERFLOW', 2: // 'VCU_GEARINTIDX_TIMEOUT'}, 'precision': 1.0, 'len': 3, 'name': // 'vcu_gearintidx', 'is_signed_var': False, 'offset': 0.0, 'physical_range': // '[0|7]', 'bit': 61, 'type': 'enum', 'order': 'motorola', 'physical_unit': ''} Scu_vcu_1_312::Vcu_gearintidxType Scuvcu1312::vcu_gearintidx( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 7); int32_t x = t0.get_byte(3, 3); Scu_vcu_1_312::Vcu_gearintidxType ret = static_cast<Scu_vcu_1_312::Vcu_gearintidxType>(x); return ret; } // config detail: {'description': 'VCU Gear drive mode', 'enum': {0: // 'VCU_GEARDRVMODE_INVALID', 1: 'VCU_GEARDRVMODE_MANUAL', 2: // 'VCU_GEARDRVMODE_INTERRUPT', 3: 'VCU_GEARDRVMODE_AUTO'}, 'precision': 1.0, // 'len': 2, 'name': 'vcu_geardrvmode', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|3]', 'bit': 63, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_vcu_1_312::Vcu_geardrvmodeType Scuvcu1312::vcu_geardrvmode( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 7); int32_t x = t0.get_byte(6, 2); Scu_vcu_1_312::Vcu_geardrvmodeType ret = static_cast<Scu_vcu_1_312::Vcu_geardrvmodeType>(x); return ret; } // config detail: {'description': 'Actual acceleration pedal position', // 'offset': 0.0, 'precision': 0.05, 'len': 12, 'name': 'vcu_accpedact', // 'is_signed_var': False, 'physical_range': '[0|100]', 'bit': 47, 'type': // 'double', 'order': 'motorola', 'physical_unit': '%'} double Scuvcu1312::vcu_accpedact(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 5); int32_t x = t0.get_byte(0, 8); Byte t1(bytes + 6); int32_t t = t1.get_byte(4, 4); x <<= 4; x |= t; double ret = x * 0.050000; return ret; } // config detail: {'description': 'Brake pedal position', 'offset': 0.0, // 'precision': 0.392, 'len': 8, 'name': 'vcu_brkpedpst', 'is_signed_var': // False, 'physical_range': '[0|99.96]', 'bit': 39, 'type': 'double', 'order': // 'motorola', 'physical_unit': '%'} double Scuvcu1312::vcu_brkpedpst(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(0, 8); double ret = x * 0.392000; return ret; } // config detail: {'description': 'Veh range', 'offset': 0.0, 'precision': 1.0, // 'len': 10, 'name': 'vcu_vehrng', 'is_signed_var': False, 'physical_range': // '[0|1000]', 'bit': 9, 'type': 'int', 'order': 'motorola', 'physical_unit': // 'km'} int Scuvcu1312::vcu_vehrng(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(0, 2); Byte t1(bytes + 2); int32_t t = t1.get_byte(0, 8); x <<= 8; x |= t; int ret = x; return ret; } // config detail: {'description': 'Actual acceleration pedal position', // 'offset': 0.0, 'precision': 0.392, 'len': 8, 'name': 'vcu_accpedpst', // 'is_signed_var': False, 'physical_range': '[0|99.96]', 'bit': 31, 'type': // 'double', 'order': 'motorola', 'physical_unit': '%'} double Scuvcu1312::vcu_accpedpst(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 3); int32_t x = t0.get_byte(0, 8); double ret = x * 0.392000; return ret; } // config detail: {'description': 'HEV system ready status', 'enum': {0: // 'VCU_VEHRDYST_NOTREADY', 1: 'VCU_VEHRDYST_READY'}, 'precision': 1.0, 'len': // 1, 'name': 'vcu_vehrdyst', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 0, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_vcu_1_312::Vcu_vehrdystType Scuvcu1312::vcu_vehrdyst( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 1); Scu_vcu_1_312::Vcu_vehrdystType ret = static_cast<Scu_vcu_1_312::Vcu_vehrdystType>(x); return ret; } // config detail: {'description': 'VCU fault status', 'enum': {0: // 'VCU_FAULTST_NORMAL', 1: 'VCU_FAULTST_DERATE', 2: 'VCU_FAULTST_RSV1', 3: // 'VCU_FAULTST_RSV2', 4: 'VCU_FAULTST_RSV3', 5: 'VCU_FAULTST_FAULT'}, // 'precision': 1.0, 'len': 4, 'name': 'vcu_faultst', 'is_signed_var': False, // 'offset': 0.0, 'physical_range': '[0|0]', 'bit': 5, 'type': 'enum', 'order': // 'motorola', 'physical_unit': ''} Scu_vcu_1_312::Vcu_faultstType Scuvcu1312::vcu_faultst( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(2, 4); Scu_vcu_1_312::Vcu_faultstType ret = static_cast<Scu_vcu_1_312::Vcu_faultstType>(x); return ret; } // config detail: {'description': 'VCU drive mode', 'enum': {0: // 'VCU_DRVMODE_INVALID', 1: 'VCU_DRVMODE_MANUAL', 2: 'VCU_DRVMODE_INTERRUPT', // 3: 'VCU_DRVMODE_AUTO'}, 'precision': 1.0, 'len': 2, 'name': 'vcu_drvmode', // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|3]', 'bit': 7, // 'type': 'enum', 'order': 'motorola', 'physical_unit': ''} Scu_vcu_1_312::Vcu_drvmodeType Scuvcu1312::vcu_drvmode( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(6, 2); Scu_vcu_1_312::Vcu_drvmodeType ret = static_cast<Scu_vcu_1_312::Vcu_drvmodeType>(x); return ret; } // config detail: {'description': 'Gear lever position', 'enum': {0: // 'VCU_GEARPST_INVALID', 1: 'VCU_GEARPST_DRIVE', 2: 'VCU_GEARPST_NEUTRAL', 3: // 'VCU_GEARPST_REVERSE', 4: 'VCU_GEARPST_PARK'}, 'precision': 1.0, 'len': 3, // 'name': 'vcu_gearpst', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|7]', 'bit': 12, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_vcu_1_312::Vcu_gearpstType Scuvcu1312::vcu_gearpst( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(2, 3); Scu_vcu_1_312::Vcu_gearpstType ret = static_cast<Scu_vcu_1_312::Vcu_gearpstType>(x); return ret; } // config detail: {'description': 'Gear fault status', 'enum': {0: // 'VCU_GEARFAULTST_NORMAL', 1: 'VCU_GEARFAULTST_FAULT'}, 'precision': 1.0, // 'len': 1, 'name': 'vcu_gearfaultst', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|0]', 'bit': 1, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_vcu_1_312::Vcu_gearfaultstType Scuvcu1312::vcu_gearfaultst( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(1, 1); Scu_vcu_1_312::Vcu_gearfaultstType ret = static_cast<Scu_vcu_1_312::Vcu_gearfaultstType>(x); return ret; } // config detail: {'description': 'Actual gear', 'enum': {0: // 'VCU_GEARACT_INVALID', 1: 'VCU_GEARACT_DRIVE', 2: 'VCU_GEARACT_NEUTRAL', 3: // 'VCU_GEARACT_REVERSE', 4: 'VCU_GEARACT_PARK'}, 'precision': 1.0, 'len': 3, // 'name': 'vcu_gearact', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|7]', 'bit': 15, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Scu_vcu_1_312::Vcu_gearactType Scuvcu1312::vcu_gearact( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(5, 3); Scu_vcu_1_312::Vcu_gearactType ret = static_cast<Scu_vcu_1_312::Vcu_gearactType>(x); return ret; } } // namespace ge3 } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun/zhongyun_controller.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include <memory> #include <thread> #include "modules/canbus/proto/canbus_conf.pb.h" #include "modules/canbus/proto/vehicle_parameter.pb.h" #include "modules/common_msgs/basic_msgs/error_code.pb.h" #include "modules/common_msgs/chassis_msgs/chassis.pb.h" #include "modules/common_msgs/control_msgs/control_cmd.pb.h" #include "modules/canbus/vehicle/vehicle_controller.h" #include "modules/canbus_vehicle/zhongyun/protocol/brake_control_a4.h" #include "modules/canbus_vehicle/zhongyun/protocol/gear_control_a1.h" #include "modules/canbus_vehicle/zhongyun/protocol/parking_control_a5.h" #include "modules/canbus_vehicle/zhongyun/protocol/steering_control_a2.h" #include "modules/canbus_vehicle/zhongyun/protocol/torque_control_a3.h" namespace apollo { namespace canbus { namespace zhongyun { class ZhongyunController final : public VehicleController<::apollo::canbus::Zhongyun> { public: ZhongyunController() {} virtual ~ZhongyunController(); ::apollo::common::ErrorCode Init( const VehicleParameter& params, CanSender<::apollo::canbus::Zhongyun>* const can_sender, MessageManager<::apollo::canbus::Zhongyun>* const message_manager) override; bool Start() override; /** * @brief stop the vehicle controller. */ void Stop() override; /** * @brief calculate and return the chassis. * @returns a copy of chassis. Use copy here to avoid multi-thread issues. */ Chassis chassis() override; FRIEND_TEST(ZhongyunControllerTest, SetDrivingMode); FRIEND_TEST(ZhongyunControllerTest, Status); FRIEND_TEST(ZhongyunControllerTest, UpdateDrivingMode); private: // main logical function for operation the car enter or exit the auto driving void Emergency() override; ::apollo::common::ErrorCode EnableAutoMode() override; ::apollo::common::ErrorCode DisableAutoMode() override; ::apollo::common::ErrorCode EnableSteeringOnlyMode() override; ::apollo::common::ErrorCode EnableSpeedOnlyMode() override; // NEUTRAL, REVERSE, DRIVE void Gear(Chassis::GearPosition state) override; // brake with new acceleration // acceleration:0.00~99.99, unit: // acceleration_spd: 60 ~ 100, suggest: 90 void Brake(double acceleration) override; // drive with old acceleration // gas:0.00~99.99 unit: void Throttle(double throttle) override; // drive with acceleration/deceleration // acc:-7.0~5.0 unit:m/s^2 void Acceleration(double acc) override; // steering with old angle speed // angle:-99.99~0.00~99.99, unit:, left:+, right:- void Steer(double angle) override; // steering with new angle speed // angle:-99.99~0.00~99.99, unit:, left:+, right:- // angle_spd:0.00~99.99, unit:deg/s void Steer(double angle, double angle_spd) override; // set Electrical Park Brake void SetEpbBreak(const ::apollo::control::ControlCommand& command) override; void SetBeam(const ::apollo::control::ControlCommand& command) override; void SetHorn(const ::apollo::control::ControlCommand& command) override; void SetTurningSignal( const ::apollo::control::ControlCommand& command) override; bool VerifyID() override; void ResetProtocol(); bool CheckChassisError(); private: void SecurityDogThreadFunc(); virtual bool CheckResponse(const int32_t flags, bool need_wait); void set_chassis_error_mask(const int32_t mask); int32_t chassis_error_mask(); Chassis::ErrorCode chassis_error_code(); void set_chassis_error_code(const Chassis::ErrorCode& error_code); private: // control protocol Brakecontrola4* brake_control_a4_ = nullptr; Gearcontrola1* gear_control_a1_ = nullptr; Parkingcontrola5* parking_control_a5_ = nullptr; Steeringcontrola2* steering_control_a2_ = nullptr; Torquecontrola3* torque_control_a3_ = nullptr; Chassis chassis_; std::unique_ptr<std::thread> thread_; bool is_chassis_error_ = false; std::mutex chassis_error_code_mutex_; Chassis::ErrorCode chassis_error_code_ = Chassis::NO_ERROR; std::mutex chassis_mask_mutex_; int32_t chassis_error_mask_ = 0; }; } // namespace zhongyun } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun/zhongyun_vehicle_factory.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ /** * @file zhongyun_vehicle_factory.h */ #pragma once #include <memory> #include "modules/canbus/proto/canbus_conf.pb.h" #include "modules/canbus/proto/vehicle_parameter.pb.h" #include "modules/canbus_vehicle/zhongyun/proto/zhongyun.pb.h" #include "modules/common_msgs/control_msgs/control_cmd.pb.h" #include "cyber/cyber.h" #include "modules/canbus/vehicle/abstract_vehicle_factory.h" #include "modules/canbus/vehicle/vehicle_controller.h" #include "modules/common/status/status.h" #include "modules/drivers/canbus/can_client/can_client.h" #include "modules/drivers/canbus/can_comm/can_receiver.h" #include "modules/drivers/canbus/can_comm/can_sender.h" #include "modules/drivers/canbus/can_comm/message_manager.h" /** * @namespace apollo::canbus * @brief apollo::canbus */ namespace apollo { namespace canbus { /** * @class ZhongyunVehicleFactory * * @brief this class is inherited from AbstractVehicleFactory. It can be used to * create controller and message manager for zhongyun vehicle. */ class ZhongyunVehicleFactory : public AbstractVehicleFactory { public: /** * @brief destructor */ virtual ~ZhongyunVehicleFactory() = default; /** * @brief init vehicle factory * @returns true if successfully initialized */ bool Init(const CanbusConf *canbus_conf) override; /** * @brief start canclient, cansender, canreceiver, vehicle controller * @returns true if successfully started */ bool Start() override; /** * @brief create ch vehicle controller * @returns a unique_ptr that points to the created controller */ void Stop() override; /** * @brief update control command */ void UpdateCommand( const apollo::control::ControlCommand *control_command) override; /** * @brief publish chassis messages */ Chassis publish_chassis() override; /** * @brief publish chassis for vehicle messages */ void PublishChassisDetail() override; private: /** * @brief create zhongyun vehicle controller * @returns a unique_ptr that points to the created controller */ std::unique_ptr<VehicleController<::apollo::canbus::Zhongyun>> CreateVehicleController(); /** * @brief create zhongyun message manager * @returns a unique_ptr that points to the created message manager */ std::unique_ptr<MessageManager<::apollo::canbus::Zhongyun>> CreateMessageManager(); std::unique_ptr<::apollo::cyber::Node> node_ = nullptr; std::unique_ptr<apollo::drivers::canbus::CanClient> can_client_; CanSender<::apollo::canbus::Zhongyun> can_sender_; apollo::drivers::canbus::CanReceiver<::apollo::canbus::Zhongyun> can_receiver_; std::unique_ptr<MessageManager<::apollo::canbus::Zhongyun>> message_manager_; std::unique_ptr<VehicleController<::apollo::canbus::Zhongyun>> vehicle_controller_; std::shared_ptr<::apollo::cyber::Writer<::apollo::canbus::Zhongyun>> chassis_detail_writer_; }; CYBER_REGISTER_VEHICLEFACTORY(ZhongyunVehicleFactory) } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun/zhongyun_message_manager_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/zhongyun/zhongyun_message_manager.h" #include "gtest/gtest.h" #include "modules/canbus_vehicle/zhongyun/protocol/brake_control_a4.h" #include "modules/canbus_vehicle/zhongyun/protocol/enable_state_feedback_c3.h" #include "modules/canbus_vehicle/zhongyun/protocol/error_state_e1.h" #include "modules/canbus_vehicle/zhongyun/protocol/gear_control_a1.h" #include "modules/canbus_vehicle/zhongyun/protocol/parking_control_a5.h" #include "modules/canbus_vehicle/zhongyun/protocol/steering_control_a2.h" #include "modules/canbus_vehicle/zhongyun/protocol/torque_control_a3.h" #include "modules/canbus_vehicle/zhongyun/protocol/vehicle_state_feedback_2_c4.h" #include "modules/canbus_vehicle/zhongyun/protocol/vehicle_state_feedback_c1.h" namespace apollo { namespace canbus { namespace zhongyun { class ZhongyunMessageManagerTest : public ::testing::Test { protected: ZhongyunMessageManager manager_; }; TEST_F(ZhongyunMessageManagerTest, GetSendProtocols) { EXPECT_NE(manager_.GetMutableProtocolDataById(Brakecontrola4::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Gearcontrola1::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Parkingcontrola5::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Steeringcontrola2::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Torquecontrola3::ID), nullptr); } TEST_F(ZhongyunMessageManagerTest, GetRecvProtocols) { EXPECT_NE(manager_.GetMutableProtocolDataById(Enablestatefeedbackc3::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Errorstatee1::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Vehiclestatefeedback2c4::ID), nullptr); EXPECT_NE(manager_.GetMutableProtocolDataById(Vehiclestatefeedbackc1::ID), nullptr); } } // namespace zhongyun } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun/zhongyun_controller_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include <string> #include "gtest/gtest.h" #include "cyber/common/file.h" #include "modules/canbus/proto/canbus_conf.pb.h" #include "modules/common_msgs/chassis_msgs/chassis.pb.h" #include "modules/canbus_vehicle/zhongyun/proto/zhongyun.pb.h" #include "modules/canbus_vehicle/zhongyun/zhongyun_controller.h" #include "modules/canbus_vehicle/zhongyun/zhongyun_message_manager.h" #include "modules/common_msgs/control_msgs/control_cmd.pb.h" #include "modules/drivers/canbus/can_comm/can_sender.h" namespace apollo { namespace canbus { namespace zhongyun { using ::apollo::common::ErrorCode; using ::apollo::control::ControlCommand; class ZhongyunControllerTest : public ::testing::Test { public: virtual void SetUp() { const std::string canbus_conf_file = "modules/canbus/testdata/conf/zhongyun_canbus_conf_test.pb.txt"; apollo::cyber::common::GetProtoFromFile(canbus_conf_file, &canbus_conf_); params_ = canbus_conf_.vehicle_parameter(); } protected: ZhongyunController controller_; CanSender<Zhongyun> sender_; CanbusConf canbus_conf_; VehicleParameter params_; ZhongyunMessageManager msg_manager_; ControlCommand control_cmd_; }; TEST_F(ZhongyunControllerTest, Init) { ErrorCode ret = controller_.Init(params_, &sender_, &msg_manager_); EXPECT_EQ(ret, ErrorCode::OK); } TEST_F(ZhongyunControllerTest, SetDrivingMode) { Chassis chassis; chassis.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE); controller_.Init(params_, &sender_, &msg_manager_); controller_.set_driving_mode(chassis.driving_mode()); EXPECT_EQ(controller_.driving_mode(), chassis.driving_mode()); EXPECT_EQ(controller_.SetDrivingMode(chassis.driving_mode()), ErrorCode::OK); } TEST_F(ZhongyunControllerTest, Status) { controller_.Init(params_, &sender_, &msg_manager_); controller_.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE); EXPECT_EQ(controller_.Update(control_cmd_), ErrorCode::OK); controller_.SetHorn(control_cmd_); controller_.SetBeam(control_cmd_); controller_.SetTurningSignal(control_cmd_); EXPECT_FALSE(controller_.CheckChassisError()); } TEST_F(ZhongyunControllerTest, UpdateDrivingMode) { controller_.Init(params_, &sender_, &msg_manager_); controller_.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE); EXPECT_EQ(controller_.SetDrivingMode(Chassis::COMPLETE_MANUAL), ErrorCode::OK); } } // namespace zhongyun } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun/zhongyun_message_manager.h
/* Copyright 2019 The Apollo Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ #pragma once #include "modules/canbus_vehicle/zhongyun/proto/zhongyun.pb.h" #include "modules/drivers/canbus/can_comm/message_manager.h" namespace apollo { namespace canbus { namespace zhongyun { using ::apollo::drivers::canbus::MessageManager; class ZhongyunMessageManager : public MessageManager<::apollo::canbus::Zhongyun> { public: ZhongyunMessageManager(); virtual ~ZhongyunMessageManager(); }; } // namespace zhongyun } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun/cyberfile.xml
<package format="2"> <name>canbus-vehicle-zhongyun</name> <version>local</version> <description> Dynamic loading for canbus module </description> <maintainer email="apollo-support@baidu.com">Apollo</maintainer> <license>Apache License 2.0</license> <url type="website">https://www.apollo.auto/</url> <url type="repository">https://github.com/ApolloAuto/apollo</url> <url type="bugtracker">https://github.com/ApolloAuto/apollo/issues</url> <type>module</type> <src_path url="https://github.com/ApolloAuto/apollo">//modules/canbus_vehicle/zhongyun</src_path> <depend type="binary" repo_name="cyber">cyber-dev</depend> <depend type="binary" repo_name="common" lib_names="common">common-dev</depend> <depend type="binary" repo_name="canbus" lib_names="canbus">canbus-dev</depend> <depend repo_name="common-msgs" lib_names="common-msgs">common-msgs-dev</depend> <depend type="binary" repo_name="drivers">drivers-dev</depend> <depend repo_name="com_google_googletest" lib_names="gtest,gtest_main">3rd-gtest-dev</depend> </package>
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun/zhongyun_vehicle_factory.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/zhongyun/zhongyun_vehicle_factory.h" #include "cyber/common/log.h" #include "modules/canbus/common/canbus_gflags.h" #include "modules/canbus_vehicle/zhongyun/zhongyun_controller.h" #include "modules/canbus_vehicle/zhongyun/zhongyun_message_manager.h" #include "modules/common/adapters/adapter_gflags.h" #include "modules/common/util/util.h" #include "modules/drivers/canbus/can_client/can_client_factory.h" using apollo::common::ErrorCode; using apollo::control::ControlCommand; using apollo::drivers::canbus::CanClientFactory; namespace apollo { namespace canbus { bool ZhongyunVehicleFactory::Init(const CanbusConf *canbus_conf) { // Init can client auto can_factory = CanClientFactory::Instance(); can_factory->RegisterCanClients(); can_client_ = can_factory->CreateCANClient(canbus_conf->can_card_parameter()); if (!can_client_) { AERROR << "Failed to create can client."; return false; } AINFO << "Can client is successfully created."; message_manager_ = this->CreateMessageManager(); if (message_manager_ == nullptr) { AERROR << "Failed to create message manager."; return false; } AINFO << "Message manager is successfully created."; if (can_receiver_.Init(can_client_.get(), message_manager_.get(), canbus_conf->enable_receiver_log()) != ErrorCode::OK) { AERROR << "Failed to init can receiver."; return false; } AINFO << "The can receiver is successfully initialized."; if (can_sender_.Init(can_client_.get(), message_manager_.get(), canbus_conf->enable_sender_log()) != ErrorCode::OK) { AERROR << "Failed to init can sender."; return false; } AINFO << "The can sender is successfully initialized."; vehicle_controller_ = CreateVehicleController(); if (vehicle_controller_ == nullptr) { AERROR << "Failed to create vehicle controller."; return false; } AINFO << "The vehicle controller is successfully created."; if (vehicle_controller_->Init(canbus_conf->vehicle_parameter(), &can_sender_, message_manager_.get()) != ErrorCode::OK) { AERROR << "Failed to init vehicle controller."; return false; } AINFO << "The vehicle controller is successfully" << " initialized with canbus conf as : " << canbus_conf->vehicle_parameter().ShortDebugString(); node_ = ::apollo::cyber::CreateNode("chassis_detail"); chassis_detail_writer_ = node_->CreateWriter<::apollo::canbus::Zhongyun>( FLAGS_chassis_detail_topic); return true; } bool ZhongyunVehicleFactory::Start() { // 1. init and start the can card hardware if (can_client_->Start() != ErrorCode::OK) { AERROR << "Failed to start can client"; return false; } AINFO << "Can client is started."; // 2. start receive first then send if (can_receiver_.Start() != ErrorCode::OK) { AERROR << "Failed to start can receiver."; return false; } AINFO << "Can receiver is started."; // 3. start send if (can_sender_.Start() != ErrorCode::OK) { AERROR << "Failed to start can sender."; return false; } // 4. start controller if (!vehicle_controller_->Start()) { AERROR << "Failed to start vehicle controller."; return false; } return true; } void ZhongyunVehicleFactory::Stop() { can_sender_.Stop(); can_receiver_.Stop(); can_client_->Stop(); vehicle_controller_->Stop(); AINFO << "Cleanup cansender, canreceiver, canclient, vehicle controller."; } void ZhongyunVehicleFactory::UpdateCommand( const apollo::control::ControlCommand *control_command) { if (vehicle_controller_->Update(*control_command) != ErrorCode::OK) { AERROR << "Failed to process callback function OnControlCommand because " "vehicle_controller_->Update error."; return; } can_sender_.Update(); } Chassis ZhongyunVehicleFactory::publish_chassis() { Chassis chassis = vehicle_controller_->chassis(); ADEBUG << chassis.ShortDebugString(); return chassis; } void ZhongyunVehicleFactory::PublishChassisDetail() { Zhongyun chassis_detail; message_manager_->GetSensorData(&chassis_detail); ADEBUG << chassis_detail.ShortDebugString(); chassis_detail_writer_->Write(chassis_detail); } std::unique_ptr<VehicleController<::apollo::canbus::Zhongyun>> ZhongyunVehicleFactory::CreateVehicleController() { return std::unique_ptr<VehicleController<::apollo::canbus::Zhongyun>>( new zhongyun::ZhongyunController()); } std::unique_ptr<MessageManager<::apollo::canbus::Zhongyun>> ZhongyunVehicleFactory::CreateMessageManager() { return std::unique_ptr<MessageManager<::apollo::canbus::Zhongyun>>( new zhongyun::ZhongyunMessageManager()); } } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun/zhongyun_message_manager.cc
/* Copyright 2019 The Apollo Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ #include "modules/canbus_vehicle/zhongyun/zhongyun_message_manager.h" #include "modules/canbus_vehicle/zhongyun/protocol/brake_control_a4.h" #include "modules/canbus_vehicle/zhongyun/protocol/gear_control_a1.h" #include "modules/canbus_vehicle/zhongyun/protocol/parking_control_a5.h" #include "modules/canbus_vehicle/zhongyun/protocol/steering_control_a2.h" #include "modules/canbus_vehicle/zhongyun/protocol/torque_control_a3.h" #include "modules/canbus_vehicle/zhongyun/protocol/enable_state_feedback_c3.h" #include "modules/canbus_vehicle/zhongyun/protocol/error_state_e1.h" #include "modules/canbus_vehicle/zhongyun/protocol/vehicle_state_feedback_2_c4.h" #include "modules/canbus_vehicle/zhongyun/protocol/vehicle_state_feedback_c1.h" namespace apollo { namespace canbus { namespace zhongyun { ZhongyunMessageManager::ZhongyunMessageManager() { // Control Messages AddSendProtocolData<Brakecontrola4, true>(); AddSendProtocolData<Gearcontrola1, true>(); AddSendProtocolData<Parkingcontrola5, true>(); AddSendProtocolData<Steeringcontrola2, true>(); AddSendProtocolData<Torquecontrola3, true>(); // Report Messages AddRecvProtocolData<Enablestatefeedbackc3, true>(); AddRecvProtocolData<Errorstatee1, true>(); AddRecvProtocolData<Vehiclestatefeedback2c4, true>(); AddRecvProtocolData<Vehiclestatefeedbackc1, true>(); } ZhongyunMessageManager::~ZhongyunMessageManager() {} } // namespace zhongyun } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun/zhongyun_controller.cc
/* Copyright 2019 The Apollo Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ #include "modules/canbus_vehicle/zhongyun/zhongyun_controller.h" #include "modules/common_msgs/basic_msgs/vehicle_signal.pb.h" #include "cyber/common/log.h" #include "cyber/time/time.h" #include "modules/canbus/vehicle/vehicle_controller.h" #include "modules/canbus_vehicle/zhongyun/zhongyun_message_manager.h" #include "modules/drivers/canbus/can_comm/can_sender.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace zhongyun { using ::apollo::common::ErrorCode; using ::apollo::control::ControlCommand; using ::apollo::drivers::canbus::ProtocolData; namespace { const int32_t kMaxFailAttempt = 10; const int32_t CHECK_RESPONSE_STEER_UNIT_FLAG = 1; const int32_t CHECK_RESPONSE_SPEED_UNIT_FLAG = 2; } // namespace ErrorCode ZhongyunController::Init( const VehicleParameter& params, CanSender<::apollo::canbus::Zhongyun>* const can_sender, MessageManager<::apollo::canbus::Zhongyun>* const message_manager) { if (is_initialized_) { AINFO << "ZhongyunController has already been initialized."; return ErrorCode::CANBUS_ERROR; } vehicle_params_.CopyFrom( common::VehicleConfigHelper::Instance()->GetConfig().vehicle_param()); params_.CopyFrom(params); if (!params_.has_driving_mode()) { AERROR << "Vehicle conf pb not set driving_mode."; return ErrorCode::CANBUS_ERROR; } if (can_sender == nullptr) { AERROR << "Canbus sender is null."; return ErrorCode::CANBUS_ERROR; } can_sender_ = can_sender; if (message_manager == nullptr) { AERROR << "Protocol manager is null."; return ErrorCode::CANBUS_ERROR; } message_manager_ = message_manager; // Sender part brake_control_a4_ = dynamic_cast<Brakecontrola4*>( message_manager_->GetMutableProtocolDataById(Brakecontrola4::ID)); if (brake_control_a4_ == nullptr) { AERROR << "Brakecontrola4 does not exist in the ZhongyunMessageManager!"; return ErrorCode::CANBUS_ERROR; } gear_control_a1_ = dynamic_cast<Gearcontrola1*>( message_manager_->GetMutableProtocolDataById(Gearcontrola1::ID)); if (gear_control_a1_ == nullptr) { AERROR << "Gearcontrola1 does not exist in the ZhongyunMessageManager!"; return ErrorCode::CANBUS_ERROR; } parking_control_a5_ = dynamic_cast<Parkingcontrola5*>( message_manager_->GetMutableProtocolDataById(Parkingcontrola5::ID)); if (parking_control_a5_ == nullptr) { AERROR << "Parkingcontrola5 does not exist in the ZhongyunMessageManager!"; return ErrorCode::CANBUS_ERROR; } steering_control_a2_ = dynamic_cast<Steeringcontrola2*>( message_manager_->GetMutableProtocolDataById(Steeringcontrola2::ID)); if (steering_control_a2_ == nullptr) { AERROR << "Steeringcontrola2 does not exist in the ZhongyunMessageManager!"; return ErrorCode::CANBUS_ERROR; } torque_control_a3_ = dynamic_cast<Torquecontrola3*>( message_manager_->GetMutableProtocolDataById(Torquecontrola3::ID)); if (torque_control_a3_ == nullptr) { AERROR << "Torquecontrola3 does not exist in the ZhongyunMessageManager!"; return ErrorCode::CANBUS_ERROR; } can_sender_->AddMessage(Brakecontrola4::ID, brake_control_a4_, false); can_sender_->AddMessage(Gearcontrola1::ID, gear_control_a1_, false); can_sender_->AddMessage(Parkingcontrola5::ID, parking_control_a5_, false); can_sender_->AddMessage(Steeringcontrola2::ID, steering_control_a2_, false); can_sender_->AddMessage(Torquecontrola3::ID, torque_control_a3_, false); // Need to sleep to ensure all messages received AINFO << "ZhongyunController is initialized."; is_initialized_ = true; return ErrorCode::OK; } ZhongyunController::~ZhongyunController() {} bool ZhongyunController::Start() { if (!is_initialized_) { AERROR << "ZhongyunController has not been initialized."; return false; } const auto& update_func = [this] { SecurityDogThreadFunc(); }; thread_.reset(new std::thread(update_func)); return true; } void ZhongyunController::Stop() { if (!is_initialized_) { AERROR << "ZhongyunController stops or starts improperly!"; return; } if (thread_ != nullptr && thread_->joinable()) { thread_->join(); thread_.reset(); AINFO << "ZhongyunController stopped."; } } Chassis ZhongyunController::chassis() { chassis_.Clear(); Zhongyun chassis_detail; message_manager_->GetSensorData(&chassis_detail); // 1, 2 // if (driving_mode() == Chassis::EMERGENCY_MODE) { // set_chassis_error_code(Chassis::NO_ERROR); // } chassis_.set_driving_mode(driving_mode()); chassis_.set_error_code(chassis_error_code()); // 3 chassis_.set_engine_started(true); // 4 engine_rpm if (chassis_detail.has_vehicle_state_feedback_2_c4() && chassis_detail.vehicle_state_feedback_2_c4().has_motor_speed()) { chassis_.set_engine_rpm(static_cast<float>( chassis_detail.vehicle_state_feedback_2_c4().motor_speed())); } else { chassis_.set_engine_rpm(0); } // 5 speed_mps if (chassis_detail.has_vehicle_state_feedback_c1() && chassis_detail.vehicle_state_feedback_c1().has_speed()) { chassis_.set_speed_mps( static_cast<float>(chassis_detail.vehicle_state_feedback_c1().speed())); } else { chassis_.set_speed_mps(0); } // 6 chassis_.set_fuel_range_m(0); // 7 acc_pedal if (chassis_detail.has_vehicle_state_feedback_2_c4() && chassis_detail.vehicle_state_feedback_2_c4() .has_driven_torque_feedback()) { chassis_.set_throttle_percentage(static_cast<float>( chassis_detail.vehicle_state_feedback_2_c4().driven_torque_feedback())); } else { chassis_.set_throttle_percentage(0); } // 8 brake_pedal if (chassis_detail.has_vehicle_state_feedback_c1() && chassis_detail.vehicle_state_feedback_c1().has_brake_torque_feedback()) { chassis_.set_brake_percentage(static_cast<float>( chassis_detail.vehicle_state_feedback_c1().brake_torque_feedback())); } else { chassis_.set_brake_percentage(0); } // 9 gear position if (chassis_detail.has_vehicle_state_feedback_c1() && chassis_detail.vehicle_state_feedback_c1().has_gear_state_actual()) { switch (chassis_detail.vehicle_state_feedback_c1().gear_state_actual()) { case Vehicle_state_feedback_c1::GEAR_STATE_ACTUAL_D: { chassis_.set_gear_location(Chassis::GEAR_DRIVE); } break; case Vehicle_state_feedback_c1::GEAR_STATE_ACTUAL_N: { chassis_.set_gear_location(Chassis::GEAR_NEUTRAL); } break; case Vehicle_state_feedback_c1::GEAR_STATE_ACTUAL_R: { chassis_.set_gear_location(Chassis::GEAR_REVERSE); } break; case Vehicle_state_feedback_c1::GEAR_STATE_ACTUAL_P: { chassis_.set_gear_location(Chassis::GEAR_PARKING); } break; default: chassis_.set_gear_location(Chassis::GEAR_INVALID); break; } } else { chassis_.set_gear_location(Chassis::GEAR_NONE); } // 11 steering_percentage if (chassis_detail.has_vehicle_state_feedback_c1() && chassis_detail.vehicle_state_feedback_c1().has_steering_actual()) { chassis_.set_steering_percentage(static_cast<float>( chassis_detail.vehicle_state_feedback_c1().steering_actual() * 100.0 / vehicle_params_.max_steer_angle() * M_PI / 180)); } else { chassis_.set_steering_percentage(0); } // 12 epb if (chassis_detail.has_vehicle_state_feedback_c1() && chassis_detail.vehicle_state_feedback_c1().has_parking_actual()) { chassis_.set_parking_brake( chassis_detail.vehicle_state_feedback_c1().parking_actual() == Vehicle_state_feedback_c1::PARKING_ACTUAL_PARKING_TRIGGER); } else { chassis_.set_parking_brake(false); } // 13 error mask if (chassis_error_mask_) { chassis_.set_chassis_error_mask(chassis_error_mask_); } // Give engage_advice based on error_code and canbus feedback if (!chassis_error_mask_ && !chassis_.parking_brake()) { chassis_.mutable_engage_advice()->set_advice( apollo::common::EngageAdvice::READY_TO_ENGAGE); } else { chassis_.mutable_engage_advice()->set_advice( apollo::common::EngageAdvice::DISALLOW_ENGAGE); chassis_.mutable_engage_advice()->set_reason( "CANBUS not ready, epb is not released or firmware error!"); } // 14 add checkresponse signal if (chassis_detail.has_enable_state_feedback_c3()) { if (chassis_detail.enable_state_feedback_c3().has_brake_enable_state()) { chassis_.mutable_check_response()->set_is_esp_online( chassis_detail.enable_state_feedback_c3().brake_enable_state() == 1); } if (chassis_detail.enable_state_feedback_c3().has_driven_enable_state() && chassis_detail.enable_state_feedback_c3().has_gear_enable_actual()) { chassis_.mutable_check_response()->set_is_vcu_online( ((chassis_detail.enable_state_feedback_c3().driven_enable_state() == 1) && (chassis_detail.enable_state_feedback_c3().gear_enable_actual() == 1)) == 1); } if (chassis_detail.enable_state_feedback_c3().has_steering_enable_state()) { chassis_.mutable_check_response()->set_is_eps_online( chassis_detail.enable_state_feedback_c3().steering_enable_state() == 1); } } return chassis_; } bool ZhongyunController::VerifyID() { return true; } void ZhongyunController::Emergency() { set_driving_mode(Chassis::EMERGENCY_MODE); ResetProtocol(); } ErrorCode ZhongyunController::EnableAutoMode() { if (driving_mode() == Chassis::COMPLETE_AUTO_DRIVE) { AINFO << "Already in COMPLETE_AUTO_DRIVE mode."; return ErrorCode::OK; } steering_control_a2_->set_steering_enable_control( Steering_control_a2::STEERING_ENABLE_CONTROL_STEERING_AUTOCONTROL); gear_control_a1_->set_gear_enable_control( Gear_control_a1::GEAR_ENABLE_CONTROL_GEAR_AUTOCONTROL); torque_control_a3_->set_driven_enable_control( Torque_control_a3::DRIVEN_ENABLE_CONTROL_DRIVE_AUTO); brake_control_a4_->set_brake_enable_control( Brake_control_a4::BRAKE_ENABLE_CONTROL_BRAKE_AUTO); parking_control_a5_->set_parking_enable_control( Parking_control_a5::PARKING_ENABLE_CONTROL_PARKING_AUTOCONTROL); can_sender_->Update(); const int32_t flag = CHECK_RESPONSE_STEER_UNIT_FLAG | CHECK_RESPONSE_SPEED_UNIT_FLAG; if (!CheckResponse(flag, true)) { AERROR << "Failed to switch to COMPLETE_AUTO_DRIVE mode."; Emergency(); set_chassis_error_code(Chassis::CHASSIS_ERROR); return ErrorCode::CANBUS_ERROR; } set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE); AINFO << "Switch to COMPLETE_AUTO_DRIVE mode ok."; return ErrorCode::OK; } ErrorCode ZhongyunController::DisableAutoMode() { ResetProtocol(); can_sender_->Update(); set_driving_mode(Chassis::COMPLETE_MANUAL); set_chassis_error_code(Chassis::NO_ERROR); AINFO << "Switch to COMPLETE_MANUAL mode ok."; return ErrorCode::OK; } ErrorCode ZhongyunController::EnableSteeringOnlyMode() { if (driving_mode() == Chassis::COMPLETE_AUTO_DRIVE || driving_mode() == Chassis::AUTO_STEER_ONLY) { set_driving_mode(Chassis::AUTO_STEER_ONLY); AINFO << "Already in AUTO_STEER_ONLY mode"; return ErrorCode::OK; } steering_control_a2_->set_steering_enable_control( Steering_control_a2::STEERING_ENABLE_CONTROL_STEERING_AUTOCONTROL); gear_control_a1_->set_gear_enable_control( Gear_control_a1::GEAR_ENABLE_CONTROL_GEAR_MANUALCONTROL); torque_control_a3_->set_driven_enable_control( Torque_control_a3::DRIVEN_ENABLE_CONTROL_DRIVE_MANUAL); brake_control_a4_->set_brake_enable_control( Brake_control_a4::BRAKE_ENABLE_CONTROL_BRAKE_MANUAL); parking_control_a5_->set_parking_enable_control( Parking_control_a5::PARKING_ENABLE_CONTROL_PARKING_MANUALCONTROL); can_sender_->Update(); const int32_t flag = CHECK_RESPONSE_STEER_UNIT_FLAG | CHECK_RESPONSE_SPEED_UNIT_FLAG; if (!CheckResponse(flag, true)) { AERROR << "Failed to switch to COMPLETE_AUTO_DRIVE mode. Please check the " "emergency button or chassis."; Emergency(); set_chassis_error_code(Chassis::CHASSIS_ERROR); return ErrorCode::CANBUS_ERROR; } set_driving_mode(Chassis::AUTO_STEER_ONLY); AINFO << "Switch to COMPLETE_AUTO_DRIVE mode ok."; return ErrorCode::OK; } ErrorCode ZhongyunController::EnableSpeedOnlyMode() { if (driving_mode() == Chassis::COMPLETE_AUTO_DRIVE || driving_mode() == Chassis::AUTO_SPEED_ONLY) { set_driving_mode(Chassis::AUTO_SPEED_ONLY); AINFO << "Already in AUTO_SPEED_ONLY mode"; return ErrorCode::OK; } steering_control_a2_->set_steering_enable_control( Steering_control_a2::STEERING_ENABLE_CONTROL_STEERING_MANUALCONTROL); gear_control_a1_->set_gear_enable_control( Gear_control_a1::GEAR_ENABLE_CONTROL_GEAR_AUTOCONTROL); torque_control_a3_->set_driven_enable_control( Torque_control_a3::DRIVEN_ENABLE_CONTROL_DRIVE_AUTO); brake_control_a4_->set_brake_enable_control( Brake_control_a4::BRAKE_ENABLE_CONTROL_BRAKE_AUTO); parking_control_a5_->set_parking_enable_control( Parking_control_a5::PARKING_ENABLE_CONTROL_PARKING_AUTOCONTROL); can_sender_->Update(); if (CheckResponse(CHECK_RESPONSE_SPEED_UNIT_FLAG, true) == false) { AERROR << "Failed to switch to AUTO_SPEED_ONLY mode."; Emergency(); set_chassis_error_code(Chassis::CHASSIS_ERROR); return ErrorCode::CANBUS_ERROR; } set_driving_mode(Chassis::AUTO_SPEED_ONLY); AINFO << "Switch to AUTO_SPEED_ONLY mode ok."; return ErrorCode::OK; } // NEUTRAL, REVERSE, DRIVE, PARK void ZhongyunController::Gear(Chassis::GearPosition gear_position) { if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE && driving_mode() != Chassis::AUTO_SPEED_ONLY) { AINFO << "This drive mode no need to set gear."; return; } switch (gear_position) { case Chassis::GEAR_NEUTRAL: { gear_control_a1_->set_gear_state_target( Gear_control_a1::GEAR_STATE_TARGET_N); break; } case Chassis::GEAR_REVERSE: { gear_control_a1_->set_gear_state_target( Gear_control_a1::GEAR_STATE_TARGET_R); break; } case Chassis::GEAR_DRIVE: { gear_control_a1_->set_gear_state_target( Gear_control_a1::GEAR_STATE_TARGET_D); break; } case Chassis::GEAR_PARKING: { gear_control_a1_->set_gear_state_target( Gear_control_a1::GEAR_STATE_TARGET_P); break; } case Chassis::GEAR_INVALID: { AERROR << "Gear command is invalid!"; gear_control_a1_->set_gear_state_target( Gear_control_a1::GEAR_STATE_TARGET_INVALID); break; } default: { gear_control_a1_->set_gear_state_target( Gear_control_a1::GEAR_STATE_TARGET_P); break; } } } // brake with brake pedal // pedal:0.00~99.99, unit:percentage void ZhongyunController::Brake(double pedal) { if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE && driving_mode() != Chassis::AUTO_SPEED_ONLY) { AINFO << "The current drive mode does not need to set brake pedal."; return; } brake_control_a4_->set_brake_torque(pedal); } // drive with throttle pedal // pedal:0.00~99.99 unit:percentage void ZhongyunController::Throttle(double pedal) { if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE && driving_mode() != Chassis::AUTO_SPEED_ONLY) { AINFO << "The current drive mode does not need to set throttle pedal."; return; } torque_control_a3_->set_driven_torque(pedal); } // confirm the car is driven by acceleration command or throttle/brake pedal // drive with acceleration/deceleration // acc:-7.0 ~ 5.0, unit:m/s^2 void ZhongyunController::Acceleration(double acc) { if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE && driving_mode() != Chassis::AUTO_SPEED_ONLY) { AINFO << "The current drive mode does not need to set acceleration."; return; } // None } // zhongyun default, -30% ~ 30%, left:+, right:- // need to be compatible with control module, so reverse // steering with old angle speed // angle:-99.99~0.00~99.99, unit:%, left:-, right:+ void ZhongyunController::Steer(double angle) { if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE && driving_mode() != Chassis::AUTO_STEER_ONLY) { AINFO << "The current driving mode does not need to set steer."; return; } const double real_angle = vehicle_params_.max_steer_angle() / M_PI * 180 * angle / 100.0; steering_control_a2_->set_steering_target(real_angle); } // steering with new angle speed // zhongyun has no angle_speed // angle:-30~30, unit:%, left:+, right:- void ZhongyunController::Steer(double angle, double angle_spd) { if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE && driving_mode() != Chassis::AUTO_STEER_ONLY) { AINFO << "The current driving mode does not need to set steer."; return; } const double real_angle = vehicle_params_.max_steer_angle() / M_PI * 180 * angle / 100.0; steering_control_a2_->set_steering_target(real_angle); } void ZhongyunController::SetEpbBreak(const ControlCommand& command) { if (command.parking_brake()) { parking_control_a5_->set_parking_target( Parking_control_a5::PARKING_TARGET_PARKING_TRIGGER); } else { parking_control_a5_->set_parking_target( Parking_control_a5::PARKING_TARGET_RELEASE); } } void ZhongyunController::SetBeam(const ControlCommand& command) { if (command.signal().high_beam()) { // None } else if (command.signal().low_beam()) { // None } else { // None } } void ZhongyunController::SetHorn(const ControlCommand& command) { if (command.signal().horn()) { // None } else { // None } } void ZhongyunController::SetTurningSignal(const ControlCommand& command) { // Set Turn Signal // None } void ZhongyunController::ResetProtocol() { message_manager_->ResetSendMessages(); } bool ZhongyunController::CheckChassisError() { Zhongyun chassis_detail; message_manager_->GetSensorData(&chassis_detail); if (!chassis_detail.has_check_response()) { AERROR_EVERY(100) << "ChassisDetail has NO zhongyun vehicle info." << chassis_detail.DebugString(); return false; } // check steer error if (chassis_detail.has_error_state_e1() && chassis_detail.error_state_e1().has_steering_error_code()) { if (chassis_detail.error_state_e1().steering_error_code() == Error_state_e1::STEERING_ERROR_CODE_ERROR) { return true; } } // check ems error if (chassis_detail.has_error_state_e1() && chassis_detail.error_state_e1().has_driven_error_code()) { if (chassis_detail.error_state_e1().driven_error_code() == Error_state_e1::DRIVEN_ERROR_CODE_ERROR) { return true; } } // check eps error if (chassis_detail.has_error_state_e1() && chassis_detail.error_state_e1().has_brake_error_code()) { if (chassis_detail.error_state_e1().brake_error_code() == Error_state_e1::BRAKE_ERROR_CODE_ERROR) { return true; } } // check gear error if (chassis_detail.has_error_state_e1() && chassis_detail.error_state_e1().has_gear_error_msg()) { if (chassis_detail.error_state_e1().gear_error_msg() == Error_state_e1::GEAR_ERROR_MSG_ERROR) { return true; } } // check parking error if (chassis_detail.has_error_state_e1() && chassis_detail.error_state_e1().has_parking_error_code()) { if (chassis_detail.error_state_e1().parking_error_code() == Error_state_e1::PARKING_ERROR_CODE_ERROR) { return true; } } return false; } void ZhongyunController::SecurityDogThreadFunc() { int32_t vertical_ctrl_fail = 0; int32_t horizontal_ctrl_fail = 0; if (can_sender_ == nullptr) { AERROR << "Failed to run SecurityDogThreadFunc() because can_sender_ is " "nullptr."; return; } while (!can_sender_->IsRunning()) { std::this_thread::yield(); } std::chrono::duration<double, std::micro> default_period{50000}; int64_t start = 0; int64_t end = 0; while (can_sender_->IsRunning()) { start = ::apollo::cyber::Time::Now().ToMicrosecond(); const Chassis::DrivingMode mode = driving_mode(); bool emergency_mode = false; // 1. horizontal control check if ((mode == Chassis::COMPLETE_AUTO_DRIVE || mode == Chassis::AUTO_STEER_ONLY) && !CheckResponse(CHECK_RESPONSE_STEER_UNIT_FLAG, false)) { ++horizontal_ctrl_fail; if (horizontal_ctrl_fail >= kMaxFailAttempt) { emergency_mode = true; AINFO << "Driving_mode is into emergency by steer manual intervention"; set_chassis_error_code(Chassis::MANUAL_INTERVENTION); } } else { horizontal_ctrl_fail = 0; } // 2. vertical control check if ((mode == Chassis::COMPLETE_AUTO_DRIVE || mode == Chassis::AUTO_SPEED_ONLY) && !CheckResponse(CHECK_RESPONSE_SPEED_UNIT_FLAG, false)) { ++vertical_ctrl_fail; if (vertical_ctrl_fail >= kMaxFailAttempt) { emergency_mode = true; AINFO << "Driving_mode is into emergency by speed manual intervention"; set_chassis_error_code(Chassis::MANUAL_INTERVENTION); } } else { vertical_ctrl_fail = 0; } if (CheckChassisError()) { set_chassis_error_code(Chassis::CHASSIS_ERROR); emergency_mode = true; } if (emergency_mode && mode != Chassis::EMERGENCY_MODE) { set_driving_mode(Chassis::EMERGENCY_MODE); message_manager_->ResetSendMessages(); can_sender_->Update(); } end = ::apollo::cyber::Time::Now().ToMicrosecond(); std::chrono::duration<double, std::micro> elapsed{end - start}; if (elapsed < default_period) { std::this_thread::sleep_for(default_period - elapsed); } else { AERROR << "Too much time consumption in ZhongyunController looping process:" << elapsed.count(); } } } bool ZhongyunController::CheckResponse(const int32_t flags, bool need_wait) { // for Zhongyun, CheckResponse commonly takes 300ms. We leave a 100ms buffer // for it. int32_t retry_num = 20; Zhongyun chassis_detail; bool is_eps_online = false; bool is_vcu_online = false; bool is_esp_online = false; do { if (message_manager_->GetSensorData(&chassis_detail) != ErrorCode::OK) { AERROR_EVERY(100) << "get chassis detail failed."; return false; } bool check_ok = true; if (flags & CHECK_RESPONSE_STEER_UNIT_FLAG) { is_eps_online = chassis_detail.has_check_response() && chassis_detail.check_response().has_is_eps_online() && chassis_detail.check_response().is_eps_online(); check_ok = check_ok && is_eps_online; } if (flags & CHECK_RESPONSE_SPEED_UNIT_FLAG) { is_vcu_online = chassis_detail.has_check_response() && chassis_detail.check_response().has_is_vcu_online() && chassis_detail.check_response().is_vcu_online(); is_esp_online = chassis_detail.has_check_response() && chassis_detail.check_response().has_is_esp_online() && chassis_detail.check_response().is_esp_online(); check_ok = check_ok && is_vcu_online && is_esp_online; } if (need_wait) { --retry_num; std::this_thread::sleep_for( std::chrono::duration<double, std::milli>(20)); } if (check_ok) { return true; } else { AINFO << "Need to check response again."; } } while (need_wait && retry_num); AINFO << "check_response fail: is_eps_online:" << is_eps_online << ", is_vcu_online:" << is_vcu_online << ", is_esp_online:" << is_esp_online; return false; } void ZhongyunController::set_chassis_error_mask(const int32_t mask) { std::lock_guard<std::mutex> lock(chassis_mask_mutex_); chassis_error_mask_ = mask; } int32_t ZhongyunController::chassis_error_mask() { std::lock_guard<std::mutex> lock(chassis_mask_mutex_); return chassis_error_mask_; } Chassis::ErrorCode ZhongyunController::chassis_error_code() { std::lock_guard<std::mutex> lock(chassis_error_code_mutex_); return chassis_error_code_; } void ZhongyunController::set_chassis_error_code( const Chassis::ErrorCode& error_code) { std::lock_guard<std::mutex> lock(chassis_error_code_mutex_); chassis_error_code_ = error_code; } } // namespace zhongyun } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun/BUILD
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("//tools/install:install.bzl", "install", "install_files", "install_src_files") load("//tools:cpplint.bzl", "cpplint") package(default_visibility = ["//visibility:public"]) CANBUS_COPTS = ["-DMODULE_NAME=\\\"canbus\\\""] cc_library( name = "zhongyun_vehicle_factory", srcs = ["zhongyun_vehicle_factory.cc"], hdrs = ["zhongyun_vehicle_factory.h"], copts = CANBUS_COPTS, alwayslink = True, deps = [ ":zhongyun_controller", ":zhongyun_message_manager", "//modules/canbus/common:canbus_gflags", "//modules/common/adapters:adapter_gflags", "//modules/common/status", "//modules/canbus/vehicle:abstract_vehicle_factory", "//modules/drivers/canbus:sensor_canbus_lib", ], ) cc_binary( name = "libzhongyun_vehicle_factory_lib.so", linkshared = True, linkstatic = True, deps = [":zhongyun_vehicle_factory"], ) cc_library( name = "zhongyun_message_manager", srcs = ["zhongyun_message_manager.cc"], hdrs = ["zhongyun_message_manager.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/zhongyun/proto:zhongyun_cc_proto", "//modules/canbus_vehicle/zhongyun/protocol:canbus_zhongyun_protocol", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_library( name = "zhongyun_controller", srcs = ["zhongyun_controller.cc"], hdrs = ["zhongyun_controller.h"], copts = CANBUS_COPTS, deps = [ ":zhongyun_message_manager", "//modules/common_msgs/chassis_msgs:chassis_cc_proto", "//modules/canbus/vehicle:vehicle_controller_base", "//modules/canbus_vehicle/zhongyun/protocol:canbus_zhongyun_protocol", "//modules/drivers/canbus/can_comm:can_sender", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "zhongyun_message_manager_test", size = "small", srcs = ["zhongyun_message_manager_test.cc"], data = ["//modules/canbus:test_data"], deps = [ ":zhongyun_message_manager", "@com_google_googletest//:gtest_main", ], ) cc_test( name = "zhongyun_vehicle_factory_test", size = "small", srcs = ["zhongyun_vehicle_factory_test.cc"], data = ["//modules/canbus:test_data"], linkstatic = True, deps = [ ":zhongyun_vehicle_factory", "@com_google_googletest//:gtest_main", ], ) cc_test( name = "zhongyun_controller_test", size = "small", srcs = ["zhongyun_controller_test.cc"], data = ["//modules/canbus:test_data"], deps = [ ":zhongyun_controller", "//modules/common/util", "@com_google_googletest//:gtest_main", ], ) install( name = "install", library_dest = "canbus-vehicle-zhongyun/lib", data_dest = "canbus-vehicle-zhongyun", data = [ ":runtime_data", ":cyberfile.xml", ":canbus-vehicle-zhongyun.BUILD", ], targets = [ ":libzhongyun_vehicle_factory_lib.so", ], deps = [ ":pb_zhongyun", ":pb_hdrs", ], ) install( name = "pb_hdrs", data_dest = "canbus-vehicle-zhongyun/include", data = [ "//modules/canbus_vehicle/zhongyun/proto:zhongyun_cc_proto", ], ) install_files( name = "pb_zhongyun", dest = "canbus-vehicle-zhongyun", files = [ "//modules/canbus_vehicle/zhongyun/proto:zhongyun_py_pb2", ], ) filegroup( name = "runtime_data", srcs = glob([ "testdata/**", ]), ) install_src_files( name = "install_src", deps = [ ":install_zhongyun_src", ":install_zhongyun_hdrs" ], ) install_src_files( name = "install_zhongyun_src", src_dir = ["."], dest = "canbus-vehicle-zhongyun/src", filter = "*", ) install_src_files( name = "install_zhongyun_hdrs", src_dir = ["."], dest = "canbus-vehicle-zhongyun/include", filter = "*.h", ) cpplint()
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun/zhongyun_vehicle_factory_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/zhongyun/zhongyun_vehicle_factory.h" #include "gtest/gtest.h" #include "modules/canbus/proto/canbus_conf.pb.h" #include "modules/canbus/proto/vehicle_parameter.pb.h" #include "cyber/common/file.h" namespace apollo { namespace canbus { class ZhongyunVehicleFactoryTest : public ::testing::Test { public: virtual void SetUp() { std::string canbus_conf_file = "/apollo/modules/canbus_vehicle/zhongyun/testdata/" "zhongyun_canbus_conf_test.pb.txt"; cyber::common::GetProtoFromFile(canbus_conf_file, &canbus_conf_); params_ = canbus_conf_.vehicle_parameter(); params_.set_brand(apollo::common::ZHONGYUN); zhongyun_factory_.SetVehicleParameter(params_); } virtual void TearDown() {} protected: ZhongyunVehicleFactory zhongyun_factory_; CanbusConf canbus_conf_; VehicleParameter params_; }; TEST_F(ZhongyunVehicleFactoryTest, Init) { apollo::cyber::Init("vehicle_factory_test"); EXPECT_EQ(zhongyun_factory_.Init(&canbus_conf_), true); } } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun/testdata/zhongyun_canbus_conf_test.pb.txt
vehicle_parameter { brand: ZHONGYUN max_enable_fail_attempt: 5 driving_mode: COMPLETE_AUTO_DRIVE } can_card_parameter { brand:SOCKET_CAN_RAW type: PCI_CARD channel_id: CHANNEL_ID_ZERO } enable_debug_mode: false
0
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun/proto/zhongyun.proto
syntax = "proto2"; package apollo.canbus; message Gear_control_a1 { // Control Message enum Gear_state_targetType { GEAR_STATE_TARGET_P = 1; GEAR_STATE_TARGET_N = 2; GEAR_STATE_TARGET_D = 3; GEAR_STATE_TARGET_R = 4; GEAR_STATE_TARGET_INVALID = 5; } enum Gear_enable_controlType { GEAR_ENABLE_CONTROL_GEAR_MANUALCONTROL = 0; GEAR_ENABLE_CONTROL_GEAR_AUTOCONTROL = 1; } // [] [0|5] optional Gear_state_targetType gear_state_target = 1; // [] [0|1] optional Gear_enable_controlType gear_enable_control = 2; } message Torque_control_a3 { // Control Message enum Driven_enable_controlType { DRIVEN_ENABLE_CONTROL_DRIVE_MANUAL = 0; DRIVEN_ENABLE_CONTROL_DRIVE_AUTO = 1; } // [%] [0|100] optional double driven_torque = 1; // [] [0|1] optional Driven_enable_controlType driven_enable_control = 2; } message Steering_control_a2 { // Control Message enum Steering_enable_controlType { STEERING_ENABLE_CONTROL_STEERING_MANUALCONTROL = 0; STEERING_ENABLE_CONTROL_STEERING_AUTOCONTROL = 1; } // [deg] [-30|30] optional double steering_target = 1; // [] [0|1] optional Steering_enable_controlType steering_enable_control = 2; } message Parking_control_a5 { // Control Message enum Parking_targetType { PARKING_TARGET_RELEASE = 0; PARKING_TARGET_PARKING_TRIGGER = 1; } enum Parking_enable_controlType { PARKING_ENABLE_CONTROL_PARKING_MANUALCONTROL = 0; PARKING_ENABLE_CONTROL_PARKING_AUTOCONTROL = 1; } // [] [0|1] optional Parking_targetType parking_target = 1; // [] [0|1] optional Parking_enable_controlType parking_enable_control = 2; } message Brake_control_a4 { // Control Message enum Brake_enable_controlType { BRAKE_ENABLE_CONTROL_BRAKE_MANUAL = 0; BRAKE_ENABLE_CONTROL_BRAKE_AUTO = 1; } // [%] [0|100] optional double brake_torque = 1; // [] [0|1] optional Brake_enable_controlType brake_enable_control = 2; } message Enable_state_feedback_c3 { // Report Message enum Parking_enable_stateType { PARKING_ENABLE_STATE_PARKING_MANUALCONTROL = 0; PARKING_ENABLE_STATE_PARKING_AUTOCONTROL = 1; PARKING_ENABLE_STATE_PARKING_TAKEOVER = 2; } enum Steering_enable_stateType { STEERING_ENABLE_STATE_STEERING_MANUALCONTROL = 0; STEERING_ENABLE_STATE_STEERING_AUTOCONTROL = 1; STEERING_ENABLE_STATE_STEERING_MANUAL_TAKEOVER = 2; } enum Gear_enable_actualType { GEAR_ENABLE_ACTUAL_GEAR_MANUALCONTROL = 0; GEAR_ENABLE_ACTUAL_GEAR_AUTOCONTROL = 1; GEAR_ENABLE_ACTUAL_GEAR_MANUAL_TAKEOVER = 2; } enum Driven_enable_stateType { DRIVEN_ENABLE_STATE_DRIVE_MANUAL = 0; DRIVEN_ENABLE_STATE_DRIVE_AUTO = 1; DRIVEN_ENABLE_STATE_DRIVE_TAKEOVER = 2; } enum Brake_enable_stateType { BRAKE_ENABLE_STATE_BRAKE_MANUAL = 0; BRAKE_ENABLE_STATE_BRAKE_AUTO = 1; BRAKE_ENABLE_STATE_BRAKE_TAKEOVER = 2; } // [] [0|1] optional Parking_enable_stateType parking_enable_state = 1; // [] [0|2] optional Steering_enable_stateType steering_enable_state = 2; // [] [0|2] optional Gear_enable_actualType gear_enable_actual = 3; // [] [0|2] optional Driven_enable_stateType driven_enable_state = 4; // [] [0|2] optional Brake_enable_stateType brake_enable_state = 5; } message Vehicle_state_feedback_c1 { // Report Message enum Parking_actualType { PARKING_ACTUAL_RELEASE = 0; PARKING_ACTUAL_PARKING_TRIGGER = 1; } enum Gear_state_actualType { GEAR_STATE_ACTUAL_P = 1; GEAR_STATE_ACTUAL_N = 2; GEAR_STATE_ACTUAL_D = 3; GEAR_STATE_ACTUAL_R = 4; GEAR_STATE_ACTUAL_INVALID = 5; } // [] [0|1] optional Parking_actualType parking_actual = 1; // [%] [0|100] optional double brake_torque_feedback = 2; // [] [0|5] optional Gear_state_actualType gear_state_actual = 3; // [deg] [-40|40] optional double steering_actual = 4; // [kph] [0|35] optional double speed = 5; } message Error_state_e1 { // Report Message enum Brake_error_codeType { BRAKE_ERROR_CODE_NO_ERROR = 0; BRAKE_ERROR_CODE_ERROR = 1; } enum Driven_error_codeType { DRIVEN_ERROR_CODE_NO_ERROR = 0; DRIVEN_ERROR_CODE_ERROR = 1; } enum Steering_error_codeType { STEERING_ERROR_CODE_NO_ERROR = 0; STEERING_ERROR_CODE_ERROR = 1; } enum Parking_error_codeType { PARKING_ERROR_CODE_NO_ERROR = 0; PARKING_ERROR_CODE_ERROR = 1; } enum Gear_error_msgType { GEAR_ERROR_MSG_NO_ERROR = 0; GEAR_ERROR_MSG_ERROR = 1; } // [bit] [0|1] optional Brake_error_codeType brake_error_code = 1; // [bit] [0|1] optional Driven_error_codeType driven_error_code = 2; // [bit] [0|1] optional Steering_error_codeType steering_error_code = 3; // [bit] [0|1] optional Parking_error_codeType parking_error_code = 4; // [] [0|1] optional Gear_error_msgType gear_error_msg = 5; } message Vehicle_state_feedback_2_c4 { // Report Message // [rpm] [0|4500] optional int32 motor_speed = 1; // [%] [0|100] optional double driven_torque_feedback = 2; } // CheckResponseSignal message CheckResponseSignal { optional bool is_eps_online = 1 [default = false]; optional bool is_epb_online = 2 [default = false]; optional bool is_esp_online = 3 [default = false]; optional bool is_vtog_online = 4 [default = false]; optional bool is_scu_online = 5 [default = false]; optional bool is_switch_online = 6 [default = false]; optional bool is_vcu_online = 7 [default = false]; } message Zhongyun { optional Gear_control_a1 gear_control_a1 = 1; // control message optional Torque_control_a3 torque_control_a3 = 2; // control message optional Steering_control_a2 steering_control_a2 = 3; // control message optional Parking_control_a5 parking_control_a5 = 4; // control message optional Brake_control_a4 brake_control_a4 = 5; // control message optional Enable_state_feedback_c3 enable_state_feedback_c3 = 6; // report message optional Vehicle_state_feedback_c1 vehicle_state_feedback_c1 = 7; // report message optional Error_state_e1 error_state_e1 = 8; // report message optional Vehicle_state_feedback_2_c4 vehicle_state_feedback_2_c4 = 9; // report message optional CheckResponseSignal check_response = 100; }
0
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun/proto/BUILD
## Auto generated by `proto_build_generator.py` load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_cc//cc:defs.bzl", "cc_proto_library") load("//tools:python_rules.bzl", "py_proto_library") package(default_visibility = ["//visibility:public"]) cc_proto_library( name = "zhongyun_cc_proto", deps = [ ":zhongyun_proto", ], ) proto_library( name = "zhongyun_proto", srcs = ["zhongyun.proto"], ) py_proto_library( name = "zhongyun_py_pb2", deps = [ ":zhongyun_proto", ], )
0
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun/protocol/vehicle_state_feedback_2_c4_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/zhongyun/protocol/vehicle_state_feedback_2_c4.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace zhongyun { class Vehiclestatefeedback2c4Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Vehiclestatefeedback2c4Test, reset) { Vehiclestatefeedback2c4 feedback_; int32_t length = 8; Zhongyun cd; uint8_t bytes[8] = {0x88, 0x44, 0x22, 0x11, 0x11, 0x12, 0x13, 0x14}; feedback_.Parse(bytes, length, &cd); auto &feedbackinfo = cd.vehicle_state_feedback_2_c4(); EXPECT_DOUBLE_EQ(feedbackinfo.motor_speed(), 17544); EXPECT_DOUBLE_EQ(feedbackinfo.driven_torque_feedback(), 219.3); } } // namespace zhongyun } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun/protocol/brake_control_a4.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/zhongyun/protocol/brake_control_a4.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace zhongyun { using ::apollo::drivers::canbus::Byte; const int32_t Brakecontrola4::ID = 0xA4; // public Brakecontrola4::Brakecontrola4() { Reset(); } uint32_t Brakecontrola4::GetPeriod() const { // TODO(ChaoM) : modify every protocol's period manually static const uint32_t PERIOD = 20 * 1000; return PERIOD; } void Brakecontrola4::UpdateData(uint8_t* data) { set_p_brake_torque(data, brake_torque_); set_p_brake_enable_control(data, brake_enable_control_); } void Brakecontrola4::Reset() { // TODO(ChaoM) : you should check this manually brake_torque_ = 0.0; brake_enable_control_ = Brake_control_a4::BRAKE_ENABLE_CONTROL_BRAKE_MANUAL; } Brakecontrola4* Brakecontrola4::set_brake_torque(double brake_torque) { brake_torque_ = brake_torque; return this; } // config detail: {'name': 'brake_torque', 'offset': 0.0, 'precision': 0.05, // 'len': 16, 'is_signed_var': False, 'physical_range': '[0|100]', 'bit': 8, // 'type': 'double', 'order': 'intel', 'physical_unit': '%'} void Brakecontrola4::set_p_brake_torque(uint8_t* data, double brake_torque) { brake_torque = ProtocolData::BoundedValue(0.0, 100.0, brake_torque); int x = static_cast<int>(brake_torque / 0.050000); uint8_t t = 0; t = static_cast<uint8_t>(x & 0xFF); Byte to_set0(data + 1); to_set0.set_value(t, 0, 8); x >>= 8; t = static_cast<uint8_t>(x & 0xFF); Byte to_set1(data + 2); to_set1.set_value(t, 0, 8); } Brakecontrola4* Brakecontrola4::set_brake_enable_control( Brake_control_a4::Brake_enable_controlType brake_enable_control) { brake_enable_control_ = brake_enable_control; return this; } // config detail: {'name': 'Brake_Enable_control', 'enum': // {0: 'BRAKE_ENABLE_CONTROL_BRAKE_MANUAL', // 1: 'BRAKE_ENABLE_CONTROL_BRAKE_AUTO'}, 'precision': 1.0, 'len': 8, // 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|1]', 'bit': 0, // 'type': 'enum', 'order': 'intel', 'physical_unit': ''} void Brakecontrola4::set_p_brake_enable_control( uint8_t* data, Brake_control_a4::Brake_enable_controlType brake_enable_control) { int x = brake_enable_control; Byte to_set(data + 0); to_set.set_value(static_cast<uint8_t>(x), 0, 8); } } // namespace zhongyun } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun/protocol/error_state_e1.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #include "modules/canbus_vehicle/zhongyun/protocol/error_state_e1.h" #include "glog/logging.h" #include "modules/drivers/canbus/common/byte.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace zhongyun { using ::apollo::drivers::canbus::Byte; Errorstatee1::Errorstatee1() {} const int32_t Errorstatee1::ID = 0xE1; void Errorstatee1::Parse(const std::uint8_t* bytes, int32_t length, Zhongyun* chassis) const { chassis->mutable_error_state_e1()->set_brake_error_code( brake_error_code(bytes, length)); chassis->mutable_error_state_e1()->set_driven_error_code( driven_error_code(bytes, length)); chassis->mutable_error_state_e1()->set_steering_error_code( steering_error_code(bytes, length)); chassis->mutable_error_state_e1()->set_parking_error_code( parking_error_code(bytes, length)); chassis->mutable_error_state_e1()->set_gear_error_msg( gear_error_msg(bytes, length)); } // config detail: {'name': 'brake_error_code', 'enum': {0: // 'BRAKE_ERROR_CODE_NO_ERROR', 1: 'BRAKE_ERROR_CODE_ERROR'}, 'precision': 1.0, // 'len': 8, 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|1]', // 'bit': 32, 'type': 'enum', 'order': 'intel', 'physical_unit': 'bit'} Error_state_e1::Brake_error_codeType Errorstatee1::brake_error_code( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(0, 8); Error_state_e1::Brake_error_codeType ret = static_cast<Error_state_e1::Brake_error_codeType>(x); return ret; } // config detail: {'name': 'driven_error_code', 'enum': {0: // 'DRIVEN_ERROR_CODE_NO_ERROR', 1: 'DRIVEN_ERROR_CODE_ERROR'}, // 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 24, 'type': 'enum', 'order': 'intel', // 'physical_unit': 'bit'} Error_state_e1::Driven_error_codeType Errorstatee1::driven_error_code( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 3); int32_t x = t0.get_byte(0, 8); Error_state_e1::Driven_error_codeType ret = static_cast<Error_state_e1::Driven_error_codeType>(x); return ret; } // config detail: {'name': 'steering_error_code', 'enum': {0: // 'STEERING_ERROR_CODE_NO_ERROR', 1: 'STEERING_ERROR_CODE_ERROR'}, // 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 16, 'type': 'enum', 'order': 'intel', // 'physical_unit': 'bit'} Error_state_e1::Steering_error_codeType Errorstatee1::steering_error_code( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 2); int32_t x = t0.get_byte(0, 8); Error_state_e1::Steering_error_codeType ret = static_cast<Error_state_e1::Steering_error_codeType>(x); return ret; } // config detail: {'name': 'parking_error_code', 'enum': {0: // 'PARKING_ERROR_CODE_NO_ERROR', 1: 'PARKING_ERROR_CODE_ERROR'}, // 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|1]', 'bit': 8, 'type': 'enum', 'order': 'intel', // 'physical_unit': 'bit'} Error_state_e1::Parking_error_codeType Errorstatee1::parking_error_code( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(0, 8); Error_state_e1::Parking_error_codeType ret = static_cast<Error_state_e1::Parking_error_codeType>(x); return ret; } // config detail: {'name': 'gear_error_msg', 'enum': {0: // 'GEAR_ERROR_MSG_NO_ERROR', 1: 'GEAR_ERROR_MSG_ERROR'}, 'precision': 1.0, // 'len': 8, 'is_signed_var': False, 'offset': 0.0, 'physical_range': '[0|1]', // 'bit': 0, 'type': 'enum', 'order': 'intel', 'physical_unit': ''} Error_state_e1::Gear_error_msgType Errorstatee1::gear_error_msg( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 8); Error_state_e1::Gear_error_msgType ret = static_cast<Error_state_e1::Gear_error_msgType>(x); return ret; } } // namespace zhongyun } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun
apollo_public_repos/apollo/modules/canbus_vehicle/zhongyun/protocol/vehicle_state_feedback_2_c4.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ #pragma once #include "modules/canbus_vehicle/zhongyun/proto/zhongyun.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace zhongyun { class Vehiclestatefeedback2c4 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Zhongyun> { public: static const int32_t ID; Vehiclestatefeedback2c4(); void Parse(const std::uint8_t* bytes, int32_t length, Zhongyun* chassis) const override; private: // config detail: {'name': 'motor_speed', 'offset': 0.0, 'precision': 1.0, // 'len': 16, 'is_signed_var': True, 'physical_range': '[-3000|3000]', 'bit': // 0, 'type': 'int', 'order': 'intel', 'physical_unit': 'rpm'} int motor_speed(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'driven_torque_feedback', 'offset': 0.0, // 'precision': 0.05, 'len': 16, 'is_signed_var': False, 'physical_range': // '[0|100]', 'bit': 16, 'type': 'double', 'order': 'intel', 'physical_unit': // '%'} double driven_torque_feedback(const std::uint8_t* bytes, const int32_t length) const; }; } // namespace zhongyun } // namespace canbus } // namespace apollo
0