Vehicle HAL(1)--整体介绍
AOSP 官网介绍:
https://source.android.com/docs/automotive/vhal
VHAL 简介:
Android Automotive and Physical Car Interaction | Android Automotive OS Book
Vehicle HAL Properties:
https://source.android.com/docs/automotive/vhal/properties
system-properties:
https://source.android.com/docs/automotive/vhal/system-properties
vhal_debug:
https://source.android.com/docs/automotive/vhal/vhal_debug
1. Vehicle HAL 整体介绍
此处的Vehicle HAL(vhal),主要介绍ard11上用hidl实现的vhal。后面vhal已经在ard13及以上迁移到aidl的实现。
(1)vhal的主要作用,处理clients(CarService, others hal) 的连接请求;
(2)与车辆通过can通信,实现车辆控制与信息反馈。
2. Vehicle HAL 要实现的功能有那些?
(1)实现IVehicle.hal接口,实现由它定义的功能,主要是属性get、set、update、传递;
(2)一个模拟的EmulatedVehicleHal,主体的功能实现部分;
(3)属性的解析和保持、更新;
(4)属性的订阅端管理;
3. Vehicle HAL 实现整体框图
4. Vehicle HAL 主要部分介绍
4.1 VehicleService
main函数的主体,构建关键对象,启动vhal。
4.2 EmulatedVehicleHal
EmulatedVehicleHal实现了vhal中关键的VehicleHal抽象类。
EmulatedVehicleHal::initStaticConfig():
EmulatedVehicleHal() > EmulatedVehicleHal::initStaticConfig() > mPropStore->registerProperty()
kVehicleProperties是静态配置好了的。
195 const ConfigDeclaration kVehicleProperties[]
android11/hardware/interfaces/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultConfig.h
EmulatedVehicleHal 的关键函数 EmulatedVehicleHal::onPropertyValue(),传递属性变化给上层和模拟car:
351 void EmulatedVehicleHal::onPropertyValue(const VehiclePropValue& value, bool updateStatus) {
352 VehiclePropValuePtr updatedPropValue = getValuePool()->obtain(value);
353
354 if (mPropStore->writeValue(*updatedPropValue, updateStatus)) {//更新属性
355 getEmulatorOrDie()->doSetValueFromClient(*updatedPropValue);//关键调用,Emulator,client,获取时通过socket走到can的另外一端
356 doHalEvent(std::move(updatedPropValue));//关键调用,返回变化到carservice
357 }
358 }
4.3 VehicleHalManager
VehicleHalManager实现了IVehiclel接口,hal服务的主体。构建VehicleHalManager的关键过程有3步。
VehicleHalManager(VehicleHal* vehicleHal): mHal(vehicleHal),//初始化mHalmSubscriptionManager(std::bind(&VehicleHalManager::onAllClientsUnsubscribed,this, std::placeholders::_1)) {//初始化mSubscriptionManagerinit();//调用自己的init()函数}
4.4 SubscriptionManager
SubscriptionManager 的作用主要是管理属性的订阅clients。