AndroidAutomotive模块介绍(四)VehicleHal介绍

前言

前面的文章中,描述了 Android Automotive 的框架中应用、Framework 层服务等知识,本篇文章将会继续按照 Android Automotive 框架介绍 Vehicle Hal 层服务的内容。

上一篇:AndroidAutomotive模块介绍(三)CarService服务

Android Vehicle HAL架构-腾讯云开发者社区-腾讯云

正文

1、VehicleHal 介绍

本篇文档将对 Andorid Automotive 框架中 VehicleHal 层展开介绍。VehicleHal 即为车辆硬件抽象层的定义。可以理解为 Android Automotive OS 中的硬件抽象层接口,包括车辆属性和方法;各厂商制造商会根据定义的 Hal 接口,实现定制化的模块服务。

VehicleHal 是链接 Android Automotive Car Services 与制造商实现车辆控制服务进程的桥梁,通过标准化接口对上层提供服务,对于服务的实现依赖厂商的定制化,可以忽略汽车制造商的具体实现,也就是说 CarService 调用 VehicleHal 定义的标准接口,厂商实现这些接口。

2、VehicleHal 模块功能

2.1 rc 文件

VehicleHal 的代码路径为:android/hardware/interfaces/automotive/vehicle/2.0/default。路径下有 android.hardware.automotive.vehicle@2.0-service.rc 文件,在开机阶段通过此 rc 文件,将 VehicleHal 进程启动,下面来看下 android.hardware.automotive.vehicle@2.0-service.rc 文件的定义

service vendor.vehicle-hal-2.0 /vendor/bin/hw/android.hardware.automotive.vehicle@2.0-service
    class hal
    user vehicle_network
    group system inet
    2.2 编译

    对于 VehicleHal 的编译,可以对以下两个 Android.bp 文件介绍。

    • Hidl 接口编译
    • VehicleHal 服务编译

    VehicleHal 定义的 Hal 接口编译介绍,Android.bp 文件路径为:android/hardware/interfaces/automotive/vehicle/2.0,目录结构如下:

    ubuntu:android/hardware/interfaces/automotive/vehicle/2.0$ ls -l
    total 132
    -rw-r--r-- 1   users    375 Nov  9  2022 Android.bp
    drwxrwxr-x 5   users   4096 Mar 22 13:55 default
    -rw-r--r-- 1   users   2336 Nov  9  2022 IVehicleCallback.hal
    -rw-r--r-- 1   users   3665 Nov  9  2022 IVehicle.hal
    -rw-r--r-- 1   users 115184 Nov  9  2022 types.hal
    

      下面是 Android.bp 文件的定义:

      // This file is autogenerated by hidl-gen -Landroidbp.
      
      hidl_interface {
          name: "android.hardware.automotive.vehicle@2.0",
          root: "android.hardware",
          vndk: {
              enabled: true,
          },
          srcs: [
              "types.hal",
              "IVehicle.hal",
              "IVehicleCallback.hal",
          ],
          interfaces: [
              "android.hidl.base@1.0",
          ],
          gen_java: true,
      }
      

        编译文件中定义了 android.hardware.automotive.vehicle@2.0 HIDL 接口编译,包含三个文件 types.hal、IVehicle.hal、IVehicleCallback.hal 文件。

        VehicleHal 服务编译介绍,Android.bp 文件路径为:android/hardware/interfaces/automotive/vehicle/2.0/default,目录结构如下:

        ubuntu16:android/hardware/interfaces/automotive/vehicle/2.0/default$ ls -l
        total 28
        -rw-r--r-- 1   users 4705 Nov  9  2022 Android.bp
        -rw-r--r-- 1   users  155 Nov  9  2022 android.hardware.automotive.vehicle@2.0-service.rc
        drwxrwxr-x 4   users 4096 Jun  7  2022 common
        drwxrwxr-x 3   users 4096 Jun  7  2022 impl
        drwxrwxr-x 2   users 4096 Nov  9  2022 tests
        -rw-r--r-- 1   users 1953 Nov  9  2022 VehicleService.cpp
        

          Android.bp 文件定义如下:

          // Vehicle reference implementation lib
          cc_library {
              name: "android.hardware.automotive.vehicle@2.0-manager-lib",
              vendor: true,
              defaults: ["vhal_v2_0_defaults"],
              srcs: [
                  "common/src/Obd2SensorStore.cpp",
                  "common/src/SubscriptionManager.cpp",
                  "common/src/VehicleHalManager.cpp",
                  "common/src/VehicleObjectPool.cpp",
                  "common/src/VehiclePropertyStore.cpp",
                  "common/src/VehicleUtils.cpp",
                  "common/src/VmsUtils.cpp",
              ],
              local_include_dirs: ["common/include/vhal_v2_0"],
              export_include_dirs: ["common/include"],
          }
          
          // Vehicle default VehicleHAL implementation
          cc_library_static {
              name: "android.hardware.automotive.vehicle@2.0-default-impl-lib",
              vendor: true,
              cflags: ["-Wno-unused-parameter", "-Wno-sign-compare"],
              defaults: ["vhal_v2_0_defaults"],
              srcs: [
                  "impl/vhal_v2_0/CommConn.cpp",
                  "impl/vhal_v2_0/EmulatedVehicleHal.cpp",
                  "impl/vhal_v2_0/VehicleEmulator.cpp",
                  "impl/vhal_v2_0/PipeComm.cpp",
                  "impl/vhal_v2_0/SocketComm.cpp",
                  "impl/vhal_v2_0/LinearFakeValueGenerator.cpp",
                  "impl/vhal_v2_0/JsonFakeValueGenerator.cpp",
              ],
              local_include_dirs: ["common/include/vhal_v2_0"],
              export_include_dirs: ["impl"],
              whole_static_libs: ["android.hardware.automotive.vehicle@2.0-manager-lib"],
              shared_libs: [
                  "libbase",
                  "libprotobuf-cpp-lite",
              ],
              static_libs: [
                  "libjsoncpp",
                  "libqemu_pipe",
                  "android.hardware.automotive.vehicle@2.0-libproto-native",
              ],
          }
          
          cc_binary {
              name: "android.hardware.automotive.vehicle@2.0-service",
              defaults: ["vhal_v2_0_defaults"],
              init_rc: ["android.hardware.automotive.vehicle@2.0-service.rc"],
              vendor: true,
              relative_install_path: "hw",
              srcs: ["VehicleService.cpp"],
              shared_libs: [
                  "libbase",
                  "libprotobuf-cpp-lite",
              ],
              static_libs: [
                  "android.hardware.automotive.vehicle@2.0-manager-lib",
                  "android.hardware.automotive.vehicle@2.0-default-impl-lib",
                  "android.hardware.automotive.vehicle@2.0-libproto-native",
                  "libjsoncpp",
                  "libqemu_pipe",
              ],
          }
          

          从 Android.bp 的定义中,VehicleHal 的服务名为 android.hardware.automotive.vehicle@2.0-service,启动 rc 文件是 android.hardware.automotive.vehicle@2.0-service.rc,入口文件是 VehicleService.cpp,依赖自定义相关模块主要有 android.hardware.automotive.vehicle@2.0-manager-lib、android.hardware.automotive.vehicle@2.0-default-impl-lib、android.hardware.automotive.vehicle@2.0-libproto-native。

          android.hardware.automotive.vehicle@2.0-manager-lib 模块是 common 目录下的文件所编译的内容,主要是 VehicleHal 所以来的模块。

          android.hardware.automotive.vehicle@2.0-default-impl-lib 模块是 impl 目录下的文件所编译的内容,主要是 VehicleHal 的功能实现模块。

          android.hardware.automotive.vehicle@2.0-libproto-native 模块是 impl/vhal_v2_0/proto 目录下的文件所编译的内容,目录下的文件为 VehicleHalProto.proto 文件,是一种序列化存储数据的方式。

          2.3 HIDL 接口

          Android Automotive 框架中 Hal 层接口文件有三个,IVehicle.hal、IVehicleCallback.hal 和 types.hal 文件。IVehicle.hal 文件中定义了 Vehicle Hal 对外提供的接口;IVehicleCallback.hal 文件中定义了 VehicleHal 的回调接口;types.hal 文件定义了 Vehicle Hal 的属性定义。

          Hidl 文件路径为:android/hardware/interfaces/automotive/vehicle/2.0。

          2.3.1 IVehicle.hal

          IVehicle.hal 文件中定义了 Vehicle Hal 对外提供的接口,上层 CarService 通过 IVehicle.hal 中定义的接口与 Vehicle Hal 通信。

          package android.hardware.automotive.vehicle@2.0;
          
          import IVehicleCallback;
          
          interface IVehicle {
            /**
             * Returns a list of all property configurations supported by this vehicle
             * HAL.
             * 返回此车辆HAL支持的所有属性配置的列表
             */
            getAllPropConfigs() generates (vec<VehiclePropConfig> propConfigs);
          
            /**
             * Returns a list of property configurations for given properties.
             *
             * If requested VehicleProperty wasn't found it must return
             * StatusCode::INVALID_ARG, otherwise a list of vehicle property
             * configurations with StatusCode::OK
             * 返回给定属性的属性配置列表。
             * 如果请求的车辆属性没有找到,它必须返回StatusCode::INVALID_ARG,否则返回一个车辆属性配置列表,StatusCode::OK
             */
            getPropConfigs(vec<int32_t> props)
                    generates (StatusCode status, vec<VehiclePropConfig> propConfigs);
          
            /**
             * Get a vehicle property value.
             *
             * For VehiclePropertyChangeMode::STATIC properties, this method must always
             * return the same value always.
             * For VehiclePropertyChangeMode::ON_CHANGE properties, it must return the
             * latest available value.
             *
             * Some properties like RADIO_PRESET requires to pass additional data in
             * GET request in VehiclePropValue object.
             *
             * If there is no data available yet, which can happen during initial stage,
             * this call must return immediately with an error code of
             * StatusCode::TRY_AGAIN.
             * 获取车辆属性值。
             * 对于 VehiclePropertyChangeMode::STATIC 的属性值,此方法会返回同一个值,不会改变。
             * 对于 VehiclePropertyChangeMode::ON_CHANGE 的属性值,此方法会返回最新值。
             */
            get(VehiclePropValue requestedPropValue)
                    generates (StatusCode status, VehiclePropValue propValue);
          
            /**
             * Set a vehicle property value.
             *
             * Timestamp of data must be ignored for set operation.
             *
             * Setting some properties require having initial state available. If initial
             * data is not available yet this call must return StatusCode::TRY_AGAIN.
             * For a property with separate power control this call must return
             * StatusCode::NOT_AVAILABLE error if property is not powered on.
             * 设置车辆属性值。
             * 特殊场景:
             * 设置一些属性值需要其初始状态可用,如果初始状态不可用,需要返回 StatusCode::TRY_AGAIN。
             * 设置单独电源控制的属性,如果属性未上电,需要返回 StatusCode::TRY_AGAIN。
             */
            set(VehiclePropValue propValue) generates (StatusCode status);
          
            /**
             * Subscribes to property events.
             *
             * Clients must be able to subscribe to multiple properties at a time
             * depending on data provided in options argument.
             *
             * @param listener Th
          评论
          添加红包

          请填写红包祝福语或标题

          红包个数最小为10个

          红包金额最低5元

          当前余额3.43前往充值 >
          需支付:10.00
          成就一亿技术人!
          领取后你会自动成为博主和红包主的粉丝 规则
          hope_wisdom
          发出的红包
          实付
          使用余额支付
          点击重新获取
          扫码支付
          钱包余额 0

          抵扣说明:

          1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
          2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

          余额充值