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/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/throttleinfo_75.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/throttleinfo_75.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::Byte; const int32_t Throttleinfo75::ID = 0x75; void Throttleinfo75::Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const { chassis_detail->mutable_ems()->set_engine_rpm(engine_rpm(bytes, length)); chassis_detail->mutable_gas()->set_accelerator_pedal( acc_pedal_percent(bytes, length)); chassis_detail->mutable_gas()->set_accelerator_pedal_rate( acc_pedal_rate(bytes, length)); } double Throttleinfo75::engine_rpm(const std::uint8_t *bytes, int32_t length) const { Byte frame_high(bytes + 1); int32_t high = frame_high.get_byte(0, 8); Byte frame_low(bytes + 0); int32_t low = frame_low.get_byte(0, 8); int32_t value = (high << 8) | low; return value * 0.25; } double Throttleinfo75::acc_pedal_percent(const std::uint8_t *bytes, int32_t length) const { Byte frame_high(bytes + 3); int32_t high = frame_high.get_byte(0, 2); Byte frame_low(bytes + 2); int32_t low = frame_low.get_byte(0, 8); int32_t value = (high << 8) | low; return value * 0.1; } double Throttleinfo75::acc_pedal_rate(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 4); int32_t x = frame.get_byte(0, 8); if (x > 0x3F) { x -= 0x100; } return x * 0.04; } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/throttle_63.h
/****************************************************************************** * Copyright 2017 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 throttle_63.h * @brief the class of Throttle63 (for lincoln vehicle) */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Throttle63 * * @brief one of the protocol data of lincoln vehicle */ class Throttle63 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /* * @brief parse received data * @param bytes a pointer to the input bytes * @param length the length of the input bytes * @param chassis_detail the parsed chassis_detail */ virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const; /** * @brief calculate pedal input based on byte array. * config detail: {'name': 'pi', 'offset': 0.0, 'precision': * 1.52590218966964e-05, 'len': 16, 'f_type': 'value', 'is_signed_var': False, * 'physical_range': '[0|1]', 'bit': 0, 'type': 'double', 'order': 'intel', * 'physical_unit': '"%"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of byte input */ double pedal_input(const std::uint8_t *bytes, int32_t length) const; /** * @brief calculate pedal command based on byte array. * config detail: {'name': 'pc', 'offset': 0.0, 'precision': * 1.52590218966964e-05, 'len': 16, 'f_type': 'value', 'is_signed_var': False, * 'physical_range': '[0|1]', 'bit': 16, 'type': 'double', 'order': 'intel', * 'physical_unit': '"%"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of pedal command */ double pedal_cmd(const std::uint8_t *bytes, int32_t length) const; /** * @brief calculate pedal output based on byte array. * config detail: {'name': 'po', 'offset': 0.0, 'precision': * 1.52590218966964e-05, 'len': 16, 'f_type': 'value', 'is_signed_var': False, * 'physical_range': '[0|1]', 'bit': 32, 'type': 'double', 'order': 'intel', * 'physical_unit': '"%"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of pedal output */ double pedal_output(const std::uint8_t *bytes, int32_t length) const; /** * @brief calculate watchdog counter source based on byte array. * config detail: {'name': 'wdcsrc', 'offset': 0.0, 'precision': 1.0, 'len': * 4, 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 52, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of watchdog counter source */ int32_t watchdog_counter_source(const std::uint8_t *bytes, int32_t length) const; /** * @brief check enabled bit based on byte array. * config detail: {'name': 'en', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 56, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of enabled bit */ bool is_enabled(const std::uint8_t *bytes, int32_t length) const; /** * @brief check driver override bit based on byte array. * config detail: {'name': 'override', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 57, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of driver override */ bool is_driver_override(const std::uint8_t *bytes, int32_t length) const; /** * @brief check driver activity bit based on byte array. * config detail: {'name': 'driver', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 58, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of driver activity */ bool is_driver_activity(const std::uint8_t *bytes, int32_t length) const; /** * @brief check watchdog counter fault bit based on byte array. * config detail: {'name': 'fltwdc', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 59, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of watchdog counter fault bit */ bool is_watchdog_counter_fault(const std::uint8_t *bytes, int32_t length) const; /** * @brief check channel 1 fault bit based on byte array. * config detail: {'name': 'flt1', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 60, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of channel 1 fault bit */ bool is_channel_1_fault(const std::uint8_t *bytes, int32_t length) const; /** * @brief check channel 2 fault bit based on byte array. * config detail: {'name': 'flt2', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 61, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of channel 2 fault bit */ bool is_channel_2_fault(const std::uint8_t *bytes, int32_t length) const; /** * @brief check connector fault bit based on byte array. * config detail: {'name': 'fltcon', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 63, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of connector fault bit */ bool is_connector_fault(const std::uint8_t *bytes, int32_t length) const; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/gyro_6c.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/gyro_6c.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::Byte; const int32_t Gyro6c::ID = 0x6C; void Gyro6c::Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const { chassis_detail->mutable_vehicle_spd()->set_roll_rate( roll_rate(bytes, length)); chassis_detail->mutable_vehicle_spd()->set_yaw_rate(yaw_rate(bytes, length)); // why chassis_detail->mutable_vehicle_spd()->set_is_yaw_rate_valid(true); } double Gyro6c::roll_rate(const std::uint8_t *bytes, int32_t length) const { Byte high_frame(bytes + 1); int32_t high = high_frame.get_byte(0, 8); Byte low_frame(bytes + 0); int32_t low = low_frame.get_byte(0, 8); int32_t value = (high << 8) | low; if (value > 0x7FFF) { value -= 0x10000; } return value * 0.000200; } double Gyro6c::yaw_rate(const std::uint8_t *bytes, int32_t length) const { Byte high_frame(bytes + 3); int32_t high = high_frame.get_byte(0, 8); Byte low_frame(bytes + 2); int32_t low = low_frame.get_byte(0, 8); int32_t value = (high << 8) | low; if (value > 0x7FFF) { value -= 0x10000; } return value * 0.000200; } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/tirepressure_71.h
/****************************************************************************** * Copyright 2017 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 tirepressure_71.h * @brief the class of Tirepressure71 (for lincoln vehicle) */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Tirepressure71 * * @brief one of the protocol data of lincoln vehicle */ class Tirepressure71 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /* * @brief parse received data * @param bytes a pointer to the input bytes * @param length the length of the input bytes * @param chassis_detail the parsed chassis_detail */ virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const; private: /** * @brief calculate front left tire based on byte array. * config detail: {'name': 'fl', 'offset': 0.0, 'precision': 1.0, 'len': 16, * 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 0, 'type': 'int', 'order': 'intel', 'physical_unit': '"kPa"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of front left tire */ int32_t front_left_tire(const std::uint8_t *bytes, int32_t length) const; /** * @brief calculate front right tire based on byte array. * config detail: {'name': 'fr', 'offset': 0.0, 'precision': 1.0, 'len': 16, * 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 16, 'type': 'int', 'order': 'intel', 'physical_unit': '"kPa"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of front right tire */ int32_t front_right_tire(const std::uint8_t *bytes, int32_t length) const; /** * @brief calculate rear left tire based on byte array. * config detail: {'name': 'rl', 'offset': 0.0, 'precision': 1.0, 'len': 16, * 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 32, 'type': 'int', 'order': 'intel', 'physical_unit': '"kPa"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of rear left tire */ int32_t rear_left_tire(const std::uint8_t *bytes, int32_t length) const; /** * @brief calculate rear right tire based on byte array. * config detail: {'name': 'rr', 'offset': 0.0, 'precision': 1.0, 'len': 16, * 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 48, 'type': 'int', 'order': 'intel', 'physical_unit': '"kPa"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of rear right tire */ int32_t rear_right_tire(const std::uint8_t *bytes, int32_t length) const; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/steering_65.h
/****************************************************************************** * Copyright 2017 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 steering_65.h * @brief the class of steering_65.h (for lincoln vehicle) */ #pragma once #include <sys/time.h> #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Steering65 * * @brief one of the protocol data of lincoln vehicle */ class Steering65 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /* * @brief parse received data * @param bytes a pointer to the input bytes * @param length the length of the input bytes * @param chassis_detail the parsed chassis_detail */ virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const; /* * @brief parse received data * @param bytes a pointer to the input bytes * @param length the length of the input bytes * @param timestamp the timestamp of input data * @param chassis_detail the parsed chassis_detail */ virtual void Parse(const std::uint8_t *bytes, int32_t length, const struct timeval &timestamp, Lincoln *chassis_detail) const; /** * @brief calculate steering angle based on byte array. * config detail: {'name': 'angle', 'offset': 0.0, 'precision': 0.1, 'len': * 16, 'f_type': 'value', 'is_signed_var': True, 'physical_range': * '[-470|470]', 'bit': 0, 'type': 'double', 'order': 'intel', * 'physical_unit': '"degrees"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of steering angle */ double steering_angle(const std::uint8_t *bytes, int32_t length) const; /** * @brief calculate reported steering angle command based on byte array. * config detail: {'name': 'cmd', 'offset': 0.0, 'precision': 0.1, 'len': 16, * 'f_type': 'value', 'is_signed_var': True, 'physical_range': '[-470|470]', * 'bit': 16, 'type': 'double', 'order': 'intel', 'physical_unit': * '"degrees"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of reported steering angle command */ double reported_steering_angle_cmd(const std::uint8_t *bytes, int32_t length) const; /** * @brief calculate vehicle speed based on byte array. * config detail: {'name': 'speed', 'offset': 0.0, 'precision': 0.01, 'len': * 16, 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 32, 'type': 'double', 'order': 'intel', 'physical_unit': '"kph"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of vehicle speed */ double vehicle_speed(const std::uint8_t *bytes, int32_t length) const; /** * @brief calculate epas torque based on byte array. * config detail: {'name': 'torque', 'offset': 0.0, 'precision': 0.0625, * 'len': 8, 'f_type': 'value', 'is_signed_var': True, 'physical_range': * '[0|0]', 'bit': 48, 'type': 'double', 'order': 'intel', 'physical_unit': * '"Nm"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of epas torque */ double epas_torque(const std::uint8_t *bytes, int32_t length) const; /** * @brief check enabled bit based on byte array. * config detail: {'name': 'en', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 56, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of enabled bit */ bool is_enabled(const std::uint8_t *bytes, int32_t length) const; /** * @brief check driver override bit based on byte array. * config detail: {'name': 'override', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 57, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of driver override */ bool is_driver_override(const std::uint8_t *bytes, int32_t length) const; /** * @brief check driver activity bit based on byte array. * config detail: {'name': 'driver', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 58, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of driver activity */ bool is_driver_activity(const std::uint8_t *bytes, int32_t length) const; /** * @brief check watchdog counter fault based on byte array. * config detail: {'name': 'fltwdc', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 59, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of watchdog counter fault */ bool is_watchdog_counter_fault(const std::uint8_t *bytes, int32_t length) const; /** * @brief check channel 1 fault bit based on byte array. * config detail: {'name': 'flt1', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 60, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of steering angle */ bool is_channel_1_fault(const std::uint8_t *bytes, int32_t length) const; /** * @brief check channel 2 fault bit based on byte array. * config detail: {'name': 'flt2', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 61, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of channel 2 fault bit */ bool is_channel_2_fault(const std::uint8_t *bytes, int32_t length) const; /** * @brief check calibration fault bit based on byte array. * config detail: {'name': 'fltcal', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 62, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of calibration fault bit */ bool is_calibration_fault(const std::uint8_t *bytes, int32_t length) const; /** * @brief check connector fault bit based on byte array. * config detail: {'name': 'fltcon', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 63, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of connector fault bit */ bool is_connector_fault(const std::uint8_t *bytes, int32_t length) const; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/brake_61_test.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/brake_61.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { TEST(Brake61Test, General) { uint8_t data[8] = {0x01, 0x02, 0x03, 0x04, 0x11, 0x12, 0x13, 0x14}; int32_t length = 8; Lincoln cd; Brake61 brake; brake.Parse(data, length, &cd); EXPECT_EQ(data[0], 0b00000001); EXPECT_EQ(data[1], 0b00000010); EXPECT_EQ(data[2], 0b00000011); EXPECT_EQ(data[3], 0b00000100); EXPECT_EQ(data[4], 0b00010001); EXPECT_EQ(data[5], 0b00010010); EXPECT_EQ(data[6], 0b00010011); EXPECT_EQ(data[7], 0b00010100); auto &brakeinfo = cd.brake(); EXPECT_DOUBLE_EQ(brakeinfo.brake_input(), 0.78278782330052543); EXPECT_DOUBLE_EQ(brakeinfo.brake_cmd(), 1.5671015487907205); EXPECT_DOUBLE_EQ(brakeinfo.brake_output(), 7.057297627222086); EXPECT_TRUE(brakeinfo.boo_input()); EXPECT_TRUE(brakeinfo.boo_cmd()); EXPECT_FALSE(brakeinfo.boo_output()); EXPECT_FALSE(brakeinfo.watchdog_applying_brakes()); EXPECT_EQ(brakeinfo.watchdog_source(), 1); EXPECT_FALSE(brakeinfo.brake_enabled()); EXPECT_FALSE(brakeinfo.driver_override()); EXPECT_TRUE(brakeinfo.driver_activity()); EXPECT_FALSE(brakeinfo.watchdog_fault()); EXPECT_TRUE(brakeinfo.channel_1_fault()); EXPECT_FALSE(brakeinfo.channel_2_fault()); EXPECT_FALSE(brakeinfo.boo_fault()); EXPECT_FALSE(brakeinfo.connector_fault()); EXPECT_TRUE(cd.check_response().is_esp_online()); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/turnsignal_68.h
/****************************************************************************** * Copyright 2017 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 turnsignal_68.h * @brief the class of Turnsignal68 (for lincoln vehicle) */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Turnsignal68 * * @brief one of the protocol data of lincoln vehicle */ class Turnsignal68 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /** * @brief get the data period * @return the value of data period */ virtual uint32_t GetPeriod() const; /** * @brief get the turn command * @return the turn command */ virtual int32_t turn_cmd() const; /** * @brief update the data * @param data a pointer to the data to be updated */ virtual void UpdateData(uint8_t *data); /** * @brief reset the private variables */ virtual void Reset(); /** * @brief set no-turn based on pedal command * @return a this pointer to the instance itself */ Turnsignal68 *set_turn_none(); /** * @brief set turn left based on pedal command * @return a this pointer to the instance itself */ Turnsignal68 *set_turn_left(); /** * @brief set turn right based on pedal command * @return a this pointer to the instance itself */ Turnsignal68 *set_turn_right(); private: /** * config detail: {'name': 'trncmd', 'offset': 0.0, 'precision': 1.0, 'len': * 2, 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 0, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} */ void set_turn_cmd_p(uint8_t *data, int32_t trncmd); private: int32_t turn_cmd_ = 0; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/misc_69.h
/****************************************************************************** * Copyright 2017 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 misc_69.h * @brief the class of Misc69 (for lincoln vehicle) */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Misc69 * * @brief one of the protocol data of lincoln vehicle */ class Misc69 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /* * @brief parse received data * @param bytes a pointer to the input bytes * @param length the length of the input bytes * @param timestamp the timestamp of input data * @param chassis_detail the parsed chassis_detail */ virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const; /** * @brief calculate the turn signal status based on byte array. * config detail: {'name': 'trnstat', 'offset': 0.0, 'precision': 1.0, 'len': * 2, 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 0, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of turn signal status */ int32_t turn_signal_status(const std::uint8_t *bytes, int32_t length) const; /** * @brief calculate the high beam status based on byte array. * config detail: {'name': 'hibeam', 'offset': 0.0, 'precision': 1.0, 'len': * 2, 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 2, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of high beam status */ int32_t high_beam_status(const std::uint8_t *bytes, int32_t length) const; /** * @brief calculate the wiper status based on byte array. * config detail: {'name': 'wiper', 'offset': 0.0, 'precision': 1.0, 'len': 4, * 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 4, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of wiper status */ int32_t wiper_status(const std::uint8_t *bytes, int32_t length) const; /** * @brief calculate the ambient light status based on byte array. * config detail: {'name': 'ambient', 'offset': 0.0, 'precision': 1.0, 'len': * 3, 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 8, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of ambient light */ int32_t ambient_light_status(const std::uint8_t *bytes, int32_t length) const; /** * @brief check acc on pressed bit based on byte array. * config detail: {'name': 'on', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 11, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of acc on pressed bit */ bool is_acc_on_pressed(const std::uint8_t *bytes, int32_t length) const; /** * @brief check acc off pressed bit based on byte array. * config detail: {'name': 'off', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 12, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of acc off pressed bit */ bool is_acc_off_pressed(const std::uint8_t *bytes, int32_t length) const; /** * @brief check acc resume pressed bit based on byte array. * config detail: {'name': 'res', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 13, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of acc resume pressed bit */ bool is_acc_resume_pressed(const std::uint8_t *bytes, int32_t length) const; /** * @brief check acc cancel pressed bit based on byte array. * config detail: {'name': 'cncl', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 14, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of acc cancel pressed bit */ bool is_acc_cancel_pressed(const std::uint8_t *bytes, int32_t length) const; /** * @brief check acc on or off pressed bit based on byte array. * config detail: {'name': 'onoff', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 16, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of acc on or off pressed bit */ bool is_acc_on_or_off_pressed(const std::uint8_t *bytes, int32_t length) const; /** * @brief check acc resume or cancel pressed bit based on byte array. * config detail: {'name': 'rescncl', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 17, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of acc resume or cancel pressed bit */ bool is_acc_resume_or_cancel_pressed(const std::uint8_t *bytes, int32_t length) const; /** * @brief check the acc increment set speed pressed bit based on byte array. * config detail: {'name': 'sinc', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 18, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of acc increment set speed pressed bit */ bool is_acc_increment_set_speed_pressed(const std::uint8_t *bytes, int32_t length) const; /** * @brief check the acc decrement set speed pressed bit based on byte array. * config detail: {'name': 'sdec', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 19, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of acc decrement set speed pressed bit */ bool is_acc_decrement_set_speed_pressed(const std::uint8_t *bytes, int32_t length) const; /** * @brief check the acc increment following gap pressed bit based on byte * array. * config detail: {'name': 'ginc', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 20, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of acc increment following gap pressed bit */ bool is_acc_increment_following_gap_pressed(const std::uint8_t *bytes, int32_t length) const; /** * @brief check the acc decrement following gap pressed bit based on byte * array. * config detail: {'name': 'gdec', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 21, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of acc decrement following gap pressed bit */ bool is_acc_decrement_following_gap_pressed(const std::uint8_t *bytes, int32_t length) const; /** * @brief check the lka on or off pressed bit based on byte array. * config detail: {'name': 'lkaen', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 22, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of lka on or off pressed bit */ bool is_lka_on_or_off_pressed(const std::uint8_t *bytes, int32_t length) const; /** * @brief check the canbus fault bit based on byte array. * config detail: {'name': 'fltbus', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 23, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of canbus fault bit */ bool is_canbus_fault(const std::uint8_t *bytes, int32_t length) const; /** * @brief check the driver door open bit based on byte array. * config detail: {'name': 'doord', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 24, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of driver door open bit */ bool is_driver_door_open(const std::uint8_t *bytes, int32_t length) const; /** * @brief check the passenger door open bit based on byte array. * config detail: {'name': 'doorp', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 25, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of passenger door open bit */ bool is_passenger_door_open(const std::uint8_t *bytes, int32_t length) const; /** * @brief check the passenger door open bit based on byte array. * config detail: {'name': 'doorl', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 26, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of rear left door open bit */ bool is_rear_left_door_open(const std::uint8_t *bytes, int32_t length) const; /** * @brief check the rear right door open bit based on byte array. * config detail: {'name': 'doorr', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 27, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of rear right door open bit */ bool is_rear_right_door_open(const std::uint8_t *bytes, int32_t length) const; /** * @brief check the hood open bit based on byte array. * config detail: {'name': 'hood', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 28, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of hood open bit */ bool is_hood_open(const std::uint8_t *bytes, int32_t length) const; /** * @brief check the trunk open bit based on byte array. * config detail: {'name': 'trunk', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 29, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of trunk open bit */ bool is_trunk_open(const std::uint8_t *bytes, int32_t length) const; /** * @brief check the passenger detected bit based on byte array. * config detail: {'name': 'pdect', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 30, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of passenger detected bit */ bool is_passenger_detected(const std::uint8_t *bytes, int32_t length) const; /** * @brief check the passenger airbag enabled bit based on byte array. * config detail: {'name': 'pabag', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 31, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of passenger airbag enabled bit */ bool is_passenger_airbag_enabled(const std::uint8_t *bytes, int32_t length) const; /** * @brief check the driver belt buckled bit based on byte array. * config detail: {'name': 'beltd', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 32, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of driver belt buckled bit */ bool is_driver_belt_buckled(const std::uint8_t *bytes, int32_t length) const; /** * @brief check the passenger belt buckled bit based on byte array. * config detail: {'name': 'beltp', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 33, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of passenger belt buckled bit */ bool is_passenger_belt_buckled(const std::uint8_t *bytes, int32_t length) const; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/gear_67.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/gear_67.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::Byte; const int32_t Gear67::ID = 0x67; void Gear67::Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const { int32_t gear = gear_state(bytes, length); switch (gear) { case 0x01: chassis_detail->mutable_gear()->set_gear_state(Chassis::GEAR_PARKING); break; case 0x02: chassis_detail->mutable_gear()->set_gear_state(Chassis::GEAR_REVERSE); break; case 0x03: chassis_detail->mutable_gear()->set_gear_state(Chassis::GEAR_NEUTRAL); break; case 0x04: chassis_detail->mutable_gear()->set_gear_state(Chassis::GEAR_DRIVE); break; case 0x05: chassis_detail->mutable_gear()->set_gear_state(Chassis::GEAR_LOW); break; case 0x00: chassis_detail->mutable_gear()->set_gear_state(Chassis::GEAR_NONE); break; default: chassis_detail->mutable_gear()->set_gear_state(Chassis::GEAR_INVALID); break; } if (is_driver_override(bytes, length)) { // last shift requested by driver chassis_detail->mutable_gear()->set_is_shift_position_valid(false); } else { // last shift requested by-wire chassis_detail->mutable_gear()->set_is_shift_position_valid(true); } chassis_detail->mutable_gear()->set_driver_override( is_driver_override(bytes, length)); int32_t gear_cmd = reported_gear_cmd(bytes, length); switch (gear_cmd) { case 0x01: chassis_detail->mutable_gear()->set_gear_cmd(Chassis::GEAR_PARKING); break; case 0x02: chassis_detail->mutable_gear()->set_gear_cmd(Chassis::GEAR_REVERSE); break; case 0x03: chassis_detail->mutable_gear()->set_gear_cmd(Chassis::GEAR_NEUTRAL); break; case 0x04: chassis_detail->mutable_gear()->set_gear_cmd(Chassis::GEAR_DRIVE); break; case 0x05: chassis_detail->mutable_gear()->set_gear_cmd(Chassis::GEAR_LOW); break; case 0x00: chassis_detail->mutable_gear()->set_gear_cmd(Chassis::GEAR_NONE); break; default: chassis_detail->mutable_gear()->set_gear_cmd(Chassis::GEAR_INVALID); break; } chassis_detail->mutable_gear()->set_canbus_fault( is_canbus_fault(bytes, length)); } int32_t Gear67::gear_state(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 0); int32_t x = frame.get_byte(0, 3); return x; } bool Gear67::is_driver_override(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 0); return frame.is_bit_1(3); } int32_t Gear67::reported_gear_cmd(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 0); int32_t x = frame.get_byte(4, 3); return x; } bool Gear67::is_canbus_fault(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 0); return frame.is_bit_1(7); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/gps_6e.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/gps_6e.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::Byte; const int32_t Gps6e::ID = 0x6E; void Gps6e::Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const { chassis_detail->mutable_basic()->set_year(year(bytes, length)); chassis_detail->mutable_basic()->set_month(month(bytes, length)); chassis_detail->mutable_basic()->set_day(day(bytes, length)); chassis_detail->mutable_basic()->set_hours(hours(bytes, length)); chassis_detail->mutable_basic()->set_minutes(minutes(bytes, length)); chassis_detail->mutable_basic()->set_seconds(seconds(bytes, length)); chassis_detail->mutable_basic()->set_compass_direction( compass_direction(bytes, length)); chassis_detail->mutable_basic()->set_pdop(pdop(bytes, length)); chassis_detail->mutable_basic()->set_is_gps_fault( is_gps_fault(bytes, length)); chassis_detail->mutable_basic()->set_is_inferred( is_inferred_position(bytes, length)); } int32_t Gps6e::year(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 0); int32_t x = frame.get_byte(0, 7); return x; } int32_t Gps6e::month(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 1); int32_t x = frame.get_byte(0, 4); return x; } int32_t Gps6e::day(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 2); int32_t x = frame.get_byte(0, 5); return x; } int32_t Gps6e::hours(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 3); int32_t x = frame.get_byte(0, 5); return x; } int32_t Gps6e::minutes(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 4); int32_t x = frame.get_byte(0, 6); return x; } int32_t Gps6e::seconds(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 5); int32_t x = frame.get_byte(0, 6); return x; } double Gps6e::compass_direction(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 6); int32_t x = frame.get_byte(0, 4); return x * 45.000000; } double Gps6e::pdop(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); int32_t x = frame.get_byte(0, 5); return x * 0.200000; } bool Gps6e::is_gps_fault(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(5); } bool Gps6e::is_inferred_position(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(6); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/gps_6e.h
/****************************************************************************** * Copyright 2017 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 gps_6e.h * @brief the class of Gps6e (for lincoln vehicle) */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Gps6e * * @brief one of the protocol data of lincoln vehicle */ class Gps6e : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /* * @brief parse received data * @param bytes a pointer to the input bytes * @param length the length of the input bytes * @param timestamp the timestamp of input data * @param chassis_detail the parsed chassis_detail */ virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const; /** * @brief get year from byte array * config detail: {'name': 'year', 'offset': 0.0, 'precision': 1.0, 'len': 7, * 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|99]', * 'bit': 0, 'type': 'int', 'order': 'intel', 'physical_unit': '"years"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of year */ int32_t year(const std::uint8_t *bytes, int32_t length) const; /** * @brief get month from byte array * config detail: {'name': 'month', 'offset': 0.0, 'precision': 1.0, 'len': 4, * 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[1|12]', * 'bit': 8, 'type': 'int', 'order': 'intel', 'physical_unit': '"months"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of month */ int32_t month(const std::uint8_t *bytes, int32_t length) const; /** * @brief get day from byte array * config detail: {'name': 'day', 'offset': 0.0, 'precision': 1.0, 'len': 5, * 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[1|31]', * 'bit': 16, 'type': 'int', 'order': 'intel', 'physical_unit': '"days"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of day */ int32_t day(const std::uint8_t *bytes, int32_t length) const; /** * @brief get hours from byte array * config detail: {'name': 'hours', 'offset': 0.0, 'precision': 1.0, 'len': 5, * 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|23]', * 'bit': 24, 'type': 'int', 'order': 'intel', 'physical_unit': '"hours"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of hours */ int32_t hours(const std::uint8_t *bytes, int32_t length) const; /** * @brief get minutes from byte array * config detail: {'name': 'minutes', 'offset': 0.0, 'precision': 1.0, 'len': * 6, 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|59]', * 'bit': 32, 'type': 'int', 'order': 'intel', 'physical_unit': '"minutes"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of minutes */ int32_t minutes(const std::uint8_t *bytes, int32_t length) const; /** * @brief get year from byte array * config detail: {'name': 'seconds', 'offset': 0.0, 'precision': 1.0, 'len': * 6, 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|59]', * 'bit': 40, 'type': 'int', 'order': 'intel', 'physical_unit': '"seconds"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of minutes */ int32_t seconds(const std::uint8_t *bytes, int32_t length) const; /** * @brief get compass direction from byte array * config detail: {'name': 'compass', 'offset': 0.0, 'precision': 45.0, 'len': * 4, 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|315]', * 'bit': 48, 'type': 'double', 'order': 'intel', 'physical_unit': * '"degrees"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of compass direction */ double compass_direction(const std::uint8_t *bytes, int32_t length) const; /** * @brief get pdop from byte array * config detail: {'name': 'pdop', 'offset': 0.0, 'precision': 0.2, 'len': 5, * 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 56, 'type': 'double', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of pdop */ double pdop(const std::uint8_t *bytes, int32_t length) const; /** * @brief check gps fault from byte array * config detail: {'name': 'fltgps', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 61, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of gps fault */ bool is_gps_fault(const std::uint8_t *bytes, int32_t length) const; /** * @brief get inferred position from byte array * config detail: {'name': 'inf', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 62, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of inferred position */ bool is_inferred_position(const std::uint8_t *bytes, int32_t length) const; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/brakeinfo_74.h
/****************************************************************************** * Copyright 2017 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 brakeinfo_74.h * @brief the class of Brakeinfo74 (for lincoln vehicle) */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Brakeinfo74 * * @brief one of the protocol data of lincoln vehicle */ class Brakeinfo74 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /* * @brief parse received data * @param bytes a pointer to the input bytes * @param length the length of the input bytes * @param timestamp the timestamp of input data * @param chassis_detail the parsed chassis_detail */ void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const override; private: /* * @brief get braking torque request * config detail: {'name': 'brktrqr', 'offset': 0.0, 'precision': 4.0, 'len': * 12, 'f_type': 'value', 'is_signed_var': False, 'physical_range': * '[0|16380]', 'bit': 0, 'type': 'double', 'order': 'intel', 'physical_unit': * '"Nm"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of braking torque request */ double braking_torque_request(const std::uint8_t *bytes, int32_t length) const; /* * @brief get hill start assist status * config detail: {'name': 'hsastat', 'offset': 0.0, 'precision': 1.0, 'len': * 3, 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 12, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of the hill start assist status */ int32_t hill_start_assist_status(const std::uint8_t *bytes, int32_t length) const; /* * @brief check vehicle stationary * config detail: {'name': 'statnry', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 15, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return boolean value of the vehicle stationary bit */ bool is_vehicle_stationary(const std::uint8_t *bytes, int32_t length) const; /* * @brief get the actual braking torque * config detail: {'name': 'brktrqa', 'offset': 0.0, 'precision': 4.0, 'len': * 12, 'f_type': 'value', 'is_signed_var': False, 'physical_range': * '[0|16380]', 'bit': 16, 'type': 'double', 'order': 'intel', * 'physical_unit': '"Nm"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of the actual braking torque */ double braking_torque_actual(const std::uint8_t *bytes, int32_t length) const; /* * @brief get the hill start assist mode * config detail: {'name': 'hsamode', 'offset': 0.0, 'precision': 1.0, 'len': * 2, 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 28, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the mode of hill start assist */ int32_t hill_start_assist_mode(const std::uint8_t *bytes, int32_t length) const; /* * @brief get the parking brake status * config detail: {'name': 'pbrake', 'offset': 0.0, 'precision': 1.0, 'len': * 2, 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 30, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of the parking brake status */ int32_t parking_brake_status(const std::uint8_t *bytes, int32_t length) const; /* * @brief get the actual wheel torque * config detail: {'name': 'whltrq', 'offset': 0.0, 'precision': 4.0, 'len': * 14, 'f_type': 'value', 'is_signed_var': True, 'physical_range': * '[-32768|32764]', 'bit': 32, 'type': 'double', 'order': 'intel', * 'physical_unit': '"Nm"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of the actual wheel torque */ double wheel_torque_actual(const std::uint8_t *bytes, int32_t length) const; /* * @brief get the acceleration over ground * config detail: {'name': 'aog', 'offset': 0.0, 'precision': 0.035, 'len': * 10, 'f_type': 'value', 'is_signed_var': True, 'physical_range': * '[-17.92|17.885]', 'bit': 48, 'type': 'double', 'order': 'intel', * 'physical_unit': '"m/s^2"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of the acceleration over ground */ double acceleration_over_ground(const std::uint8_t *bytes, int32_t length) const; /* * @brief check abs active * config detail: {'name': 'absa', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 58, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return boolean value of the abs active bit */ bool is_abs_active(const std::uint8_t *bytes, int32_t length) const; /* * @brief abs enabled * config detail: {'name': 'abse', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 59, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return boolean value of the abs enabled bit */ bool is_abs_enabled(const std::uint8_t *bytes, int32_t length) const; /* * @brief check stability control active * config detail: {'name': 'staba', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 60, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return boolean value of the stability control active bit */ bool is_stability_control_active(const std::uint8_t *bytes, int32_t length) const; /* * @brief check stability control enabled bit * config detail: {'name': 'stabe', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 61, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return boolean value of the stability control enabled bit */ bool is_stability_control_enabled(const std::uint8_t *bytes, int32_t length) const; /* * @brief traction control active bit * config detail: {'name': 'traca', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 62, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return boolean value of the traction control active bit */ bool is_traction_control_active(const std::uint8_t *bytes, int32_t length) const; /* * @brief traction control enabled bit * config detail: {'name': 'trace', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 63, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return boolean value of the traction control enabled bit */ bool is_traction_control_enabled(const std::uint8_t *bytes, int32_t length) const; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/gyro_6c_test.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/gyro_6c.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { TEST(Gyro6cTest, General) { uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; int32_t length = 8; Lincoln cd; Gyro6c gyro; gyro.Parse(data, length, &cd); EXPECT_TRUE(cd.vehicle_spd().is_yaw_rate_valid()); EXPECT_DOUBLE_EQ(cd.vehicle_spd().yaw_rate(), 5.1398); EXPECT_DOUBLE_EQ(cd.vehicle_spd().roll_rate(), 5.0382); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/throttle_63_test.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/throttle_63.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { TEST(Throttle63Test, General) { uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; int32_t length = 8; Lincoln cd; Throttle63 throttle; throttle.Parse(data, length, &cd); EXPECT_DOUBLE_EQ(cd.gas().throttle_input(), 38.439002059967905); EXPECT_DOUBLE_EQ(cd.gas().throttle_cmd(), 39.21416037232008); EXPECT_DOUBLE_EQ(cd.gas().throttle_output(), 32.155336842908326); EXPECT_EQ(cd.gas().watchdog_source(), 5); EXPECT_FALSE(cd.gas().throttle_enabled()); EXPECT_FALSE(cd.gas().driver_override()); EXPECT_TRUE(cd.gas().driver_activity()); EXPECT_FALSE(cd.gas().watchdog_fault()); EXPECT_TRUE(cd.gas().channel_1_fault()); EXPECT_FALSE(cd.gas().channel_2_fault()); EXPECT_FALSE(cd.gas().connector_fault()); EXPECT_TRUE(cd.check_response().is_vcu_online()); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/steering_64.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/steering_64.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::Byte; const int32_t Steering64::ID = 0x64; uint32_t Steering64::GetPeriod() const { // receive rate?? // receive timeout would trigger fault, letting en=0 and etc. static const uint32_t PERIOD = 10 * 1000; return PERIOD; } void Steering64::UpdateData(uint8_t *data) { set_steering_angle_p(data, steering_angle_); set_enable_p(data, steering_enable_); set_clear_driver_override_flag_p(data, clear_driver_override_flag_); set_ignore_driver_override_p(data, ignore_driver_override_); set_steering_angle_speed_p(data, steering_angle_speed_); set_watchdog_counter_p(data, watchdog_counter_); set_disable_audible_warning_p(data, disable_audible_warning_); } void Steering64::Reset() { steering_angle_ = 0.0; steering_enable_ = false; clear_driver_override_flag_ = false; ignore_driver_override_ = false; steering_angle_speed_ = 0.0; watchdog_counter_ = 0; disable_audible_warning_ = false; } Steering64 *Steering64::set_steering_angle(double angle) { steering_angle_ = angle; return this; } Steering64 *Steering64::set_enable() { steering_enable_ = true; return this; } Steering64 *Steering64::set_disable() { steering_enable_ = false; return this; } Steering64 *Steering64::set_steering_angle_speed(double angle_speed) { steering_angle_speed_ = angle_speed; return this; } // private // positive for left, negative for right void Steering64::set_steering_angle_p(uint8_t *data, double angle) { angle = ProtocolData::BoundedValue(-470.0, 470.0, angle); int32_t x = static_cast<int32_t>(angle / 0.100000); // add offset if (x < 0) { x += 0x10000; } std::uint8_t t = 0; t = static_cast<uint8_t>(x & 0xFF); // low Byte frame_low(data + 0); frame_low.set_value(t, 0, 8); x >>= 8; // high t = static_cast<uint8_t>(x & 0xFF); Byte frame_high(data + 1); frame_high.set_value(t, 0, 8); } void Steering64::set_enable_p(uint8_t *bytes, bool enable) { Byte frame(bytes + 2); if (enable) { frame.set_bit_1(0); } else { frame.set_bit_0(0); } } void Steering64::set_clear_driver_override_flag_p(uint8_t *bytes, bool clear) { Byte frame(bytes + 2); if (clear) { frame.set_bit_1(1); } else { frame.set_bit_0(1); } } void Steering64::set_ignore_driver_override_p(uint8_t *bytes, bool ignore) { Byte frame(bytes + 2); if (ignore) { frame.set_bit_1(2); } else { frame.set_bit_0(2); } } void Steering64::set_steering_angle_speed_p(uint8_t *data, double angle_speed) { angle_speed = ProtocolData::BoundedValue(0.0, 500.0, angle_speed); int32_t x = static_cast<int32_t>(angle_speed / 2.000000); Byte frame(data + 3); frame.set_value(static_cast<uint8_t>(x), 0, 8); } void Steering64::set_watchdog_counter_p(uint8_t *data, int32_t count) { count = ProtocolData::BoundedValue(0, 255, count); Byte frame(data + 7); frame.set_value(static_cast<uint8_t>(count), 0, 8); } void Steering64::set_disable_audible_warning_p(uint8_t *data, bool disable) { Byte frame(data + 2); if (disable) { frame.set_bit_1(4); } else { frame.set_bit_0(4); } } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/steering_64_test.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/steering_64.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { TEST(Steering64Test, General) { uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; Steering64 steering; EXPECT_EQ(steering.GetPeriod(), 10 * 1000); steering.UpdateData(data); EXPECT_EQ(data[0], 0b00000000); EXPECT_EQ(data[1], 0b00000000); EXPECT_EQ(data[2], 0b01100000); EXPECT_EQ(data[3], 0b00000000); EXPECT_EQ(data[4], 0b01010001); EXPECT_EQ(data[5], 0b01010010); EXPECT_EQ(data[6], 0b01010011); EXPECT_EQ(data[7], 0b00000000); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/throttle_63.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/throttle_63.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::Byte; const int32_t Throttle63::ID = 0x63; void Throttle63::Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const { chassis_detail->mutable_gas()->set_throttle_input(pedal_input(bytes, length)); chassis_detail->mutable_gas()->set_throttle_cmd(pedal_cmd(bytes, length)); chassis_detail->mutable_gas()->set_throttle_output( pedal_output(bytes, length)); chassis_detail->mutable_gas()->set_watchdog_source( watchdog_counter_source(bytes, length)); chassis_detail->mutable_gas()->set_throttle_enabled( is_enabled(bytes, length)); chassis_detail->mutable_gas()->set_driver_override( is_driver_override(bytes, length)); chassis_detail->mutable_gas()->set_driver_activity( is_driver_activity(bytes, length)); chassis_detail->mutable_gas()->set_watchdog_fault( is_watchdog_counter_fault(bytes, length)); chassis_detail->mutable_gas()->set_channel_1_fault( is_channel_1_fault(bytes, length)); chassis_detail->mutable_gas()->set_channel_2_fault( is_channel_2_fault(bytes, length)); chassis_detail->mutable_gas()->set_connector_fault( is_connector_fault(bytes, length)); chassis_detail->mutable_check_response()->set_is_vcu_online( !is_driver_override(bytes, length)); } double Throttle63::pedal_input(const std::uint8_t *bytes, int32_t length) const { // Pedal Input from the physical pedal Byte frame_high(bytes + 1); int32_t high = frame_high.get_byte(0, 8); Byte frame_low(bytes + 0); int32_t low = frame_low.get_byte(0, 8); int32_t value = (high << 8) | low; // control needs a value in range [0, 100] % double output = 100.0 * value * 1.52590218966964e-05; output = ProtocolData::BoundedValue(0.0, 100.0, output); return output; } double Throttle63::pedal_cmd(const std::uint8_t *bytes, int32_t length) const { // Pedal Command from the command message Byte frame_high(bytes + 3); int32_t high = frame_high.get_byte(0, 8); Byte frame_low(bytes + 2); int32_t low = frame_low.get_byte(0, 8); int32_t value = (high << 8) | low; // control needs a value in range [0, 100] % double output = 100.0 * value * 1.52590218966964e-05; output = ProtocolData::BoundedValue(0.0, 100.0, output); return output; } double Throttle63::pedal_output(const std::uint8_t *bytes, int32_t length) const { // Pedal Output is the maximum of PI and PC Byte frame_high(bytes + 5); int32_t high = frame_high.get_byte(0, 8); Byte frame_low(bytes + 4); int32_t low = frame_low.get_byte(0, 8); int32_t value = (high << 8) | low; // control needs a value in range [0, 100] % double output = 100.0 * value * 1.52590218966964e-05; output = ProtocolData::BoundedValue(0.0, 100.0, output); return output; } int32_t Throttle63::watchdog_counter_source(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 6); int32_t x = frame.get_byte(4, 4); return x; } bool Throttle63::is_enabled(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(0); } bool Throttle63::is_driver_override(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(1); } bool Throttle63::is_driver_activity(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(2); } bool Throttle63::is_watchdog_counter_fault(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(3); } bool Throttle63::is_channel_1_fault(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(4); } bool Throttle63::is_channel_2_fault(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(5); } bool Throttle63::is_connector_fault(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(7); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/license_7e.h
/****************************************************************************** * Copyright 2017 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/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { class License7e : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { private: mutable std::string vin_part0_; mutable std::string vin_part1_; mutable std::string vin_part2_; mutable bool vin_part0_flag_; mutable bool vin_part1_flag_; mutable bool vin_part2_flag_; mutable bool parse_success_; public: static const int32_t ID; License7e(); virtual void Parse(const std::uint8_t* bytes, int32_t length, Lincoln* chassis_detail) const; // config detail: {'name': 'mux', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 0, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int mux(const std::uint8_t* bytes, int length) const; bool is_ready(const std::uint8_t* bytes, int length) const; bool is_trial(const std::uint8_t* bytes, int length) const; bool is_expired(const std::uint8_t* bytes, int length) const; bool is_feat_base_enabled(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'date0', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 16, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int date0(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'date6', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 16, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int date6(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'mac0', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 16, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int mac0(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'vin00', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 16, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string vin00(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'vin06', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 16, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string vin06(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'vin12', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 16, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string vin12(const std::uint8_t* bytes, int length) const; bool is_feat_base_trial(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'date1', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 24, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int date1(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'date7', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 24, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int date7(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'mac1', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 24, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int mac1(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'vin01', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 24, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string vin01(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'vin07', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 24, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string vin07(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'vin13', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 24, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string vin13(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'date2', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 32, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int date2(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'date8', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 32, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int date8(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'mac2', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 32, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int mac2(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'vin02', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 32, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string vin02(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'vin08', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 32, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string vin08(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'vin14', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 32, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string vin14(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'feat_base_trials_used', 'offset': 0.0, // 'precision': 1.0, 'len': 16, 'f_type': 'value', 'is_signed_var': False, // 'physical_range': '[0|0]', 'bit': 32, 'type': 'int', 'order': 'intel', // 'physical_unit': '""'} int feat_base_trials_used(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'date3', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 40, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int date3(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'date9', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 40, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int date9(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'mac3', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 40, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int mac3(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'vin03', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 40, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string vin03(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'vin09', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 40, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string vin09(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'vin15', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 40, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string vin15(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'date4', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 48, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int date4(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'mac4', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 48, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int mac4(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'vin04', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 48, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string vin04(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'vin10', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 48, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string vin10(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'vin16', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 48, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string vin16(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'feat_base_trials_remaining', 'offset': 0.0, // 'precision': 1.0, 'len': 16, 'f_type': 'value', 'is_signed_var': False, // 'physical_range': '[0|0]', 'bit': 48, 'type': 'int', 'order': 'intel', // 'physical_unit': '""'} int feat_base_trials_remaining(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'date5', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 56, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int date5(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'mac5', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 56, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int mac5(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'vin05', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 56, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string vin05(const std::uint8_t* bytes, int length) const; // config detail: {'name': 'vin11', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 56, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string vin11(const std::uint8_t* bytes, int length) const; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/steering_65_test.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/steering_65.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { TEST(Steering65Test, General) { uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; int32_t length = 8; Lincoln cd; Steering65 steering; steering.Parse(data, length, &cd); EXPECT_FALSE(cd.eps().steering_enabled()); EXPECT_TRUE(cd.vehicle_spd().is_vehicle_spd_valid()); EXPECT_DOUBLE_EQ(cd.vehicle_spd().vehicle_spd(), 58.536111111111111); EXPECT_TRUE(cd.eps().is_steering_angle_valid()); EXPECT_DOUBLE_EQ(cd.eps().steering_angle(), 2519.1); EXPECT_DOUBLE_EQ(cd.eps().steering_angle_cmd(), 2569.9); EXPECT_DOUBLE_EQ(cd.eps().vehicle_speed(), 58.536111111111111); EXPECT_DOUBLE_EQ(cd.eps().epas_torque(), 5.1875); EXPECT_FALSE(cd.eps().steering_enabled()); EXPECT_FALSE(cd.eps().driver_override()); EXPECT_TRUE(cd.eps().driver_activity()); EXPECT_FALSE(cd.eps().watchdog_fault()); EXPECT_TRUE(cd.eps().channel_1_fault()); EXPECT_FALSE(cd.eps().channel_2_fault()); EXPECT_TRUE(cd.eps().calibration_fault()); EXPECT_FALSE(cd.eps().connector_fault()); EXPECT_TRUE(cd.check_response().is_eps_online()); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/throttleinfo_75_test.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/throttleinfo_75.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { TEST(Throttleinfo75Test, General) { uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; int32_t length = 8; Lincoln cd; Throttleinfo75 throttle_info; throttle_info.Parse(data, length, &cd); EXPECT_TRUE(cd.has_ems()); EXPECT_TRUE(cd.ems().has_engine_rpm()); EXPECT_TRUE(cd.has_gas()); EXPECT_TRUE(cd.gas().has_accelerator_pedal()); EXPECT_TRUE(cd.gas().has_accelerator_pedal_rate()); EXPECT_DOUBLE_EQ(cd.ems().engine_rpm(), 6297.75); EXPECT_DOUBLE_EQ(cd.gas().accelerator_pedal(), 9.9); EXPECT_DOUBLE_EQ(cd.gas().accelerator_pedal_rate(), -7); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/throttle_62.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/throttle_62.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::Byte; // public const int32_t Throttle62::ID = 0x62; uint32_t Throttle62::GetPeriod() const { static const uint32_t PERIOD = 10 * 1000; return PERIOD; } void Throttle62::UpdateData(uint8_t *data) { set_pedal_p(data, pedal_cmd_); set_enable_p(data, pedal_enable_); set_clear_driver_override_flag_p(data, clear_driver_override_flag_); set_ignore_driver_override_p(data, ignore_driver_override_); set_watchdog_counter_p(data, watchdog_counter_); } void Throttle62::Reset() { pedal_cmd_ = 0.0; pedal_enable_ = false; clear_driver_override_flag_ = false; ignore_driver_override_ = false; watchdog_counter_ = 0; } Throttle62 *Throttle62::set_pedal(double pedal) { pedal_cmd_ = pedal; return this; } Throttle62 *Throttle62::set_enable() { pedal_enable_ = true; return this; } Throttle62 *Throttle62::set_disable() { pedal_enable_ = false; return this; } // private void Throttle62::set_pedal_p(uint8_t *data, double pedal) { // change from [0-100] to [0.00-1.00] // and a rough mapping pedal /= 100.0; pedal = ProtocolData::BoundedValue(0.0, 1.0, pedal); int32_t x = static_cast<int32_t>(pedal / 1.52590218966964e-05); std::uint8_t t = 0; t = static_cast<uint8_t>(x & 0xFF); Byte frame_low(data + 0); frame_low.set_value(t, 0, 8); x >>= 8; t = static_cast<uint8_t>(x & 0xFF); Byte frame_high(data + 1); frame_high.set_value(t, 0, 8); } void Throttle62::set_enable_p(uint8_t *bytes, bool enable) { Byte frame(bytes + 3); if (enable) { frame.set_bit_1(0); } else { frame.set_bit_0(0); } } void Throttle62::set_clear_driver_override_flag_p(uint8_t *bytes, bool clear) { Byte frame(bytes + 3); if (clear) { frame.set_bit_1(1); } else { frame.set_bit_0(1); } } void Throttle62::set_ignore_driver_override_p(uint8_t *bytes, bool ignore) { Byte frame(bytes + 3); if (ignore) { frame.set_bit_1(2); } else { frame.set_bit_0(2); } } void Throttle62::set_watchdog_counter_p(uint8_t *data, int32_t count) { count = ProtocolData::BoundedValue(0, 255, count); Byte frame(data + 7); frame.set_value(static_cast<uint8_t>(count), 0, 8); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/tirepressure_71.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/tirepressure_71.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::Byte; const int32_t Tirepressure71::ID = 0x71; void Tirepressure71::Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const { chassis_detail->mutable_safety()->set_front_left_tire_press( front_left_tire(bytes, length)); chassis_detail->mutable_safety()->set_front_right_tire_press( front_right_tire(bytes, length)); chassis_detail->mutable_safety()->set_rear_left_tire_press( rear_left_tire(bytes, length)); chassis_detail->mutable_safety()->set_rear_right_tire_press( rear_right_tire(bytes, length)); } int32_t Tirepressure71::front_left_tire(const std::uint8_t *bytes, int32_t length) const { Byte high_frame(bytes + 1); int32_t high = high_frame.get_byte(0, 8); Byte low_frame(bytes + 0); int32_t low = low_frame.get_byte(0, 8); return (high << 8) | low; } int32_t Tirepressure71::front_right_tire(const std::uint8_t *bytes, int32_t length) const { Byte high_frame(bytes + 3); int32_t high = high_frame.get_byte(0, 8); Byte low_frame(bytes + 2); int32_t low = low_frame.get_byte(0, 8); return (high << 8) | low; } int32_t Tirepressure71::rear_left_tire(const std::uint8_t *bytes, int32_t length) const { Byte high_frame(bytes + 5); int32_t high = high_frame.get_byte(0, 8); Byte low_frame(bytes + 4); int32_t low = low_frame.get_byte(0, 8); return (high << 8) | low; } int32_t Tirepressure71::rear_right_tire(const std::uint8_t *bytes, int32_t length) const { Byte high_frame(bytes + 7); int32_t high = high_frame.get_byte(0, 8); Byte low_frame(bytes + 6); int32_t low = low_frame.get_byte(0, 8); return (high << 8) | low; } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/accel_6b.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/accel_6b.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 lincoln { using ::apollo::drivers::canbus::Byte; const int32_t Accel6b::ID = 0x6B; void Accel6b::Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const { chassis_detail->mutable_vehicle_spd()->set_lat_acc( lateral_acceleration(bytes, length)); chassis_detail->mutable_vehicle_spd()->set_long_acc( longitudinal_acceleration(bytes, length)); chassis_detail->mutable_vehicle_spd()->set_vert_acc( vertical_acceleration(bytes, length)); } double Accel6b::lateral_acceleration(const std::uint8_t *bytes, const int32_t length) const { DCHECK_GE(length, 2); return parse_two_frames(bytes[0], bytes[1]); } double Accel6b::longitudinal_acceleration(const std::uint8_t *bytes, const int32_t length) const { DCHECK_GE(length, 4); return parse_two_frames(bytes[2], bytes[3]); } double Accel6b::vertical_acceleration(const std::uint8_t *bytes, const int32_t length) const { DCHECK_GE(length, 6); return parse_two_frames(bytes[4], bytes[5]); } double Accel6b::parse_two_frames(const std::uint8_t low_byte, const std::uint8_t high_byte) const { Byte high_frame(&high_byte); int32_t high = high_frame.get_byte(0, 8); Byte low_frame(&low_byte); int32_t low = low_frame.get_byte(0, 8); int32_t value = (high << 8) | low; if (value > 0x7FFF) { value -= 0x10000; } return value * 0.010000; } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/gyro_6c.h
/****************************************************************************** * Copyright 2017 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 gyro_6c.h * @brief the class of Gyro6c (for lincoln vehicle) */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Gyro6c * * @brief one of the protocol data of lincoln vehicle */ class Gyro6c : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /* * @brief parse received data * @param bytes a pointer to the input bytes * @param length the length of the input bytes * @param timestamp the timestamp of input data * @param chassis_detail the parsed chassis_detail */ virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const; /** * @brief calculate the roll rate based on byte array. * config detail: {'name': 'roll', 'offset': 0.0, 'precision': 0.0002, 'len': * 16, 'f_type': 'value', 'is_signed_var': True, 'physical_range': '[0|0]', * 'bit': 0, 'type': 'double', 'order': 'intel', 'physical_unit': '"rad/s"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of roll rate */ double roll_rate(const std::uint8_t *bytes, int32_t length) const; /** * @brief calculate longitudinal_acceleration based on byte array. * config detail: {'name': 'yaw', 'offset': 0.0, 'precision': 0.0002, 'len': * 16, 'f_type': 'value', 'is_signed_var': True, 'physical_range': '[0|0]', * 'bit': 16, 'type': 'double', 'order': 'intel', 'physical_unit': '"rad/s"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of yaw rate */ double yaw_rate(const std::uint8_t *bytes, int32_t length) const; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/gear_67.h
/****************************************************************************** * Copyright 2017 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 gear_67.h * @brief the class of Gear67 (for lincoln vehicle) */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Gear67 * * @brief one of the protocol data of lincoln vehicle */ class Gear67 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /* * @brief parse received data * @param bytes a pointer to the input bytes * @param length the length of the input bytes * @param timestamp the timestamp of input data * @param chassis_detail the parsed chassis_detail */ virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const; /** * @brief get the gear state from byte array * config detail: {'name': 'state', 'offset': 0.0, 'precision': 1.0, 'len': 3, * 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 0, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of the gear state */ int32_t gear_state(const std::uint8_t *bytes, int32_t length) const; /** * @brief check canbus fault from byte array * config detail: {'name': 'fltbus', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 7, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of canbus fault */ bool is_canbus_fault(const std::uint8_t *bytes, int32_t length) const; /** * @brief check driver override from byte array * config detail: {'name': 'driver', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 3, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of driver override */ bool is_driver_override(const std::uint8_t *bytes, int32_t length) const; /** * @brief get reported gear command from byte array * config detail: {'name': 'cmd', 'offset': 0.0, 'precision': 1.0, 'len': 3, * 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 4, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of reported gear command */ int32_t reported_gear_cmd(const std::uint8_t *bytes, int32_t length) const; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/brake_60.h
/****************************************************************************** * Copyright 2017 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 brake_60.h * @brief the class of Brake60 (for lincoln vehicle) */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Brake60 * * @brief one of the protocol data of lincoln vehicle */ class Brake60 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /** * @brief get the data period * @return the value of data period */ uint32_t GetPeriod() const override; /** * @brief update the data * @param data a pointer to the data to be updated */ void UpdateData(uint8_t *data) override; /** * @brief reset the private variables */ void Reset() override; /** * @brief set pedal based on pedal command * @return a this pointer to the instance itself */ Brake60 *set_pedal(double pcmd); /** * @brief set pedal_enable_ to true * @return a this pointer to the instance itself */ Brake60 *set_enable(); /** * @brief set pedal_enable_ to false * @return a this pointer to the instance itself */ Brake60 *set_disable(); private: /** * @brief enable boo command * @return a this pointer to the instance itself */ Brake60 *enable_boo_cmd(); /** * @brief disable boo command * @return a this pointer to the instance itself */ Brake60 *disable_boo_cmd(); /** * config detail: {'name': 'pcmd', 'offset': 0.0, 'precision': * 1.52590218966964e-05, 'len': 16, 'f_type': 'value', 'is_signed_var': False, * 'physical_range': '[0|1]', 'bit': 0, 'type': 'double', 'order': 'intel', * 'physical_unit': '"%"'} */ void set_pedal_p(uint8_t *data, double pedal); /** * config detail: {'name': 'bcmd', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 16, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} */ void set_boo_cmd_p(uint8_t *bytes, bool boo_cmd); /** * config detail: {'name': 'en', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 24, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} */ void set_enable_p(uint8_t *bytes, bool en); /** * config detail: {'name': 'clear', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 25, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} */ void set_clear_driver_override_flag_p(uint8_t *bytes, bool clear); /** * config detail: {'name': 'ignore', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 26, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} */ void set_ignore_driver_override_p(uint8_t *bytes, bool ignore); /* * config detail: {'name': 'count', 'offset': 0.0, 'precision': 1.0, 'len': 8, * 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|255]', * 'bit': 56, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} */ void set_watchdog_counter_p(uint8_t *data, int32_t count); private: double pedal_cmd_ = 0.0; bool boo_cmd_ = false; bool pedal_enable_ = false; bool clear_driver_override_flag_ = false; bool ignore_driver_override_ = false; int32_t watchdog_counter_ = 0.0; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/surround_73_test.cc
/****************************************************************************** * Copyright 2018 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/lincoln/protocol/surround_73.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { TEST(Surround73Test, General) { uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x00, 0x53, 0x54}; int32_t length = 8; Lincoln cd; Surround73 surround; surround.Parse(data, length, &cd); EXPECT_TRUE(cd.surround().cross_traffic_alert_left()); EXPECT_TRUE(cd.surround().cross_traffic_alert_left_enabled()); EXPECT_TRUE(cd.surround().blind_spot_left_alert()); EXPECT_FALSE(cd.surround().blind_spot_left_alert_enabled()); EXPECT_FALSE(cd.surround().cross_traffic_alert_right()); EXPECT_FALSE(cd.surround().cross_traffic_alert_right_enabled()); EXPECT_TRUE(cd.surround().blind_spot_right_alert()); EXPECT_FALSE(cd.surround().blind_spot_right_alert_enabled()); EXPECT_DOUBLE_EQ(cd.surround().sonar00(), 0.44499999999999995); EXPECT_DOUBLE_EQ(cd.surround().sonar01(), 1.0249999999999999); EXPECT_DOUBLE_EQ(cd.surround().sonar02(), 0.58999999999999997); EXPECT_DOUBLE_EQ(cd.surround().sonar03(), 1.0249999999999999); EXPECT_DOUBLE_EQ(cd.surround().sonar04(), 0.73499999999999988); EXPECT_DOUBLE_EQ(cd.surround().sonar05(), 1.0249999999999999); EXPECT_DOUBLE_EQ(cd.surround().sonar06(), 0.29999999999999999); EXPECT_DOUBLE_EQ(cd.surround().sonar07(), 0.87999999999999989); EXPECT_DOUBLE_EQ(cd.surround().sonar08(), 100); EXPECT_DOUBLE_EQ(cd.surround().sonar09(), 100); EXPECT_DOUBLE_EQ(cd.surround().sonar10(), 0.58999999999999997); EXPECT_DOUBLE_EQ(cd.surround().sonar11(), 0.87999999999999989); EXPECT_FALSE(cd.surround().sonar_enabled()); EXPECT_FALSE(cd.surround().sonar_fault()); EXPECT_DOUBLE_EQ(cd.surround().sonar_range(0), 0.44499999999999995); EXPECT_DOUBLE_EQ(cd.surround().sonar_range(1), 1.0249999999999999); EXPECT_DOUBLE_EQ(cd.surround().sonar_range(2), 0.58999999999999997); EXPECT_DOUBLE_EQ(cd.surround().sonar_range(3), 1.0249999999999999); EXPECT_DOUBLE_EQ(cd.surround().sonar_range(4), 0.73499999999999988); EXPECT_DOUBLE_EQ(cd.surround().sonar_range(5), 1.0249999999999999); EXPECT_DOUBLE_EQ(cd.surround().sonar_range(6), 0.29999999999999999); EXPECT_DOUBLE_EQ(cd.surround().sonar_range(7), 0.87999999999999989); EXPECT_DOUBLE_EQ(cd.surround().sonar_range(8), 100); EXPECT_DOUBLE_EQ(cd.surround().sonar_range(9), 100); EXPECT_DOUBLE_EQ(cd.surround().sonar_range(10), 0.58999999999999997); EXPECT_DOUBLE_EQ(cd.surround().sonar_range(11), 0.87999999999999989); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/wheelspeed_6a_test.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/wheelspeed_6a.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { TEST(Wheelspeed6aTest, General) { Wheelspeed6a wheelspeed; uint8_t data[8] = {0x61, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; int32_t length = 8; Lincoln cd; struct timeval timestamp; gettimeofday(&timestamp, NULL); wheelspeed.Parse(data, length, timestamp, &cd); EXPECT_TRUE(cd.vehicle_spd().is_wheel_spd_fl_valid()); EXPECT_DOUBLE_EQ(cd.vehicle_spd().wheel_spd_rr(), 215.87); EXPECT_TRUE(cd.vehicle_spd().is_wheel_spd_fr_valid()); EXPECT_DOUBLE_EQ(cd.vehicle_spd().wheel_spd_rl(), 210.73); EXPECT_TRUE(cd.vehicle_spd().is_wheel_spd_rl_valid()); EXPECT_DOUBLE_EQ(cd.vehicle_spd().wheel_spd_fr(), 256.99); EXPECT_TRUE(cd.vehicle_spd().is_wheel_spd_rr_valid()); EXPECT_DOUBLE_EQ(cd.vehicle_spd().wheel_spd_fl(), 251.85); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/brakeinfo_74.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/brakeinfo_74.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::Byte; const int32_t Brakeinfo74::ID = 0x74; void Brakeinfo74::Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const { chassis_detail->mutable_brake()->set_brake_torque_req( braking_torque_request(bytes, length)); switch (hill_start_assist_status(bytes, length)) { case 0: chassis_detail->mutable_brake()->set_hsa_status(Brake::HSA_INACTIVE); break; case 1: chassis_detail->mutable_brake()->set_hsa_status( Brake::HSA_FINDING_GRADIENT); break; case 2: chassis_detail->mutable_brake()->set_hsa_status( Brake::HSA_ACTIVE_PRESSED); break; case 3: chassis_detail->mutable_brake()->set_hsa_status( Brake::HSA_ACTIVE_RELEASED); break; case 4: chassis_detail->mutable_brake()->set_hsa_status(Brake::HSA_FAST_RELEASE); break; case 5: chassis_detail->mutable_brake()->set_hsa_status(Brake::HSA_SLOW_RELEASE); break; case 6: chassis_detail->mutable_brake()->set_hsa_status(Brake::HSA_FAILED); break; case 7: chassis_detail->mutable_brake()->set_hsa_status(Brake::HSA_UNDEFINED); break; } chassis_detail->mutable_vehicle_spd()->set_is_vehicle_standstill( is_vehicle_stationary(bytes, length)); chassis_detail->mutable_brake()->set_brake_torque_act( braking_torque_actual(bytes, length)); switch (hill_start_assist_mode(bytes, length)) { case 0: chassis_detail->mutable_brake()->set_hsa_mode(Brake::HSA_OFF); break; case 1: chassis_detail->mutable_brake()->set_hsa_mode(Brake::HSA_AUTO); break; case 2: chassis_detail->mutable_brake()->set_hsa_mode(Brake::HSA_MANUAL); break; case 3: chassis_detail->mutable_brake()->set_hsa_mode(Brake::HSA_MODE_UNDEFINED); break; } switch (parking_brake_status(bytes, length)) { case 0: chassis_detail->mutable_epb()->set_parking_brake_status(Epb::PBRAKE_OFF); break; case 1: chassis_detail->mutable_epb()->set_parking_brake_status( Epb::PBRAKE_TRANSITION); break; case 2: chassis_detail->mutable_epb()->set_parking_brake_status(Epb::PBRAKE_ON); break; case 3: chassis_detail->mutable_epb()->set_parking_brake_status( Epb::PBRAKE_FAULT); break; } chassis_detail->mutable_brake()->set_wheel_torque_act( wheel_torque_actual(bytes, length)); chassis_detail->mutable_vehicle_spd()->set_acc_est( acceleration_over_ground(bytes, length)); chassis_detail->mutable_esp()->set_is_abs_active( is_abs_active(bytes, length)); chassis_detail->mutable_esp()->set_is_abs_enabled( is_abs_enabled(bytes, length)); chassis_detail->mutable_esp()->set_is_stab_active( is_stability_control_active(bytes, length)); chassis_detail->mutable_esp()->set_is_stab_enabled( is_stability_control_enabled(bytes, length)); chassis_detail->mutable_esp()->set_is_trac_active( is_traction_control_active(bytes, length)); chassis_detail->mutable_esp()->set_is_trac_enabled( is_traction_control_enabled(bytes, length)); } double Brakeinfo74::braking_torque_request(const std::uint8_t *bytes, int32_t length) const { Byte frame_high(bytes + 1); int32_t high = frame_high.get_byte(0, 4); Byte frame_low(bytes + 0); int32_t low = frame_low.get_byte(0, 8); int32_t value = (high << 8) | low; return value * 4.000000; } int32_t Brakeinfo74::hill_start_assist_status(const std::uint8_t *bytes, int32_t length) const { // see table for status code Byte frame(bytes + 1); int32_t x = frame.get_byte(4, 3); return x; } bool Brakeinfo74::is_vehicle_stationary(const std::uint8_t *bytes, int32_t length) const { // false for moving, true for stationary Byte frame(bytes + 1); return frame.is_bit_1(7); } double Brakeinfo74::braking_torque_actual(const std::uint8_t *bytes, int32_t length) const { Byte frame_high(bytes + 3); int32_t high = frame_high.get_byte(0, 4); Byte frame_low(bytes + 2); int32_t low = frame_low.get_byte(0, 8); int32_t value = (high << 8) | low; return value * 4.000000; } int32_t Brakeinfo74::hill_start_assist_mode(const std::uint8_t *bytes, int32_t length) const { // see table for status code Byte frame(bytes + 3); int32_t x = frame.get_byte(4, 2); return x; } int32_t Brakeinfo74::parking_brake_status(const std::uint8_t *bytes, int32_t length) const { // see table for status code Byte frame(bytes + 3); int32_t x = frame.get_byte(6, 2); return x; } double Brakeinfo74::wheel_torque_actual(const std::uint8_t *bytes, int32_t length) const { Byte frame_high(bytes + 5); int32_t high = frame_high.get_byte(0, 6); Byte frame_low(bytes + 4); int32_t low = frame_low.get_byte(0, 8); int32_t value = (high << 8) | low; if (value > 0x1FFF) { value -= 0x4000; } return value * 4.000000; } double Brakeinfo74::acceleration_over_ground(const std::uint8_t *bytes, int32_t length) const { // vehicle acceleration over ground estimate Byte frame_high(bytes + 7); int32_t high = frame_high.get_byte(0, 2); Byte frame_low(bytes + 6); int32_t low = frame_low.get_byte(0, 8); int32_t value = (high << 8) | low; if (value > 0x1FF) { value -= 0x400; } return value * 0.035000; } bool Brakeinfo74::is_abs_active(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(2); } bool Brakeinfo74::is_abs_enabled(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(3); } bool Brakeinfo74::is_stability_control_active(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(4); } bool Brakeinfo74::is_stability_control_enabled(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(5); } bool Brakeinfo74::is_traction_control_active(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(6); } bool Brakeinfo74::is_traction_control_enabled(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(7); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/wheelspeed_6a.h
/****************************************************************************** * Copyright 2017 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 throttle_63.h * @brief the class of Throttle63 (for lincoln vehicle) */ #pragma once #include <sys/time.h> // #include "modules/common_msgs/chassis_msgs/chassis.pb.h" #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Wheelspeed6a * * @brief one of the protocol data of lincoln vehicle */ class Wheelspeed6a : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /* * @brief parse received data * @param bytes a pointer to the input bytes * @param length the length of the input bytes * @param chassis_detail the parsed chassis_detail */ virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const; /* * @brief parse received data * @param bytes a pointer to the input bytes * @param length the length of the input bytes * @param timestamp the timestamp of input bytes * @param chassis_detail the parsed chassis_detail */ virtual void Parse(const std::uint8_t *bytes, int32_t length, const struct timeval &timestamp, Lincoln *chassis_detail) const; private: /** * @brief calculate front left wheel speed based on byte array. * config detail: {'name': 'fl', 'offset': 0.0, 'precision': 0.01, 'len': 16, * 'f_type': 'value', 'is_signed_var': True, 'physical_range': '[0|0]', 'bit': * 0, 'type': 'double', 'order': 'intel', 'physical_unit': '"rad/s"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of byte input */ double front_left_wheel_speed(const std::uint8_t *bytes, int32_t length) const; /** * @brief calculate front right wheel speed based on byte array. * config detail: {'name': 'fr', 'offset': 0.0, 'precision': 0.01, 'len': 16, * 'f_type': 'value', 'is_signed_var': True, 'physical_range': '[0|0]', 'bit': * 16, 'type': 'double', 'order': 'intel', 'physical_unit': '"rad/s"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of front right wheel speed */ double front_right_wheel_speed(const std::uint8_t *bytes, int32_t length) const; /** * @brief calculate rear left wheel speed based on byte array. * config detail: {'name': 'rl', 'offset': 0.0, 'precision': 0.01, 'len': 16, * 'f_type': 'value', 'is_signed_var': True, 'physical_range': '[0|0]', 'bit': * 32, 'type': 'double', 'order': 'intel', 'physical_unit': '"rad/s"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of rear left wheel speed */ double rear_left_wheel_speed(const std::uint8_t *bytes, int32_t length) const; /** * @brief calculate rear right wheel speed based on byte array. * config detail: {'name': 'rr', 'offset': 0.0, 'precision': 0.01, 'len': 16, * 'f_type': 'value', 'is_signed_var': True, 'physical_range': '[0|0]', 'bit': * 48, 'type': 'double', 'order': 'intel', 'physical_unit': '"rad/s"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of rear right wheel speed */ double rear_right_wheel_speed(const std::uint8_t *bytes, int32_t length) const; double parse_two_frames(const std::uint8_t low_byte, const std::uint8_t high_byte) const; WheelSpeed::WheelSpeedType wheel_direction_convert(double wheel_speed) const; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/throttle_62_test.cc
/* Copyright 2017 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/lincoln/protocol/throttle_62.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { TEST(Throttle62Test, General) { uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; Throttle62 throttle; EXPECT_EQ(throttle.GetPeriod(), 10 * 1000); throttle.UpdateData(data); EXPECT_EQ(data[0], 0b00000000); EXPECT_EQ(data[1], 0b00000000); EXPECT_EQ(data[2], 0b01100011); EXPECT_EQ(data[3], 0b01100000); EXPECT_EQ(data[4], 0b01010001); EXPECT_EQ(data[5], 0b01010010); EXPECT_EQ(data[6], 0b01010011); EXPECT_EQ(data[7], 0b00000000); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/steering_65.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/steering_65.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::Byte; const int32_t Steering65::ID = 0x65; void Steering65::Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const { chassis_detail->mutable_eps()->set_steering_angle( steering_angle(bytes, length)); // no steering angle speed chassis_detail->mutable_eps()->set_steering_angle_cmd( reported_steering_angle_cmd(bytes, length)); // ? chassis_detail->mutable_eps()->set_is_steering_angle_valid(true); // vehicle speed from steering, kph -> mps chassis_detail->mutable_eps()->set_vehicle_speed( vehicle_speed(bytes, length) / 3.6); // speed, as it has a higher accuracy // kph -> mps chassis_detail->mutable_vehicle_spd()->set_vehicle_spd( vehicle_speed(bytes, length) / 3.6); chassis_detail->mutable_vehicle_spd()->set_is_vehicle_spd_valid(true); chassis_detail->mutable_eps()->set_epas_torque(epas_torque(bytes, length)); chassis_detail->mutable_eps()->set_steering_enabled( is_enabled(bytes, length)); chassis_detail->mutable_eps()->set_driver_override( is_driver_override(bytes, length)); chassis_detail->mutable_eps()->set_driver_activity( is_driver_activity(bytes, length)); chassis_detail->mutable_eps()->set_watchdog_fault( is_watchdog_counter_fault(bytes, length)); chassis_detail->mutable_eps()->set_channel_1_fault( is_channel_1_fault(bytes, length)); chassis_detail->mutable_eps()->set_channel_2_fault( is_channel_2_fault(bytes, length)); chassis_detail->mutable_eps()->set_calibration_fault( is_calibration_fault(bytes, length)); chassis_detail->mutable_eps()->set_connector_fault( is_connector_fault(bytes, length)); chassis_detail->mutable_check_response()->set_is_eps_online( !is_driver_override(bytes, length)); } void Steering65::Parse(const std::uint8_t *bytes, int32_t length, const struct timeval &timestamp, Lincoln *chassis_detail) const { chassis_detail->mutable_eps()->set_timestamp_65( static_cast<double>(timestamp.tv_sec) + static_cast<double>(timestamp.tv_usec) / 1000000.0); Parse(bytes, length, chassis_detail); } double Steering65::steering_angle(const std::uint8_t *bytes, int32_t length) const { Byte frame_high(bytes + 1); int32_t high = frame_high.get_byte(0, 8); Byte frame_low(bytes + 0); int32_t low = frame_low.get_byte(0, 8); int32_t value = (high << 8) | low; if (value > 0x8000) { value = value - 0x10000; } return value * 0.100000; } double Steering65::reported_steering_angle_cmd(const std::uint8_t *bytes, int32_t length) const { Byte frame_high(bytes + 3); int32_t high = frame_high.get_byte(0, 8); Byte frame_low(bytes + 2); int32_t low = frame_low.get_byte(0, 8); int32_t value = (high << 8) | low; if (value > 0x8000) { value = value - 0x10000; } return value * 0.100000; } double Steering65::vehicle_speed(const std::uint8_t *bytes, int32_t length) const { Byte frame_high(bytes + 5); int32_t high = frame_high.get_byte(0, 8); Byte frame_low(bytes + 4); int32_t low = frame_low.get_byte(0, 8); int32_t value = (high << 8) | low; return value * 0.010000; } double Steering65::epas_torque(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 6); int32_t x = frame.get_byte(0, 8); if (x > 0x7F) { x -= 0x100; } return x * 0.062500; } bool Steering65::is_enabled(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(0); } bool Steering65::is_driver_override(const std::uint8_t *bytes, int32_t length) const { // Cleared on rising edge of EN bit in command message Byte frame(bytes + 7); return frame.is_bit_1(1); } bool Steering65::is_driver_activity(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(2); } bool Steering65::is_watchdog_counter_fault(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(3); } bool Steering65::is_channel_1_fault(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(4); } bool Steering65::is_channel_2_fault(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(5); } bool Steering65::is_calibration_fault(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(6); } bool Steering65::is_connector_fault(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(7); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/brake_61.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/brake_61.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 lincoln { using ::apollo::drivers::canbus::Byte; const int32_t Brake61::ID = 0x61; void Brake61::Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const { chassis_detail->mutable_brake()->set_brake_input(pedal_input(bytes, length)); chassis_detail->mutable_brake()->set_brake_cmd(pedal_cmd(bytes, length)); chassis_detail->mutable_brake()->set_brake_output( pedal_output(bytes, length)); chassis_detail->mutable_brake()->set_boo_input(boo_input(bytes, length)); chassis_detail->mutable_brake()->set_boo_cmd(boo_cmd(bytes, length)); chassis_detail->mutable_brake()->set_boo_output(boo_output(bytes, length)); chassis_detail->mutable_brake()->set_watchdog_applying_brakes( is_watchdog_counter_applying_brakes(bytes, length)); chassis_detail->mutable_brake()->set_watchdog_source( watchdog_counter_source(bytes, length)); chassis_detail->mutable_brake()->set_brake_enabled(is_enabled(bytes, length)); chassis_detail->mutable_brake()->set_driver_override( is_driver_override(bytes, length)); chassis_detail->mutable_brake()->set_driver_activity( is_driver_activity(bytes, length)); chassis_detail->mutable_brake()->set_watchdog_fault( is_watchdog_counter_fault(bytes, length)); chassis_detail->mutable_brake()->set_channel_1_fault( is_channel_1_fault(bytes, length)); chassis_detail->mutable_brake()->set_channel_2_fault( is_channel_2_fault(bytes, length)); chassis_detail->mutable_brake()->set_boo_fault( is_boo_switch_fault(bytes, length)); chassis_detail->mutable_brake()->set_connector_fault( is_connector_fault(bytes, length)); chassis_detail->mutable_check_response()->set_is_esp_online( !is_driver_override(bytes, length)); } double Brake61::pedal_input(const std::uint8_t *bytes, int32_t length) const { DCHECK_GE(length, 2); // Pedal Input from the physical pedal return parse_two_frames(bytes[0], bytes[1]); } double Brake61::pedal_cmd(const std::uint8_t *bytes, int32_t length) const { DCHECK_GE(length, 4); // Pedal Command from the command message return parse_two_frames(bytes[2], bytes[3]); } double Brake61::pedal_output(const std::uint8_t *bytes, int32_t length) const { DCHECK_GE(length, 6); // Pedal Output is the maximum of PI and PC return parse_two_frames(bytes[4], bytes[5]); } double Brake61::parse_two_frames(const std::uint8_t low_byte, const std::uint8_t high_byte) const { Byte frame_high(&high_byte); int32_t high = frame_high.get_byte(0, 8); Byte frame_low(&low_byte); int32_t low = frame_low.get_byte(0, 8); int32_t value = (high << 8) | low; // control needs a value in range [0, 100] % double output = 100.0 * value * 1.52590218966964e-05; output = ProtocolData::BoundedValue(0.0, 100.0, output); return output; } bool Brake61::boo_input(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 6); // seems typo here return frame.is_bit_1(0); } bool Brake61::boo_cmd(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 6); return frame.is_bit_1(1); } bool Brake61::boo_output(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 6); // seems typo here return frame.is_bit_1(2); } bool Brake61::is_watchdog_counter_applying_brakes(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 6); return frame.is_bit_1(3); } int32_t Brake61::watchdog_counter_source(const std::uint8_t *bytes, int32_t length) const { // see table for status code Byte frame(bytes + 6); int32_t x = frame.get_byte(4, 4); return x; } bool Brake61::is_enabled(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(0); } bool Brake61::is_driver_override(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(1); } bool Brake61::is_driver_activity(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(2); } bool Brake61::is_watchdog_counter_fault(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(3); } bool Brake61::is_channel_1_fault(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(4); } bool Brake61::is_channel_2_fault(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(5); } bool Brake61::is_boo_switch_fault(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(6); } bool Brake61::is_connector_fault(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(7); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/gps_6d.h
/****************************************************************************** * Copyright 2017 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 gps_6d.h * @brief the class of Gps6d (for lincoln vehicle) */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Gps6d * * @brief one of the protocol data of lincoln vehicle */ class Gps6d : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /* * @brief parse received data * @param bytes a pointer to the input bytes * @param length the length of the input bytes * @param timestamp the timestamp of input data * @param chassis_detail the parsed chassis_detail */ virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const; /** * @brief get latitude from byte array * config detail: {'name': 'latitude', 'offset': 0.0, 'precision': * 3.3333333e-07, 'len': 31, 'f_type': 'value', 'is_signed_var': True, * 'physical_range': '[0|0]', 'bit': 0, 'type': 'double', 'order': 'intel', * 'physical_unit': '"degrees"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of latitude */ double latitude(const std::uint8_t *bytes, int32_t length) const; /** * @brief get longitude from byte array * config detail: {'name': 'longitude', 'offset': 0.0, 'precision': * 3.3333333e-07, 'len': 31, 'f_type': 'value', 'is_signed_var': True, * 'physical_range': '[0|0]', 'bit': 32, 'type': 'double', 'order': 'intel', * 'physical_unit': '"degrees"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of longitude */ double longitude(const std::uint8_t *bytes, int32_t length) const; /** * @brief check is_valid from byte array * config detail: {'name': 'valid', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 63, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the boolean value of is_valid bit */ bool is_valid(const std::uint8_t *bytes, int32_t length) const; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/wheelspeed_6a.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/wheelspeed_6a.h" #include "glog/logging.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::Byte; const int32_t Wheelspeed6a::ID = 0x6A; void Wheelspeed6a::Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const { // how to set direction // what is "valid" // front left chassis_detail->mutable_vehicle_spd()->set_wheel_spd_fl( front_left_wheel_speed(bytes, length)); chassis_detail->mutable_vehicle_spd()->set_is_wheel_spd_fl_valid(true); chassis_detail->mutable_vehicle_spd()->set_wheel_direction_fl( wheel_direction_convert(front_left_wheel_speed(bytes, length))); // front right chassis_detail->mutable_vehicle_spd()->set_wheel_spd_fr( front_right_wheel_speed(bytes, length)); chassis_detail->mutable_vehicle_spd()->set_is_wheel_spd_fr_valid(true); chassis_detail->mutable_vehicle_spd()->set_wheel_direction_fr( wheel_direction_convert(front_right_wheel_speed(bytes, length))); // rear left chassis_detail->mutable_vehicle_spd()->set_wheel_spd_rl( rear_left_wheel_speed(bytes, length)); chassis_detail->mutable_vehicle_spd()->set_is_wheel_spd_rl_valid(true); chassis_detail->mutable_vehicle_spd()->set_wheel_direction_rl( wheel_direction_convert(rear_left_wheel_speed(bytes, length))); // rear right chassis_detail->mutable_vehicle_spd()->set_wheel_spd_rr( rear_right_wheel_speed(bytes, length)); chassis_detail->mutable_vehicle_spd()->set_is_wheel_spd_rr_valid(true); chassis_detail->mutable_vehicle_spd()->set_wheel_direction_rr( wheel_direction_convert(rear_right_wheel_speed(bytes, length))); /* -?(rr(bytes, length)); -?(rl(bytes, length)); -?(fr(bytes, length)); -?(fl(bytes, length));*/ } void Wheelspeed6a::Parse(const std::uint8_t *bytes, int32_t length, const struct timeval &timestamp, Lincoln *chassis_detail) const { chassis_detail->mutable_vehicle_spd()->set_timestamp_sec( static_cast<double>(timestamp.tv_sec) + static_cast<double>(timestamp.tv_usec) / 1000000.0); Parse(bytes, length, chassis_detail); } double Wheelspeed6a::front_left_wheel_speed(const std::uint8_t *bytes, int32_t length) const { DCHECK_GE(length, 2); return parse_two_frames(bytes[0], bytes[1]); } double Wheelspeed6a::front_right_wheel_speed(const std::uint8_t *bytes, int32_t length) const { DCHECK_GE(length, 4); return parse_two_frames(bytes[2], bytes[3]); } double Wheelspeed6a::rear_left_wheel_speed(const std::uint8_t *bytes, int32_t length) const { DCHECK_GE(length, 6); return parse_two_frames(bytes[4], bytes[5]); } double Wheelspeed6a::rear_right_wheel_speed(const std::uint8_t *bytes, int32_t length) const { DCHECK_GE(length, 8); return parse_two_frames(bytes[6], bytes[7]); } double Wheelspeed6a::parse_two_frames(const std::uint8_t low_byte, const std::uint8_t high_byte) const { Byte high_frame(&high_byte); int32_t high = high_frame.get_byte(0, 8); Byte low_frame(&low_byte); int32_t low = low_frame.get_byte(0, 8); int32_t value = (high << 8) | low; if (value > 0x7FFF) { value -= 0x10000; } return value * 0.010000; } WheelSpeed::WheelSpeedType Wheelspeed6a::wheel_direction_convert( double wheel_speed) const { WheelSpeed::WheelSpeedType wheel_direction = WheelSpeed::INVALID; if (wheel_speed > 0) { wheel_direction = WheelSpeed::FORWARD; } else if ((wheel_speed > -0.01) && (wheel_speed < 0.01)) { wheel_direction = WheelSpeed::STANDSTILL; } else if (wheel_speed < 0) { wheel_direction = WheelSpeed::BACKWARD; } else { wheel_direction = WheelSpeed::INVALID; } return wheel_direction; } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/surround_73.h
/****************************************************************************** * Copyright 2017 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 surround_73.h * @brief the class of Surround73 (for lincoln vehicle) */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Surround73 * * @brief one of the protocol data of lincoln vehicle */ class Surround73 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /* * @brief parse received data * @param bytes a pointer to the input bytes * @param length the length of the input bytes * @param chassis_detail the parsed chassis_detail */ virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const; private: bool is_cross_traffic_alert_left(const std::uint8_t *bytes, int32_t length) const; bool is_cross_traffic_alert_left_enabled(const std::uint8_t *bytes, int32_t length) const; bool is_blind_spot_left_alert(const std::uint8_t *bytes, int32_t length) const; bool is_blind_spot_left_alert_enabled(const std::uint8_t *bytes, int32_t length) const; bool is_cross_traffic_alert_right(const std::uint8_t *bytes, int32_t length) const; bool is_cross_traffic_alert_right_enabled(const std::uint8_t *bytes, int32_t length) const; bool is_blind_spot_right_alert(const std::uint8_t *bytes, int32_t length) const; bool is_blind_spot_right_alert_enabled(const std::uint8_t *bytes, int32_t length) const; double sonar00(const std::uint8_t *bytes, int32_t length) const; double sonar01(const std::uint8_t *bytes, int32_t length) const; double sonar02(const std::uint8_t *bytes, int32_t length) const; double sonar03(const std::uint8_t *bytes, int32_t length) const; double sonar04(const std::uint8_t *bytes, int32_t length) const; double sonar05(const std::uint8_t *bytes, int32_t length) const; double sonar06(const std::uint8_t *bytes, int32_t length) const; double sonar07(const std::uint8_t *bytes, int32_t length) const; double sonar08(const std::uint8_t *bytes, int32_t length) const; double sonar09(const std::uint8_t *bytes, int32_t length) const; double sonar10(const std::uint8_t *bytes, int32_t length) const; double sonar11(const std::uint8_t *bytes, int32_t length) const; bool sonar_enabled(const std::uint8_t *bytes, int32_t length) const; bool sonar_fault(const std::uint8_t *bytes, int32_t length) const; double sonar_range(const std::int32_t x) const; double sonars(const std::uint8_t *bytes, std::uint8_t sonar_number, int32_t length) const; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/gear_67_test.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/gear_67.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { TEST(Gear67Test, General) { uint8_t data[8] = {0x56, 0x52, 0x53, 0x54, 0xF1, 0xF2, 0xF3, 0xF4}; int32_t length = 8; Lincoln cd; Gear67 gear; int32_t state = gear.gear_state(data, 8); EXPECT_EQ(state, (data[0] & 0b00000111)); EXPECT_EQ((data[0] >> 3 & 0b00000001), gear.is_driver_override(data, 8)); gear.Parse(data, length, &cd); EXPECT_TRUE(cd.gear().is_shift_position_valid()); EXPECT_EQ(cd.gear().gear_state(), Chassis::GEAR_INVALID); EXPECT_FALSE(cd.gear().driver_override()); EXPECT_EQ(cd.gear().gear_cmd(), Chassis::GEAR_LOW); EXPECT_FALSE(cd.gear().canbus_fault()); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/license_7e.cc
/* Copyright 2017 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/lincoln/protocol/license_7e.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { namespace { using ::apollo::drivers::canbus::Byte; template <class T> inline T ByteTo(const Byte& byte) { return static_cast<T>(byte.get_byte(0, 8)); } inline std::string ByteToString(const Byte& byte) { return std::string(1, ByteTo<char>(byte)); } } // namespace const int32_t License7e::ID = 0x7E; License7e::License7e() : vin_part0_(""), vin_part1_(""), vin_part2_(""), vin_part0_flag_(false), vin_part1_flag_(false), vin_part2_flag_(false), parse_success_(false) {} void License7e::Parse(const std::uint8_t* bytes, int length, Lincoln* chassis_detail) const { if (!parse_success_) { switch (mux(bytes, length)) { case 0x83: vin_part0_ = vin00(bytes, length) + vin01(bytes, length) + vin02(bytes, length) + vin03(bytes, length) + vin04(bytes, length) + vin05(bytes, length); vin_part0_flag_ = true; break; case 0x84: vin_part1_ = vin06(bytes, length) + vin07(bytes, length) + vin08(bytes, length) + vin09(bytes, length) + vin10(bytes, length) + vin11(bytes, length); vin_part1_flag_ = true; break; case 0x85: vin_part2_ = vin12(bytes, length) + vin13(bytes, length) + vin14(bytes, length) + vin15(bytes, length) + vin16(bytes, length); vin_part2_flag_ = true; break; } if (vin_part0_flag_ && vin_part1_flag_ && vin_part2_flag_) { parse_success_ = true; chassis_detail->mutable_vehicle_id()->set_vin( (vin_part0_ + vin_part1_ + vin_part2_)); } } } // config detail: {'name': 'mux', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 0, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int License7e::mux(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 0); return ByteTo<int>(frame); } // config detail: {'name': 'ready', 'offset': 0.0, 'precision': 1.0, 'len': 1, // 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 8, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} bool License7e::is_ready(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 1); return frame.is_bit_1(0); } // config detail: {'name': 'trial', 'offset': 0.0, 'precision': 1.0, 'len': 1, // 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 9, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} bool License7e::is_trial(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 1); return frame.is_bit_1(1); } // config detail: {'name': 'expired', 'offset': 0.0, 'precision': 1.0, 'len': 1, // 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 10, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} bool License7e::is_expired(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 1); return frame.is_bit_1(2); } // config detail: {'name': 'feat_base_enabled', 'offset': 0.0, 'precision': 1.0, // 'len': 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 16, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} bool License7e::is_feat_base_enabled(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 2); return frame.is_bit_1(0); } // config detail: {'name': 'date0', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 16, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int License7e::date0(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 2); return ByteTo<int>(frame); } // config detail: {'name': 'date6', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 16, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int License7e::date6(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 2); return ByteTo<int>(frame); } // config detail: {'name': 'mac0', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 16, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int License7e::mac0(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 2); return ByteTo<int>(frame); } // config detail: {'name': 'vin00', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 16, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string License7e::vin00(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 2); return ByteToString(frame); } // config detail: {'name': 'vin06', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 16, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string License7e::vin06(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 2); return ByteToString(frame); } // config detail: {'name': 'vin12', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 16, 'type': 'int', 'order': 'intel', 'physical_unit': '""'}t std::string License7e::vin12(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 2); return ByteToString(frame); } // config detail: {'name': 'feat_base_trial', 'offset': 0.0, 'precision': 1.0, // 'len': 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 17, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} bool License7e::is_feat_base_trial(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 2); return frame.is_bit_1(1); } // config detail: {'name': 'date1', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 24, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int License7e::date1(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 3); return ByteTo<int>(frame); } // config detail: {'name': 'date7', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 24, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int License7e::date7(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 3); return ByteTo<int>(frame); } // config detail: {'name': 'mac1', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 24, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int License7e::mac1(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 3); return ByteTo<int>(frame); } // config detail: {'name': 'vin01', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 24, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string License7e::vin01(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 3); return ByteToString(frame); } // config detail: {'name': 'vin07', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 24, 'type': 'int', 'order': 'intel', 'physical_unit': '""' std::string License7e::vin07(const std::uint8_t* bytes, int32_t length) const { Byte frame(bytes + 3); return ByteToString(frame); } // config detail: {'name': 'vin13', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 24, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string License7e::vin13(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 3); return ByteToString(frame); } // config detail: {'name': 'date2', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 32, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int License7e::date2(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 4); return ByteTo<int>(frame); } // config detail: {'name': 'date8', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 32, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int License7e::date8(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 4); return ByteTo<int>(frame); } // config detail: {'name': 'mac2', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 32, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int License7e::mac2(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 4); return ByteTo<int>(frame); } // config detail: {'name': 'vin02', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 32, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string License7e::vin02(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 4); return ByteToString(frame); } // config detail: {'name': 'vin08', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 32, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string License7e::vin08(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 4); return ByteToString(frame); } // config detail: {'name': 'vin14', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 32, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string License7e::vin14(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 4); return ByteToString(frame); } // config detail: {'name': 'feat_base_trials_used', 'offset': 0.0, // 'precision': 1.0, 'len': 16, 'f_type': 'value', 'is_signed_var': False, // 'physical_range': '[0|0]', 'bit': 32, 'type': 'int', 'order': 'intel', // 'physical_unit': '""'} int License7e::feat_base_trials_used(const std::uint8_t* bytes, int length) const { Byte t0(bytes + 5); int x = t0.get_byte(0, 8); Byte t1(bytes + 4); int t = t1.get_byte(0, 8); x <<= 8; x |= t; return x; } // config detail: {'name': 'date3', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 40, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int License7e::date3(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 5); return ByteTo<int>(frame); } // config detail: {'name': 'date9', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 40, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int License7e::date9(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 5); return ByteTo<int>(frame); } // config detail: {'name': 'mac3', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 40, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int License7e::mac3(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 5); return ByteTo<int>(frame); } // config detail: {'name': 'vin03', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 40, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string License7e::vin03(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 5); return ByteToString(frame); } // config detail: {'name': 'vin09', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 40, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string License7e::vin09(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 5); return ByteToString(frame); } // config detail: {'name': 'vin15', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 40, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string License7e::vin15(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 5); return ByteToString(frame); } // config detail: {'name': 'date4', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 48, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int License7e::date4(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 6); return ByteTo<int>(frame); } // config detail: {'name': 'mac4', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 48, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int License7e::mac4(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 6); return ByteTo<int>(frame); } // config detail: {'name': 'vin04', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 48, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string License7e::vin04(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 6); return ByteToString(frame); } // config detail: {'name': 'vin10', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 48, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string License7e::vin10(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 6); return ByteToString(frame); } // config detail: {'name': 'vin16', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 48, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string License7e::vin16(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 6); return ByteToString(frame); } // config detail: {'name': 'feat_base_trials_remaining', 'offset': 0.0, // 'precision': 1.0, 'len': 16, 'f_type': 'value', 'is_signed_var': False, // 'physical_range': '[0|0]', 'bit': 48, 'type': 'int', 'order': 'intel', // 'physical_unit': '""'} int License7e::feat_base_trials_remaining(const std::uint8_t* bytes, int length) const { Byte t0(bytes + 7); int x = t0.get_byte(0, 8); Byte t1(bytes + 6); int t = t1.get_byte(0, 8); x <<= 8; x |= t; return x; } // config detail: {'name': 'date5', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 56, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int License7e::date5(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 7); return ByteTo<int>(frame); } // config detail: {'name': 'mac5', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 56, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} int License7e::mac5(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 7); return ByteTo<int>(frame); } // config detail: {'name': 'vin05', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 56, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string License7e::vin05(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 7); return ByteToString(frame); } // config detail: {'name': 'vin11', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 56, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} std::string License7e::vin11(const std::uint8_t* bytes, int length) const { Byte frame(bytes + 7); return ByteToString(frame); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/accel_6b_test.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/accel_6b.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { class Accel6bTest : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Accel6bTest, Parse) { Accel6b acc; int32_t length = 8; Lincoln chassis_detail; uint8_t bytes[8] = {0, 0}; bytes[0] = 0b11111100; bytes[1] = 0b11111110; bytes[2] = 0b11111110; bytes[3] = 0b11111110; bytes[4] = 0b11111110; bytes[5] = 0b11111110; acc.Parse(bytes, length, &chassis_detail); EXPECT_DOUBLE_EQ(chassis_detail.vehicle_spd().lat_acc(), -2.6); EXPECT_DOUBLE_EQ(chassis_detail.vehicle_spd().long_acc(), -2.58); EXPECT_DOUBLE_EQ(chassis_detail.vehicle_spd().vert_acc(), -2.58); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/gear_66_test.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/gear_66.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { class Accel6bTest : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Accel6bTest, Parse) { Gear66 gear; uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; EXPECT_EQ(gear.GetPeriod(), 10 * 1000); gear.UpdateData(data); EXPECT_EQ(data[0], 0b01100000); 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 lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/gear_66.h
/****************************************************************************** * Copyright 2017 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 gear_66.h * @brief the class of Gear66 (for lincoln vehicle) */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Gear66 * * @brief one of the protocol data of lincoln vehicle */ class Gear66 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /** * @brief get the data period * @return the value of data period */ virtual uint32_t GetPeriod() const; /** * @brief update the data * @param data a pointer to the data to be updated */ virtual void UpdateData(uint8_t *data); /** * @brief reset the private variables */ virtual void Reset(); /** * @brief set gear to none * @return a this pointer to the instance itself */ Gear66 *set_gear_none(); /** * @brief set gear to park * @return a this pointer to the instance itself */ Gear66 *set_gear_park(); /** * @brief set gear to reverse * @return a this pointer to the instance itself */ Gear66 *set_gear_reverse(); /** * @brief set gear to neutral * @return a this pointer to the instance itself */ Gear66 *set_gear_neutral(); /** * @brief set gear to drive * @return a this pointer to the instance itself */ Gear66 *set_gear_drive(); /** * @brief set gear to low * @return a this pointer to the instance itself */ Gear66 *set_gear_low(); private: /** * @brief set gear position * config detail: {'name': 'gcmd', 'offset': 0.0, 'precision': 1.0, 'len': 3, * 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 0, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} */ void set_gear_p(uint8_t *data, int32_t gear); /** * @brief set clear driver override position * config detail: {'name': 'clear', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 7, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} */ void set_clear_driver_override_flag_p(uint8_t *bytes); private: int32_t gear_ = 0; bool update_ = false; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/fuellevel_72_test.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/fuellevel_72.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { class Accel6bTest : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Accel6bTest, Parse) { Fuellevel72 fuel; uint8_t data[8] = {0x61, 0x62, 0x63, 0x64, 0xF1, 0xF2, 0xF3, 0xF4}; int32_t length = 8; Lincoln chassis_detail; fuel.Parse(data, length, &chassis_detail); EXPECT_DOUBLE_EQ(chassis_detail.battery().fuel_level(), 2737.50876); EXPECT_EQ(data[0], 0x61); EXPECT_EQ(data[1], 0x62); EXPECT_EQ(data[2], 0x63); EXPECT_EQ(data[3], 0x64); EXPECT_EQ(data[4], 0xF1); EXPECT_EQ(data[5], 0xF2); EXPECT_EQ(data[6], 0xF3); EXPECT_EQ(data[7], 0xF4); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/gps_6f_test.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/gps_6f.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { TEST(Gps6fTest, General) { uint8_t data[8] = {0x56, 0x52, 0x53, 0x54, 0xF1, 0xF2, 0xF3, 0xF4}; int32_t length = 8; Lincoln cd; Gps6f gps; gps.Parse(data, length, &cd); EXPECT_TRUE(cd.has_basic()); EXPECT_TRUE(cd.basic().has_altitude()); EXPECT_TRUE(cd.basic().has_heading()); EXPECT_TRUE(cd.basic().has_gps_speed()); EXPECT_DOUBLE_EQ(cd.basic().altitude(), 5269.5); EXPECT_DOUBLE_EQ(cd.basic().heading(), 215.87); EXPECT_DOUBLE_EQ(cd.basic().hdop(), 3.6); EXPECT_DOUBLE_EQ(cd.basic().vdop(), 3.8); EXPECT_DOUBLE_EQ(cd.basic().quality(), FIX_INVALID); EXPECT_DOUBLE_EQ(cd.basic().gps_speed(), 107.73664); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/version_7f.h
/****************************************************************************** * Copyright 2017 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 verion_7f.h * @brief the class of Version7f (for lincoln vehicle) */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Version7f * * @brief one of the protocol data of lincoln vehicle */ class Version7f : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /* * @brief parse received data * @param bytes a pointer to the input bytes * @param length the length of the input bytes * @param chassis_detail the parsed chassis_detail */ virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const; /** * @brief get module name based on byte array. * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of byte input */ int32_t module_name(const std::uint8_t *bytes, int32_t length) const; /** * @brief get major version based on byte array. * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of major version */ int32_t major_version(const std::uint8_t *bytes, int32_t length) const; /** * @brief get minor version based on byte array. * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of minor version */ int32_t minor_version(const std::uint8_t *bytes, int32_t length) const; /** * @brief get build number based on byte array. * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of build number */ int32_t build_number(const std::uint8_t *bytes, int32_t length) const; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/brake_60.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/brake_60.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::Byte; // public const int32_t Brake60::ID = 0x60; uint32_t Brake60::GetPeriod() const { static const uint32_t PERIOD = 10 * 1000; return PERIOD; } void Brake60::UpdateData(uint8_t *data) { set_pedal_p(data, pedal_cmd_); set_boo_cmd_p(data, boo_cmd_); set_enable_p(data, pedal_enable_); set_clear_driver_override_flag_p(data, clear_driver_override_flag_); set_watchdog_counter_p(data, watchdog_counter_); } void Brake60::Reset() { pedal_cmd_ = 0.0; boo_cmd_ = false; pedal_enable_ = false; clear_driver_override_flag_ = false; ignore_driver_override_ = false; watchdog_counter_ = 0; } Brake60 *Brake60::set_pedal(double pedal) { pedal_cmd_ = pedal; if (pedal_cmd_ < 1e-3) { disable_boo_cmd(); } else { enable_boo_cmd(); } return this; } Brake60 *Brake60::enable_boo_cmd() { boo_cmd_ = true; return this; } Brake60 *Brake60::disable_boo_cmd() { boo_cmd_ = false; return this; } Brake60 *Brake60::set_enable() { pedal_enable_ = true; return this; } Brake60 *Brake60::set_disable() { pedal_enable_ = false; return this; } void Brake60::set_pedal_p(uint8_t *data, double pedal) { // change from [0-100] to [0.00-1.00] // and a rough mapping pedal /= 100.; pedal = ProtocolData::BoundedValue(0.0, 1.0, pedal); int32_t x = static_cast<int32_t>(pedal / 1.52590218966964e-05); std::uint8_t t = 0; t = static_cast<uint8_t>(x & 0xFF); Byte frame_low(data + 0); frame_low.set_value(t, 0, 8); x >>= 8; t = static_cast<uint8_t>(x & 0xFF); Byte frame_high(data + 1); frame_high.set_value(t, 0, 8); } void Brake60::set_boo_cmd_p(uint8_t *bytes, bool boo_cmd) { Byte frame(bytes + 2); if (boo_cmd) { frame.set_bit_1(0); } else { frame.set_bit_0(0); } } void Brake60::set_enable_p(uint8_t *bytes, bool enable) { Byte frame(bytes + 3); if (enable) { frame.set_bit_1(0); } else { frame.set_bit_0(0); } } void Brake60::set_clear_driver_override_flag_p(uint8_t *bytes, bool clear) { Byte frame(bytes + 3); if (clear) { frame.set_bit_1(1); } else { frame.set_bit_0(1); } } void Brake60::set_watchdog_counter_p(uint8_t *data, int32_t count) { count = ProtocolData::BoundedValue(0, 255, count); Byte frame(data + 7); frame.set_value(static_cast<uint8_t>(count), 0, 8); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/version_7f.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/version_7f.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::Byte; const int32_t Version7f::ID = 0x7f; void Version7f::Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const { switch (module_name(bytes, length)) { case 0x01: chassis_detail->mutable_brake()->set_major_version( major_version(bytes, length)); chassis_detail->mutable_brake()->set_minor_version( minor_version(bytes, length)); chassis_detail->mutable_brake()->set_build_number( build_number(bytes, length)); break; case 0x02: chassis_detail->mutable_gas()->set_major_version( major_version(bytes, length)); chassis_detail->mutable_gas()->set_minor_version( minor_version(bytes, length)); chassis_detail->mutable_gas()->set_build_number( build_number(bytes, length)); break; case 0x03: chassis_detail->mutable_eps()->set_major_version( major_version(bytes, length)); chassis_detail->mutable_eps()->set_minor_version( minor_version(bytes, length)); chassis_detail->mutable_eps()->set_build_number( build_number(bytes, length)); break; default: break; } } int32_t Version7f::module_name(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 0); int32_t x = frame.get_byte(0, 8); return x; // 0x03 means Steering/Shifter, otherwise ignore } int32_t Version7f::major_version(const std::uint8_t *bytes, int32_t length) const { Byte frame_high(bytes + 3); int32_t high = frame_high.get_byte(0, 8); Byte frame_low(bytes + 2); int32_t low = frame_low.get_byte(0, 8); int32_t value = (high << 8) | low; return value; } int32_t Version7f::minor_version(const std::uint8_t *bytes, int32_t length) const { Byte frame_high(bytes + 5); int32_t high = frame_high.get_byte(0, 8); Byte frame_low(bytes + 4); int32_t low = frame_low.get_byte(0, 8); int32_t value = (high << 8) | low; return value; } int32_t Version7f::build_number(const std::uint8_t *bytes, int32_t length) const { Byte frame_high(bytes + 7); int32_t high = frame_high.get_byte(0, 8); Byte frame_low(bytes + 6); int32_t low = frame_low.get_byte(0, 8); int32_t value = (high << 8) | low; return value; } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/brake_61.h
/****************************************************************************** * Copyright 2017 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 brake_61.h * @brief the class of Brake61 (for lincoln vehicle) */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Brake61 * * @brief one of the protocol data of lincoln vehicle */ class Brake61 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /* * @brief parse received data * @param bytes a pointer to the input bytes * @param length the length of the input bytes * @param timestamp the timestamp of input data * @param chassis_detail the parsed chassis_detail */ virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const; private: /** * @brief get pedal input from byte array * config detail: {'name': 'pi', 'offset': 0.0, 'precision': * 1.52590218966964e-05, 'len': 16, 'f_type': 'value', 'is_signed_var': False, * 'physical_range': '[0|1]', 'bit': 0, 'type': 'double', 'order': 'intel', * 'physical_unit': '"%"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of pedal input */ double pedal_input(const std::uint8_t *bytes, int32_t length) const; /** * @brief get pedal command for control from byte array * config detail: {'name': 'pc', 'offset': 0.0, 'precision': * 1.52590218966964e-05, 'len': 16, 'f_type': 'value', 'is_signed_var': False, * 'physical_range': '[0|1]', 'bit': 16, 'type': 'double', 'order': 'intel', * 'physical_unit': '"%"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of pedal command for control */ double pedal_cmd(const std::uint8_t *bytes, int32_t length) const; /** * @brief get pedal output from byte array * config detail: {'name': 'po', 'offset': 0.0, 'precision': * 1.52590218966964e-05, 'len': 16, 'f_type': 'value', 'is_signed_var': False, * 'physical_range': '[0|1]', 'bit': 32, 'type': 'double', 'order': 'intel', * 'physical_unit': '"%"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of pedal command for control */ double pedal_output(const std::uint8_t *bytes, int32_t length) const; double parse_two_frames(const std::uint8_t low_byte, const std::uint8_t high_byte) const; /** * @brief check if boo bit from input byte array is 1 or 0 (at position 0) * config detail: {'name': 'bi', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 50, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return boolean value of the corresponding bit */ bool boo_input(const std::uint8_t *bytes, int32_t length) const; /** * @brief check if cmd bit from input byte array is 1 or 0 (at position 1) * config detail: {'name': 'bc', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 49, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return boolean value of the corresponding bit */ bool boo_cmd(const std::uint8_t *bytes, int32_t length) const; /** * @brief check the boo bit for output from byte array (at position 2) * config detail: {'name': 'bo', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 48, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return boolean value of the corresponding bit */ bool boo_output(const std::uint8_t *bytes, int32_t length) const; /** * @brief check watchdog_counter bit (at position 3) * config detail: {'name': 'wdcbrk', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 51, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return boolean value of the corresponding bit */ bool is_watchdog_counter_applying_brakes(const std::uint8_t *bytes, int32_t length) const; /** * @brief check watchdog_counter bit (at position 4) * config detail: {'name': 'wdcsrc', 'offset': 0.0, 'precision': 1.0, 'len': * 4, 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 52, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return boolean value of the corresponding bit */ int32_t watchdog_counter_source(const std::uint8_t *bytes, int32_t length) const; /** * @brief check if enabled * config detail: {'name': 'en', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 56, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return true when enabled */ bool is_enabled(const std::uint8_t *bytes, int32_t length) const; /** * brief check driver override * config detail: {'name': 'override', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 57, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return true if driver override */ bool is_driver_override(const std::uint8_t *bytes, int32_t length) const; /** * brief check if is_driver activity * config detail: {'name': 'driver', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 58, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return true if driving activity */ bool is_driver_activity(const std::uint8_t *bytes, int32_t length) const; /** * brief check if is watchdog counter fault * config detail: {'name': 'fltwdc', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 59, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return true if watchdog counter fault */ bool is_watchdog_counter_fault(const std::uint8_t *bytes, int32_t length) const; /** * brief check if is channel 1 fault * config detail: {'name': 'flt1', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 60, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return true if channel 1 fault */ bool is_channel_1_fault(const std::uint8_t *bytes, int32_t length) const; /** * brief check if is channel 2 fault * config detail: {'name': 'flt2', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 61, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return true if channel 2 fault */ bool is_channel_2_fault(const std::uint8_t *bytes, int32_t length) const; /** * brief check if boo switch fault * config detail: {'name': 'fltboo', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 62, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return true if boo switch fault */ bool is_boo_switch_fault(const std::uint8_t *bytes, int32_t length) const; /** * brief check if connector fault * config detail: {'name': 'fltcon', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 63, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return true if connector fault */ bool is_connector_fault(const std::uint8_t *bytes, int32_t length) const; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/fuellevel_72.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/fuellevel_72.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::Byte; const int32_t Fuellevel72::ID = 0x72; void Fuellevel72::Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const { chassis_detail->mutable_battery()->set_fuel_level(fuel_level(bytes, length)); } double Fuellevel72::fuel_level(const std::uint8_t *bytes, int32_t length) const { Byte high_frame(bytes + 1); int32_t high = high_frame.get_byte(0, 8); Byte low_frame(bytes); int32_t low = low_frame.get_byte(0, 8); int32_t value = (high << 8) | low; if (value > 0x7FFF) { value -= 0x10000; } // should be in range of // [0x0000, 0x0398] // or [0xfc68, 0xffff] const double fuel_level_coeff = 0.108696; return value * fuel_level_coeff; } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/version_7f_test.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/version_7f.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { TEST(Version7fTest, General) { int32_t length = 8; Lincoln cd; Version7f version; uint8_t data[8] = {0x01, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; version.Parse(data, length, &cd); EXPECT_TRUE(cd.has_brake()); EXPECT_FALSE(cd.has_gas()); EXPECT_FALSE(cd.has_eps()); EXPECT_EQ(cd.brake().major_version(), 25699); EXPECT_EQ(cd.brake().minor_version(), 21073); EXPECT_EQ(cd.brake().build_number(), 21587); data[0] = 0x02; cd.Clear(); version.Parse(data, length, &cd); EXPECT_FALSE(cd.has_brake()); EXPECT_TRUE(cd.has_gas()); EXPECT_FALSE(cd.has_eps()); EXPECT_EQ(cd.gas().major_version(), 25699); EXPECT_EQ(cd.gas().minor_version(), 21073); EXPECT_EQ(cd.gas().build_number(), 21587); data[0] = 0x03; cd.Clear(); version.Parse(data, length, &cd); EXPECT_FALSE(cd.has_brake()); EXPECT_FALSE(cd.has_gas()); EXPECT_TRUE(cd.has_eps()); EXPECT_EQ(cd.eps().major_version(), 25699); EXPECT_EQ(cd.eps().minor_version(), 21073); EXPECT_EQ(cd.eps().build_number(), 21587); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/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_lincoln_protocol", srcs = [ "accel_6b.cc", "brake_60.cc", "brake_61.cc", "brakeinfo_74.cc", "fuellevel_72.cc", "gear_66.cc", "gear_67.cc", "gps_6d.cc", "gps_6e.cc", "gps_6f.cc", "gyro_6c.cc", "license_7e.cc", "misc_69.cc", "steering_64.cc", "steering_65.cc", "surround_73.cc", "throttle_62.cc", "throttle_63.cc", "throttleinfo_75.cc", "tirepressure_71.cc", "turnsignal_68.cc", "version_7f.cc", "wheelspeed_6a.cc", ], hdrs = [ "accel_6b.h", "brake_60.h", "brake_61.h", "brakeinfo_74.h", "fuellevel_72.h", "gear_66.h", "gear_67.h", "gps_6d.h", "gps_6e.h", "gps_6f.h", "gyro_6c.h", "license_7e.h", "misc_69.h", "steering_64.h", "steering_65.h", "surround_73.h", "throttle_62.h", "throttle_63.h", "throttleinfo_75.h", "tirepressure_71.h", "turnsignal_68.h", "version_7f.h", "wheelspeed_6a.h", ], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/lincoln/proto:lincoln_cc_proto", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_test( name = "accel_6b_test", size = "small", srcs = ["accel_6b_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "brake_60_test", size = "small", srcs = ["brake_60_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "brake_61_test", size = "small", srcs = ["brake_61_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "brakeinfo_74_test", size = "small", srcs = ["brakeinfo_74_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "fuellevel_72_test", size = "small", srcs = ["fuellevel_72_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "gear_66_test", size = "small", srcs = ["gear_66_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "gear_67_test", size = "small", srcs = ["gear_67_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "gps_6d_test", size = "small", srcs = ["gps_6d_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "gps_6e_test", size = "small", srcs = ["gps_6e_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "gps_6f_test", size = "small", srcs = ["gps_6f_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "gyro_6c_test", size = "small", srcs = ["gyro_6c_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "misc_69_test", size = "small", srcs = ["misc_69_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "steering_64_test", size = "small", srcs = ["steering_64_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "steering_65_test", size = "small", srcs = ["steering_65_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "throttle_62_test", size = "small", srcs = ["throttle_62_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "throttle_63_test", size = "small", srcs = ["throttle_63_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "throttleinfo_75_test", size = "small", srcs = ["throttleinfo_75_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "tirepressure_71_test", size = "small", srcs = ["tirepressure_71_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "turnsignal_68_test", size = "small", srcs = ["turnsignal_68_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "version_7f_test", size = "small", srcs = ["version_7f_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "wheelspeed_6a_test", size = "small", srcs = ["wheelspeed_6a_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cc_test( name = "surround_73_test", size = "small", srcs = ["surround_73_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) cpplint()
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/throttle_62.h
/****************************************************************************** * Copyright 2017 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 throttle_62.h * @brief the class of Throttle62 (for lincoln vehicle) */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Throttle62 * * @brief one of the protocol data of lincoln vehicle */ class Throttle62 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /** * @brief get the data period * @return the value of data period */ virtual uint32_t GetPeriod() const; /** * @brief update the data * @param data a pointer to the data to be updated */ virtual void UpdateData(uint8_t *data); /** * @brief reset the private variables */ virtual void Reset(); /** * @brief set pedal based on pedal command * @return a this pointer to the instance itself */ Throttle62 *set_pedal(double pcmd); /** * @brief set enable * @return a this pointer to the instance itself */ Throttle62 *set_enable(); /** * @brief set disable * @return a this pointer to the instance itself */ Throttle62 *set_disable(); /** * @brief set enable ignore driver override * @return a this pointer to the instance itself */ Throttle62 *set_enable_ignore_driver_override(); private: /** * config detail: {'name': 'pcmd', 'offset': 0.0, 'precision': * 1.52590218966964e-05, 'len': 16, 'f_type': 'value', 'is_signed_var': False, * 'physical_range': '[0|1]', 'bit': 0, 'type': 'double', 'order': 'intel', * 'physical_unit': '"%"'} */ void set_pedal_p(uint8_t *data, double pcmd); /** * config detail: {'name': 'en', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 24, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} */ void set_enable_p(uint8_t *bytes, bool en); /** * config detail: {'name': 'clear', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 25, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} */ void set_clear_driver_override_flag_p(uint8_t *bytes, bool clear); /** * config detail: {'name': 'ignore', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 26, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} */ void set_ignore_driver_override_p(uint8_t *bytes, bool ignore); /** * config detail: {'name': 'count', 'offset': 0.0, 'precision': 1.0, 'len': 8, * 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|255]', * 'bit': 56, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} */ void set_watchdog_counter_p(uint8_t *data, int32_t count); private: double pedal_cmd_ = 0.0; bool pedal_enable_ = false; bool clear_driver_override_flag_ = false; bool ignore_driver_override_ = false; int32_t watchdog_counter_ = 0; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/surround_73.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/surround_73.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::Byte; const int32_t Surround73::ID = 0x73; void Surround73::Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const { // sonar left chassis_detail->mutable_surround()->set_cross_traffic_alert_left( is_cross_traffic_alert_left(bytes, length)); chassis_detail->mutable_surround()->set_cross_traffic_alert_left_enabled( is_cross_traffic_alert_left_enabled(bytes, length)); // blind spot left chassis_detail->mutable_surround()->set_blind_spot_left_alert( is_blind_spot_left_alert(bytes, length)); chassis_detail->mutable_surround()->set_blind_spot_left_alert_enabled( is_blind_spot_left_alert_enabled(bytes, length)); // sonar right chassis_detail->mutable_surround()->set_cross_traffic_alert_right( is_cross_traffic_alert_right(bytes, length)); chassis_detail->mutable_surround()->set_cross_traffic_alert_left_enabled( is_cross_traffic_alert_left_enabled(bytes, length)); // blind spot right chassis_detail->mutable_surround()->set_blind_spot_right_alert( is_blind_spot_right_alert(bytes, length)); chassis_detail->mutable_surround()->set_blind_spot_right_alert_enabled( is_blind_spot_right_alert_enabled(bytes, length)); // sonar00 ~ sonar11, output in meters chassis_detail->mutable_surround()->set_sonar00(sonar00(bytes, length)); chassis_detail->mutable_surround()->set_sonar01(sonar01(bytes, length)); chassis_detail->mutable_surround()->set_sonar02(sonar02(bytes, length)); chassis_detail->mutable_surround()->set_sonar03(sonar03(bytes, length)); chassis_detail->mutable_surround()->set_sonar04(sonar04(bytes, length)); chassis_detail->mutable_surround()->set_sonar05(sonar05(bytes, length)); chassis_detail->mutable_surround()->set_sonar06(sonar06(bytes, length)); chassis_detail->mutable_surround()->set_sonar07(sonar07(bytes, length)); chassis_detail->mutable_surround()->set_sonar08(sonar08(bytes, length)); chassis_detail->mutable_surround()->set_sonar09(sonar09(bytes, length)); chassis_detail->mutable_surround()->set_sonar10(sonar10(bytes, length)); chassis_detail->mutable_surround()->set_sonar11(sonar11(bytes, length)); // alternative representations. const int8_t kSonarNumbers = 12; chassis_detail->mutable_surround()->clear_sonar_range(); for (std::int8_t i = 0; i < kSonarNumbers; ++i) { chassis_detail->mutable_surround()->add_sonar_range( sonars(bytes, i, length / 2)); } } bool Surround73::is_cross_traffic_alert_left(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 0); return frame.is_bit_1(0); } bool Surround73::is_cross_traffic_alert_left_enabled(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 0); return frame.is_bit_1(1); } bool Surround73::is_blind_spot_left_alert(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 0); return frame.is_bit_1(2); } bool Surround73::is_blind_spot_left_alert_enabled(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 0); return frame.is_bit_1(3); } bool Surround73::is_cross_traffic_alert_right(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 0); return frame.is_bit_1(4); } bool Surround73::is_cross_traffic_alert_right_enabled(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 0); return frame.is_bit_1(5); } bool Surround73::is_blind_spot_right_alert(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 0); return frame.is_bit_1(6); } bool Surround73::is_blind_spot_right_alert_enabled(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 0); return frame.is_bit_1(7); } double Surround73::sonar00(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 1); int32_t x = frame.get_byte(0, 3); return sonar_range(x); } double Surround73::sonar01(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 1); int32_t x = frame.get_byte(4, 7); return sonar_range(x); } double Surround73::sonar02(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 2); int32_t x = frame.get_byte(0, 3); return sonar_range(x); } double Surround73::sonar03(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 2); int32_t x = frame.get_byte(4, 7); return sonar_range(x); } double Surround73::sonar04(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 3); int32_t x = frame.get_byte(0, 3); return sonar_range(x); } double Surround73::sonar05(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 3); int32_t x = frame.get_byte(4, 7); return sonar_range(x); } double Surround73::sonar06(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 4); int32_t x = frame.get_byte(0, 3); return sonar_range(x); } double Surround73::sonar07(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 4); int32_t x = frame.get_byte(4, 7); return sonar_range(x); } double Surround73::sonar08(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 5); int32_t x = frame.get_byte(0, 3); return sonar_range(x); } double Surround73::sonar09(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 5); int32_t x = frame.get_byte(4, 7); return sonar_range(x); } double Surround73::sonar10(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 6); int32_t x = frame.get_byte(0, 3); return sonar_range(x); } double Surround73::sonar11(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 6); int32_t x = frame.get_byte(4, 7); return sonar_range(x); } bool Surround73::sonar_enabled(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(6); } bool Surround73::sonar_fault(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(7); } double Surround73::sonar_range(const std::int32_t x) const { if (x == 0x0) { return 100.0; // If nothing detected, set test range to 100.0m. } return 0.145 * (x - 0x1) + 0.3; } double Surround73::sonars(const std::uint8_t *bytes, std::uint8_t sonar_number, int32_t length) const { Byte frame(bytes + sonar_number / 2 + 1); int32_t start = (sonar_number % 2) * length; int32_t x = frame.get_byte(start, start + length); return sonar_range(x); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/gps_6d_test.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/gps_6d.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { TEST(Gps6dTest, General) { uint8_t data[8] = {0x56, 0x52, 0x53, 0x54, 0xF1, 0xF2, 0xF3, 0xF4}; int32_t length = 8; Lincoln cd; Gps6d gps; gps.Parse(data, length, &cd); EXPECT_TRUE(cd.basic().gps_valid()); EXPECT_DOUBLE_EQ(cd.basic().latitude(), -244.245646); EXPECT_DOUBLE_EQ(cd.basic().longitude(), -61.779717); EXPECT_EQ(data[0], 0b01010110); EXPECT_EQ(data[1], 0b01010010); EXPECT_EQ(data[2], 0b01010011); EXPECT_EQ(data[3], 0b01010100); EXPECT_EQ(data[4], 0b11110001); EXPECT_EQ(data[5], 0b11110010); EXPECT_EQ(data[6], 0b11110011); EXPECT_EQ(data[7], 0b11110100); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/gps_6f.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/gps_6f.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::Byte; const int32_t Gps6f::ID = 0x6F; void Gps6f::Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const { chassis_detail->mutable_basic()->set_altitude(altitude(bytes, length)); chassis_detail->mutable_basic()->set_heading(heading(bytes, length)); // speed mph -> mps chassis_detail->mutable_basic()->set_gps_speed(speed(bytes, length) * 0.44704); chassis_detail->mutable_basic()->set_hdop(hdop(bytes, length)); chassis_detail->mutable_basic()->set_vdop(vdop(bytes, length)); switch (fix_quality(bytes, length)) { case 0: chassis_detail->mutable_basic()->set_quality(FIX_NO); break; case 1: chassis_detail->mutable_basic()->set_quality(FIX_2D); break; case 2: chassis_detail->mutable_basic()->set_quality(FIX_3D); break; default: chassis_detail->mutable_basic()->set_quality(FIX_INVALID); break; } chassis_detail->mutable_basic()->set_num_satellites( num_satellites(bytes, length)); } double Gps6f::altitude(const std::uint8_t *bytes, int32_t length) const { Byte high_frame(bytes + 1); int32_t high = high_frame.get_byte(0, 8); Byte low_frame(bytes + 0); int32_t low = low_frame.get_byte(0, 8); int32_t value = (high << 8) | low; if (value > 0x7FFF) { value -= 0x10000; } return value * 0.250000; } double Gps6f::heading(const std::uint8_t *bytes, int32_t length) const { Byte high_frame(bytes + 3); int32_t high = high_frame.get_byte(0, 8); Byte low_frame(bytes + 2); int32_t low = low_frame.get_byte(0, 8); int32_t value = (high << 8) | low; return value * 0.010000; } int32_t Gps6f::speed(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 4); int32_t x = frame.get_byte(0, 8); return x; } double Gps6f::hdop(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 5); int32_t x = frame.get_byte(0, 5); return x * 0.200000; } double Gps6f::vdop(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 6); int32_t x = frame.get_byte(0, 5); return x * 0.200000; } int32_t Gps6f::fix_quality(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); int32_t x = frame.get_byte(0, 3); return x; } int32_t Gps6f::num_satellites(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); int32_t x = frame.get_byte(3, 5); return x; } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/tirepressure_71_test.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/tirepressure_71.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { TEST(Tirepressure71Test, General) { uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; int32_t length = 8; Tirepressure71 tire_pressure; Lincoln cd; tire_pressure.Parse(data, length, &cd); EXPECT_EQ(cd.safety().front_left_tire_press(), 25191); EXPECT_EQ(cd.safety().front_right_tire_press(), 25699); EXPECT_EQ(cd.safety().rear_left_tire_press(), 21073); EXPECT_EQ(cd.safety().rear_right_tire_press(), 21587); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/accel_6b.h
/****************************************************************************** * Copyright 2017 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 accel_6b.h * @brief the class of Accel6b (for lincoln vehicle) */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Accel6b * * @brief one of the protocol data of lincoln vehicle */ class Accel6b : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /* * @brief parse received data * @param bytes a pointer to the input bytes * @param length the length of the input bytes * @param chassis_detail the parsed chassis_detail */ virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const; private: /** * @brief calculate lateral acceleration based on byte array. * Config detail: {'name': 'lat', 'offset': 0.0, 'precision': 0.01, 'len': 16, * 'f_type': 'value', 'is_signed_var': True, 'physical_range': '[0|0]', 'bit': * 0, 'type': 'double', 'order': 'intel', 'physical_unit': '"m/s^2"'} * @param bytes a pointer to the byte array * @return the value of lateral acceleration */ double lateral_acceleration(const std::uint8_t *bytes, const int32_t length) const; /** * @brief calculate longitudinal_acceleration based on byte array. * Config detail: {'name': 'long', 'offset': 0.0, 'precision': 0.01, 'len': * 16, 'f_type': 'value', 'is_signed_var': True, 'physical_range': '[0|0]', * 'bit': 16, 'type': 'double', 'order': 'intel', 'physical_unit': '"m/s^2"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of longitudinal acceleration */ double longitudinal_acceleration(const std::uint8_t *bytes, const int32_t length) const; /** * @brief calculate vertical_acceleration based on byte array. * Config detail: {'name': 'vert', 'offset': 0.0, 'precision': 0.01, 'len': * 16, 'f_type': 'value', 'is_signed_var': True, 'physical_range': '[0|0]', * 'bit': 32, 'type': 'double', 'order': 'intel', 'physical_unit': '"m/s^2"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of vertical acceleration */ double vertical_acceleration(const std::uint8_t *bytes, const int32_t length) const; double parse_two_frames(const std::uint8_t low_byte, const std::uint8_t high_byte) const; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/gps_6e_test.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/gps_6e.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { TEST(Gps6eTest, General) { uint8_t data[8] = {0x56, 0x52, 0x53, 0x54, 0xF1, 0xF2, 0xF3, 0xF4}; int32_t length = 8; Lincoln cd; Gps6e gps; gps.Parse(data, length, &cd); EXPECT_EQ(cd.basic().year(), 86); EXPECT_EQ(cd.basic().month(), 2); EXPECT_EQ(cd.basic().day(), 19); EXPECT_EQ(cd.basic().hours(), 20); EXPECT_EQ(cd.basic().minutes(), 49); EXPECT_EQ(cd.basic().seconds(), 50); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/steering_64.h
/****************************************************************************** * Copyright 2017 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 steering_64.h * @brief the class of Steering64 (for lincoln vehicle) */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Steering64 * * @brief one of the protocol data of lincoln vehicle */ class Steering64 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /** * @brief get the data period * @return the value of data period */ virtual uint32_t GetPeriod() const; /** * @brief update the data * @param data a pointer to the data to be updated */ virtual void UpdateData(uint8_t *data); /** * @brief reset the private variables */ virtual void Reset(); /** * @brief set steering request enable to true * @return a this pointer to the instance itself */ Steering64 *set_enable(); /** * @brief set steering request disable to true * @return a this pointer to the instance itself */ Steering64 *set_disable(); /** * @brief set steering angle * @return a this pointer to the instance itself */ Steering64 *set_steering_angle(double angle); /** * @brief set steering angle speed * @return a this pointer to the instance itself */ Steering64 *set_steering_angle_speed(double angle_speed); private: /** * config detail: {'name': 'scmd', 'offset': 0.0, 'precision': 0.1, 'len': 16, * 'f_type': 'value', 'is_signed_var': True, 'physical_range': '[-470|470]', * 'bit': 0, 'type': 'double', 'order': 'intel', 'physical_unit': '"degrees"'} */ void set_steering_angle_p(uint8_t *data, double angle); /** * config detail: {'name': 'en', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 16, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} */ void set_enable_p(uint8_t *bytes, bool enable); /** * config detail: {'name': 'clear', 'offset': 0.0, 'precision': 1.0, 'len': 1, * 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 17, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} */ void set_clear_driver_override_flag_p(uint8_t *bytes, bool clear); /** * config detail: {'name': 'ignore', 'offset': 0.0, 'precision': 1.0, 'len': * 1, 'f_type': 'valid', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 18, 'type': 'bool', 'order': 'intel', 'physical_unit': '""'} */ void set_ignore_driver_override_p(uint8_t *bytes, bool ignore); /** * config detail: {'name': 'svel', 'offset': 0.0, 'precision': 2.0, 'len': 8, * 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|500]', * 'bit': 24, 'type': 'double', 'order': 'intel', 'physical_unit': * '"degrees/s"'} */ void set_steering_angle_speed_p(uint8_t *data, double angle_speed); /** * config detail: {'name': 'count', 'offset': 0.0, 'precision': 1.0, 'len': 8, * 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|255]', * 'bit': 56, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} */ void set_watchdog_counter_p(uint8_t *data, int32_t count); void set_disable_audible_warning_p(uint8_t *data, bool disable); private: double steering_angle_ = 0.0; bool steering_enable_ = false; bool clear_driver_override_flag_ = false; bool ignore_driver_override_ = false; double steering_angle_speed_ = 0.0; int32_t watchdog_counter_ = 0; bool disable_audible_warning_ = false; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/fuellevel_72.h
/****************************************************************************** * Copyright 2017 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 fuellevel_72.h * @brief the class of (Fuellevel72) for lincoln vehicle) */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Fuellevel72 * * @brief one of the protocol data of lincoln vehicle */ class Fuellevel72 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /* * @brief parse received data * @param bytes a pointer to the input bytes * @param length the length of the input bytes * @param timestamp the timestamp of input data * @param chassis_detail the parsed chassis_detail */ virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const; private: /** * brief get the fuel level based on byte array * config detail: {'name': 'fuel', 'offset': 0.0, 'precision': 0.108696, * 'len': 16, 'f_type': 'value', 'is_signed_var': True, 'physical_range': * '[0|0]', 'bit': 0, 'type': 'double', 'order': 'intel', 'physical_unit': * '"%"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of fuel level */ double fuel_level(const std::uint8_t *bytes, int32_t length) const; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/throttleinfo_75.h
/****************************************************************************** * Copyright 2017 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 throttleinfo_75.h * @brief the class of Throttleinfo75 (for lincoln vehicle) */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Throttleinfo75 * * @brief one of the protocol data of lincoln vehicle */ class Throttleinfo75 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /* * @brief parse received data * @param bytes a pointer to the input bytes * @param length the length of the input bytes * @param chassis_detail the parsed chassis_detail */ virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const; /** * @brief calculate engine rpm based on byte array. * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of lateral acceleration */ double engine_rpm(const std::uint8_t *bytes, int32_t length) const; /** * @brief calculate acc pedal percent based on byte array. * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of lateral acceleration */ double acc_pedal_percent(const std::uint8_t *bytes, int32_t length) const; /** * @brief calculate acc pedal rate based on byte array. * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of lateral acceleration */ double acc_pedal_rate(const std::uint8_t *bytes, int32_t length) const; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/misc_69_test.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/misc_69.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { TEST(Misc69Test, General) { uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; int32_t length = 8; Lincoln cd; Misc69 misc; misc.Parse(data, length, &cd); EXPECT_FALSE(cd.basic().acc_on_button()); EXPECT_FALSE(cd.basic().acc_off_button()); EXPECT_TRUE(cd.basic().acc_res_button()); EXPECT_TRUE(cd.basic().acc_cancel_button()); EXPECT_TRUE(cd.basic().acc_on_off_button()); EXPECT_TRUE(cd.basic().acc_res_cancel_button()); EXPECT_FALSE(cd.basic().acc_inc_spd_button()); EXPECT_FALSE(cd.basic().acc_dec_spd_button()); EXPECT_FALSE(cd.basic().acc_inc_gap_button()); EXPECT_TRUE(cd.basic().acc_dec_gap_button()); EXPECT_TRUE(cd.basic().lka_button()); EXPECT_FALSE(cd.basic().canbus_fault()); EXPECT_TRUE(cd.safety().is_driver_car_door_close()); EXPECT_TRUE(cd.safety().is_driver_buckled()); EXPECT_FALSE(cd.safety().is_passenger_door_open()); EXPECT_TRUE(cd.safety().is_rearleft_door_open()); EXPECT_FALSE(cd.safety().is_rearright_door_open()); EXPECT_FALSE(cd.safety().is_hood_open()); EXPECT_TRUE(cd.safety().is_trunk_open()); EXPECT_TRUE(cd.safety().is_passenger_detected()); EXPECT_FALSE(cd.safety().is_passenger_airbag_enabled()); EXPECT_FALSE(cd.safety().is_passenger_buckled()); EXPECT_EQ(cd.light().lincoln_lamp_type(), Light::BEAM_FLASH_TO_PASS); EXPECT_EQ(cd.light().lincoln_wiper(), Light::WIPER_MANUAL_HIGH); EXPECT_EQ(cd.light().lincoln_ambient(), Light::AMBIENT_TWILIGHT); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/brakeinfo_74_test.cc
/****************************************************************************** * Copyright 2017 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/lincoln/protocol/brakeinfo_74.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { class Brakeinfo74Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Brakeinfo74Test, simple) { Brakeinfo74 brakeinfo; uint8_t data[8] = {0x64U, 0x02, 0x03, 0x04, 0x11, 0x12, 0x13, 0x14}; int32_t length = 8; Lincoln cd; brakeinfo.Parse(data, length, &cd); EXPECT_TRUE(cd.esp().is_abs_active()); EXPECT_FALSE(cd.esp().is_abs_enabled()); EXPECT_TRUE(cd.esp().is_stab_active()); EXPECT_FALSE(cd.esp().is_stab_enabled()); EXPECT_FALSE(cd.esp().is_trac_active()); EXPECT_FALSE(cd.esp().is_trac_enabled()); EXPECT_EQ(cd.epb().parking_brake_status(), Epb::PBRAKE_OFF); EXPECT_DOUBLE_EQ(cd.brake().brake_torque_req(), 2448.0); EXPECT_EQ(cd.brake().hsa_status(), Brake::HSA_INACTIVE); EXPECT_DOUBLE_EQ(cd.brake().brake_torque_act(), 4108.0); EXPECT_EQ(cd.brake().hsa_status(), Brake::HSA_OFF); EXPECT_DOUBLE_EQ(cd.brake().wheel_torque_act(), 18500.0); EXPECT_FALSE(cd.vehicle_spd().is_vehicle_standstill()); EXPECT_DOUBLE_EQ(cd.vehicle_spd().acc_est(), 0.665); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/neolix_edu_message_manager.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/neolix_edu/proto/neolix_edu.pb.h" #include "modules/drivers/canbus/can_comm/message_manager.h" namespace apollo { namespace canbus { namespace neolix_edu { using ::apollo::drivers::canbus::MessageManager; class Neolix_eduMessageManager : public MessageManager<::apollo::canbus::Neolix_edu> { public: Neolix_eduMessageManager(); virtual ~Neolix_eduMessageManager(); }; } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/neolix_edu_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/neolix_edu/neolix_edu_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 Neolix_eduVehicleFactoryTest : public ::testing::Test { public: virtual void SetUp() { std::string canbus_conf_file = "/apollo/modules/canbus_vehicle/neolix_edu/testdata/" "neolix_edu_canbus_conf_test.pb.txt"; cyber::common::GetProtoFromFile(canbus_conf_file, &canbus_conf_); params_ = canbus_conf_.vehicle_parameter(); params_.set_brand(apollo::common::NEOLIX); neolix_edu_factory_.SetVehicleParameter(params_); } virtual void TearDown() {} protected: Neolix_eduVehicleFactory neolix_edu_factory_; CanbusConf canbus_conf_; VehicleParameter params_; }; TEST_F(Neolix_eduVehicleFactoryTest, Init) { apollo::cyber::Init("vehicle_factory_test"); EXPECT_EQ(neolix_edu_factory_.Init(&canbus_conf_), true); } } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/neolix_edu_vehicle_factory.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. *****************************************************************************/ /** * @file neolix_edu_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/neolix_edu/proto/neolix_edu.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 Neolix_eduVehicleFactory * * @brief this class is inherited from AbstractVehicleFactory. It can be used to * create controller and message manager for neolix_edu vehicle. */ class Neolix_eduVehicleFactory : public AbstractVehicleFactory { public: /** * @brief destructor */ virtual ~Neolix_eduVehicleFactory() = 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 Neolix_edu vehicle controller * @returns a unique_ptr that points to the created controller */ std::unique_ptr<VehicleController<::apollo::canbus::Neolix_edu>> CreateVehicleController(); /** * @brief create Neolix_edu message manager * @returns a unique_ptr that points to the created message manager */ std::unique_ptr<MessageManager<::apollo::canbus::Neolix_edu>> CreateMessageManager(); std::unique_ptr<::apollo::cyber::Node> node_ = nullptr; std::unique_ptr<apollo::drivers::canbus::CanClient> can_client_; CanSender<::apollo::canbus::Neolix_edu> can_sender_; apollo::drivers::canbus::CanReceiver<::apollo::canbus::Neolix_edu> can_receiver_; std::unique_ptr<MessageManager<::apollo::canbus::Neolix_edu>> message_manager_; std::unique_ptr<VehicleController<::apollo::canbus::Neolix_edu>> vehicle_controller_; std::shared_ptr<::apollo::cyber::Writer<::apollo::canbus::Neolix_edu>> chassis_detail_writer_; }; CYBER_REGISTER_VEHICLEFACTORY(Neolix_eduVehicleFactory) } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/neolix_edu_message_manager.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/neolix_edu/neolix_edu_message_manager.h" #include "modules/canbus_vehicle/neolix_edu/protocol/ads_brake_command_46.h" #include "modules/canbus_vehicle/neolix_edu/protocol/ads_diagnosis_628.h" #include "modules/canbus_vehicle/neolix_edu/protocol/ads_drive_command_50.h" #include "modules/canbus_vehicle/neolix_edu/protocol/ads_eps_command_56.h" #include "modules/canbus_vehicle/neolix_edu/protocol/ads_light_horn_command_310.h" #include "modules/canbus_vehicle/neolix_edu/protocol/aeb_diagnosis1_626.h" #include "modules/canbus_vehicle/neolix_edu/protocol/aeb_diagresp_718.h" #include "modules/canbus_vehicle/neolix_edu/protocol/aeb_frontwheelspeed_353.h" #include "modules/canbus_vehicle/neolix_edu/protocol/aeb_rearwheelspeed_354.h" #include "modules/canbus_vehicle/neolix_edu/protocol/aeb_systemstate_11.h" #include "modules/canbus_vehicle/neolix_edu/protocol/aeb_wheelimpulse_355.h" #include "modules/canbus_vehicle/neolix_edu/protocol/pas_1st_data_311.h" #include "modules/canbus_vehicle/neolix_edu/protocol/pas_2nd_data_312.h" #include "modules/canbus_vehicle/neolix_edu/protocol/vcu_brake_report_47.h" #include "modules/canbus_vehicle/neolix_edu/protocol/vcu_drive_report_52.h" #include "modules/canbus_vehicle/neolix_edu/protocol/vcu_eps_report_57.h" #include "modules/canbus_vehicle/neolix_edu/protocol/vcu_nm_401.h" #include "modules/canbus_vehicle/neolix_edu/protocol/vcu_powerstatus_214.h" #include "modules/canbus_vehicle/neolix_edu/protocol/vcu_vehicle_fault_response_201.h" #include "modules/canbus_vehicle/neolix_edu/protocol/vcu_vehicle_info_response_502.h" #include "modules/canbus_vehicle/neolix_edu/protocol/vcu_vehicle_status_report_101.h" namespace apollo { namespace canbus { namespace neolix_edu { Neolix_eduMessageManager::Neolix_eduMessageManager() { // Control Messages AddSendProtocolData<Adsbrakecommand46, true>(); AddSendProtocolData<Adsdiagnosis628, true>(); AddSendProtocolData<Adsdrivecommand50, true>(); AddSendProtocolData<Adsepscommand56, true>(); AddSendProtocolData<Adslighthorncommand310, true>(); // Report Messages AddRecvProtocolData<Aebsystemstate11, true>(); AddRecvProtocolData<Vcubrakereport47, true>(); AddRecvProtocolData<Vcudrivereport52, true>(); AddRecvProtocolData<Vcuepsreport57, true>(); AddRecvProtocolData<Vcunm401, true>(); AddRecvProtocolData<Vcupowerstatus214, true>(); AddRecvProtocolData<Vcuvehiclefaultresponse201, true>(); AddRecvProtocolData<Vcuvehicleinforesponse502, true>(); AddRecvProtocolData<Vcuvehiclestatusreport101, true>(); AddRecvProtocolData<Aebdiagnosis1626, true>(); AddRecvProtocolData<Aebdiagresp718, true>(); AddRecvProtocolData<Aebfrontwheelspeed353, true>(); AddRecvProtocolData<Aebrearwheelspeed354, true>(); AddRecvProtocolData<Aebwheelimpulse355, true>(); AddRecvProtocolData<Pas1stdata311, true>(); AddRecvProtocolData<Pas2nddata312, true>(); } Neolix_eduMessageManager::~Neolix_eduMessageManager() {} } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/cyberfile.xml
<package format="2"> <name>canbus-vehicle-neolix-edu</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/neolix_edu</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/neolix_edu/neolix_edu_controller.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 <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/neolix_edu/protocol/ads_brake_command_46.h" #include "modules/canbus_vehicle/neolix_edu/protocol/ads_diagnosis_628.h" #include "modules/canbus_vehicle/neolix_edu/protocol/ads_drive_command_50.h" #include "modules/canbus_vehicle/neolix_edu/protocol/ads_eps_command_56.h" #include "modules/canbus_vehicle/neolix_edu/protocol/ads_light_horn_command_310.h" #include "modules/canbus/vehicle/vehicle_controller.h" namespace apollo { namespace canbus { namespace neolix_edu { class Neolix_eduController final : public VehicleController<::apollo::canbus::Neolix_edu> { public: virtual ~Neolix_eduController(); ::apollo::common::ErrorCode Init( const VehicleParameter& params, CanSender<::apollo::canbus::Neolix_edu>* const can_sender, MessageManager<::apollo::canbus::Neolix_edu>* 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(Neolix_eduControllerTest, SetDrivingMode); FRIEND_TEST(Neolix_eduControllerTest, Status); FRIEND_TEST(Neolix_eduControllerTest, 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 Adsbrakecommand46* ads_brake_command_46_ = nullptr; Adsdiagnosis628* ads_diagnosis_628_ = nullptr; Adsdrivecommand50* ads_drive_command_50_ = nullptr; Adsepscommand56* ads_eps_command_56_ = nullptr; Adslighthorncommand310* ads_light_horn_command_310_ = 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 neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/neolix_edu_vehicle_factory.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/neolix_edu/neolix_edu_vehicle_factory.h" #include "cyber/common/log.h" #include "modules/canbus/common/canbus_gflags.h" #include "modules/canbus_vehicle/neolix_edu/neolix_edu_controller.h" #include "modules/canbus_vehicle/neolix_edu/neolix_edu_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 Neolix_eduVehicleFactory::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::Neolix_edu>( FLAGS_chassis_detail_topic); return true; } bool Neolix_eduVehicleFactory::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 Neolix_eduVehicleFactory::Stop() { can_sender_.Stop(); can_receiver_.Stop(); can_client_->Stop(); vehicle_controller_->Stop(); AINFO << "Cleanup cansender, canreceiver, canclient, vehicle controller."; } void Neolix_eduVehicleFactory::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 Neolix_eduVehicleFactory::publish_chassis() { Chassis chassis = vehicle_controller_->chassis(); ADEBUG << chassis.ShortDebugString(); return chassis; } void Neolix_eduVehicleFactory::PublishChassisDetail() { Neolix_edu chassis_detail; message_manager_->GetSensorData(&chassis_detail); ADEBUG << chassis_detail.ShortDebugString(); chassis_detail_writer_->Write(chassis_detail); } std::unique_ptr<VehicleController<::apollo::canbus::Neolix_edu>> Neolix_eduVehicleFactory::CreateVehicleController() { return std::unique_ptr<VehicleController<::apollo::canbus::Neolix_edu>>( new neolix_edu::Neolix_eduController()); } std::unique_ptr<MessageManager<::apollo::canbus::Neolix_edu>> Neolix_eduVehicleFactory::CreateMessageManager() { return std::unique_ptr<MessageManager<::apollo::canbus::Neolix_edu>>( new neolix_edu::Neolix_eduMessageManager()); } } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/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 = "neolix_edu_vehicle_factory", srcs = [ "neolix_edu_vehicle_factory.cc", ], hdrs = [ "neolix_edu_vehicle_factory.h", ], copts = CANBUS_COPTS, alwayslink = True, deps = [ ":neolix_edu_controller", ":neolix_edu_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 = "libneolix_edu_vehicle_factory_lib.so", linkshared = True, linkstatic = True, deps = [":neolix_edu_vehicle_factory"], ) cc_library( name = "neolix_edu_message_manager", srcs = [ "neolix_edu_message_manager.cc", ], hdrs = [ "neolix_edu_message_manager.h", ], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/neolix_edu/proto:neolix_edu_cc_proto", "//modules/canbus_vehicle/neolix_edu/protocol:canbus_neolix_edu_protocol", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_library( name = "neolix_edu_controller", srcs = [ "neolix_edu_controller.cc", ], hdrs = [ "neolix_edu_controller.h", ], copts = CANBUS_COPTS, deps = [ ":neolix_edu_message_manager", "//modules/common_msgs/chassis_msgs:chassis_cc_proto", "//modules/canbus/vehicle:vehicle_controller_base", "//modules/canbus_vehicle/neolix_edu/protocol:canbus_neolix_edu_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 = "neolix_edu_controller_test", size = "small", srcs = ["neolix_edu_controller_test.cc"], data = ["//modules/canbus:test_data"], deps = [ ":neolix_edu_controller", "@com_google_googletest//:gtest_main", ], ) cc_test( name = "neolix_edu_message_manager_test", size = "small", srcs = ["neolix_edu_message_manager_test.cc"], deps = [ ":neolix_edu_message_manager", "@com_google_googletest//:gtest_main", ], ) cc_test( name = "neolix_edu_vehicle_factory_test", size = "small", srcs = ["neolix_edu_vehicle_factory_test.cc"], data = ["//modules/canbus:test_data"], linkstatic = True, deps = [ ":neolix_edu_vehicle_factory", "@com_google_googletest//:gtest_main", ], ) install( name = "install", library_dest = "canbus-vehicle-neolix-edu/lib", data_dest = "canbus-vehicle-neolix-edu", data = [ ":runtime_data", ":cyberfile.xml", ":canbus-vehicle-neolix-edu.BUILD", ], targets = [ ":libneolix_edu_vehicle_factory_lib.so", ], deps = [ ":pb_neolix_edu", ":pb_hdrs", ], ) install( name = "pb_hdrs", data_dest = "canbus-vehicle-neolix-edu/include", data = [ "//modules/canbus_vehicle/neolix_edu/proto:neolix_edu_cc_proto", ], ) install_files( name = "pb_neolix_edu", dest = "canbus-vehicle-neolix-edu", files = [ "//modules/canbus_vehicle/neolix_edu/proto:neolix_edu_py_pb2", ], ) filegroup( name = "runtime_data", srcs = glob([ "testdata/**", ]), ) install_src_files( name = "install_src", deps = [ ":install_neolix_edu_src", ":install_neolix_edu_hdrs" ], ) install_src_files( name = "install_neolix_edu_src", src_dir = ["."], dest = "canbus-vehicle-neolix-edu/src", filter = "*", ) install_src_files( name = "install_neolix_edu_hdrs", src_dir = ["."], dest = "canbus-vehicle-neolix-edu/include", filter = "*.h", ) cpplint()
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/neolix_edu_message_manager_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/neolix_edu/neolix_edu_message_manager.h" #include "gtest/gtest.h" #include "modules/canbus_vehicle/neolix_edu/protocol/ads_brake_command_46.h" #include "modules/canbus_vehicle/neolix_edu/protocol/ads_diagnosis_628.h" #include "modules/canbus_vehicle/neolix_edu/protocol/ads_drive_command_50.h" #include "modules/canbus_vehicle/neolix_edu/protocol/ads_eps_command_56.h" #include "modules/canbus_vehicle/neolix_edu/protocol/ads_light_horn_command_310.h" #include "modules/canbus_vehicle/neolix_edu/protocol/aeb_diagnosis1_626.h" #include "modules/canbus_vehicle/neolix_edu/protocol/aeb_diagresp_718.h" #include "modules/canbus_vehicle/neolix_edu/protocol/aeb_frontwheelspeed_353.h" #include "modules/canbus_vehicle/neolix_edu/protocol/aeb_rearwheelspeed_354.h" #include "modules/canbus_vehicle/neolix_edu/protocol/aeb_systemstate_11.h" #include "modules/canbus_vehicle/neolix_edu/protocol/aeb_wheelimpulse_355.h" #include "modules/canbus_vehicle/neolix_edu/protocol/pas_1st_data_311.h" #include "modules/canbus_vehicle/neolix_edu/protocol/pas_2nd_data_312.h" #include "modules/canbus_vehicle/neolix_edu/protocol/vcu_brake_report_47.h" #include "modules/canbus_vehicle/neolix_edu/protocol/vcu_drive_report_52.h" #include "modules/canbus_vehicle/neolix_edu/protocol/vcu_eps_report_57.h" #include "modules/canbus_vehicle/neolix_edu/protocol/vcu_nm_401.h" #include "modules/canbus_vehicle/neolix_edu/protocol/vcu_powerstatus_214.h" #include "modules/canbus_vehicle/neolix_edu/protocol/vcu_vehicle_fault_response_201.h" #include "modules/canbus_vehicle/neolix_edu/protocol/vcu_vehicle_info_response_502.h" #include "modules/canbus_vehicle/neolix_edu/protocol/vcu_vehicle_status_report_101.h" namespace apollo { namespace canbus { namespace neolix_edu { using ::apollo::canbus::Neolix_edu; using ::apollo::drivers::canbus::ProtocolData; class Neolix_eduMessageManagerTest : public ::testing::Test { public: virtual void SetUp() {} }; // Control Messages TEST_F(Neolix_eduMessageManagerTest, Adsbrakecommand46) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Adsbrakecommand46::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Adsbrakecommand46 *>(pd)->ID, Adsbrakecommand46::ID); } TEST_F(Neolix_eduMessageManagerTest, Adsdiagnosis628) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Adsdiagnosis628::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Adsdiagnosis628 *>(pd)->ID, Adsdiagnosis628::ID); } TEST_F(Neolix_eduMessageManagerTest, Adsdrivecommand50) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Adsdrivecommand50::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Adsdrivecommand50 *>(pd)->ID, Adsdrivecommand50::ID); } TEST_F(Neolix_eduMessageManagerTest, Adsepscommand56) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Adsepscommand56::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Adsepscommand56 *>(pd)->ID, Adsepscommand56::ID); } TEST_F(Neolix_eduMessageManagerTest, Adslighthorncommand310) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Adslighthorncommand310::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Adslighthorncommand310 *>(pd)->ID, Adslighthorncommand310::ID); } // Report Messages TEST_F(Neolix_eduMessageManagerTest, Aebsystemstate11) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Aebsystemstate11::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Aebsystemstate11 *>(pd)->ID, Aebsystemstate11::ID); } TEST_F(Neolix_eduMessageManagerTest, Vcubrakereport47) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Vcubrakereport47::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Vcubrakereport47 *>(pd)->ID, Vcubrakereport47::ID); } TEST_F(Neolix_eduMessageManagerTest, Vcudrivereport52) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Vcudrivereport52::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Vcudrivereport52 *>(pd)->ID, Vcudrivereport52::ID); } TEST_F(Neolix_eduMessageManagerTest, Vcuepsreport57) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Vcuepsreport57::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Vcuepsreport57 *>(pd)->ID, Vcuepsreport57::ID); } TEST_F(Neolix_eduMessageManagerTest, Vcunm401) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Vcunm401::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Vcunm401 *>(pd)->ID, Vcunm401::ID); } TEST_F(Neolix_eduMessageManagerTest, Vcupowerstatus214) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Vcupowerstatus214::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Vcupowerstatus214 *>(pd)->ID, Vcupowerstatus214::ID); } TEST_F(Neolix_eduMessageManagerTest, Vcuvehiclefaultresponse201) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Vcuvehiclefaultresponse201::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Vcuvehiclefaultresponse201 *>(pd)->ID, Vcuvehiclefaultresponse201::ID); } TEST_F(Neolix_eduMessageManagerTest, Vcuvehicleinforesponse502) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Vcuvehicleinforesponse502::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Vcuvehicleinforesponse502 *>(pd)->ID, Vcuvehicleinforesponse502::ID); } TEST_F(Neolix_eduMessageManagerTest, Vcuvehiclestatusreport101) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Vcuvehiclestatusreport101::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Vcuvehiclestatusreport101 *>(pd)->ID, Vcuvehiclestatusreport101::ID); } TEST_F(Neolix_eduMessageManagerTest, Aebdiagnosis1626) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Aebdiagnosis1626::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Aebdiagnosis1626 *>(pd)->ID, Aebdiagnosis1626::ID); } TEST_F(Neolix_eduMessageManagerTest, Aebdiagresp718) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Aebdiagresp718::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Aebdiagresp718 *>(pd)->ID, Aebdiagresp718::ID); } TEST_F(Neolix_eduMessageManagerTest, Aebfrontwheelspeed353) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Aebfrontwheelspeed353::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Aebfrontwheelspeed353 *>(pd)->ID, Aebfrontwheelspeed353::ID); } TEST_F(Neolix_eduMessageManagerTest, Aebrearwheelspeed354) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Aebrearwheelspeed354::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Aebrearwheelspeed354 *>(pd)->ID, Aebrearwheelspeed354::ID); } TEST_F(Neolix_eduMessageManagerTest, Aebwheelimpulse355) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Aebwheelimpulse355::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Aebwheelimpulse355 *>(pd)->ID, Aebwheelimpulse355::ID); } TEST_F(Neolix_eduMessageManagerTest, Pas1stdata311) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Pas1stdata311::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Pas1stdata311 *>(pd)->ID, Pas1stdata311::ID); } TEST_F(Neolix_eduMessageManagerTest, Pas2nddata312) { Neolix_eduMessageManager manager; ProtocolData<Neolix_edu> *pd = manager.GetMutableProtocolDataById(Pas2nddata312::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Pas2nddata312 *>(pd)->ID, Pas2nddata312::ID); } } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/neolix_edu_controller_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/neolix_edu/neolix_edu_controller.h" #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/neolix_edu/proto/neolix_edu.pb.h" #include "modules/canbus_vehicle/neolix_edu/neolix_edu_message_manager.h" #include "modules/common_msgs/basic_msgs/vehicle_signal.pb.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 neolix_edu { using apollo::common::ErrorCode; using apollo::common::VehicleSignal; using apollo::control::ControlCommand; class Neolix_eduControllerTest : public ::testing::Test { public: virtual void SetUp() { std::string canbus_conf_file = "/apollo/modules/canbus/testdata/conf/" "neolix_edu_canbus_conf_test.pb.txt"; cyber::common::GetProtoFromFile(canbus_conf_file, &canbus_conf_); params_ = canbus_conf_.vehicle_parameter(); control_cmd_.set_throttle(20.0); control_cmd_.set_brake(0.0); control_cmd_.set_steering_rate(80.0); control_cmd_.set_horn(false); } protected: Neolix_eduController controller_; ControlCommand control_cmd_; VehicleSignal vehicle_signal_; CanSender<::apollo::canbus::Neolix_edu> sender_; Neolix_eduMessageManager msg_manager_; CanbusConf canbus_conf_; VehicleParameter params_; }; TEST_F(Neolix_eduControllerTest, Init) { ErrorCode ret = controller_.Init(params_, &sender_, &msg_manager_); EXPECT_EQ(ret, ErrorCode::OK); } TEST_F(Neolix_eduControllerTest, 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(Neolix_eduControllerTest, 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()); EXPECT_EQ(controller_.chassis_error_code(), Chassis::NO_ERROR); } TEST_F(Neolix_eduControllerTest, UpdateDrivingMode) { controller_.Init(params_, &sender_, &msg_manager_); controller_.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE); EXPECT_EQ(controller_.SetDrivingMode(Chassis::COMPLETE_MANUAL), ErrorCode::OK); controller_.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE); EXPECT_EQ(controller_.SetDrivingMode(Chassis::AUTO_STEER_ONLY), ErrorCode::OK); controller_.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE); EXPECT_EQ(controller_.SetDrivingMode(Chassis::AUTO_SPEED_ONLY), ErrorCode::OK); EXPECT_EQ(controller_.SetDrivingMode(Chassis::COMPLETE_AUTO_DRIVE), ErrorCode::CANBUS_ERROR); } } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/neolix_edu_controller.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/neolix_edu/neolix_edu_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/neolix_edu/neolix_edu_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 neolix_edu { 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 Neolix_eduController::Init( const VehicleParameter& params, CanSender<::apollo::canbus::Neolix_edu>* const can_sender, MessageManager<::apollo::canbus::Neolix_edu>* const message_manager) { if (is_initialized_) { AINFO << "Neolix_eduController 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) { 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 ads_brake_command_46_ = dynamic_cast<Adsbrakecommand46*>( message_manager_->GetMutableProtocolDataById(Adsbrakecommand46::ID)); if (ads_brake_command_46_ == nullptr) { AERROR << "Adsbrakecommand46 does not exist in the Neolix_eduMessageManager!"; return ErrorCode::CANBUS_ERROR; } ads_diagnosis_628_ = dynamic_cast<Adsdiagnosis628*>( message_manager_->GetMutableProtocolDataById(Adsdiagnosis628::ID)); if (ads_diagnosis_628_ == nullptr) { AERROR << "Adsdiagnosis628 does not exist in the Neolix_eduMessageManager!"; return ErrorCode::CANBUS_ERROR; } ads_drive_command_50_ = dynamic_cast<Adsdrivecommand50*>( message_manager_->GetMutableProtocolDataById(Adsdrivecommand50::ID)); if (ads_drive_command_50_ == nullptr) { AERROR << "Adsdrivecommand50 does not exist in the Neolix_eduMessageManager!"; return ErrorCode::CANBUS_ERROR; } ads_eps_command_56_ = dynamic_cast<Adsepscommand56*>( message_manager_->GetMutableProtocolDataById(Adsepscommand56::ID)); if (ads_eps_command_56_ == nullptr) { AERROR << "Adsepscommand56 does not exist in the Neolix_eduMessageManager!"; return ErrorCode::CANBUS_ERROR; } ads_light_horn_command_310_ = dynamic_cast<Adslighthorncommand310*>( message_manager_->GetMutableProtocolDataById(Adslighthorncommand310::ID)); if (ads_light_horn_command_310_ == nullptr) { AERROR << "Adslighthorncommand310 does not exist in the " "Neolix_eduMessageManager!"; return ErrorCode::CANBUS_ERROR; } can_sender_->AddMessage(Adsbrakecommand46::ID, ads_brake_command_46_, false); can_sender_->AddMessage(Adsdiagnosis628::ID, ads_diagnosis_628_, false); can_sender_->AddMessage(Adsdrivecommand50::ID, ads_drive_command_50_, false); can_sender_->AddMessage(Adsepscommand56::ID, ads_eps_command_56_, false); can_sender_->AddMessage(Adslighthorncommand310::ID, ads_light_horn_command_310_, false); // need sleep to ensure all messages received AINFO << "Neolix_eduController is initialized."; is_initialized_ = true; return ErrorCode::OK; } Neolix_eduController::~Neolix_eduController() {} bool Neolix_eduController::Start() { if (!is_initialized_) { AERROR << "Neolix_eduController has NOT been initiated."; return false; } const auto& update_func = [this] { SecurityDogThreadFunc(); }; thread_.reset(new std::thread(update_func)); return true; } void Neolix_eduController::Stop() { if (!is_initialized_) { AERROR << "Neolix_eduController stops or starts improperly!"; return; } if (thread_ != nullptr && thread_->joinable()) { thread_->join(); thread_.reset(); AINFO << "Neolix_eduController stopped."; } } Chassis Neolix_eduController::chassis() { chassis_.Clear(); Neolix_edu 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); // 3 speed_mps if (chassis_detail.has_aeb_frontwheelspeed_353() && chassis_detail.has_aeb_rearwheelspeed_354()) { auto wheelspeed = chassis_.mutable_wheel_speed(); wheelspeed->set_wheel_spd_fl( chassis_detail.aeb_frontwheelspeed_353().wheelspeed_fl()); wheelspeed->set_wheel_spd_fr( chassis_detail.aeb_frontwheelspeed_353().wheelspeed_fr()); wheelspeed->set_wheel_spd_rl( chassis_detail.aeb_rearwheelspeed_354().wheelspeed_rl()); wheelspeed->set_wheel_spd_rr( chassis_detail.aeb_rearwheelspeed_354().wheelspeed_rr()); chassis_.set_speed_mps( (chassis_detail.aeb_frontwheelspeed_353().wheelspeed_fl() + chassis_detail.aeb_frontwheelspeed_353().wheelspeed_fr() + chassis_detail.aeb_rearwheelspeed_354().wheelspeed_rl() + chassis_detail.aeb_rearwheelspeed_354().wheelspeed_rr()) / 4 / 3.6); } else { chassis_.set_speed_mps(0); } // 4 SOC if (chassis_detail.has_vcu_vehicle_status_report_101() && chassis_detail.vcu_vehicle_status_report_101().has_vcu_display_soc()) { chassis_.set_battery_soc_percentage( chassis_detail.vcu_vehicle_status_report_101().vcu_display_soc()); } else { chassis_.set_battery_soc_percentage(0); } // 5 steering if (chassis_detail.has_vcu_eps_report_57() && chassis_detail.vcu_eps_report_57().has_vcu_real_angle()) { chassis_.set_steering_percentage(static_cast<float>( chassis_detail.vcu_eps_report_57().vcu_real_angle() * 100 / vehicle_params_.max_steer_angle() * M_PI / 180)); } else { chassis_.set_steering_percentage(0); } // 6 throttle if (chassis_detail.has_vcu_drive_report_52() && chassis_detail.vcu_drive_report_52().has_vcu_real_torque()) { chassis_.set_throttle_percentage( chassis_detail.vcu_drive_report_52().vcu_real_torque() * 2); } else { chassis_.set_throttle_percentage(0); } // 7 brake if (chassis_detail.has_vcu_brake_report_47() && chassis_detail.vcu_brake_report_47().has_vcu_real_brake()) { chassis_.set_brake_percentage( chassis_detail.vcu_brake_report_47().vcu_real_brake()); } else { chassis_.set_brake_percentage(0); } // 8 gear if (chassis_detail.has_vcu_drive_report_52() && chassis_detail.vcu_drive_report_52().has_vcu_real_shift()) { chassis_.set_gear_location((apollo::canbus::Chassis_GearPosition) chassis_detail.vcu_drive_report_52() .vcu_real_shift()); } // 9 epb if (chassis_detail.has_vcu_brake_report_47() && chassis_detail.vcu_brake_report_47().has_vcu_real_parking_status()) { if (chassis_detail.vcu_brake_report_47().vcu_real_parking_status() == 1) { chassis_.set_parking_brake(true); } else { chassis_.set_parking_brake(false); } } else { chassis_.set_parking_brake(false); } if (chassis_error_mask_) { chassis_.set_chassis_error_mask(chassis_error_mask_); } // 10 give engage_advice based on error_code and canbus feedback if (!chassis_error_mask_ && !chassis_.parking_brake() && (chassis_.throttle_percentage() == 0.0)) { chassis_.mutable_engage_advice()->set_advice( apollo::common::EngageAdvice::READY_TO_ENGAGE); } else { chassis_.mutable_engage_advice()->set_advice( apollo::common::EngageAdvice::DISALLOW_ENGAGE); } // 11 bumper event if (chassis_detail.has_vcu_brake_report_47() && chassis_detail.vcu_brake_report_47().has_vcu_ehb_brake_state()) { if (chassis_detail.vcu_brake_report_47().vcu_ehb_brake_state() == Vcu_brake_report_47::VCU_EHB_BUMPER_BRAKE) { chassis_.set_front_bumper_event(Chassis::BUMPER_PRESSED); chassis_.set_back_bumper_event(Chassis::BUMPER_PRESSED); } else { chassis_.set_front_bumper_event(Chassis::BUMPER_NORMAL); chassis_.set_back_bumper_event(Chassis::BUMPER_NORMAL); } } else { chassis_.set_front_bumper_event(Chassis::BUMPER_INVALID); chassis_.set_back_bumper_event(Chassis::BUMPER_INVALID); } // 12 add checkresponse signal if (chassis_detail.has_vcu_brake_report_47() && chassis_detail.vcu_brake_report_47().has_brake_enable_resp()) { chassis_.mutable_check_response()->set_is_esp_online( chassis_detail.vcu_brake_report_47().brake_enable_resp() == 1); } if (chassis_detail.has_vcu_drive_report_52() && chassis_detail.vcu_drive_report_52().has_drive_enable_resp()) { chassis_.mutable_check_response()->set_is_vcu_online( chassis_detail.vcu_drive_report_52().drive_enable_resp() == 1); } if (chassis_detail.has_vcu_eps_report_57() && chassis_detail.vcu_eps_report_57().has_drive_enable_resp()) { chassis_.mutable_check_response()->set_is_eps_online( chassis_detail.vcu_eps_report_57().drive_enable_resp() == 1); } return chassis_; } bool Neolix_eduController::VerifyID() { return true; } void Neolix_eduController::Emergency() { set_driving_mode(Chassis::EMERGENCY_MODE); ResetProtocol(); } ErrorCode Neolix_eduController::EnableAutoMode() { if (driving_mode() == Chassis::COMPLETE_AUTO_DRIVE) { AINFO << "already in COMPLETE_AUTO_DRIVE mode"; return ErrorCode::OK; } // set enable ads_brake_command_46_->set_drive_enable(true); ads_drive_command_50_->set_drive_enable(true); ads_eps_command_56_->set_drive_enable(true); 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::COMPLETE_AUTO_DRIVE); AINFO << "Switch to COMPLETE_AUTO_DRIVE mode ok."; return ErrorCode::OK; } ErrorCode Neolix_eduController::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 Neolix_eduController::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; } AFATAL << "SpeedOnlyMode is not supported in Neolix_edu!"; return ErrorCode::OK; } ErrorCode Neolix_eduController::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; } AFATAL << "SpeedOnlyMode is not supported in Neolix_edu!"; return ErrorCode::OK; } // NEUTRAL, REVERSE, DRIVE void Neolix_eduController::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: { ads_drive_command_50_->set_auto_shift_command( Ads_drive_command_50::AUTO_SHIFT_COMMAND_N); ads_brake_command_46_->set_auto_parking_command(false); break; } case Chassis::GEAR_REVERSE: { ads_drive_command_50_->set_auto_shift_command( Ads_drive_command_50::AUTO_SHIFT_COMMAND_R); break; } case Chassis::GEAR_DRIVE: { ads_drive_command_50_->set_auto_shift_command( Ads_drive_command_50::AUTO_SHIFT_COMMAND_D); break; } case Chassis::GEAR_PARKING: { ads_brake_command_46_->set_auto_parking_command(true); break; } default: break; } } // brake with pedal // pedal:0.00~99.99, unit: void Neolix_eduController::Brake(double pedal) { // TODO(All) : 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 brake pedal."; return; } ads_brake_command_46_->set_auto_brake_command(pedal); } // drive with old acceleration // gas:0.00~99.99 unit: void Neolix_eduController::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; } ads_drive_command_50_->set_auto_drive_torque(pedal / 2); } // 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 Neolix_eduController::Acceleration(double acc) { // None } // neolix_edu default, -380 ~ 380, 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 Neolix_eduController::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; ads_eps_command_56_->set_auto_target_angle(real_angle); } // 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 Neolix_eduController::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; ads_eps_command_56_->set_auto_target_angle(real_angle); } void Neolix_eduController::SetEpbBreak(const ControlCommand& command) { if (command.parking_brake()) { ads_brake_command_46_->set_auto_parking_command(true); } else { ads_brake_command_46_->set_auto_parking_command(false); } } void Neolix_eduController::SetBeam(const ControlCommand& command) { if (command.signal().high_beam()) { // None } else if (command.signal().low_beam()) { // None } else { // None } } void Neolix_eduController::SetHorn(const ControlCommand& command) { if (command.signal().horn()) { // None } else { // None } } void Neolix_eduController::SetTurningSignal(const ControlCommand& command) { // None } void Neolix_eduController::ResetProtocol() { message_manager_->ResetSendMessages(); } bool Neolix_eduController::CheckChassisError() { /* ADD YOUR OWN CAR CHASSIS OPERATION */ return false; } void Neolix_eduController::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) == 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 Neolix_eduController looping " "process:" << elapsed.count(); } } } bool Neolix_eduController::CheckResponse(const int32_t flags, bool need_wait) { int32_t retry_num = 20; Neolix_edu 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; } else { 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 Neolix_eduController::set_chassis_error_mask(const int32_t mask) { std::lock_guard<std::mutex> lock(chassis_mask_mutex_); chassis_error_mask_ = mask; } int32_t Neolix_eduController::chassis_error_mask() { std::lock_guard<std::mutex> lock(chassis_mask_mutex_); return chassis_error_mask_; } Chassis::ErrorCode Neolix_eduController::chassis_error_code() { std::lock_guard<std::mutex> lock(chassis_error_code_mutex_); return chassis_error_code_; } void Neolix_eduController::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 neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/testdata/neolix_edu_canbus_conf_test.pb.txt
vehicle_parameter { brand: NEOLIX 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 interface: NATIVE } enable_debug_mode: true enable_receiver_log: true enable_sender_log: true
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/proto/neolix_edu.proto
syntax = "proto2"; package apollo.canbus; import "modules/common_msgs/chassis_msgs/chassis.proto"; message Aeb_systemstate_11 { // Report Message // 0x00:read only;0x01:brake enable [] [0|1] optional int32 aeb_state = 1; // 0x00:off;0x01:on [] [0|1] optional bool aeb_brakestate = 2; // 0x0:Nomal;0x1:Level 1;0x2:Level 2;0x3:Level 3;0x4:Level 4;0x5:Level // 5;0x6:Reserved;0x7:Reserved [] [0|5] optional int32 faultrank = 3; // [] [0|120] optional int32 currenttemperature = 4; // 0x0:Normal;0x1:ActivateBrake [] [0|1] optional bool pas_f1_stop = 5; // 0x0:Normal;0x1:ActivateBrake [] [0|1] optional bool pas_f2_stop = 6; // 0x0:Normal;0x1:ActivateBrake [] [0|1] optional bool pas_f3_stop = 7; // 0x0:Normal;0x1:ActivateBrake [] [0|1] optional bool pas_f4_stop = 8; // 0x0:Normal;0x1:ActivateBrake [] [0|1] optional bool pas_b1_stop = 9; // 0x0:Normal;0x1:ActivateBrake [] [0|1] optional bool pas_b2_stop = 10; // 0x0:Normal;0x1:ActivateBrake [] [0|1] optional bool pas_b3_stop = 11; // 0x0:Normal;0x1:ActivateBrake [] [0|1] optional bool pas_b4_stop = 12; // [] [0|15] optional int32 aeb_livecounter_rear = 13; // [bit] [0|255] optional int32 aeb_cheksum = 14; } message Vcu_vehicle_fault_response_201 { // Report Message // 0x0: no error;0x1: level 1 error;0x2: level 2 error;0x3: level 3 error;0x4: // level 4 error;0x5: level 5 error [] [0|0] optional int32 vehicle_error_indicationsvcu = 1; // 0x0: no error;0x1: level 1 error;0x2: level 2 error;0x3: level 3 error;0x4: // level 4 error;0x5: level 5 error [] [0|0] optional int32 brake_system_errorehb = 2; // 0x0: no error;0x1: level 1 error;0x2: level 2 error;0x3: level 3 error;0x4: // level 4 error;0x5: level 5 error [] [0|0] optional int32 eps_error = 3; // 0x0: no error;0x1: level 1 error;0x2: level 2 error;0x3: level 3 error;0x4: // level 4 error;0x5: level 5 error [] [0|0] optional int32 motor_error = 4; // 0x0: no error;0x1: level 1 error;0x2: level 2 error;0x3: level 3 error;0x4: // level 4 error;0x5: level 5 error [] [0|0] optional int32 epb_error = 5; // 0x0: no error;0x1: level 1 error;0x2: level 2 error;0x3: level 3 error;0x4: // level 4 error;0x5: level 5 error [] [0|0] optional int32 high_voltage_battery_errorbcu = 6; // 0x0:Normal;0x1:Failure [] [0|0] optional bool automode_exit_reason_losscommuni = 7; // 0x0:Normal;0x1:Failure [] [0|0] optional bool automode_exit_reason_reqsignalno = 8; // 0x0:Normal;0x1:Failure [] [0|0] optional bool automode_exit_reason_low_power = 9; // 0x0:Normal;0x1:Failure [] [0|0] optional bool automode_exit_reason_highvolt = 10; // 0x0:Normal;0x1:Failure [] [0|0] optional bool automode_exit_reason_vehicle_flt = 11; // 0x0:Normal;0x1:Failure [] [0|0] optional bool automode_exit_reason_press_emerg = 12; // 0x0:Normal;0x1:Failure [] [0|0] optional bool automode_exit_reason_press_remot = 13; // 0x0:Normal;0x1:Failure [] [0|0] optional bool automode_exit_reason_pdu_control = 14; // [] [0|0] optional int32 vcu_faultrept_alivecounter = 15; // [] [0|0] optional int32 vcu_faultrept_checksum = 16; } message Vcu_powerstatus_214 { // Report Message // 0x0:OFF;0x1:IG_ON;0x2:Power_ON;0x3:Auto_ON;0x4:Reserved;0x5:Reserved;0x6:Reserved;0x7:Reserved // [bit] [0|7] optional int32 vcu_powermode = 1; // 0x0:Not Available;0x1:Invalid;0x2:Valid;0x3:Reserved [bit] [0|3] optional int32 vcu_powermodevalid = 2; // 0x0:NotActivate;0x1:Activate [bit] [0|1] optional bool replacebatterystateindication = 3; // 0x0:Normal AEB;0x1:Forbidden [bit] [0|1] optional bool forbidden_aeb_signal = 4; // [A] [-400|910.68] optional double bcu_chargedischargecurrent = 5; // [V] [0|655.35] optional double bcu_batt_internalvoltage = 6; // [bit] [0|15] optional int32 vcu_driverinfo_alivecounter = 7; // [bit] [0|255] optional int32 vcu_driverinfo_checksum = 8; } message Ads_light_horn_command_310 { // Control Message // 0x0:disable ;0x1:enable [bit] [0|1] optional bool turn_right_light_command = 1; // 0x0:disable ;0x1:enable ;0x2-0x3:Reserved [bit] [0|1] optional bool turn_left_light_command = 2; // [bit] [0|1] optional bool horn_command = 3; // 0x0:Off;0x1:LowBeam;0x2:HighBeam [bit] [0|1] optional int32 beam_command = 4; // [] [0|0] optional int32 auto_drivercmd_alivecounter = 5; // [] [0|0] optional int32 auto_drivercmd_checksum = 6; } message Ads_brake_command_46 { // Control Message // 0x0:disable ;0x1:enable [] [0|0] optional bool drive_enable = 1; // [] [0|0] optional int32 auto_brake_command = 2; // 0x0:Release ;0x1:Apply [] [0|0] optional bool auto_parking_command = 3; // 0x0:off;0x1:on [] [0|0] optional bool epb_rampauxiliarycommand = 4; // [] [0|0] optional int32 auto_drivercmd_alivecounter = 5; // [] [0|0] optional int32 auto_drivercmd_checksum = 6; } message Vcu_brake_report_47 { // Report Message enum Control_mode_respType { CONTROL_MODE_RESP_STANDBY = 0; CONTROL_MODE_RESP_AUTO_DRIVE = 1; CONTROL_MODE_RESP_NET_DRIVE = 2; CONTROL_MODE_RESP_REMOTE_CONTROL = 3; CONTROL_MODE_RESP_EMERGENCY_BRAKE = 4; } enum Vcu_ehb_brakeType { VCU_EHB_NORMAL_BRAKE = 0; VCU_EHB_BACKUP_REMOTE_BRAKE = 1; VCU_EHB_EMERGENCY_BUTTON_BRAKE = 2; VCU_EHB_ULTR_BRAKE = 3; VCU_EHB_BUMPER_BRAKE = 4; } // 0x0:disable;0x1:enable [] [0|0] optional bool brake_enable_resp = 1; // 0x0:Standby;0x1:auto drive;0x2:net drive;0x3:remote control;0x4:emergency // brake;0x5~0x7:Reserved [bit] [0|7] optional Control_mode_respType control_mode_resp = 2; // 0x0:disable;0x1:enable [] [0|0] optional bool vcu_real_brake_valid = 3; // [] [0|0] optional int32 vcu_real_brake = 4; // 0x0:EPB_Released;0x1:EPB_Applied;0x2:EPB_Releasing;0x3:EPB_Fault;0x4:EPB_Applying // [] [0|0] optional int32 vcu_real_parking_status = 5; // 0x0:disable;0x1:enable [] [0|0] optional bool vcu_real_parking_valid = 6; // 0x0:off;0x1:on [] [0|0] optional bool rampauxiliaryindication = 7; // [°] [0|45] optional double vehicleslope = 8; // [] [0|0] optional int32 vcu_brakerept_alivecounter = 9; // [] [0|0] optional int32 vcu_brakerept_checksum = 10; // [] optional Vcu_ehb_brakeType vcu_ehb_brake_state = 11; } message Vcu_eps_report_57 { // Report Message enum Control_mode_respType { CONTROL_MODE_RESP_STANDBY = 0; CONTROL_MODE_RESP_AUTO_DRIVE = 1; CONTROL_MODE_RESP_NET_DRIVE = 2; CONTROL_MODE_RESP_REMOTE_CONTROL = 3; CONTROL_MODE_RESP_EMERGENCY_BRAKE = 4; } // 0x0:disable;0x1:enable [] [0|0] optional bool drive_enable_resp = 1; // 0x0:Standby;0x1:auto drive;0x2:net drive;0x3:remote control;0x4:emergency // brake;0x5~0x7:Reserved [] [0|7] optional Control_mode_respType control_mode_resp = 2; // 0x0:not overflow;0x1:overflow [] [0|0] optional bool vcu_eps_report = 3; // ; [] [0|0] optional double vcu_real_angle = 4; // 0x0:disable;0x1:enable [] [0|0] optional bool vcu_real_angle_valid = 5; // 0x0:disable;0x1:enable; [] [0|0] optional bool vcu_target_angle_valid = 6; // [deg] [-380|380] optional double vcu_target_angle = 7; // [] [0|0] optional int32 vcu_eps_rept_alivecounter = 8; // [] [0|0] optional int32 vcu_eps_rept_checksum = 9; } message Ads_eps_command_56 { // Control Message // 0x0:disable ;0x1:enable [] [0|0] optional bool drive_enable = 1; // [] [0|0] optional double auto_target_angle = 2; // [] [0|0] optional int32 auto_drivercmd_alivecounter = 3; // [] [0|0] optional int32 auto_drivercmd_checksum = 4; } message Ads_drive_command_50 { // Control Message enum Auto_shift_commandType { AUTO_SHIFT_COMMAND_N = 0; AUTO_SHIFT_COMMAND_D = 1; AUTO_SHIFT_COMMAND_R = 2; AUTO_SHIFT_COMMAND_RESERVED = 3; } // 0x0:disable ;0x1:enable [] [0|0] optional bool drive_enable = 1; // 0x0:N ;0x1:D ;0x2:R ;0x3:Reserved [] [0|3] optional Auto_shift_commandType auto_shift_command = 2; // [] [0|0] optional double auto_drive_torque = 3; // [] [0|0] optional int32 auto_drivercmd_alivecounter = 4; // [] [0|0] optional int32 auto_drivercmd_checksum = 5; } message Vcu_drive_report_52 { // Report Message enum Control_mode_respType { CONTROL_MODE_RESP_STANDBY = 0; CONTROL_MODE_RESP_AUTO_DRIVE = 1; CONTROL_MODE_RESP_NET_DRIVE = 2; CONTROL_MODE_RESP_REMOTE_CONTROL = 3; CONTROL_MODE_RESP_EMERGENCY_BRAKE = 4; } enum Vcu_real_shiftType { VCU_REAL_SHIFT_N = 0; VCU_REAL_SHIFT_D = 1; VCU_REAL_SHIFT_R = 2; VCU_REAL_SHIFT_RESERVED = 3; } // 0x0:disable;0x1:enable [] [0|0] optional bool drive_enable_resp = 1; // 0x0:Standby;0x1:auto drive;0x2:net drive;0x3:remote control;0x4:emergency // brake;0x5~0x7:Reserved [] [0|7] optional Control_mode_respType control_mode_resp = 2; // 0x0:N档;0x1:D档;0x2:R档;0x3:Reserved [] [0|3] optional Vcu_real_shiftType vcu_real_shift = 3; // 0x0:disable;0x1:enable [] [0|0] optional bool vcu_real_shift_valid = 4; // 0x0:disable;0x1:enable [] [0|0] optional bool vcu_real_torque_valid = 5; // [Nm] [0|0] optional double vcu_real_torque = 6; // 0x0:disable;0x1:enable [] [0|0] optional bool vcu_limitedtorquemode = 7; // [] [0|0] optional int32 vcu_driverept_alivecounter = 8; // [] [0|0] optional int32 vcu_driverept_checksum = 9; } message Ads_diagnosis_628 { // Control Message // 0x0:Nomal;0x1:Level 1;0x2:Level 2;0x3:Level 3;0x4:Level 4;0x5:Level // 5;0x6:Reserved;0x7:Reserved [bit] [0|5] optional int32 faultrank = 1; // [] [0|65535] optional int32 adas_fault_code = 2; // [bit] [0|255] optional int32 adas_softwareversion = 3; // [bit] [0|255] optional int32 adas_hardwareversion = 4; } message Vcu_nm_401 { // Report Message // 0x0:Inactive;0x1:Active [bit] [0|1] optional bool vcu_sleepcommand = 1; } message Vcu_vehicle_status_report_101 { // Report Message enum Control_mode_respType { CONTROL_MODE_RESP_STANDBY = 0; CONTROL_MODE_RESP_AUTO_DRIVE = 1; CONTROL_MODE_RESP_NET_DRIVE = 2; CONTROL_MODE_RESP_REMOTE_CONTROL = 3; CONTROL_MODE_RESP_EMERGENCY_BRAKE = 4; } // 0x0:disable;0x1:enable [] [0|0] optional bool drive_enable_resp = 1; // 0x0:Disconnect;0x1:Connect [] [0|0] optional bool vcu_highvoltagecircuitstate = 2; // 0x0: Disable;0x1:Enable [] [0|0] optional bool vcu_dcdc_enabledstates = 3; // 0x0:Standby;0x1:auto drive;0x2:net drive;0x3:remote control;0x4:emergency // brake;0x5~0x7:Reserved [] [0|7] optional Control_mode_respType control_mode_resp = 4; // [Km/h] [0|460.69] optional double vcu_vehicle_speed = 5; // 0x0:Reserved;0x1:Start;0x2:Stop;0x3:Invalid [] [0|0] optional int32 vcu_lowbatterychargingfunctionst = 6; // [%] [0|100] optional int32 vcu_display_soc = 7; // [] [0|0] optional double vcu_motor_speed = 8; // 0x0:Standby Status;0x1:Forward Mode;0x2:Reverse Mode [] [0|0] optional int32 vcu_motor_direction = 9; // 0x0:disable;0x1:enable [] [0|0] optional bool vcu_motor_speed_valid = 10; // [] [0|0] optional int32 vcu_statusrept_alivecounter = 11; // [] [0|0] optional int32 vcu_statusrept_checksum = 12; } message Vcu_vehicle_info_response_502 { // Report Message // [] [0|16777215] optional int32 vehicle_softwareversion_indicati = 1; // [] [0|15] optional int32 project = 2; // [] [0|15] optional int32 manufacturer = 3; // [] [0|255] optional int32 year = 4; // [] [1|12] optional int32 month = 5; // [] [1|31] optional int32 day = 6; // [] [0|32767] optional int32 vehicle_serial_number = 7; } message Aeb_diagnosis1_626 { // Report Message // [bit] [0.0|255.0] optional double aeb_softwareversion = 1; // [bit] [0.0|255.0] optional double aeb_hardwareversion = 2; } message Aeb_diagresp_718 { // Report Message // [bit] [0.0|1.0] optional bool aeb_diagresp = 1; } message Pas_1st_data_311 { // Report Message // phy=int*2;0xFF:no obstacle [cm] [0|510] optional double pasdistance4 = 1; // phy=int*2;0xFF:no obstacle [cm] [0|510] optional double pasdistance3 = 2; // 0x0:Invalid;0x1:Valid [bit] [0|1] optional bool pas_f1_status = 3; // 0x0:Invalid;0x1:Valid [bit] [0|1] optional bool pas_f2_status = 4; // 0x0:Invalid;0x1:Valid [bit] [0|1] optional bool pas_f3_status = 5; // 0x0:Invalid;0x1:Valid [bit] [0|1] optional bool pas_f4_status = 6; // phy=int*2;0xFF:no obstacle [cm] [0|510] optional double pasdistance2 = 7; // [cm] [0|510] optional double pasdistance1 = 8; } message Pas_2nd_data_312 { // Report Message // 0x0:Invalid;0x1:Valid [bit] [0.0|1.0] optional bool pas_b1_status = 1; // 0x0:Invalid;0x1:Valid [bit] [0.0|1.0] optional bool pas_b2_status = 2; // 0x0:Invalid;0x1:Valid [bit] [0.0|1.0] optional bool pas_b3_status = 3; // 0x0:Invalid;0x1:Valid [bit] [0.0|1.0] optional bool pas_b4_status = 4; // phy=int*2;0xFF:no obstacle [cm] [0.0|510.0] optional double pasdistance1 = 5; // phy=int*2;0xFF:no obstacle [cm] [0.0|510.0] optional double pasdistance2 = 6; // phy=int*2;0xFF:no obstacle [cm] [0.0|510.0] optional double pasdistance3 = 7; // phy=int*2;0xFF:no obstacle [cm] [0.0|510.0] optional double pasdistance4 = 8; } message Aeb_wheelimpulse_355 { // Report Message // 0x0:Invalid;0x1:Valid [bit] [0.0|1023.0] optional double flimpulse = 1; // 0x0:Invalid;0x1:Valid [bit] [0.0|1.0] optional bool flimpulsevalid = 2; // [km/h] [0.0|1023.0] optional double frimpulse = 3; // [km/h] [0.0|1.0] optional bool frimpulsevalid = 4; // 0x0:Invalid;0x1:Valid [bit] [0.0|1023.0] optional double rlimpulse = 5; // 0x0:Invalid;0x1:Valid [bit] [0.0|1.0] optional bool rlimpulsevalid = 6; // [km/h] [0.0|1023.0] optional double rrimpulse = 7; // [km/h] [0.0|1.0] optional bool rrimpulsevalid = 8; // [] [0.0|15.0] optional double alivecounter = 9; // [] [0.0|255.0] optional double checksum = 10; } message Aeb_rearwheelspeed_354 { // Report Message // 0x0:Invalid;0x1:Valid [bit] [0.0|1.0] optional bool wheelspeed_rl_valid = 1; // [km/h] [0.0|327.67] optional double wheelspeed_rl = 2; // 0x0:Invalid;0x1:Valid [bit] [0.0|1.0] optional bool wheelspeed_rr_valid = 3; // [km/h] [0.0|327.67] optional double wheelspeed_rr = 4; // 0x0:Invalid;0x1:D;0x2:N;0x3:R [bit] [0.0|3.0] optional double wheelspeed_rl_direct = 5; // 0x0:Invalid;0x1:D;0x2:N;0x3:R [bit] [0.0|3.0] optional double wheelspeed_rr_direct = 6; // [] [0.0|15.0] optional double alivecounter_rear = 7; // [] [0.0|255.0] optional double checksum_rear = 8; } message Aeb_frontwheelspeed_353 { // Report Message // 0x0:Invalid;0x1:Valid [bit] [0.0|1.0] optional bool vehiclespeedvalid = 1; // [Km/h] [0.0|460.69] optional double vehiclespeed = 2; // 0x0:Invalid;0x1:D;0x2:N;0x3:R [bit] [0.0|3.0] optional double vehiclerealdirect = 3; // 0x0:Invalid;0x1:Valid [bit] [0.0|1.0] optional bool wheelspeed_fl_valid = 4; // [km/h] [0.0|327.67] optional double wheelspeed_fl = 5; // 0x0:Invalid;0x1:Valid [bit] [0.0|1.0] optional bool wheelspeed_fr_valid = 6; // [km/h] [0.0|327.67] optional double wheelspeed_fr = 7; // 0x0:Invalid;0x1:D;0x2:N;0x3:R [bit] [0.0|3.0] optional double wheelspeed_fl_direct = 8; // 0x0:Invalid;0x1:D;0x2:N;0x3:R [bit] [0.0|3.0] optional double wheelspeed_fr_direct = 9; // [] [0.0|15.0] optional double alivecounter_front = 10; // [] [0.0|255.0] optional double checksum_front = 11; } message VehicleSpd { optional double vehicle_spd = 1 [default = 0]; // unit:m/s } // Battery message Battery { optional double battery_percent = 1; // unit:%, battery percentage left } message Safety { optional int32 driving_mode = 1; } message Gas { optional double gas_pedal_position = 1 [default = 0]; // manual gas } message Gear { optional Chassis.GearPosition gear_state = 1; } message Brake { optional double brake_pedal_position = 1; } // Electrical Power Steering message Eps { optional double steering_angle = 1; // unit:degree } // Electrical Parking Brake message Epb { enum PBrakeType { PBRAKE_OFF = 0; PBRAKE_TRANSITION = 1; PBRAKE_ON = 2; PBRAKE_FAULT = 3; } optional PBrakeType parking_brake_status = 4; } // 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 Neolix_edu { optional Aeb_systemstate_11 aeb_systemstate_11 = 1; // report message optional Vcu_vehicle_fault_response_201 vcu_vehicle_fault_response_201 = 2; // report message optional Vcu_powerstatus_214 vcu_powerstatus_214 = 3; // report message optional Ads_light_horn_command_310 ads_light_horn_command_310 = 4; // control message optional Ads_brake_command_46 ads_brake_command_46 = 5; // control message optional Vcu_brake_report_47 vcu_brake_report_47 = 6; // report message optional Vcu_eps_report_57 vcu_eps_report_57 = 7; // report message optional Ads_eps_command_56 ads_eps_command_56 = 8; // control message optional Ads_drive_command_50 ads_drive_command_50 = 9; // control message optional Vcu_drive_report_52 vcu_drive_report_52 = 10; // report message optional Ads_diagnosis_628 ads_diagnosis_628 = 11; // control message optional Vcu_nm_401 vcu_nm_401 = 12; // report message optional Vcu_vehicle_status_report_101 vcu_vehicle_status_report_101 = 13; // report message optional Vcu_vehicle_info_response_502 vcu_vehicle_info_response_502 = 14; // report message optional Aeb_diagnosis1_626 aeb_diagnosis1_626 = 15; // report message optional Aeb_diagresp_718 aeb_diagresp_718 = 16; // report message optional Pas_1st_data_311 pas_1st_data_311 = 17; // report message optional Pas_2nd_data_312 pas_2nd_data_312 = 18; // report message optional Aeb_wheelimpulse_355 aeb_wheelimpulse_355 = 19; // report message optional Aeb_rearwheelspeed_354 aeb_rearwheelspeed_354 = 20; // report message optional Aeb_frontwheelspeed_353 aeb_frontwheelspeed_353 = 21; // report message optional VehicleSpd vehicle_spd = 50; optional Battery battery = 51; // Battery info optional Safety safety = 52; // safety optional Gas gas = 53; // gas pedal optional Gear gear = 54; // gear optional Brake brake = 55; // brake pedal optional Eps eps = 56; // Electronic Power Steering optional Epb epb = 57; // Electronic parking brake optional CheckResponseSignal check_response = 58; }
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/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 = "neolix_edu_cc_proto", deps = [ ":neolix_edu_proto", ], ) proto_library( name = "neolix_edu_proto", srcs = ["neolix_edu.proto"], deps = [ "//modules/common_msgs/chassis_msgs:chassis_proto", ], ) py_proto_library( name = "neolix_edu_py_pb2", deps = [ ":neolix_edu_proto", ], )
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/vcu_drive_report_52_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/neolix_edu/protocol/vcu_drive_report_52.h" #include "glog/logging.h" #include "gtest/gtest.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace neolix_edu { class Vcudrivereport52Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Vcudrivereport52Test, reset) { uint8_t data[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; int32_t length = 8; Neolix_edu cd; Vcudrivereport52 accel_cmd; accel_cmd.Parse(data, length, &cd); EXPECT_EQ(data[0], 0b00000000); EXPECT_EQ(data[1], 0b00000000); EXPECT_EQ(data[2], 0b00000000); EXPECT_EQ(data[3], 0b00000000); EXPECT_EQ(data[4], 0b00000000); EXPECT_EQ(data[5], 0b00000000); EXPECT_EQ(data[6], 0b00000000); EXPECT_EQ(data[7], 0b00000000); EXPECT_EQ(cd.vcu_drive_report_52().drive_enable_resp(), false); EXPECT_EQ(cd.vcu_drive_report_52().control_mode_resp(), 0); EXPECT_EQ(cd.vcu_drive_report_52().vcu_real_shift(), 0); EXPECT_EQ(cd.vcu_drive_report_52().vcu_real_shift_valid(), false); EXPECT_EQ(cd.vcu_drive_report_52().vcu_real_torque_valid(), false); EXPECT_EQ(cd.vcu_drive_report_52().vcu_real_torque(), -665); EXPECT_EQ(cd.vcu_drive_report_52().vcu_limitedtorquemode(), false); } } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/aeb_diagnosis1_626.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/neolix_edu/protocol/aeb_diagnosis1_626.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 neolix_edu { using ::apollo::drivers::canbus::Byte; Aebdiagnosis1626::Aebdiagnosis1626() {} const int32_t Aebdiagnosis1626::ID = 0x626; void Aebdiagnosis1626::Parse(const std::uint8_t* bytes, int32_t length, Neolix_edu* chassis) const { chassis->mutable_aeb_diagnosis1_626()->set_aeb_softwareversion( aeb_softwareversion(bytes, length)); chassis->mutable_aeb_diagnosis1_626()->set_aeb_hardwareversion( aeb_hardwareversion(bytes, length)); } // config detail: {'name': 'aeb_softwareversion', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'physical_range': // '[0.0|255.0]', 'bit': 55, 'type': 'double', 'order': 'motorola', // 'physical_unit': 'bit'} double Aebdiagnosis1626::aeb_softwareversion(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 6); int32_t x = t0.get_byte(0, 8); double ret = x; return ret; } // config detail: {'name': 'aeb_hardwareversion', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'physical_range': // '[0.0|255.0]', 'bit': 63, 'type': 'double', 'order': 'motorola', // 'physical_unit': 'bit'} double Aebdiagnosis1626::aeb_hardwareversion(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 7); int32_t x = t0.get_byte(0, 8); double ret = x; return ret; } } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/vcu_vehicle_info_response_502_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/neolix_edu/protocol/vcu_vehicle_info_response_502.h" #include "glog/logging.h" #include "gtest/gtest.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace neolix_edu { class Vcuvehicleinforesponse502Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Vcuvehicleinforesponse502Test, reset) { uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; int32_t length = 8; Neolix_edu cd; Vcuvehicleinforesponse502 accel_cmd; accel_cmd.Parse(data, length, &cd); EXPECT_EQ(data[0], 0b01100111); 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); EXPECT_EQ(cd.vcu_vehicle_info_response_502() .vehicle_softwareversion_indicati(), 6775395); EXPECT_EQ(cd.vcu_vehicle_info_response_502().project(), 4); EXPECT_EQ(cd.vcu_vehicle_info_response_502().manufacturer(), 6); EXPECT_EQ(cd.vcu_vehicle_info_response_502().year(), 81); EXPECT_EQ(cd.vcu_vehicle_info_response_502().month(), 5); EXPECT_EQ(cd.vcu_vehicle_info_response_502().day(), 4); EXPECT_EQ(cd.vcu_vehicle_info_response_502().vehicle_serial_number(), 21332); } } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/vcu_vehicle_fault_response_201.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/neolix_edu/protocol/vcu_vehicle_fault_response_201.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 neolix_edu { using ::apollo::drivers::canbus::Byte; Vcuvehiclefaultresponse201::Vcuvehiclefaultresponse201() {} const int32_t Vcuvehiclefaultresponse201::ID = 0x201; void Vcuvehiclefaultresponse201::Parse(const std::uint8_t* bytes, int32_t length, Neolix_edu* chassis) const { chassis->mutable_vcu_vehicle_fault_response_201() ->set_vehicle_error_indicationsvcu( vehicle_error_indicationsvcu(bytes, length)); chassis->mutable_vcu_vehicle_fault_response_201() ->set_brake_system_errorehb( brake_system_errorehb(bytes, length)); chassis->mutable_vcu_vehicle_fault_response_201() ->set_eps_error(eps_error(bytes, length)); chassis->mutable_vcu_vehicle_fault_response_201() ->set_motor_error(motor_error(bytes, length)); chassis->mutable_vcu_vehicle_fault_response_201() ->set_epb_error(epb_error(bytes, length)); chassis->mutable_vcu_vehicle_fault_response_201() ->set_high_voltage_battery_errorbcu( high_voltage_battery_errorbcu(bytes, length)); chassis->mutable_vcu_vehicle_fault_response_201() ->set_automode_exit_reason_losscommuni( automode_exit_reason_losscommuni(bytes, length)); chassis->mutable_vcu_vehicle_fault_response_201() ->set_automode_exit_reason_reqsignalno( automode_exit_reason_reqsignalno(bytes, length)); chassis->mutable_vcu_vehicle_fault_response_201() ->set_automode_exit_reason_low_power( automode_exit_reason_low_power(bytes, length)); chassis->mutable_vcu_vehicle_fault_response_201() ->set_automode_exit_reason_highvolt( automode_exit_reason_highvolt(bytes, length)); chassis->mutable_vcu_vehicle_fault_response_201() ->set_automode_exit_reason_vehicle_flt( automode_exit_reason_vehicle_flt(bytes, length)); chassis->mutable_vcu_vehicle_fault_response_201() ->set_automode_exit_reason_press_emerg( automode_exit_reason_press_emerg(bytes, length)); chassis->mutable_vcu_vehicle_fault_response_201() ->set_automode_exit_reason_press_remot( automode_exit_reason_press_remot(bytes, length)); chassis->mutable_vcu_vehicle_fault_response_201() ->set_automode_exit_reason_pdu_control( automode_exit_reason_pdu_control(bytes, length)); chassis->mutable_vcu_vehicle_fault_response_201() ->set_vcu_faultrept_alivecounter( vcu_faultrept_alivecounter(bytes, length)); chassis->mutable_vcu_vehicle_fault_response_201() ->set_vcu_faultrept_checksum( vcu_faultrept_checksum(bytes, length)); } // config detail: {'description': '0x0: no error;0x1: level 1 error;0x2: level 2 // error;0x3: level 3 error;0x4: level 4 error;0x5: level 5 error', 'offset': // 0.0, 'precision': 1.0, 'len': 4, 'name': 'vehicle_error_indicationsvcu', // 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': 3, 'type': 'int', // 'order': 'motorola', 'physical_unit': ''} int Vcuvehiclefaultresponse201::vehicle_error_indicationsvcu( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 4); int ret = x; return ret; } // config detail: {'description': '0x0: no error;0x1: level 1 error;0x2: level 2 // error;0x3: level 3 error;0x4: level 4 error;0x5: level 5 error', 'offset': // 0.0, 'precision': 1.0, 'len': 4, 'name': 'brake_system_errorehb', // 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': 7, 'type': 'int', // 'order': 'motorola', 'physical_unit': ''} int Vcuvehiclefaultresponse201::brake_system_errorehb(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(4, 4); int ret = x; return ret; } // config detail: {'description': '0x0: no error;0x1: level 1 error;0x2: level 2 // error;0x3: level 3 error;0x4: level 4 error;0x5: level 5 error', 'offset': // 0.0, 'precision': 1.0, 'len': 4, 'name': 'eps_error', 'is_signed_var': False, // 'physical_range': '[0|0]', 'bit': 11, 'type': 'int', 'order': 'motorola', // 'physical_unit': ''} int Vcuvehiclefaultresponse201::eps_error(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(0, 4); int ret = x; return ret; } // config detail: {'description': '0x0: no error;0x1: level 1 error;0x2: level 2 // error;0x3: level 3 error;0x4: level 4 error;0x5: level 5 error', 'offset': // 0.0, 'precision': 1.0, 'len': 4, 'name': 'motor_error', 'is_signed_var': // False, 'physical_range': '[0|0]', 'bit': 15, 'type': 'int', 'order': // 'motorola', 'physical_unit': ''} int Vcuvehiclefaultresponse201::motor_error(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(4, 4); int ret = x; return ret; } // config detail: {'description': '0x0: no error;0x1: level 1 error;0x2: level 2 // error;0x3: level 3 error;0x4: level 4 error;0x5: level 5 error', 'offset': // 0.0, 'precision': 1.0, 'len': 4, 'name': 'epb_error', 'is_signed_var': False, // 'physical_range': '[0|0]', 'bit': 19, 'type': 'int', 'order': 'motorola', // 'physical_unit': ''} int Vcuvehiclefaultresponse201::epb_error(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 2); int32_t x = t0.get_byte(0, 4); int ret = x; return ret; } // config detail: {'description': '0x0: no error;0x1: level 1 error;0x2: level 2 // error;0x3: level 3 error;0x4: level 4 error;0x5: level 5 error', 'offset': // 0.0, 'precision': 1.0, 'len': 4, 'name': 'high_voltage_battery_errorbcu', // 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': 23, 'type': 'int', // 'order': 'motorola', 'physical_unit': ''} int Vcuvehiclefaultresponse201::high_voltage_battery_errorbcu( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 2); int32_t x = t0.get_byte(4, 4); int ret = x; return ret; } // config detail: {'description': '0x0:Normal;0x1:Failure', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'automode_exit_reason_losscommuni', // 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': 32, 'type': 'bool', // 'order': 'motorola', 'physical_unit': ''} bool Vcuvehiclefaultresponse201::automode_exit_reason_losscommuni( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(0, 1); bool ret = x; return ret; } // config detail: {'description': '0x0:Normal;0x1:Failure', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'automode_exit_reason_reqsignalno', // 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': 33, 'type': 'bool', // 'order': 'motorola', 'physical_unit': ''} bool Vcuvehiclefaultresponse201::automode_exit_reason_reqsignalno( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(1, 1); bool ret = x; return ret; } // config detail: {'description': '0x0:Normal;0x1:Failure', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'automode_exit_reason_low_power', // 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': 34, 'type': 'bool', // 'order': 'motorola', 'physical_unit': ''} bool Vcuvehiclefaultresponse201::automode_exit_reason_low_power( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(2, 1); bool ret = x; return ret; } // config detail: {'description': '0x0:Normal;0x1:Failure', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'automode_exit_reason_highvolt', // 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': 35, 'type': 'bool', // 'order': 'motorola', 'physical_unit': ''} bool Vcuvehiclefaultresponse201::automode_exit_reason_highvolt( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(3, 1); bool ret = x; return ret; } // config detail: {'description': '0x0:Normal;0x1:Failure', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'automode_exit_reason_vehicle_flt', // 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': 36, 'type': 'bool', // 'order': 'motorola', 'physical_unit': ''} bool Vcuvehiclefaultresponse201::automode_exit_reason_vehicle_flt( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(4, 1); bool ret = x; return ret; } // config detail: {'description': '0x0:Normal;0x1:Failure', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'automode_exit_reason_press_emerg', // 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': 37, 'type': 'bool', // 'order': 'motorola', 'physical_unit': ''} bool Vcuvehiclefaultresponse201::automode_exit_reason_press_emerg( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(5, 1); bool ret = x; return ret; } // config detail: {'description': '0x0:Normal;0x1:Failure', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'automode_exit_reason_press_remot', // 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': 38, 'type': 'bool', // 'order': 'motorola', 'physical_unit': ''} bool Vcuvehiclefaultresponse201::automode_exit_reason_press_remot( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(6, 1); bool ret = x; return ret; } // config detail: {'description': '0x0:Normal;0x1:Failure', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'automode_exit_reason_pdu_control', // 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': 39, 'type': 'bool', // 'order': 'motorola', 'physical_unit': ''} bool Vcuvehiclefaultresponse201::automode_exit_reason_pdu_control( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(7, 1); bool ret = x; return ret; } // config detail: {'name': 'vcu_faultrept_alivecounter', 'offset': 0.0, // 'precision': 1.0, 'len': 4, 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 51, 'type': 'int', 'order': 'motorola', 'physical_unit': ''} int Vcuvehiclefaultresponse201::vcu_faultrept_alivecounter( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 6); int32_t x = t0.get_byte(0, 4); int ret = x; return ret; } // config detail: {'name': 'vcu_faultrept_checksum', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 63, 'type': 'int', 'order': 'motorola', 'physical_unit': ''} int Vcuvehiclefaultresponse201::vcu_faultrept_checksum( 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 neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/aeb_diagnosis1_626.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/neolix_edu/proto/neolix_edu.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace neolix_edu { class Aebdiagnosis1626 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Neolix_edu> { public: static const int32_t ID; Aebdiagnosis1626(); void Parse(const std::uint8_t* bytes, int32_t length, Neolix_edu* chassis) const override; private: // config detail: {'name': 'AEB_SoftwareVersion', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'physical_range': // '[0.0|255.0]', 'bit': 55, 'type': 'double', 'order': 'motorola', // 'physical_unit': 'bit'} double aeb_softwareversion(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'AEB_HardwareVersion', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'physical_range': // '[0.0|255.0]', 'bit': 63, 'type': 'double', 'order': 'motorola', // 'physical_unit': 'bit'} double aeb_hardwareversion(const std::uint8_t* bytes, const int32_t length) const; }; } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/ads_light_horn_command_310_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/neolix_edu/protocol/ads_light_horn_command_310.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace neolix_edu { class Adslighthorncommand310Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Adslighthorncommand310Test, reset) { uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; Adslighthorncommand310 accel_cmd; EXPECT_EQ(accel_cmd.GetPeriod(), 20 * 1000); accel_cmd.UpdateData(data); EXPECT_EQ(data[0], 0b01100111); EXPECT_EQ(data[1], 0b01000000); EXPECT_EQ(data[2], 0b01100011); EXPECT_EQ(data[3], 0b01100100); EXPECT_EQ(data[4], 0b01010001); EXPECT_EQ(data[5], 0b01010010); EXPECT_EQ(data[6], 0b01010001); EXPECT_EQ(data[7], 0b01110010); } } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/ads_eps_command_56.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/neolix_edu/proto/neolix_edu.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace neolix_edu { class Adsepscommand56 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Neolix_edu> { public: static const int32_t ID; Adsepscommand56(); uint32_t GetPeriod() const override; void UpdateData(uint8_t* data) override; void Reset() override; // config detail: {'description': '0x0:disable ;0x1:enable', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'Drive_Enable', 'is_signed_var': False, // 'physical_range': '[0|0]', 'bit': 0, 'type': 'bool', 'order': 'motorola', // 'physical_unit': ''} Adsepscommand56* set_drive_enable(bool drive_enable); // config detail: {'name': 'AUTO_Target_Angle', 'offset': -2048.0, // 'precision': 0.0625, 'len': 16, 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 23, 'type': 'double', 'order': 'motorola', 'physical_unit': // ''} Adsepscommand56* set_auto_target_angle(double auto_target_angle); // config detail: {'name': 'AUTO_DriverCmd_AliveCounter', 'offset': 0.0, // 'precision': 1.0, 'len': 4, 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 51, 'type': 'int', 'order': 'motorola', 'physical_unit': // ''} Adsepscommand56* set_auto_drivercmd_alivecounter( int auto_drivercmd_alivecounter); // config detail: {'name': 'AUTO_DriverCmd_CheckSum', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 63, 'type': 'int', 'order': 'motorola', 'physical_unit': // ''} Adsepscommand56* set_auto_drivercmd_checksum(int auto_drivercmd_checksum); private: // config detail: {'description': '0x0:disable ;0x1:enable', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'Drive_Enable', 'is_signed_var': False, // 'physical_range': '[0|0]', 'bit': 0, 'type': 'bool', 'order': 'motorola', // 'physical_unit': ''} void set_p_drive_enable(uint8_t* data, bool drive_enable); // config detail: {'name': 'AUTO_Target_Angle', 'offset': -2048.0, // 'precision': 0.0625, 'len': 16, 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 23, 'type': 'double', 'order': 'motorola', 'physical_unit': // ''} void set_p_auto_target_angle(uint8_t* data, double auto_target_angle); // config detail: {'name': 'AUTO_DriverCmd_AliveCounter', 'offset': 0.0, // 'precision': 1.0, 'len': 4, 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 51, 'type': 'int', 'order': 'motorola', 'physical_unit': // ''} void set_p_auto_drivercmd_alivecounter(uint8_t* data, int auto_drivercmd_alivecounter); // config detail: {'name': 'AUTO_DriverCmd_CheckSum', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 63, 'type': 'int', 'order': 'motorola', 'physical_unit': // ''} void set_p_auto_drivercmd_checksum(uint8_t* data, int auto_drivercmd_checksum); private: bool drive_enable_; double auto_target_angle_; int auto_drivercmd_alivecounter_; int auto_drivercmd_checksum_; }; } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/vcu_vehicle_status_report_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/neolix_edu/proto/neolix_edu.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace neolix_edu { class Vcuvehiclestatusreport101 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Neolix_edu> { public: static const int32_t ID; Vcuvehiclestatusreport101(); void Parse(const std::uint8_t* bytes, int32_t length, Neolix_edu* chassis) const override; private: // config detail: {'description': '0x0:disable;0x1:enable', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'Drive_Enable_Resp', 'is_signed_var': // False, 'physical_range': '[0|0]', 'bit': 0, 'type': 'bool', 'order': // 'motorola', 'physical_unit': ''} bool drive_enable_resp(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': '0x0:Disconnect;0x1:Connect', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'VCU_HighVoltageCircuitState', // 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': 2, 'type': // 'bool', 'order': 'motorola', 'physical_unit': ''} bool vcu_highvoltagecircuitstate(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': '0x0: Disable;0x1:Enable', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'VCU_DCDC_EnabledStates', // 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': 3, 'type': // 'bool', 'order': 'motorola', 'physical_unit': ''} bool vcu_dcdc_enabledstates(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': '0x0:Standby;0x1:auto drive;0x2:net // drive;0x3:remote control;0x4:emergency brake;0x5~0x7:Reserved', 'enum': {0: // 'CONTROL_MODE_RESP_STANDBY', 1: 'CONTROL_MODE_RESP_AUTO_DRIVE', 2: // 'CONTROL_MODE_RESP_NET_DRIVE', 3: 'CONTROL_MODE_RESP_REMOTE_CONTROL', 4: // 'CONTROL_MODE_RESP_EMERGENCY_BRAKE'}, 'precision': 1.0, 'len': 3, 'name': // 'Control_Mode_Resp', 'is_signed_var': False, 'offset': 0.0, // 'physical_range': '[0|7]', 'bit': 6, 'type': 'enum', 'order': 'motorola', // 'physical_unit': ''} Vcu_vehicle_status_report_101::Control_mode_respType control_mode_resp( const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'VCU_Vehicle_Speed', 'offset': 0.0, 'precision': // 0.05625, 'len': 13, 'is_signed_var': False, 'physical_range': '[0|460.69]', // 'bit': 15, 'type': 'double', 'order': 'motorola', 'physical_unit': 'Km/h'} double vcu_vehicle_speed(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': '0x0:Reserved;0x1:Start;0x2:Stop;0x3:Invalid // ', 'offset': 0.0, 'precision': 1.0, 'len': 2, 'name': // 'VCU_LowBatteryChargingFunctionSt', 'is_signed_var': False, // 'physical_range': '[0|0]', 'bit': 17, 'type': 'int', 'order': 'motorola', // 'physical_unit': ''} int vcu_lowbatterychargingfunctionst(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'VCU_Display_SOC', 'offset': 0.0, 'precision': 1.0, // 'len': 8, 'is_signed_var': False, 'physical_range': '[0|100]', 'bit': 31, // 'type': 'int', 'order': 'motorola', 'physical_unit': '%'} int vcu_display_soc(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'VCU_Motor_Speed', 'offset': 0.0, 'precision': // 0.25, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': // 39, 'type': 'double', 'order': 'motorola', 'physical_unit': ''} double vcu_motor_speed(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': '0x0:Standby Status;0x1:Forward // Mode;0x2:Reverse Mode', 'offset': 0.0, 'precision': 1.0, 'len': 2, 'name': // 'VCU_Motor_Direction', 'is_signed_var': False, 'physical_range': '[0|0]', // 'bit': 54, 'type': 'int', 'order': 'motorola', 'physical_unit': ''} int vcu_motor_direction(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': '0x0:disable;0x1:enable', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'VCU_Motor_Speed_Valid', // 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': 55, 'type': // 'bool', 'order': 'motorola', 'physical_unit': ''} bool vcu_motor_speed_valid(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'VCU_StatusRept_AliveCounter', 'offset': 0.0, // 'precision': 1.0, 'len': 4, 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 51, 'type': 'int', 'order': 'motorola', 'physical_unit': // ''} int vcu_statusrept_alivecounter(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'VCU_StatusRept_CheckSum', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 63, 'type': 'int', 'order': 'motorola', 'physical_unit': // ''} int vcu_statusrept_checksum(const std::uint8_t* bytes, const int32_t length) const; }; } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/aeb_systemstate_11_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/neolix_edu/protocol/aeb_systemstate_11.h" #include "glog/logging.h" #include "gtest/gtest.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace neolix_edu { class Aebsystemstate11Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Aebsystemstate11Test, reset) { uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; int32_t length = 8; Neolix_edu cd; Aebsystemstate11 accel_cmd; accel_cmd.Parse(data, length, &cd); EXPECT_EQ(data[0], 0b01100111); 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); EXPECT_EQ(cd.aeb_systemstate_11().aeb_state(), 3); EXPECT_EQ(cd.aeb_systemstate_11().aeb_brakestate(), true); EXPECT_EQ(cd.aeb_systemstate_11().faultrank(), 2); EXPECT_EQ(cd.aeb_systemstate_11().currenttemperature(), 59); EXPECT_EQ(cd.aeb_systemstate_11().pas_f1_stop(), false); EXPECT_EQ(cd.aeb_systemstate_11().pas_f2_stop(), false); EXPECT_EQ(cd.aeb_systemstate_11().pas_f3_stop(), true); EXPECT_EQ(cd.aeb_systemstate_11().pas_f4_stop(), false); EXPECT_EQ(cd.aeb_systemstate_11().pas_b1_stop(), false); EXPECT_EQ(cd.aeb_systemstate_11().pas_b2_stop(), true); EXPECT_EQ(cd.aeb_systemstate_11().pas_b3_stop(), true); EXPECT_EQ(cd.aeb_systemstate_11().pas_b4_stop(), false); } } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/vcu_eps_report_57.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/neolix_edu/protocol/vcu_eps_report_57.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 neolix_edu { using ::apollo::drivers::canbus::Byte; Vcuepsreport57::Vcuepsreport57() {} const int32_t Vcuepsreport57::ID = 0x57; void Vcuepsreport57::Parse(const std::uint8_t* bytes, int32_t length, Neolix_edu* chassis) const { chassis->mutable_vcu_eps_report_57()->set_drive_enable_resp( drive_enable_resp(bytes, length)); chassis->mutable_vcu_eps_report_57()->set_control_mode_resp( control_mode_resp(bytes, length)); chassis->mutable_vcu_eps_report_57()->set_vcu_eps_report( vcu_eps_report(bytes, length)); chassis->mutable_vcu_eps_report_57()->set_vcu_real_angle( vcu_real_angle(bytes, length)); chassis->mutable_vcu_eps_report_57()->set_vcu_real_angle_valid( vcu_real_angle_valid(bytes, length)); chassis->mutable_vcu_eps_report_57()->set_vcu_target_angle_valid( vcu_target_angle_valid(bytes, length)); chassis->mutable_vcu_eps_report_57()->set_vcu_target_angle( vcu_target_angle(bytes, length)); chassis->mutable_vcu_eps_report_57()->set_vcu_eps_rept_alivecounter( vcu_eps_rept_alivecounter(bytes, length)); chassis->mutable_vcu_eps_report_57()->set_vcu_eps_rept_checksum( vcu_eps_rept_checksum(bytes, length)); chassis->mutable_eps()->set_steering_angle(vcu_real_angle(bytes, length)); chassis->mutable_check_response()->set_is_eps_online( drive_enable_resp(bytes, length) == 1); } // config detail: {'description': '0x0:disable;0x1:enable', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'drive_enable_resp', 'is_signed_var': // False, 'physical_range': '[0|0]', 'bit': 0, 'type': 'bool', 'order': // 'motorola', 'physical_unit': ''} bool Vcuepsreport57::drive_enable_resp(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 1); bool ret = x; return ret; } // config detail: {'description': '0x0:Standby;0x1:auto drive;0x2:net // drive;0x3:remote control;0x4:emergency brake;0x5~0x7:Reserved', 'enum': {0: // 'CONTROL_MODE_RESP_STANDBY', 1: 'CONTROL_MODE_RESP_AUTO_DRIVE', 2: // 'CONTROL_MODE_RESP_NET_DRIVE', 3: 'CONTROL_MODE_RESP_REMOTE_CONTROL', 4: // 'CONTROL_MODE_RESP_EMERGENCY_BRAKE'}, 'precision': 1.0, 'len': 3, 'name': // 'control_mode_resp', 'is_signed_var': False, 'offset': 0.0, 'physical_range': // '[0|7]', 'bit': 6, 'type': 'enum', 'order': 'motorola', 'physical_unit': ''} Vcu_eps_report_57::Control_mode_respType Vcuepsreport57::control_mode_resp( const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(4, 3); Vcu_eps_report_57::Control_mode_respType ret = static_cast<Vcu_eps_report_57::Control_mode_respType>(x); return ret; } // config detail: {'description': '0x0:not overflow;0x1:overflow', 'offset': // 0.0, 'precision': 1.0, 'len': 1, 'name': 'vcu_eps_report', 'is_signed_var': // False, 'physical_range': '[0|0]', 'bit': 7, 'type': 'bool', 'order': // 'motorola', 'physical_unit': ''} bool Vcuepsreport57::vcu_eps_report(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(7, 1); bool ret = x; return ret; } // config detail: {'description': ';', 'offset': -2048.0, 'precision': 0.0625, // 'len': 16, 'name': 'vcu_real_angle', 'is_signed_var': False, // 'physical_range': '[0|0]', 'bit': 23, 'type': 'double', 'order': 'motorola', // 'physical_unit': ''} double Vcuepsreport57::vcu_real_angle(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.062500 + -2048.000000; return -ret; } // config detail: {'description': '0x0:disable;0x1:enable', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'vcu_real_angle_valid', 'is_signed_var': // False, 'physical_range': '[0|0]', 'bit': 32, 'type': 'bool', 'order': // 'motorola', 'physical_unit': ''} bool Vcuepsreport57::vcu_real_angle_valid(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(0, 1); bool ret = x; return ret; } // config detail: {'description': '0x0:disable;0x1:enable;', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'vcu_target_angle_valid', // 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': 33, 'type': 'bool', // 'order': 'motorola', 'physical_unit': ''} bool Vcuepsreport57::vcu_target_angle_valid(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 4); int32_t x = t0.get_byte(1, 1); bool ret = x; return ret; } // config detail: {'name': 'vcu_target_angle', 'offset': -512.0, 'precision': // 0.25, 'len': 12, 'is_signed_var': False, 'physical_range': '[-380|380]', // 'bit': 47, 'type': 'double', 'order': 'motorola', 'physical_unit': 'deg'} double Vcuepsreport57::vcu_target_angle(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.250000 + -512.000000; return ret; } // config detail: {'name': 'vcu_eps_rept_alivecounter', 'offset': 0.0, // 'precision': 1.0, 'len': 4, 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 51, 'type': 'int', 'order': 'motorola', 'physical_unit': ''} int Vcuepsreport57::vcu_eps_rept_alivecounter(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 6); int32_t x = t0.get_byte(0, 4); int ret = x; return ret; } // config detail: {'name': 'vcu_eps_rept_checksum', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 63, 'type': 'int', 'order': 'motorola', 'physical_unit': ''} int Vcuepsreport57::vcu_eps_rept_checksum(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 neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/aeb_diagresp_718.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/neolix_edu/proto/neolix_edu.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace neolix_edu { class Aebdiagresp718 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Neolix_edu> { public: static const int32_t ID; Aebdiagresp718(); void Parse(const std::uint8_t* bytes, int32_t length, Neolix_edu* chassis) const override; private: // config detail: {'name': 'AEB_DiagResp', 'offset': 0.0, 'precision': 1.0, // 'len': 1, 'is_signed_var': False, 'physical_range': '[0.0|1.0]', 'bit': 0, // 'type': 'bool', 'order': 'motorola', 'physical_unit': 'bit'} bool aeb_diagresp(const std::uint8_t* bytes, const int32_t length) const; }; } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/ads_brake_command_46.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/neolix_edu/proto/neolix_edu.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace neolix_edu { class Adsbrakecommand46 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Neolix_edu> { public: static const int32_t ID; Adsbrakecommand46(); uint32_t GetPeriod() const override; void UpdateData(uint8_t* data) override; void Reset() override; // config detail: {'description': '0x0:disable ;0x1:enable', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'Drive_Enable', 'is_signed_var': False, // 'physical_range': '[0|0]', 'bit': 0, 'type': 'bool', 'order': 'motorola', // 'physical_unit': ''} Adsbrakecommand46* set_drive_enable(bool drive_enable); // config detail: {'name': 'AUTO_Brake_Command', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 23, 'type': 'int', 'order': 'motorola', 'physical_unit': // ''} Adsbrakecommand46* set_auto_brake_command(int auto_brake_command); // config detail: {'description': '0x0:Release ;0x1:Apply ', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'AUTO_Parking_Command', // 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': 24, 'type': // 'bool', 'order': 'motorola', 'physical_unit': ''} Adsbrakecommand46* set_auto_parking_command(bool auto_parking_command); // config detail: {'description': '0x0:off;0x1:on', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'EPB_RampAuxiliaryCommand', // 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': 25, 'type': // 'bool', 'order': 'motorola', 'physical_unit': ''} Adsbrakecommand46* set_epb_rampauxiliarycommand( bool epb_rampauxiliarycommand); // config detail: {'name': 'AUTO_DriverCmd_AliveCounter', 'offset': 0.0, // 'precision': 1.0, 'len': 4, 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 51, 'type': 'int', 'order': 'motorola', 'physical_unit': // ''} Adsbrakecommand46* set_auto_drivercmd_alivecounter( int auto_drivercmd_alivecounter); // config detail: {'name': 'AUTO_DriverCmd_CheckSum', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 63, 'type': 'int', 'order': 'motorola', 'physical_unit': // ''} Adsbrakecommand46* set_auto_drivercmd_checksum(int auto_drivercmd_checksum); private: // config detail: {'description': '0x0:disable ;0x1:enable', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'Drive_Enable', 'is_signed_var': False, // 'physical_range': '[0|0]', 'bit': 0, 'type': 'bool', 'order': 'motorola', // 'physical_unit': ''} void set_p_drive_enable(uint8_t* data, bool drive_enable); // config detail: {'name': 'AUTO_Brake_Command', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 23, 'type': 'int', 'order': 'motorola', 'physical_unit': // ''} void set_p_auto_brake_command(uint8_t* data, int auto_brake_command); // config detail: {'description': '0x0:Release ;0x1:Apply ', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'AUTO_Parking_Command', // 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': 24, 'type': // 'bool', 'order': 'motorola', 'physical_unit': ''} void set_p_auto_parking_command(uint8_t* data, bool auto_parking_command); // config detail: {'description': '0x0:off;0x1:on', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'EPB_RampAuxiliaryCommand', // 'is_signed_var': False, 'physical_range': '[0|0]', 'bit': 25, 'type': // 'bool', 'order': 'motorola', 'physical_unit': ''} void set_p_epb_rampauxiliarycommand(uint8_t* data, bool epb_rampauxiliarycommand); // config detail: {'name': 'AUTO_DriverCmd_AliveCounter', 'offset': 0.0, // 'precision': 1.0, 'len': 4, 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 51, 'type': 'int', 'order': 'motorola', 'physical_unit': // ''} void set_p_auto_drivercmd_alivecounter(uint8_t* data, int auto_drivercmd_alivecounter); // config detail: {'name': 'AUTO_DriverCmd_CheckSum', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 63, 'type': 'int', 'order': 'motorola', 'physical_unit': // ''} void set_p_auto_drivercmd_checksum(uint8_t* data, int auto_drivercmd_checksum); private: bool drive_enable_; int auto_brake_command_; bool auto_parking_command_; bool epb_rampauxiliarycommand_; int auto_drivercmd_alivecounter_; int auto_drivercmd_checksum_; }; } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/aeb_systemstate_11.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/neolix_edu/protocol/aeb_systemstate_11.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 neolix_edu { using ::apollo::drivers::canbus::Byte; Aebsystemstate11::Aebsystemstate11() {} const int32_t Aebsystemstate11::ID = 0x11; void Aebsystemstate11::Parse(const std::uint8_t* bytes, int32_t length, Neolix_edu* chassis) const { chassis->mutable_aeb_systemstate_11()->set_aeb_state( aeb_state(bytes, length)); chassis->mutable_aeb_systemstate_11()->set_aeb_brakestate( aeb_brakestate(bytes, length)); chassis->mutable_aeb_systemstate_11()->set_faultrank( faultrank(bytes, length)); chassis->mutable_aeb_systemstate_11()->set_currenttemperature( currenttemperature(bytes, length)); chassis->mutable_aeb_systemstate_11()->set_pas_f1_stop( pas_f1_stop(bytes, length)); chassis->mutable_aeb_systemstate_11()->set_pas_f2_stop( pas_f2_stop(bytes, length)); chassis->mutable_aeb_systemstate_11()->set_pas_f3_stop( pas_f3_stop(bytes, length)); chassis->mutable_aeb_systemstate_11()->set_pas_f4_stop( pas_f4_stop(bytes, length)); chassis->mutable_aeb_systemstate_11()->set_pas_b1_stop( pas_b1_stop(bytes, length)); chassis->mutable_aeb_systemstate_11()->set_pas_b2_stop( pas_b2_stop(bytes, length)); chassis->mutable_aeb_systemstate_11()->set_pas_b3_stop( pas_b3_stop(bytes, length)); chassis->mutable_aeb_systemstate_11()->set_pas_b4_stop( pas_b4_stop(bytes, length)); chassis->mutable_aeb_systemstate_11()->set_aeb_livecounter_rear( aeb_livecounter_rear(bytes, length)); chassis->mutable_aeb_systemstate_11()->set_aeb_cheksum( aeb_cheksum(bytes, length)); } // config detail: {'description': '0x00:read only;0x01:brake enable', 'offset': // 0.0, 'precision': 1.0, 'len': 2, 'name': 'aeb_state', 'is_signed_var': False, // 'physical_range': '[0|1]', 'bit': 1, 'type': 'int', 'order': 'motorola', // 'physical_unit': ''} int Aebsystemstate11::aeb_state(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 2); int ret = x; return ret; } // config detail: {'description': '0x00:off;0x01:on', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'aeb_brakestate', 'is_signed_var': False, // 'physical_range': '[0|1]', 'bit': 2, 'type': 'bool', 'order': 'motorola', // 'physical_unit': ''} bool Aebsystemstate11::aeb_brakestate(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(2, 1); bool ret = x; return ret; } // config detail: {'description': '0x0:Nomal;0x1:Level 1;0x2:Level 2;0x3:Level // 3;0x4:Level 4;0x5:Level 5;0x6:Reserved;0x7:Reserved', 'offset': 0.0, // 'precision': 1.0, 'len': 3, 'name': 'faultrank', 'is_signed_var': False, // 'physical_range': '[0|5]', 'bit': 10, 'type': 'int', 'order': 'motorola', // 'physical_unit': ''} int Aebsystemstate11::faultrank(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 1); int32_t x = t0.get_byte(0, 3); int ret = x; return ret; } // config detail: {'name': 'currenttemperature', 'offset': -40.0, // 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'physical_range': // '[0|120]', 'bit': 23, 'type': 'int', 'order': 'motorola', 'physical_unit': // ''} int Aebsystemstate11::currenttemperature(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 2); int32_t x = t0.get_byte(0, 8); int ret = x + -40.000000; return ret; } // config detail: {'description': '0x0:Normal;0x1:ActivateBrake', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'pas_f1_stop', 'is_signed_var': False, // 'physical_range': '[0|1]', 'bit': 24, 'type': 'bool', 'order': 'motorola', // 'physical_unit': ''} bool Aebsystemstate11::pas_f1_stop(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 3); int32_t x = t0.get_byte(0, 1); bool ret = x; return ret; } // config detail: {'description': '0x0:Normal;0x1:ActivateBrake', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'pas_f2_stop', 'is_signed_var': False, // 'physical_range': '[0|1]', 'bit': 25, 'type': 'bool', 'order': 'motorola', // 'physical_unit': ''} bool Aebsystemstate11::pas_f2_stop(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 3); int32_t x = t0.get_byte(1, 1); bool ret = x; return ret; } // config detail: {'description': '0x0:Normal;0x1:ActivateBrake', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'pas_f3_stop', 'is_signed_var': False, // 'physical_range': '[0|1]', 'bit': 26, 'type': 'bool', 'order': 'motorola', // 'physical_unit': ''} bool Aebsystemstate11::pas_f3_stop(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 3); int32_t x = t0.get_byte(2, 1); bool ret = x; return ret; } // config detail: {'description': '0x0:Normal;0x1:ActivateBrake', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'pas_f4_stop', 'is_signed_var': False, // 'physical_range': '[0|1]', 'bit': 27, 'type': 'bool', 'order': 'motorola', // 'physical_unit': ''} bool Aebsystemstate11::pas_f4_stop(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 3); int32_t x = t0.get_byte(3, 1); bool ret = x; return ret; } // config detail: {'description': '0x0:Normal;0x1:ActivateBrake', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'pas_b1_stop', 'is_signed_var': False, // 'physical_range': '[0|1]', 'bit': 28, 'type': 'bool', 'order': 'motorola', // 'physical_unit': ''} bool Aebsystemstate11::pas_b1_stop(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 3); int32_t x = t0.get_byte(4, 1); bool ret = x; return ret; } // config detail: {'description': '0x0:Normal;0x1:ActivateBrake', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'pas_b2_stop', 'is_signed_var': False, // 'physical_range': '[0|1]', 'bit': 29, 'type': 'bool', 'order': 'motorola', // 'physical_unit': ''} bool Aebsystemstate11::pas_b2_stop(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 3); int32_t x = t0.get_byte(5, 1); bool ret = x; return ret; } // config detail: {'description': '0x0:Normal;0x1:ActivateBrake', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'pas_b3_stop', 'is_signed_var': False, // 'physical_range': '[0|1]', 'bit': 30, 'type': 'bool', 'order': 'motorola', // 'physical_unit': ''} bool Aebsystemstate11::pas_b3_stop(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 3); int32_t x = t0.get_byte(6, 1); bool ret = x; return ret; } // config detail: {'description': '0x0:Normal;0x1:ActivateBrake', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'pas_b4_stop', 'is_signed_var': False, // 'physical_range': '[0|1]', 'bit': 31, 'type': 'bool', 'order': 'motorola', // 'physical_unit': ''} bool Aebsystemstate11::pas_b4_stop(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 3); int32_t x = t0.get_byte(7, 1); bool ret = x; return ret; } // config detail: {'name': 'aeb_livecounter_rear', 'offset': 0.0, // 'precision': 1.0, 'len': 4, 'is_signed_var': False, 'physical_range': // '[0|15]', 'bit': 51, 'type': 'int', 'order': 'motorola', 'physical_unit': ''} int Aebsystemstate11::aeb_livecounter_rear(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 6); int32_t x = t0.get_byte(0, 4); int ret = x; return ret; } // config detail: {'name': 'aeb_cheksum', 'offset': 0.0, 'precision': 1.0, // 'len': 8, 'is_signed_var': False, 'physical_range': '[0|255]', 'bit': 63, // 'type': 'int', 'order': 'motorola', 'physical_unit': 'bit'} int Aebsystemstate11::aeb_cheksum(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 neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/vcu_eps_report_57_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/neolix_edu/protocol/vcu_eps_report_57.h" #include "glog/logging.h" #include "gtest/gtest.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace neolix_edu { class Vcuepsreport57Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Vcuepsreport57Test, reset) { uint8_t data[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; int32_t length = 8; Neolix_edu cd; Vcuepsreport57 accel_cmd; accel_cmd.Parse(data, length, &cd); EXPECT_EQ(data[0], 0b00000000); EXPECT_EQ(data[1], 0b00000000); EXPECT_EQ(data[2], 0b00000000); EXPECT_EQ(data[3], 0b00000000); EXPECT_EQ(data[4], 0b00000000); EXPECT_EQ(data[5], 0b00000000); EXPECT_EQ(data[6], 0b00000000); EXPECT_EQ(data[7], 0b00000000); EXPECT_EQ(cd.vcu_eps_report_57().drive_enable_resp(), false); EXPECT_EQ(cd.vcu_eps_report_57().control_mode_resp(), 0); EXPECT_EQ(cd.vcu_eps_report_57().vcu_eps_report(), false); EXPECT_EQ(cd.vcu_eps_report_57().vcu_real_angle(), 2048); EXPECT_EQ(cd.vcu_eps_report_57().vcu_real_angle_valid(), false); EXPECT_EQ(cd.vcu_eps_report_57().vcu_target_angle_valid(), false); EXPECT_EQ(cd.vcu_eps_report_57().vcu_target_angle(), -512); } } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/vcu_vehicle_info_response_502.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/neolix_edu/protocol/vcu_vehicle_info_response_502.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 neolix_edu { using ::apollo::drivers::canbus::Byte; Vcuvehicleinforesponse502::Vcuvehicleinforesponse502() {} const int32_t Vcuvehicleinforesponse502::ID = 0x502; void Vcuvehicleinforesponse502::Parse(const std::uint8_t* bytes, int32_t length, Neolix_edu* chassis) const { chassis->mutable_vcu_vehicle_info_response_502() ->set_vehicle_softwareversion_indicati( vehicle_softwareversion_indicati(bytes, length)); chassis->mutable_vcu_vehicle_info_response_502() ->set_project(project(bytes, length)); chassis->mutable_vcu_vehicle_info_response_502() ->set_manufacturer(manufacturer(bytes, length)); chassis ->mutable_vcu_vehicle_info_response_502() ->set_year(year(bytes, length)); chassis->mutable_vcu_vehicle_info_response_502() ->set_month(month(bytes, length)); chassis->mutable_vcu_vehicle_info_response_502() ->set_day(day(bytes, length)); chassis->mutable_vcu_vehicle_info_response_502() ->set_vehicle_serial_number(vehicle_serial_number(bytes, length)); } // config detail: {'name': 'vehicle_softwareversion_indicati', 'offset': 0.0, // 'precision': 1.0, 'len': 24, 'is_signed_var': False, 'physical_range': // '[0|16777215]', 'bit': 7, 'type': 'int', 'order': 'motorola', // 'physical_unit': ''} int Vcuvehicleinforesponse502::vehicle_softwareversion_indicati( 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; Byte t2(bytes + 2); t = t2.get_byte(0, 8); x <<= 8; x |= t; int ret = x; return ret; } // config detail: {'name': 'project', 'offset': 0.0, 'precision': 1.0, 'len': 4, // 'is_signed_var': False, 'physical_range': '[0|15]', 'bit': 27, 'type': 'int', // 'order': 'motorola', 'physical_unit': ''} int Vcuvehicleinforesponse502::project(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 3); int32_t x = t0.get_byte(0, 4); int ret = x; return ret; } // config detail: {'name': 'manufacturer', 'offset': 0.0, 'precision': 1.0, // 'len': 4, 'is_signed_var': False, 'physical_range': '[0|15]', 'bit': 31, // 'type': 'int', 'order': 'motorola', 'physical_unit': ''} int Vcuvehicleinforesponse502::manufacturer(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 3); int32_t x = t0.get_byte(4, 4); int ret = x; return ret; } // config detail: {'name': 'year', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'is_signed_var': False, 'physical_range': '[0|255]', 'bit': 39, 'type': // 'int', 'order': 'motorola', 'physical_unit': ''} int Vcuvehicleinforesponse502::year(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: {'name': 'month', 'offset': 0.0, 'precision': 1.0, 'len': 4, // 'is_signed_var': False, 'physical_range': '[1|12]', 'bit': 47, 'type': 'int', // 'order': 'motorola', 'physical_unit': ''} int Vcuvehicleinforesponse502::month(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 5); int32_t x = t0.get_byte(4, 4); int ret = x; return ret; } // config detail: {'name': 'day', 'offset': 0.0, 'precision': 1.0, 'len': 5, // 'is_signed_var': False, 'physical_range': '[1|31]', 'bit': 43, 'type': 'int', // 'order': 'motorola', 'physical_unit': ''} int Vcuvehicleinforesponse502::day(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 5); int32_t x = t0.get_byte(0, 4); Byte t1(bytes + 6); int32_t t = t1.get_byte(7, 1); x <<= 1; x |= t; int ret = x; return ret; } // config detail: {'name': 'vehicle_serial_number', 'offset': 0.0, // 'precision': 1.0, 'len': 15, 'is_signed_var': False, 'physical_range': // '[0|32767]', 'bit': 54, 'type': 'int', 'order': 'motorola', 'physical_unit': // ''} int Vcuvehicleinforesponse502::vehicle_serial_number(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 6); int32_t x = t0.get_byte(0, 7); Byte t1(bytes + 7); int32_t t = t1.get_byte(0, 8); x <<= 8; x |= t; int ret = x; return ret; } } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/vcu_nm_401.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/neolix_edu/protocol/vcu_nm_401.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 neolix_edu { using ::apollo::drivers::canbus::Byte; Vcunm401::Vcunm401() {} const int32_t Vcunm401::ID = 0x401; void Vcunm401::Parse(const std::uint8_t* bytes, int32_t length, Neolix_edu* chassis) const { chassis->mutable_vcu_nm_401()->set_vcu_sleepcommand( vcu_sleepcommand(bytes, length)); } // config detail: {'description': '0x0:Inactive;0x1:Active', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'vcu_sleepcommand', 'is_signed_var': // False, 'physical_range': '[0|1]', 'bit': 0, 'type': 'bool', 'order': // 'motorola', 'physical_unit': 'bit'} bool Vcunm401::vcu_sleepcommand(const std::uint8_t* bytes, int32_t length) const { Byte t0(bytes + 0); int32_t x = t0.get_byte(0, 1); bool ret = x; return ret; } } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/ads_light_horn_command_310.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/neolix_edu/protocol/ads_light_horn_command_310.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace neolix_edu { using ::apollo::drivers::canbus::Byte; const int32_t Adslighthorncommand310::ID = 0x310; // public Adslighthorncommand310::Adslighthorncommand310() { Reset(); } uint32_t Adslighthorncommand310::GetPeriod() const { // TODO(All) : modify every protocol's period manually static const uint32_t PERIOD = 20 * 1000; return PERIOD; } void Adslighthorncommand310::UpdateData(uint8_t* data) { set_p_turn_right_light_command(data, turn_right_light_command_); set_p_turn_left_light_command(data, turn_left_light_command_); set_p_horn_command(data, horn_command_); set_p_beam_command(data, beam_command_); ++auto_drivercmd_alivecounter_; auto_drivercmd_alivecounter_ = (auto_drivercmd_alivecounter_) % 16; set_p_auto_drivercmd_alivecounter(data, auto_drivercmd_alivecounter_); auto_drivercmd_checksum_ = data[0] ^ data[1] ^ data[2] ^ data[3] ^ data[4] ^ data[5] ^ data[6]; set_p_auto_drivercmd_checksum(data, auto_drivercmd_checksum_); } void Adslighthorncommand310::Reset() { // TODO(All) : you should check this manually turn_right_light_command_ = false; turn_left_light_command_ = false; horn_command_ = false; beam_command_ = 0; auto_drivercmd_alivecounter_ = 0; auto_drivercmd_checksum_ = 0; } Adslighthorncommand310* Adslighthorncommand310::set_turn_right_light_command( bool turn_right_light_command) { turn_right_light_command_ = turn_right_light_command; return this; } // config detail: {'description': '0x0:disable ;0x1:enable', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'Turn_Right_Light_Command', // 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 8, 'type': 'bool', // 'order': 'motorola', 'physical_unit': 'bit'} void Adslighthorncommand310::set_p_turn_right_light_command( uint8_t* data, bool turn_right_light_command) { int x = turn_right_light_command; Byte to_set(data + 1); to_set.set_value(x, 0, 1); } Adslighthorncommand310* Adslighthorncommand310::set_turn_left_light_command( bool turn_left_light_command) { turn_left_light_command_ = turn_left_light_command; return this; } // config detail: {'description': '0x0:disable ;0x1:enable ;0x2-0x3:Reserved ', // 'offset': 0.0, 'precision': 1.0, 'len': 1, 'name': 'Turn_Left_Light_Command', // 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 9, 'type': 'bool', // 'order': 'motorola', 'physical_unit': 'bit'} void Adslighthorncommand310::set_p_turn_left_light_command( uint8_t* data, bool turn_left_light_command) { int x = turn_left_light_command; Byte to_set(data + 1); to_set.set_value(x, 1, 1); } Adslighthorncommand310* Adslighthorncommand310::set_horn_command( bool horn_command) { horn_command_ = horn_command; return this; } // config detail: {'name': 'Horn_Command', 'offset': 0.0, 'precision': 1.0, // 'len': 1, 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 10, // 'type': 'bool', 'order': 'motorola', 'physical_unit': 'bit'} void Adslighthorncommand310::set_p_horn_command(uint8_t* data, bool horn_command) { int x = horn_command; Byte to_set(data + 1); to_set.set_value(x, 2, 1); } Adslighthorncommand310* Adslighthorncommand310::set_beam_command( int beam_command) { beam_command_ = beam_command; return this; } // config detail: {'description': '0x0:Off;0x1:LowBeam;0x2:HighBeam', 'offset': // 0.0, 'precision': 1.0, 'len': 2, 'name': 'Beam_Command', 'is_signed_var': // False, 'physical_range': '[0|1]', 'bit': 13, 'type': 'int', 'order': // 'motorola', 'physical_unit': 'bit'} void Adslighthorncommand310::set_p_beam_command(uint8_t* data, int beam_command) { beam_command = ProtocolData::BoundedValue(0, 1, beam_command); int x = beam_command; Byte to_set(data + 1); to_set.set_value(x, 4, 2); } Adslighthorncommand310* Adslighthorncommand310::set_auto_drivercmd_alivecounter( int auto_drivercmd_alivecounter) { auto_drivercmd_alivecounter_ = auto_drivercmd_alivecounter; return this; } // config detail: {'name': 'AUTO_DriverCmd_AliveCounter', 'offset': 0.0, // 'precision': 1.0, 'len': 4, 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 51, 'type': 'int', 'order': 'motorola', 'physical_unit': ''} void Adslighthorncommand310::set_p_auto_drivercmd_alivecounter( uint8_t* data, int auto_drivercmd_alivecounter) { auto_drivercmd_alivecounter = ProtocolData::BoundedValue(0, 15, auto_drivercmd_alivecounter); int x = auto_drivercmd_alivecounter; Byte to_set(data + 6); to_set.set_value(x, 0, 4); } Adslighthorncommand310* Adslighthorncommand310::set_auto_drivercmd_checksum( int auto_drivercmd_checksum) { auto_drivercmd_checksum_ = auto_drivercmd_checksum; return this; } // config detail: {'name': 'AUTO_DriverCmd_CheckSum', 'offset': 0.0, // 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'physical_range': // '[0|0]', 'bit': 63, 'type': 'int', 'order': 'motorola', 'physical_unit': ''} void Adslighthorncommand310::set_p_auto_drivercmd_checksum( uint8_t* data, int auto_drivercmd_checksum) { auto_drivercmd_checksum = ProtocolData::BoundedValue(0, 255, auto_drivercmd_checksum); int x = auto_drivercmd_checksum; Byte to_set(data + 7); to_set.set_value(x, 0, 8); } } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/vcu_vehicle_info_response_502.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/neolix_edu/proto/neolix_edu.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace neolix_edu { class Vcuvehicleinforesponse502 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Neolix_edu> { public: static const int32_t ID; Vcuvehicleinforesponse502(); void Parse(const std::uint8_t* bytes, int32_t length, Neolix_edu* chassis) const override; private: // config detail: {'name': 'Vehicle_Softwareversion_Indicati', 'offset': 0.0, // 'precision': 1.0, 'len': 24, 'is_signed_var': False, 'physical_range': // '[0|16777215]', 'bit': 7, 'type': 'int', 'order': 'motorola', // 'physical_unit': ''} int vehicle_softwareversion_indicati(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'Project', 'offset': 0.0, 'precision': 1.0, 'len': // 4, 'is_signed_var': False, 'physical_range': '[0|15]', 'bit': 27, 'type': // 'int', 'order': 'motorola', 'physical_unit': ''} int project(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'Manufacturer', 'offset': 0.0, 'precision': 1.0, // 'len': 4, 'is_signed_var': False, 'physical_range': '[0|15]', 'bit': 31, // 'type': 'int', 'order': 'motorola', 'physical_unit': ''} int manufacturer(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'Year', 'offset': 0.0, 'precision': 1.0, 'len': 8, // 'is_signed_var': False, 'physical_range': '[0|255]', 'bit': 39, 'type': // 'int', 'order': 'motorola', 'physical_unit': ''} int year(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'Month', 'offset': 0.0, 'precision': 1.0, 'len': 4, // 'is_signed_var': False, 'physical_range': '[1|12]', 'bit': 47, 'type': // 'int', 'order': 'motorola', 'physical_unit': ''} int month(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'Day', 'offset': 0.0, 'precision': 1.0, 'len': 5, // 'is_signed_var': False, 'physical_range': '[1|31]', 'bit': 43, 'type': // 'int', 'order': 'motorola', 'physical_unit': ''} int day(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'Vehicle_Serial_Number', 'offset': 0.0, // 'precision': 1.0, 'len': 15, 'is_signed_var': False, 'physical_range': // '[0|32767]', 'bit': 54, 'type': 'int', 'order': 'motorola', // 'physical_unit': ''} int vehicle_serial_number(const std::uint8_t* bytes, const int32_t length) const; }; } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/vcu_brake_report_47_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/neolix_edu/protocol/vcu_brake_report_47.h" #include "glog/logging.h" #include "gtest/gtest.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace neolix_edu { class Vcubrakereport47Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Vcubrakereport47Test, reset) { uint8_t data[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; int32_t length = 8; Neolix_edu cd; Vcubrakereport47 accel_cmd; accel_cmd.Parse(data, length, &cd); EXPECT_EQ(data[0], 0b00000000); EXPECT_EQ(data[1], 0b00000000); EXPECT_EQ(data[2], 0b00000000); EXPECT_EQ(data[3], 0b00000000); EXPECT_EQ(data[4], 0b00000000); EXPECT_EQ(data[5], 0b00000000); EXPECT_EQ(data[6], 0b00000000); EXPECT_EQ(data[7], 0b00000000); EXPECT_EQ(cd.vcu_brake_report_47().brake_enable_resp(), false); EXPECT_EQ(cd.vcu_brake_report_47().control_mode_resp(), 0); EXPECT_EQ(cd.vcu_brake_report_47().vcu_real_brake_valid(), false); EXPECT_EQ(cd.vcu_brake_report_47().vcu_real_brake(), 0); EXPECT_EQ(cd.vcu_brake_report_47().vcu_real_parking_status(), 0); EXPECT_EQ(cd.vcu_brake_report_47().vcu_real_parking_valid(), false); EXPECT_EQ(cd.vcu_brake_report_47().rampauxiliaryindication(), false); EXPECT_EQ(cd.vcu_brake_report_47().vehicleslope(), 0); EXPECT_EQ(cd.vcu_brake_report_47().vcu_ehb_brake_state(), 0); } } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/ads_eps_command_56_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/neolix_edu/protocol/ads_eps_command_56.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace neolix_edu { class Adsepscommand56Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Adsepscommand56Test, reset) { uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; Adsepscommand56 accel_cmd; EXPECT_EQ(accel_cmd.GetPeriod(), 20 * 1000); accel_cmd.UpdateData(data); EXPECT_EQ(data[0], 0b01100110); EXPECT_EQ(data[1], 0b01100010); EXPECT_EQ(data[2], 0b10000000); EXPECT_EQ(data[3], 0b00000000); EXPECT_EQ(data[4], 0b01010001); EXPECT_EQ(data[5], 0b01010010); EXPECT_EQ(data[6], 0b01010001); EXPECT_EQ(data[7], 0b11010110); } } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/aeb_frontwheelspeed_353_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/neolix_edu/protocol/aeb_frontwheelspeed_353.h" #include "glog/logging.h" #include "gtest/gtest.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace neolix_edu { class Aebfrontwheelspeed353Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Aebfrontwheelspeed353Test, reset) { uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; int32_t length = 8; Neolix_edu cd; Aebfrontwheelspeed353 accel_cmd; accel_cmd.Parse(data, length, &cd); EXPECT_EQ(data[0], 0b01100111); 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); EXPECT_EQ(cd.aeb_frontwheelspeed_353().vehiclespeedvalid(), false); EXPECT_DOUBLE_EQ(cd.aeb_frontwheelspeed_353().vehiclespeed(), 106.3125); EXPECT_EQ(cd.aeb_frontwheelspeed_353().vehiclerealdirect(), 3); EXPECT_EQ(cd.aeb_frontwheelspeed_353().wheelspeed_fl_valid(), false); EXPECT_EQ(cd.aeb_frontwheelspeed_353().wheelspeed_fl(), 254.44); EXPECT_EQ(cd.aeb_frontwheelspeed_353().wheelspeed_fr_valid(), false); EXPECT_EQ(cd.aeb_frontwheelspeed_353().wheelspeed_fr(), 208.18); EXPECT_EQ(cd.aeb_frontwheelspeed_353().wheelspeed_fl_direct(), 1); EXPECT_EQ(cd.aeb_frontwheelspeed_353().wheelspeed_fr_direct(), 1); } } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/aeb_systemstate_11.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/neolix_edu/proto/neolix_edu.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace neolix_edu { class Aebsystemstate11 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Neolix_edu> { public: static const int32_t ID; Aebsystemstate11(); void Parse(const std::uint8_t* bytes, int32_t length, Neolix_edu* chassis) const override; private: // config detail: {'description': '0x00:read only;0x01:brake enable', // 'offset': 0.0, 'precision': 1.0, 'len': 2, 'name': 'AEB_State', // 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 1, 'type': 'int', // 'order': 'motorola', 'physical_unit': ''} int aeb_state(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': '0x00:off;0x01:on', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'AEB_BrakeState', 'is_signed_var': // False, 'physical_range': '[0|1]', 'bit': 2, 'type': 'bool', 'order': // 'motorola', 'physical_unit': ''} bool aeb_brakestate(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': '0x0:Nomal;0x1:Level 1;0x2:Level 2;0x3:Level // 3;0x4:Level 4;0x5:Level 5;0x6:Reserved;0x7:Reserved', 'offset': 0.0, // 'precision': 1.0, 'len': 3, 'name': 'FaultRank', 'is_signed_var': False, // 'physical_range': '[0|5]', 'bit': 10, 'type': 'int', 'order': 'motorola', // 'physical_unit': ''} int faultrank(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'CurrentTemperature', 'offset': -40.0, // 'precision': 1.0, 'len': 8, 'is_signed_var': False, 'physical_range': // '[0|120]', 'bit': 23, 'type': 'int', 'order': 'motorola', 'physical_unit': // ''} int currenttemperature(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': '0x0:Normal;0x1:ActivateBrake', 'offset': // 0.0, 'precision': 1.0, 'len': 1, 'name': 'PAS_F1_Stop', 'is_signed_var': // False, 'physical_range': '[0|1]', 'bit': 24, 'type': 'bool', 'order': // 'motorola', 'physical_unit': ''} bool pas_f1_stop(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': '0x0:Normal;0x1:ActivateBrake', 'offset': // 0.0, 'precision': 1.0, 'len': 1, 'name': 'PAS_F2_Stop', 'is_signed_var': // False, 'physical_range': '[0|1]', 'bit': 25, 'type': 'bool', 'order': // 'motorola', 'physical_unit': ''} bool pas_f2_stop(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': '0x0:Normal;0x1:ActivateBrake', 'offset': // 0.0, 'precision': 1.0, 'len': 1, 'name': 'PAS_F3_Stop', 'is_signed_var': // False, 'physical_range': '[0|1]', 'bit': 26, 'type': 'bool', 'order': // 'motorola', 'physical_unit': ''} bool pas_f3_stop(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': '0x0:Normal;0x1:ActivateBrake', 'offset': // 0.0, 'precision': 1.0, 'len': 1, 'name': 'PAS_F4_Stop', 'is_signed_var': // False, 'physical_range': '[0|1]', 'bit': 27, 'type': 'bool', 'order': // 'motorola', 'physical_unit': ''} bool pas_f4_stop(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': '0x0:Normal;0x1:ActivateBrake', 'offset': // 0.0, 'precision': 1.0, 'len': 1, 'name': 'PAS_B1_Stop', 'is_signed_var': // False, 'physical_range': '[0|1]', 'bit': 28, 'type': 'bool', 'order': // 'motorola', 'physical_unit': ''} bool pas_b1_stop(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': '0x0:Normal;0x1:ActivateBrake', 'offset': // 0.0, 'precision': 1.0, 'len': 1, 'name': 'PAS_B2_Stop', 'is_signed_var': // False, 'physical_range': '[0|1]', 'bit': 29, 'type': 'bool', 'order': // 'motorola', 'physical_unit': ''} bool pas_b2_stop(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': '0x0:Normal;0x1:ActivateBrake', 'offset': // 0.0, 'precision': 1.0, 'len': 1, 'name': 'PAS_B3_Stop', 'is_signed_var': // False, 'physical_range': '[0|1]', 'bit': 30, 'type': 'bool', 'order': // 'motorola', 'physical_unit': ''} bool pas_b3_stop(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': '0x0:Normal;0x1:ActivateBrake', 'offset': // 0.0, 'precision': 1.0, 'len': 1, 'name': 'PAS_B4_Stop', 'is_signed_var': // False, 'physical_range': '[0|1]', 'bit': 31, 'type': 'bool', 'order': // 'motorola', 'physical_unit': ''} bool pas_b4_stop(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'AEB_LiveCounter_Rear', 'offset': 0.0, // 'precision': 1.0, 'len': 4, 'is_signed_var': False, 'physical_range': // '[0|15]', 'bit': 51, 'type': 'int', 'order': 'motorola', 'physical_unit': // ''} int aeb_livecounter_rear(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'name': 'AEB_Cheksum', 'offset': 0.0, 'precision': 1.0, // 'len': 8, 'is_signed_var': False, 'physical_range': '[0|255]', 'bit': 63, // 'type': 'int', 'order': 'motorola', 'physical_unit': 'bit'} int aeb_cheksum(const std::uint8_t* bytes, const int32_t length) const; }; } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/pas_2nd_data_312.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/neolix_edu/proto/neolix_edu.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace neolix_edu { class Pas2nddata312 : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Neolix_edu> { public: static const int32_t ID; Pas2nddata312(); void Parse(const std::uint8_t* bytes, int32_t length, Neolix_edu* chassis) const override; private: // config detail: {'description': '0x0:Invalid;0x1:Valid', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'PAS_B1_Status', 'is_signed_var': // False, 'physical_range': '[0|1]', 'bit': 0, 'type': 'bool', 'order': // 'motorola', 'physical_unit': 'bit'} bool pas_b1_status(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': '0x0:Invalid;0x1:Valid', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'PAS_B2_Status', 'is_signed_var': // False, 'physical_range': '[0|1]', 'bit': 1, 'type': 'bool', 'order': // 'motorola', 'physical_unit': 'bit'} bool pas_b2_status(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': '0x0:Invalid;0x1:Valid', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'PAS_B3_Status', 'is_signed_var': // False, 'physical_range': '[0|1]', 'bit': 2, 'type': 'bool', 'order': // 'motorola', 'physical_unit': 'bit'} bool pas_b3_status(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': '0x0:Invalid;0x1:Valid', 'offset': 0.0, // 'precision': 1.0, 'len': 1, 'name': 'PAS_B4_Status', 'is_signed_var': // False, 'physical_range': '[0|1]', 'bit': 3, 'type': 'bool', 'order': // 'motorola', 'physical_unit': 'bit'} bool pas_b4_status(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'phy=int*2;0xFF:no obstacle', 'offset': 0.0, // 'precision': 2.0, 'len': 8, 'name': 'PASDistance1', 'is_signed_var': False, // 'physical_range': '[0|510]', 'bit': 15, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'cm'} double pasdistance1(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'phy=int*2;0xFF:no obstacle', 'offset': 0.0, // 'precision': 2.0, 'len': 8, 'name': 'PASDistance2', 'is_signed_var': False, // 'physical_range': '[0|510]', 'bit': 23, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'cm'} double pasdistance2(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'phy=int*2;0xFF:no obstacle', 'offset': 0.0, // 'precision': 2.0, 'len': 8, 'name': 'PASDistance3', 'is_signed_var': False, // 'physical_range': '[0|510]', 'bit': 31, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'cm'} double pasdistance3(const std::uint8_t* bytes, const int32_t length) const; // config detail: {'description': 'phy=int*2;0xFF:no obstacle', 'offset': 0.0, // 'precision': 2.0, 'len': 8, 'name': 'PASDistance4', 'is_signed_var': False, // 'physical_range': '[0|510]', 'bit': 39, 'type': 'double', 'order': // 'motorola', 'physical_unit': 'cm'} double pasdistance4(const std::uint8_t* bytes, const int32_t length) const; }; } // namespace neolix_edu } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu
apollo_public_repos/apollo/modules/canbus_vehicle/neolix_edu/protocol/vcu_vehicle_fault_response_201_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/neolix_edu/protocol/vcu_vehicle_fault_response_201.h" #include "glog/logging.h" #include "gtest/gtest.h" #include "modules/drivers/canbus/common/canbus_consts.h" namespace apollo { namespace canbus { namespace neolix_edu { class Vcuvehiclefaultresponse201Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Vcuvehiclefaultresponse201Test, reset) { uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; int32_t length = 8; Neolix_edu cd; Vcuvehiclefaultresponse201 accel_cmd; accel_cmd.Parse(data, length, &cd); EXPECT_EQ(data[0], 0b01100111); 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); EXPECT_EQ(cd.vcu_vehicle_fault_response_201() .vehicle_error_indicationsvcu(), 7); EXPECT_EQ(cd.vcu_vehicle_fault_response_201() .brake_system_errorehb(), 6); EXPECT_EQ(cd.vcu_vehicle_fault_response_201().eps_error(), 2); EXPECT_EQ(cd.vcu_vehicle_fault_response_201().motor_error(), 6); EXPECT_EQ(cd.vcu_vehicle_fault_response_201().epb_error(), 3); EXPECT_EQ(cd.vcu_vehicle_fault_response_201() .high_voltage_battery_errorbcu(), 6); EXPECT_EQ(cd.vcu_vehicle_fault_response_201() .automode_exit_reason_losscommuni(), true); EXPECT_EQ(cd.vcu_vehicle_fault_response_201() .automode_exit_reason_reqsignalno(), false); EXPECT_EQ(cd.vcu_vehicle_fault_response_201() .automode_exit_reason_low_power(), false); EXPECT_EQ(cd.vcu_vehicle_fault_response_201() .automode_exit_reason_highvolt(), false); EXPECT_EQ(cd.vcu_vehicle_fault_response_201() .automode_exit_reason_vehicle_flt(), true); EXPECT_EQ(cd.vcu_vehicle_fault_response_201() .automode_exit_reason_press_emerg(), false); EXPECT_EQ(cd.vcu_vehicle_fault_response_201() .automode_exit_reason_press_remot(), true); EXPECT_EQ(cd.vcu_vehicle_fault_response_201() .automode_exit_reason_pdu_control(), false); } } // namespace neolix_edu } // namespace canbus } // namespace apollo
0