Dbus配置与运行

官方例程配置过程

[toc]

完成CommonAPI SomIP运行后,研究官网例程

因为利用了dbus,出现了一些问题,予以记录

安装

将E01HelloWorld从capicxx-core-tools-master.zip\capicxx-core-tools-master\CommonAPI-Examples\中拖出

利用generator工具重新生成src-gen.注意使用绝对路径.

dbus 错误

编译时,出现dbus错误.

重新安装capicxx-dbus-runtime-master,编译时,出现错误: error: ‘dbus_connection_send_with_reply_set_notify’ was not declared in this scope

在该github仓库的issue中,有人问了类似的问题,作者回答: You need to apply the patches (capicxx-dbus-runtime/tree/master/src/dbus-patches) to dbus before compiling capicxx-dbus-runtime.

参考了patch的用法https://www.cnblogs.com/xingboy/p/15954771.html,明白需要将补丁打到dbus上去.

曾利用命令,对dbus进行了安装

wget http://dbus.freedesktop.org/releases/dbus/dbus-1.10.10.tar.gz
tar -xzf dbus-1.10.10.tar.gz
cd dbus-1.10.10/
patch -p1 < </path/to/CommonAPI-D-Bus/src/dbus-patches/patch-names>.patch 
./configure
make -C dbus 
make -C dbus install
make install-pkgconfigDATA

patch理解

但是没有使用patch -p1 < </path/to/CommonAPI-D-Bus/src/dbus-patches/patch-names>.patch,也没有出错,以为patch是需要给capicxx-dbus-runtime-master打不补丁. patch中的终端输出也对思路产生了迷惑,因为其运行提示与文件DBusConnection.cpp,DBusConnection.hpp名称极为相似,有同在capicxx-dbus-runtime-master\src\下. 尝试多次patch后,扔无法成功.

回头看教程,发现是在dbus中进行patch. 从而在cd dbus-1.10.10/进行了patch,路径为绝对路径.

capi-dbus-1-pc.patch
capi-dbus-add-send-with-reply-set-notify.patch
capi-dbus-add-support-for-custom-marshalling.patch
capi-dbus-block-acquire-io-path-on-send.patch
capi-dbus-correct-dbus-connection-block-pending-call.patch
capi-dbus-send-with-reply-and-block-delete-reply-on-error.patch

现在想来,完全可以用脚本遍历:

for i in ../capicxx-dbus-runtime/src/dbus-patches/*.patch; do patch -p1 < $i; done

将其执行完后,再编译capicxx-dbus-runtime-master.

dbus编译

cd ./capicxx-dbus-runtime
make build
cd ./build
export PKG_CONFIG_PATH="../../dbus-1.10.10"
cmake -DUSE_INSTALLED_COMMONAPI=OFF -DUSE_INSTALLED_DBUS=OFF ..
make -j12

generator与编译

同样利用代码生成工具将sen-gen生成,具体见someip安装

src-gen下生成的文件如下:

E01HelloWorld.hpp
E01HelloWorldProxy.hpp
E01HelloWorldProxyBase.hpp
E01HelloWorldSomeIPDeployment.cpp
E01HelloWorldSomeIPDeployment.hpp
E01HelloWorldSomeIPProxy.cpp
E01HelloWorldSomeIPProxy.hpp
E01HelloWorldSomeIPStubAdapter.cpp
E01HelloWorldSomeIPStubAdapter.hpp
E01HelloWorldStub.hpp
E01HelloWorldStubDefault.hpp

同样CMakeLists.txt也存在问题,对其进行修改:

cmake_minimum_required(VERSION 2.8)
project(E01HelloWorld)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++0x")
include_directories(
    src-gen
    src
    /usr/local/include/CommonAPI-3.2
    /usr/local/include/vsomeip
)
link_directories(
    /usr/local/lib
)
add_executable(E01HelloWorldClient
        src/E01HelloWorldClient.cpp
        src-gen/v0/commonapi/examples/E01HelloWorldSomeIPProxy.cpp
        src-gen/v0/commonapi/examples/E01HelloWorldSomeIPDeployment.cpp
)

target_link_libraries(E01HelloWorldClient CommonAPI CommonAPI-SomeIP vsomeip3)
add_executable(E01HelloWorldService
        src/E01HelloWorldService.cpp
        src/E01HelloWorldStubImpl.cpp
        src-gen/v0/commonapi/examples/E01HelloWorldSomeIPStubAdapter.cpp
        src-gen/v0/commonapi/examples/E01HelloWorldSomeIPDeployment.cpp
)

target_link_libraries(E01HelloWorldService CommonAPI CommonAPI-SomeIP vsomeip3)

add_library(E01HelloWorldShared SHARED  
#	src/pythonWrapper.cpp
        src/E01HelloWorldStubImpl.cpp
        src-gen/v0/commonapi/examples/E01HelloWorldSomeIPStubAdapter.cpp
        src-gen/v0/commonapi/examples/E01HelloWorldSomeIPDeployment.cpp
)

target_link_libraries(E01HelloWorldShared CommonAPI CommonAPI-SomeIP vsomeip3)
  • 同样需要注意vsomeip3的问题
  • 出现了src/pythonWrapper.cpp无法找到,故将其屏蔽

编译后,在build中产生

E01HelloWorldClient
E01HelloWorldService
libE01HelloWorldShared

运行

同样是两个终端

#t1:
touch vsomeio.json
VSOMEIP_APPLICATION_NAME=service-sample ./E01HelloWorldService
#t2:
VSOMEIP_APPLICATION_NAME=client-sample ./E01HelloWorldClient

client与service数据打通

updatedupdated2023-03-032023-03-03