CarService对外接口(cpp)

一、简介

TOPDIR/apps/micar/apps/CarService/libs/
├── example                             #接口使用样例
├── include
│   ├── micar_prop_interface.h          #接口定义
│   ├── micar_prop_types.h              #信号类型定义
│   ├── micar_prop_value_generic.h      #通用信号值
│   └── micar_prop_value.h              #信号值
├── README.md
└── src                                 #接口实现

二、信号

信号值传输结构体

struct VehiclePropValue {
  enum class VehiclePropStatus {
    AVAILABLE       = 0,
    UNAVAILABLE     = 1,
    ERROR           = 2
  };
  int32_t               prop;
  int64_t               time_stamp;  // required for valid data from HAL, skipped for set
  VehiclePropStatus      status;  // required for valid data from HAL, skipped for set
 
  // values
  int32_t                             area_id;
  std::vector<int32_t>                int32_values;  // this also covers boolean value.
  std::vector<int64_t>                int64_values;
  std::vector<float>                  float_values;
  std::vector<unsigned char>          bytes_value;
  std::string                         string_value;
};

信号值解析

enum class MiVehicleProperty : int32_t {
  // ...
  BASIC_INFO_POWER_MODE = 1631613447 /* (0x07 | MiVehicleZoneDriving:BASIC_INFO | MiVehiclePropertyGroup:MICAR |
    VehiclePropertyType:INT32 | VehicleArea:GLOBAL), ValueEnum = BasicInfoPowerMode */,
    // ...
};
 
struct BasicInfoPowerMode : PropValDefMapping<BasicInfoPowerMode,
    MiVehicleProperty::BASIC_INFO_POWER_MODE> {
  static const int32_t OFF = 0;
  static const int32_t AWAKE = 1;
  static const int32_t ACC = 2;
  static const int32_t ON = 3;
  static const int32_t START = 3;
};

如上定义,可通过如下方式使用信号值。

#include "micar_prop_value.h"
auto valDef = propToPropValDef<MiVehicleProperty::BASIC_INFO_POWER_MODE>{};
if (propval == valDef.OFF) {
  // ...
}

三、接口说明

获取实例

static std::unique_ptr<PropClient> getPropClientInstance(std::string);

通过该接口获取client实例(获取实例后需要调用waitServiceReady接口等待服务初始化的完成)其余所有的调用需要通过该实例来完成。参数为使用该接口的应用名,方便获取日志。

CallStatus waitServiceReady(uint32_t timeoutMs = UINT32_MAX);

阻塞接口,等待服务初始化完成之后会返回OK,入参timeoutMs为最大等待时间,超过该时间服务未初始化好会返回TIMEOUT。

get方法

CallStatus PropClient::getProp(int32_t prop, int32_t area, VehiclePropValue *value);

通过该接口阻塞的获取信号值。通过prop,area指定信号,信号值存在value中。

set方法

CallStatus PropClient::setProp(constVehiclePropValue&value);

阻塞的set一个信号值

subscribe

void subscribe(conststd::set<int32_t>&props, std::unique_ptr<Callback> cb);

通过该接口注册props中信号的回调函数,这些信号有变化时会调用指定的回调。

**2023.1月新增:**在首次订阅的时候,会主动获取到信号的当前状态来执行注册的回调函数。

Unsubscribe

void unsubscribe(conststd::set<int32_t>&props);

取消props中信号之前注册的回调。

四、使用说明

引用:bazel工程适配说明(docx,递归候选)

直接使用

使用前需要执行8295_DIR/apps/micar/bazel_build_base/scripts/build_micar_base.sh

头文件路径: 8295_DIR/apps/micar/install/include

动态库路径:8295_DIR/apps/micar/install/lib/libprop_interface.so(gnu)

动态库路径:8295_DIR/apps/micar/install/lib/libprop_interface_normal.so(llvm)

DCD上动态库路径:/emmc/svp/lib

通过bazel添加项目依赖

cc_binary(
    name = "cpp_example",
    srcs = [
        "client.cpp",
    ],
    deps = [
        "@micar//apps/CarService/libs:prop_interface",
    ],
    linkstatic = False,
)

通过bazel单独编译

cd 8295_DIR/apps/micar
 
source env_bazel_set.sh
 
# llvm
bazel build apps/CarService/libs:prop_interface_pkg --config=qnx_aarch_gnu_64
# gnu
bazel build apps/CarService/libs:prop_interface_deprecated_lib_pkg --config=qnx_aarch_gnu_64

编译产物位于8295_DIR/apps/micar/bazel-bin/apps/CarService/libs/

五、其他工具

qnx信号mock:pps_mock工具使用方法(docx,递归候选)