[someip专题]vsomeip使用以及代码解析1

本文在linux ubuntu 18.04版本上进行运行。

1. someip基础知识

参考

2.vsomeip 准备工作

2.1 vsomeip 源码下载

2.2 依赖项下载

vsomeip 主要依赖boost库,因此需要下载boost,同时采用g++ cmake进行编译。

    A C++11 enabled compiler like gcc >= 4.8 is needed. vsomeip uses CMake as buildsystem. vsomeip uses Boost >= 1.55:
sudo apt-get install libboost-system-dev libboost-thread-dev libboost-log-dev
sudo apt-get install asciidoc source-highlight doxygen graphviz
sudo apt-get install gcc g++ make

3.vsomeip 编译

进入vsomeip 目录

mkdir build
cd build
cmake ..
make

此处会编译出vsomeip库

接着,我们可以使用其中的Hello world 案例来进一步进行编译使用;

cmake --build . --target hello_world
cd ./examples/hello_world/
make

编译完成后,在目录下生成两个可执行文件 hello_world_client 和 hello_world_service

接着就可以继续执行Helloworld程序了。

4. vsomeip helloworld使用

在执行前,先将 配置 json文件拷贝到执行目录下

启动服务端

VSOMEIP_CONFIGURATION=./helloworld-local.json 
VSOMEIP_APPLICATION_NAME=hello_world_service 
./hello_world_service

启动客户端

VSOMEIP_CONFIGURATION=./helloworld-local.json 
VSOMEIP_APPLICATION_NAME=hello_world_client 
./hello_world_client
[info] Using configuration file: ../helloworld-local.json [debug] Routing endpoint at /tmp/vsomeip-0 [info] Service Discovery disabled. Using static routing information. [debug] Application(hello_world_service, 4444) is initialized. [debug] Application/Client 5555 got registered!
[info] Using configuration file: ../helloworld-local.json [debug] Connecting to [0] at /tmp/vsomeip-0 [debug] Listening at /tmp/vsomeip-5555 [debug] Application(hello_world_client, 5555) is initialized. Sending: World Received: Hello World
经验分享 程序员 微信小程序 职场和发展