1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 18 #include "canbus_config.pb.h" 19 20 #include <aidl/android/hardware/automotive/can/BusConfig.h> 21 #include <aidl/android/hardware/automotive/can/InterfaceType.h> 22 #include <aidl/android/hardware/automotive/can/Result.h> 23 24 namespace android::hardware::automotive::can::config { 25 26 /** 27 * This reads the protobuf config file into a protobuf object. Both text based protobuf files as 28 * well as binary format protobuf files are supported. 29 * 30 * \param filepath string containing the name of the config file to read. 31 * \return a CanBusConfig protobuf object constructed from the config file. 32 */ 33 std::optional<CanBusConfig> parseConfigFile(const std::string& filepath); 34 35 /** 36 * Converts protobuf format single-bus config object to a HAL bus config object. 37 * 38 * \param pb_bus is the protobuf object representing a the configuration of one CAN bus. 39 * \return a converted HAL bus config object. 40 */ 41 std::optional<::aidl::android::hardware::automotive::can::BusConfig> fromPbBus(const Bus& pb_bus); 42 43 /** 44 * Get the CAN HAL interface type specified by a given protobuf config object. 45 * 46 * \param pb_bus is the protobuf object representing a the configuration of one CAN bus. 47 * \return the CAN HAL interface type. 48 */ 49 std::optional<::aidl::android::hardware::automotive::can::InterfaceType> getHalIftype( 50 const Bus& pb_bus); 51 52 std::string resultStringFromStatus(const ndk::ScopedAStatus& status); 53 54 } // namespace android::hardware::automotive::can::config 55