当前位置: 首页 > biancheng >正文

Android Automotive(六) HAL数据结构

Android Automotive(六) HAL数据结构

Andorid Automotiv中,硬件抽象层和系统框架层是通信通过HIDL语言定义接口的。我们前面知道了IVehicle.hal定义操作的接口,IVehicleCallback.hal处理回调的事件。其实还有一个文件types.hal定义了操作数据的数据结构。

代码路径:hardware/interfaces/automotive/vehicle/2.0/types.hal

VehiclePropertyType

车辆属性支持的数据类型

enum VehiclePropertyType : int32_t {
    STRING          = 0x00100000,
    BOOLEAN         = 0x00200000,
    INT32           = 0x00400000,
    INT32_VEC       = 0x00410000,
    INT64           = 0x00500000,
    INT64_VEC       = 0x00510000,
    FLOAT           = 0x00600000,
    FLOAT_VEC       = 0x00610000,
    BYTES           = 0x00700000,

    /**
     * Any combination of scalar or vector types. The exact format must be
     * provided in the description of the property.
     *
     * For vendor MIXED type properties, configArray needs to be formatted in this
     * structure.
     * configArray[0], 1 indicates the property has a String value
     * configArray[1], 1 indicates the property has a Boolean value .
     * configArray[2], 1 indicates the property has an Integer value.
     * configArray[3], the number indicates the size of Integer[] in the property.
     * configArray[4], 1 indicates the property has a Long value.
     * configArray[5], the number indicates the size of Long[] in the property.
     * configArray[6], 1 indicates the property has a Float value.
     * configArray[7], the number indicates the size of Float[] in the property.
     * configArray[8], the number indicates the size of byte[] in the property.
     * For example:
     * {@code configArray = {1, 1, 1, 3, 0, 0, 0, 0, 0}} indicates the property has
     * a String value, a Boolean value, an Integer value and an array with 3 integers.
     */
    MIXED           = 0x00e00000,

    MASK            = 0x00ff0000
};

VehicleArea

车辆属性的区域

enum VehicleArea : int32_t {
    GLOBAL      = 0x01000000,
    /** WINDOW maps to enum VehicleAreaWindow */
    WINDOW      = 0x03000000,
    /** MIRROR maps to enum VehicleAreaMirror */
    MIRROR      = 0x04000000,
    /** SEAT maps to enum VehicleAreaSeat */
    SEAT        = 0x05000000,
    /** DOOR maps to enum VehicleAreaDoor */
    DOOR        = 0x06000000,
    /** WHEEL maps to enum VehicleAreaWheel */
    WHEEL       = 0x07000000,

    MASK        = 0x0f000000,
};

VehiclePropertyGroup

车辆属性的所属组

enum VehiclePropertyGroup : int32_t {
    /**
     * Properties declared in AOSP must use this flag.
     */
    SYSTEM      = 0x10000000,

    /**
     * Properties declared by vendors must use this flag.
     */
    VENDOR      = 0x20000000,

    MASK        = 0xf0000000,
};

VehicleProperty

车辆属性配置,这里有很多值的配置,表示不同的功能。

/** Undefined property. */
INVALID = 0x00000000,

/**
 * VIN of vehicle
 *
 * @change_mode VehiclePropertyChangeMode:STATIC
 * @access VehiclePropertyAccess:READ
 */
INFO_VIN = (
    0x0100
    | VehiclePropertyGroup:SYSTEM
    | VehiclePropertyType:STRING
    | VehicleArea:GLOBAL),
......

VehicleVendorPermission

定义车辆属性使用所需要的权限

enum VehicleVendorPermission : int32_t {
    PERMISSION_DEFAULT = 0x00000000,

    // permissions for the property related with window
    PERMISSION_SET_VENDOR_CATEGORY_WINDOW= 0X00000001,
    PERMISSION_GET_VENDOR_CATEGORY_WINDOW = 0x00000002,
    // permissions for the property related with door
    PERMISSION_SET_VENDOR_CATEGORY_DOOR  = 0x00000003,
    PERMISSION_GET_VENDOR_CATEGORY_DOOR   = 0x00000004,
    // permissions for the property related with seat
    PERMISSION_SET_VENDOR_CATEGORY_SEAT  = 0x00000005,
    PERMISSION_GET_VENDOR_CATEGORY_SEAT   = 0x00000006,
    // permissions for the property related with mirror
    PERMISSION_SET_VENDOR_CATEGORY_MIRROR= 0x00000007,
    PERMISSION_GET_VENDOR_CATEGORY_MIRROR = 0x00000008,

    // permissions for the property related with car's information
    PERMISSION_SET_VENDOR_CATEGORY_INFO  = 0x00000009,
    PERMISSION_GET_VENDOR_CATEGORY_INFO   = 0x0000000A,
    // permissions for the property related with car's engine
    PERMISSION_SET_VENDOR_CATEGORY_ENGINE= 0x0000000B,
    PERMISSION_GET_VENDOR_CATEGORY_ENGINE = 0x0000000C,
    // permissions for the property related with car's HVAC
    PERMISSION_SET_VENDOR_CATEGORY_HVAC  = 0x0000000D,
    PERMISSION_GET_VENDOR_CATEGORY_HVAC   = 0x0000000E,
    // permissions for the property related with car's light
    PERMISSION_SET_VENDOR_CATEGORY_LIGHT = 0x0000000F,
    PERMISSION_GET_VENDOR_CATEGORY_LIGHT  = 0x00000010,

    // permissions reserved for other vendor permission
    PERMISSION_SET_VENDOR_CATEGORY_1  = 0x00010000,
    PERMISSION_GET_VENDOR_CATEGORY_1   = 0x00011000,
    PERMISSION_SET_VENDOR_CATEGORY_2  = 0x00020000,
    PERMISSION_GET_VENDOR_CATEGORY_2   = 0x00021000,
    PERMISSION_SET_VENDOR_CATEGORY_3  = 0x00030000,
    PERMISSION_GET_VENDOR_CATEGORY_3   = 0x00031000,
    PERMISSION_SET_VENDOR_CATEGORY_4  = 0x00040000,
    PERMISSION_GET_VENDOR_CATEGORY_4   = 0x00041000,
    PERMISSION_SET_VENDOR_CATEGORY_5  = 0x00050000,
    PERMISSION_GET_VENDOR_CATEGORY_5   = 0x00051000,
    PERMISSION_SET_VENDOR_CATEGORY_6  = 0x00060000,
    PERMISSION_GET_VENDOR_CATEGORY_6   = 0x00061000,
    PERMISSION_SET_VENDOR_CATEGORY_7  = 0x00070000,
    PERMISSION_GET_VENDOR_CATEGORY_7   = 0x00071000,
    PERMISSION_SET_VENDOR_CATEGORY_8  = 0x00080000,
    PERMISSION_GET_VENDOR_CATEGORY_8   = 0x00081000,
    PERMISSION_SET_VENDOR_CATEGORY_9  = 0x00090000,
    PERMISSION_GET_VENDOR_CATEGORY_9   = 0x00091000,
    PERMISSION_SET_VENDOR_CATEGORY_10 = 0x000A0000,
    PERMISSION_GET_VENDOR_CATEGORY_10  = 0x000A1000,

    // Indicate not available for android to access.
    PERMISSION_NOT_ACCESSIBLE = 0xF0000000
};

VehicleUnit

车辆属性使用的国际单位

enum VehicleUnit : int32_t {
    SHOULD_NOT_USE      = 0x000,

    METER_PER_SEC       = 0x01,
    RPM                 = 0x02,
    HERTZ               = 0x03,
    PERCENTILE          = 0x10,
    MILLIMETER          = 0x20,
    METER               = 0x21,
    KILOMETER           = 0x23,
    MILE                = 0x24,
    CELSIUS             = 0x30,
    FAHRENHEIT          = 0x31,
    KELVIN              = 0x32,
    MILLILITER          = 0x40,
    LITER               = 0x41,

    /** deprecated. Use US_GALLON instead. */
    GALLON              = 0x42,
    US_GALLON           = 0x42,
    IMPERIAL_GALLON     = 0x43,
    NANO_SECS           = 0x50,
    SECS                = 0x53,
    YEAR                = 0x59,

    // Electrical Units
    WATT_HOUR           = 0x60,
    MILLIAMPERE         = 0x61,
    MILLIVOLT           = 0x62,
    MILLIWATTS          = 0x63,
    AMPERE_HOURS        = 0x64,
    KILOWATT_HOUR       = 0x65,

    KILOPASCAL          = 0x70,
    PSI                 = 0x71,
    BAR                 = 0x72,
    DEGREES             = 0x80,

    MILES_PER_HOUR      = 0x90,
    KILOMETERS_PER_HOUR = 0x91,
};

VehiclePropertyChangeMode

车辆属性的变化类型

enum VehiclePropertyChangeMode : int32_t {
    /**
     * Property of this type must never be changed. Subscription is not supported
     * for these properties.
     */
    STATIC = 0x00,

    /**
     * Properties of this type must report when there is a change.
     * IVehicle#get call must return the current value.
     * Set operation for this property is assumed to be asynchronous. When the
     * property is read (using IVehicle#get) after IVehicle#set, it may still
     * return old value until underlying H/W backing this property has actually
     * changed the state. Once state is changed, the property must dispatch
     * changed value as event.
     */
    ON_CHANGE = 0x01,

    /**
     * Properties of this type change continuously and require a fixed rate of
     * sampling to retrieve the data.  Implementers may choose to send extra
     * notifications on significant value changes.
     */
    CONTINUOUS = 0x02,
};

VehiclePropertyAccess

车辆属性的读写性质

enum VehiclePropertyAccess : int32_t {
    NONE = 0x00,

    READ = 0x01,
    WRITE = 0x02,
    READ_WRITE = 0x03,
};

VehiclePropertyStatus

车辆属性的状态

enum VehiclePropertyStatus : int32_t {
    /** Property is available and behaving normally */
    AVAILABLE   = 0x00,
    /**
     * A property in this state is not available for reading and writing.  This
     * is a transient state that depends on the availability of the underlying
     * implementation (e.g. hardware or driver). It MUST NOT be used to
     * represent features that this vehicle is always incapable of.  A get() of
     * a property in this state MAY return an undefined value, but MUST
     * correctly describe its status as UNAVAILABLE A set() of a property in
     * this state MAY return NOT_AVAILABLE. The HAL implementation MUST ignore
     * the value of the status field when writing a property value coming from
     * Android.
     */
    UNAVAILABLE = 0x01,
    /** There is an error with this property. */
    ERROR       = 0x02,
};

VehicleAreaSeat

座椅的区域定义

enum VehicleAreaSeat : int32_t {
    ROW_1_LEFT   = 0x0001,
    ROW_1_CENTER = 0x0002,
    ROW_1_RIGHT  = 0x0004,
    ROW_2_LEFT   = 0x0010,
    ROW_2_CENTER = 0x0020,
    ROW_2_RIGHT  = 0x0040,
    ROW_3_LEFT   = 0x0100,
    ROW_3_CENTER = 0x0200,
    ROW_3_RIGHT  = 0x0400
}

VehicleAreaWindow

窗户的区域定义

enum VehicleAreaWindow : int32_t {
    FRONT_WINDSHIELD  = 0x00000001,
    REAR_WINDSHIELD   = 0x00000002,
    ROW_1_LEFT        = 0x00000010,
    ROW_1_RIGHT       = 0x00000040,
    ROW_2_LEFT        = 0x00000100,
    ROW_2_RIGHT       = 0x00000400,
    ROW_3_LEFT        = 0x00001000,
    ROW_3_RIGHT       = 0x00004000,

    ROOF_TOP_1        = 0x00010000,
    ROOF_TOP_2        = 0x00020000,

};

VehicleAreaDoor

门的区域定义

enum VehicleAreaDoor : int32_t {
    ROW_1_LEFT = 0x00000001,
    ROW_1_RIGHT = 0x00000004,
    ROW_2_LEFT = 0x00000010,
    ROW_2_RIGHT = 0x00000040,
    ROW_3_LEFT = 0x00000100,
    ROW_3_RIGHT = 0x00000400,
    HOOD = 0x10000000,
    REAR = 0x20000000,
};

VehicleAreaMirror

镜子的区域定义

enum VehicleAreaMirror : int32_t {
    DRIVER_LEFT = 0x00000001,
    DRIVER_RIGHT = 0x00000002,
    DRIVER_CENTER = 0x00000004,
};

VehicleAreaWheel

轮子的区域定义

enum VehicleAreaWheel : int32_t {
    UNKNOWN = 0x0,

    LEFT_FRONT = 0x1,
    RIGHT_FRONT = 0x2,
    LEFT_REAR = 0x4,
    RIGHT_REAR = 0x8,
};

SubscribeFlags

订阅的类型

enum SubscribeFlags : int32_t {
    UNDEFINED = 0x0,

    /**
     * Subscribe to event that was originated in vehicle HAL
     * (most likely this event came from the vehicle itself).
     */
    EVENTS_FROM_CAR = 0x1,

    /**
     * Use this flag to subscribe on events when IVehicle#set(...) was called by
     * vehicle HAL's client (e.g. Car Service).
     */
    EVENTS_FROM_ANDROID = 0x2,
};

StatusCode

状态码,作为一些操作的返回值

enum StatusCode : int32_t {
    OK = 0,

    /** Try again. */
    TRY_AGAIN = 1,

    /** Invalid argument provided. */
    INVALID_ARG = 2,

    /**
     * This code must be returned when device that associated with the vehicle
     * property is not available. For example, when client tries to set HVAC
     * temperature when the whole HVAC unit is turned OFF.
     */
    NOT_AVAILABLE = 3,

    /** Access denied */
    ACCESS_DENIED = 4,

    /** Something unexpected has happened in Vehicle HAL */
    INTERNAL_ERROR = 5,
};

枚举常量

处理上面这些固定的常量,还有一些用来定义车辆属性返回值的枚举。

VehicleGear

车辆档位定义

enum VehicleGear : int32_t {
    GEAR_UNKNOWN = 0x0000,

    GEAR_NEUTRAL = 0x0001,
    GEAR_REVERSE = 0x0002,
    GEAR_PARK = 0x0004,
    GEAR_DRIVE = 0x0008,
    GEAR_1 = 0x0010,
    GEAR_2 = 0x0020,
    GEAR_3 = 0x0040,
    GEAR_4 = 0x0080,
    GEAR_5 = 0x0100,
    GEAR_6 = 0x0200,
    GEAR_7 = 0x0400,
    GEAR_8 = 0x0800,
    GEAR_9 = 0x1000,
};

数据结构


VehicleAreaConfig

定义车辆属性区域的配置

struct VehicleAreaConfig {
    /**
     * Area id is ignored for VehiclePropertyGroup:GLOBAL properties.
     */
    int32_t areaId;

    /**
     * If the property has @data_enum, leave the range to zero.
     *
     * Range will be ignored in the following cases:
     *    - The VehiclePropertyType is not INT32, INT64 or FLOAT.
     *    - Both of min value and max value are zero.
     */

    int32_t minInt32Value;
    int32_t maxInt32Value;

    int64_t minInt64Value;
    int64_t maxInt64Value;

    float minFloatValue;
    float maxFloatValue;
};

VehiclePropConfig

定义车辆属性的配置

struct VehiclePropConfig {
    /** Property identifier */
    int32_t prop;

    /**
     * Defines if the property is read or write or both.
     */
    VehiclePropertyAccess access;

    /**
     * Defines the change mode of the property.
     */
    VehiclePropertyChangeMode changeMode;

    /**
     * Contains per-area configuration.
     */
    vec<VehicleAreaConfig> areaConfigs;

    /** Contains additional configuration parameters */
    vec<int32_t> configArray;

    /**
     * Some properties may require additional information passed over this
     * string. Most properties do not need to set this.
     */
    string configString;

    /**
     * Min sample rate in Hz.
     * Must be defined for VehiclePropertyChangeMode::CONTINUOUS
     */
    float minSampleRate;

    /**
     * Must be defined for VehiclePropertyChangeMode::CONTINUOUS
     * Max sample rate in Hz.
     */
    float maxSampleRate;
};

VehiclePropValue

定义车辆属性的值

struct VehiclePropValue {
    /** Time is elapsed nanoseconds since boot */
    int64_t timestamp;

    /**
     * Area type(s) for non-global property it must be one of the value from
     * VehicleArea* enums or 0 for global properties.
     */
    int32_t areaId;

    /** Property identifier */
    int32_t prop;

    /** Status of the property */
    VehiclePropertyStatus status;

    /**
     * Contains value for a single property. Depending on property data type of
     * this property (VehiclePropetyType) one field of this structure must be filled in.
     */
    struct RawValue {
        /**
         * This is used for properties of types VehiclePropertyType#INT
         * and VehiclePropertyType#INT_VEC
         */
        vec<int32_t> int32Values;

        /**
         * This is used for properties of types VehiclePropertyType#FLOAT
         * and VehiclePropertyType#FLOAT_VEC
         */
        vec<float> floatValues;

        /** This is used for properties of type VehiclePropertyType#INT64 */
        vec<int64_t> int64Values;

        /** This is used for properties of type VehiclePropertyType#BYTES */
        vec<uint8_t> bytes;

        /** This is used for properties of type VehiclePropertyType#STRING */
        string stringValue;
    };

    RawValue value;
};

SubscribeOptions

订阅的配置

struct SubscribeOptions {
    /** Property to subscribe */
    int32_t propId;

    /**
     * Sample rate in Hz.
     *
     * Must be provided for properties with
     * VehiclePropertyChangeMode::CONTINUOUS. The value must be within
     * VehiclePropConfig#minSamplingRate .. VehiclePropConfig#maxSamplingRate
     * for a given property.
     * This value indicates how many updates per second client wants to receive.
     */
    float sampleRate;

    /** Flags that indicate to which event sources to listen. */
    SubscribeFlags flags;
};

相关文章:

  • 牛客练习赛#84 F 莫比乌斯反演+杜教筛+技巧+斐波那契数列和gcd的结论+矩阵快速幂
  • ZZNUOJ_用C语言编写程序实现1342:支配值数目(附完整源码)
  • java毕业设计后勤管理系统餐饮评价监督系统(附源码、数据库)
  • 前端基础学习笔记
  • 【TS】联合类型--类型断言--类型推断
  • 谈笑风声的秘密
  • QT影城网上售票系统
  • NetCDF数据在ArcMap中的使用
  • 打怪升级(考验思路)
  • 持续精进,改变自己