IVI车载设备硬件抽象层VHAL
Posted xhBruce
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IVI车载设备硬件抽象层VHAL相关的知识,希望对你有一定的参考价值。
【IVI】车载设备硬件抽象层VHAL
android12-release
Android Automotive OS知识体系
Android 知识体系
1、概要
车载硬件抽象层 (HAL) 接口会定义原始设备制造商 (OEM) 可以实现的属性,并会包含属性元数据(例如,属性是否为 int 以及允许使用哪些更改模式)。VHAL 接口以对属性(特定功能的抽象表示)的访问(读取、写入、订阅)为基础。
2、HAL 接口
2.1 VHAL 使用以下接口
hardware/interfaces/automotive/vehicle/2.0/IVehicle.hal
- getAllPropConfigs() 会生成 (vecpropConfigs)
列出 VHAL 所支持的所有属性的配置。CarService 仅使用支持的属性。 - getPropConfigs(vec<int32_t> props) 会生成 (StatusCode status,vec propConfigs);
返回所选属性的配置。 - set(VehiclePropValue propValue) 会生成 (StatusCodestatus);
向属性写入一个值。写入的结果是按属性进行定义的。 - subscribe(IVehicleCallback callback, vec options) 会生成 (StatusCode status);
开始监视属性值的变化。对于区域属性,unsubscribe(IVehicleCallback callback, int32_t propId) 会生成 (StatusCode status);
2.2 VHAL 使用以下回调接口
hardware/interfaces/automotive/vehicle/2.0/IVehicleCallback.hal
- oneway onPropertyEvent(vecpropValues);
通知车辆属性值的变化。应只针对已订阅属性执行。 - oneway onPropertySetError(StatusCode errorCode,int32_t propId,int32_tareaId);
返回全局 VHAL 级错误或每个属性的错误。全局错误会导致 HAL 重新启动,这可能会导致包括应用在内的其他组件重新启动。
2.3 Set 调用
set
调用属于异步操作,涉及所请求更改发生之后的事件通知。在通常的操作中,set
调用会导致在车辆网络中发出更改请求。某些set
调用可能要求准备好初始数据,而这些数据在初始化期间可能尚不可用。在这种情况下,set
调用应返回-EAGAIN
。某些具有独立的电源开/关的属性应在属性关闭且无法设置时返回-ESHUTDOWN
。在set
生效之前,get
不一定会返回所设置的值。例如:set HVAC Temperature
。
(CS = CarService、VHAL = 车载 HAL)
2.4 Get 调用
在初始化期间,由于尚未收到匹配的车辆网络消息,属性的值可能不可用。在这种情况下,
get
调用应返回-EAGAIN
。一些属性(例如HVAC
)具有独立的电源开/关属性。对此类属性调用get
(关闭电源时)应返回UNAVAILABLE
状态,而不是返回错误。例如,get HVAC
温度
(CS = CarService、VHAL = 车载 HAL)
3、车辆属性
3.1 车辆属性
hardware/interfaces/automotive/vehicle/2.0/types.hal
属性可以为只读、只写(用于将信息传递到 VHAL 一级),也可以为读写(对大多数属性而言对读写的支持是可选的)。每个属性都由一个 int32 键唯一标识,且具有一个预定义的类型 (value_type):
- BYTES
- BOOLEAN
- EPOCH_TIME
- FLOAT
- FLOAT[]
- INT32
- INT32[]
- INT64
- INT64[]
- STRING
- MIXED
区域属性可能具有多个值,具体取决于属性所支持的区域数量。
/**
* Enumerates supported data type for VehicleProperty.
*
* Used to create property ID in VehicleProperty enum.
*/
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
;
3.2 区域类型
区域类型 | 说明 |
---|---|
GLOBAL | 此属性是一个单例,不具备多个区域。 |
WINDOW | 基于车窗的区域,使用 VehicleAreaWindow 枚举。 |
MIRROR | 基于车镜的区域,使用 VehicleAreaMirror 枚举。 |
SEAT | 基于座椅的区域,使用 VehicleAreaSeat 枚举。 |
DOOR | 基于车门的区域,使用 VehicleAreaDoor 枚举。 |
WHEEL | 基于车轮的区域,使用 VehicleAreaWheel 枚举。 |
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,
;
3.2.1 WINDOW区域类型 VehicleAreaWindow
/**
* Various windshields/windows in the car.
*/
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,
;
3.2.2 MIRROR区域类型 VehicleAreaMirror
enum VehicleAreaMirror : int32_t
DRIVER_LEFT = 0x00000001,
DRIVER_RIGHT = 0x00000002,
DRIVER_CENTER = 0x00000004,
;
3.2.3 SEAT区域类型 VehicleAreaSeat
/**
* Various Seats in the car.
*/
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
;
3.2.4 DOOR区域类型 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,
;
3.2.5 WHEEL区域类型 VehicleAreaWheel
enum VehicleAreaWheel : int32_t
UNKNOWN = 0x0,
LEFT_FRONT = 0x1,
RIGHT_FRONT = 0x2,
LEFT_REAR = 0x4,
RIGHT_REAR = 0x8,
;
3.3 属性状态
每个属性值都有一个 VehiclePropertyStatus 值。该值指示相应属性的当前状态:
项目 | 说明 |
---|---|
AVAILABLE | 属性可用,且值有效。 |
UNAVAILABLE | 属性值目前不可用。用于某个受支持属性的被暂时停用的功能。 |
ERROR | 该属性有问题。 |
/**
* Property status is a dynamic value that may change based on the vehicle state.
*/
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,
;
2.4 配置属性
使用 VehiclePropConfig 为每个属性提供配置信息。具体信息包括:
变量 | 说明 |
---|---|
access | r、w、rw |
changeMode | 表示监视属性的方式:变化时监视或持续监视。 |
areaConfigs | areaId、min 和 max 值。 |
configArray | 额外配置参数。 |
configString | 以字符串形式传递的额外信息。 |
minSampleRate | maxSampleRate |
prop | 属性 ID,整数 |
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;
;
2.4.1 property可读、可写或读写
/**
* Property config defines the capabilities of it. User of the API
* must first get the property config to understand the output from get()
* commands and also to ensure that set() or events commands are in sync with
* the expected output.
*/
enum VehiclePropertyAccess : int32_t
NONE = 0x00,
READ = 0x01,
WRITE = 0x02,
READ_WRITE = 0x03,
;
2.4.2 property改变模式
/**
* This describes how value of property can change.
*/
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,
;
以上是关于IVI车载设备硬件抽象层VHAL的主要内容,如果未能解决你的问题,请参考以下文章