Vehicle HAL(4)--vhal 的属性如何配置?
本文介绍ard11的 vhal 属性配置方法,后面vhal升级为aidl后,配置位置在其他位置,将另行介绍。
1. vhal属性配置文件DefaultConfig.h的位置
android11/hardware/interfaces/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultConfig.h
195 const ConfigDeclaration kVehicleProperties[]{
196 {.config =
197 {
198 .prop = toInt(VehicleProperty::INFO_FUEL_CAPACITY),
199 .access = VehiclePropertyAccess::READ,
200 .changeMode = VehiclePropertyChangeMode::STATIC,
201 },
202 .initialValue = {.floatValues = {15000.0f}}},
203
.......
1.1 属性解析需要注意的数据结构
1.1.1 struct ConfigDeclaration
android11/hardware/interfaces/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultConfig.h
struct ConfigDeclaration {VehiclePropConfig config;//注意这里/* This value will be used as an initial value for the property. If this field is specified for* property that supports multiple areas then it will be used for all areas unless particular* area is overridden in initialAreaValue field. */VehiclePropValue::RawValue initialValue;///* Use initialAreaValues if it is necessary to specify different values per each area. */std::map<int32_t, VehiclePropValue::RawValue> initialAreaValues;
};
1.1.1.1 struct VehiclePropConfig
android11/hardware/interfaces/automotive/vehicle/2.0/types.hal
3512 struct VehiclePropConfig {
3513 /** Property identifier */
3514 int32_t prop;
3515
3516 /**
3517 * Defines if the property is read or write or both.
3518 */
3519 VehiclePropertyAccess access;
3520
3521 /**
3522 * Defines the change mode of the property.
3523 */
3524 VehiclePropertyChangeMode changeMode;
3525
3526 /**
3527 * Contains per-area configuration.
3528 */
3529 vec<VehicleAreaConfig> areaConfigs;
3530
3531 /** Contains additional configuration parameters */
3532 vec<int32_t> configArray;
3533
3534 /**
3535 * Some properties may require additional information passed over this
3536 * string. Most properties do not need to set this.
3537 */
3538 string configString;
3539
3540 /**
3541 * Min sample rate in Hz.
3542 * Must be defined for VehiclePropertyChangeMode::CONTINUOUS
3543 */
3544 float minSampleRate;
3545
3546 /**
3547 * Must be defined for VehiclePropertyChangeMode::CONTINUOUS
3548 * Max sample rate in Hz.
3549 */
3550 float maxSampleRate;
3551 };
1.1.1.2 struct VehiclePropValue
android11/hardware/interfaces/automotive/vehicle/2.0/types.hal
3553 /**
3554 * Encapsulates the property name and the associated value. It
3555 * is used across various API calls to set values, get values or to register for
3556 * events.
3557 */
3558 struct VehiclePropValue {
3559 /** Time is elapsed nanoseconds since boot */
3560 int64_t timestamp;
3561
3562 /**
3563 * Area type(s) for non-global property it must be one of the value from
3564 * VehicleArea* enums or 0 for global properties.
3565 */
3566 int32_t areaId;
3567
3568 /** Property identifier */
3569 int32_t prop;
3570
3571 /** Status of the property */
3572 VehiclePropertyStatus status;
3573
3574 /**
3575 * Contains value for a single property. Depending on property data type of
3576 * this property (VehiclePropetyType) one field of this structure must be filled in.
3577 */
3578 struct RawValue {
3579 /**
3580 * This is used for properties of types VehiclePropertyType#INT
3581 * and VehiclePropertyType#INT_VEC
3582 */
3583 vec<int32_t> int32Values;
3584
3585 /**
3586 * This is used for properties of types VehiclePropertyType#FLOAT
3587 * and VehiclePropertyType#FLOAT_VEC
3588 */
3589 vec<float> floatValues;
3590
3591 /** This is used for properties of type VehiclePropertyType#INT64 */
3592 vec<int64_t> int64Values;
3593
3594 /** This is used for properties of type VehiclePropertyType#BYTES */
3595 vec<uint8_t> bytes;
3596
3597 /** This is used for properties of type VehiclePropertyType#STRING */
3598 string stringValue;
3599 };
3600
3601 RawValue value;
3602 };
2. vhal常见的属性id
(1) 0x15600503--358614275(HVAC_TEMPERATURE_SET)
android11/packages/services/Car/car-lib/src/android/car/VehiclePropertyIds.java
359 @RequiresPermission(Car.PERMISSION_CONTROL_CAR_CLIMATE)
360 public static final int HVAC_TEMPERATURE_SET = 358614275;
android11/packages/services/Car/tests/vehiclehal_test/Android.mk
android11/packages/services/Car/tests/vehiclehal_test/assets/car_hvac_test.json
8 {
9 "timestamp": 1526063904959113984,
10 "areaId": 49,
11 "value": 28,
12 "prop": 358614275
13 },
hvac的控制代码
android11/frameworks/base/packages/CarSystemUI/src/com/android/systemui/car/hvac/
android11/frameworks/base/packages/CarSystemUI/src/com/android/systemui/car/hvac/HvacController.java
60 /**
61 * Callback for getting changes from {@link CarHvacManager} and setting the UI elements to
62 * match.
63 */
64 private final CarHvacEventCallback mHardwareCallback = new CarHvacEventCallback() {
65 @Override
66 public void onChangeEvent(final CarPropertyValue val) {
67 try {
68 int areaId = val.getAreaId();
69 int propertyId = val.getPropertyId();
70 List<TemperatureView> temperatureViews = mTempComponents.get(
71 new HvacKey(propertyId, areaId));
72 if (temperatureViews != null && !temperatureViews.isEmpty()) {
73 float value = (float) val.getValue();
74 if (DEBUG) {
75 Log.d(TAG, "onChangeEvent: " + areaId + ":" + propertyId + ":" + value);
76 }
77 for (TemperatureView tempView : temperatureViews) {
78 tempView.setTemp(value);
79 }
80 } // else the data is not of interest
81 } catch (Exception e) {
82 // catch all so we don't take down the sysui if a new data type is
83 // introduced.
84 Log.e(TAG, "Failed handling hvac change event", e);
85 }
86 }
87
88 @Override
89 public void onErrorEvent(final int propertyId, final int zone) {
90 Log.d(TAG, "HVAC error event, propertyId: " + propertyId
91 + " zone: " + zone);
92 }
93 };
94
95 private final CarServiceProvider.CarServiceOnConnectedListener mCarServiceLifecycleListener =
96 car -> {
97 try {
98 mHvacManager = (CarHvacManager) car.getCarManager(Car.HVAC_SERVICE);
99 mHvacManager.registerCallback(mHardwareCallback);
100 initComponents();
101 } catch (Exception e) {
102 Log.e(TAG, "Failed to correctly connect to HVAC", e);
103 }
104 };
(2) 0x11410a00--289475072(AP_POWER_STATE_REQ )
553 /**
554 * Property to control power state of application processor
555 *
556 * It is assumed that AP's power state is controller by separate power
557 * controller.
558 * The property is protected by the signature permission: android.car.permission.CAR_POWER.
559 */
560 @RequiresPermission(Car.PERMISSION_CAR_POWER)
561 public static final int AP_POWER_STATE_REQ = 289475072;
562 /**
563 * Property to report power state of application processor
564 *
565 * It is assumed that AP's power state is controller by separate power
566 * controller.
567 * The property is protected by the signature permission: android.car.permission.CAR_POWER.
568 */
569 @RequiresPermission(Car.PERMISSION_CAR_POWER)
570 public static final int AP_POWER_STATE_REPORT = 289475073;
(3) 0x11400a03--289409539(DISPLAY_BRIGHTNESS )
581 /**
582 * Property to represent brightness of the display. Some cars have single
583 * control for the brightness of all displays and this property is to share
584 * change in that control.
585 * The property is protected by the signature permission: android.car.permission.CAR_POWER.
586 */
587 @RequiresPermission(Car.PERMISSION_CAR_POWER)
588 public static final int DISPLAY_BRIGHTNESS = 289409539;