AndroidP HAL Vehicle --- types.hal 分析

 types.hal:定义的是一些数据结构,这里面内容比较多。列举一些
 

```java

enum VehiclePropertyType : int32_t { // VehicleProperty 的类型是 string、bool、还是 int32 等等
    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.
     */
    MIXED           = 0x00e00000, // 这两个主要就是VehicleProperty 用来或的。不理解看了 VehicleProperty 类型就知道了

    MASK            = 0x00ff0000
};

  enum VehicleArea : int32_t {  // VehicleProperty 作用的区域,是全局、窗户、我猜是屏幕位置什么的、位置、车门、车轮。
                                // VehicleArea的使用在  VehicleProperty中比如HVAC_FAN_SPEED ,VehicleArea:SEAT 
    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,
};
   enum VehicleModule : int32_t { // 从名字就知道将车参分成了四个模块 空调、radio、传感器、MCU
        HVAC = 0x0500,
        RADIO = 0x5100,
        SENSOR = 0x1500,
        MCU = 0x1600,
        MASK = 0xffff,
    };
 enum VehiclePropertyGroup : int32_t { // AndroidO之后的treble,用于区分android原生的property和厂商的property
    /**
     * Properties declared in AOSP must use this flag.
     */
    SYSTEM      = 0x10000000,

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

    MASK        = 0xf0000000,
};
enum VehicleProperty : int32_t { // 这个类一个大户了枚举了所有的VehicleProperty
    .......
        /**
     * Fan speed setting
     *
     * @change_mode VehiclePropertyChangeMode:ON_CHANGE
     * @access VehiclePropertyAccess:READ_WRITE
     */
    HVAC_FAN_SPEED = ( // 这边或下来的结果是 0x15400500,在
                       //packages/services/Car/tools/emulator/vhal_consts_2_0.py 都有的,我自己也或下来验证了。我们
                       //可以起这里的gui.py来测试
        0x0500
        | VehiclePropertyGroup:SYSTEM //系统VehicleProperty
        | VehiclePropertyType:INT32 //数据类型在java层是int 32 表示的
        | VehicleArea:SEAT),   // 和位置作用相关的。

     /**
     * HVAC current temperature.
     *
     * @change_mode VehiclePropertyChangeMode:ON_CHANGE
     * @access VehiclePropertyAccess:READ
     * @unit VehicleUnit:CELSIUS
     */
    HVAC_TEMPERATURE_CURRENT = (
        0x0502
        | VehiclePropertyGroup:SYSTEM
        | VehiclePropertyType:FLOAT
        | VehicleArea:SEAT),  // 这边或下来的结果是 0x15600502

    /**
     * BSR chime type.
     *
     * @change_mode VehiclePropertyChangeMode:STATIC
     * @access VehiclePropertyAccess:READ
     */
    SENSOR_BSR_CHIME_TYPE = (
        VehicleModule:SENSOR + 11  //是传感器相关的
        | VehiclePropertyGroup:VENDOR
        | VehiclePropertyType:INT32
        | VehicleArea:GLOBAL),


    /* read only
    * MCU_UPDATE_STS: start,success, failed, updating, no_mcu_file, get_mcu_file_max_block
    * */
    MCU_UPDATE_STS = (
        VehicleModule:MCU + 1 // MCU相关的
        | VehiclePropertyGroup:VENDOR
        | VehiclePropertyType:INT32
        | VehicleArea:GLOBAL),

    ......
        /**
     * High beam lights state
     *
     * Return the current state of high beam lights.
     *
     * @change_mode VehiclePropertyChangeMode:ON_CHANGE
     * @access VehiclePropertyAccess:READ
     * @data_enum VehicleLightState
     */
    HIGH_BEAM_LIGHTS_STATE = (
        0x0E01
        | VehiclePropertyGroup:SYSTEM
        | VehiclePropertyType:INT32
        | VehicleArea:GLOBAL),

    ......
    /**
     * Headlight switch
     *
     * The setting that the user wants.
     *
     * @change_mode VehiclePropertyChangeMode:ON_CHANGE
     * @access VehiclePropertyAccess:READ_WRITE
     * @data_enum VehicleLightSwitch
     */
    HEADLIGHTS_SWITCH = (
        0x0E10
        | VehiclePropertyGroup:SYSTEM
        | VehiclePropertyType:INT32
        | VehicleArea:GLOBAL),
   ......
   }
enum  VehicleLightState : int32_t {  //上面的 Vehicle Property的返回值枚举或者设定值枚举,比如 property HIGH_BEAM_LIGHTS_STATE ,返回值有关闭 、打开、

    OFF = 0,
    ON = 1,
    DAYTIME_RUNNING = 2 // Only the HEADLIGHTS_STATE property will report DAYTIME_RUNNING.
};

enum VehicleLightSwitch : int32_t { // 见 HEADLIGHTS_SWITCH 
    OFF = 0,
    ON = 1,
    /**
     * Daytime running lights mode.  Most cars automatically use DRL but some
     * cars allow the user to activate them manually.
     */
    DAYTIME_RUNNING = 2,
    /**
     * Allows the vehicle ECU to set the lights automatically
     */
    AUTOMATIC = 0x100,
};

后面的 
enum EvConnectorType, 
enum PortLocationType,
enum FuelType, 
enum VehicleHvacFanDirection, 
enum VehicleOilLevel,
enum VehicleApPowerStateConfigFlag,
enum VehicleApPowerStateReq,
.
.
.
.
.
以上基本都是某个property的参数取值枚举

enum VehiclePropertyChangeMode : int32_t { // 不接受订阅类型的,要自己去get
    /**
     * 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, // 此类型的属性会不断变化
};


enum VehiclePropertyAccess : int32_t {
    NONE = 0x00,

    READ = 0x01,  // 只读
    WRITE = 0x02, // 只写
    READ_WRITE = 0x03, // 读写都可以
};

啊啊啊啊,这里面枚举值太多了,其他的大家自己看。
把下面三个结构体在说一下,

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

    int32_t minInt32Value;
    int32_t maxInt32Value;

    int64_t minInt64Value;
    int64_t maxInt64Value;

    float minFloatValue;
    float maxFloatValue;
};

struct VehiclePropConfig {  // vehicle Property的配置
    /** Property identifier */
    int32_t prop;  // property的具体数值

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

    /**
     * Defines the change mode of the property.
     */
    VehiclePropertyChangeMode changeMode; //是 static 、no_changed、continue

    /**
     * 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;  // 对于CONTINUOUS类型的,返回值最小频率

    /**
     * Must be defined for VehiclePropertyChangeMode::CONTINUOUS
     * Max sample rate in Hz.
     */
    float maxSampleRate; // 对于CONTINUOUS类型的,返回值的最大频率
};

/**
 * Encapsulates the property name and the associated value. It
 * is used across various API calls to set values, get values or to register for
 * events.
 */
struct VehiclePropValue { // HAl  层到 java层的传输类型 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;
};
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MQ-2 is a gas sensor module that can detect various types of gases such as methane, propane, butane, alcohol, smoke, and others. It uses a semiconductor sensor to detect the presence of gases and provides an analog output that can be read by an STM32 microcontroller. To interface the MQ-2 sensor with an STM32 microcontroller using HAL (Hardware Abstraction Layer) drivers, the following steps can be followed: 1. Configure the analog input pin of the STM32 microcontroller that will be used to read the analog output from the MQ-2 sensor. 2. Initialize the ADC (Analog-to-Digital Converter) peripheral of the STM32 microcontroller using the HAL ADC driver. 3. Configure the ADC channel that will be used to read the analog output from the MQ-2 sensor. 4. Use the HAL ADC driver to start the ADC conversion and wait for the conversion to complete. 5. Read the converted value from the ADC data register using the HAL ADC driver. 6. Convert the ADC reading into a gas concentration value using the calibration data provided by the manufacturer of the MQ-2 sensor. 7. Repeat the above steps periodically to continuously monitor the gas concentration value. The specific steps and code for each of the above steps will depend on the specific STM32 microcontroller and the MQ-2 sensor module being used. It is recommended to refer to the datasheets and application notes provided by the manufacturer of the STM32 microcontroller and the MQ-2 sensor module for detailed instructions on how to interface them using HAL drivers.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值