前言:当你学习了SOMEIP理论基础后,一定很希望上手实操一波吧,本文档以SOMEIP协议里比较成熟的VSOMEIP开源框架为例,带你从0到1实现开源框架的下载到上手,坐稳啦,开车!!!!
1. 下载源码:
在linux终端输入或者windows的minGW里输入:
git clone Gitee 极速下载/vsomeipGitee 极速下载/vsomeiphttps://gitee.com/mirrors/vsomeip.git
完成所有编译工作后的目录结构如下:
2. 必要包的安装:
由于linux版本之间有差异性,难以全部罗列,统一以ubuntu20.04举例说明:
请敲以下命令完成boost以及其他
代码 |
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路径下。编译vsomeip库,请执行以下命令:
代码 |
mkdir build
cd build
cmake ..
make
sudo make install |
完成所有工作后的记录如下:
4. 编译官方提供的helloworld测试案例(熟手跳过)
(可以参考官方关于helloworld案例的readme提示:../vsomeip/examples/hello_world/readme)
请cd 到/examples/hello_world路径下:执行同样的编译命令
代码 |
mkdir build
cd build
cmake ..
make |
编译过程如下图所示:
5. 执行helloworld测试用例:
5.1 请注意,官方helloworld教程关于“Running Hello World Example”部分有误,需要按照以下方式修改:
把helloworld目录下的helloworld-local.json 复制到build目录里去。
给小白的提示:假设您现在处以 /vsomeip/examples/hello_world/build 路径下,请执行以下代码:
代码 |
cp ../helloworld-local.json ./ |
复制完成后helloworld的build应该和我一样。如下图所示:
5.2 开两个终端,执行程序:(直接复制粘贴代码)
终端1运行 service端:
env VSOMEIP_CONFIGURATION=./helloworld-local.json \
VSOMEIP_APPLICATION_NAME=hello_world_service \
./hello_world_service
终端2运行 client端:
env VSOMEIP_CONFIGURATION=./helloworld-local.json \
VSOMEIP_APPLICATION_NAME=hello_world_client \
./hello_world_client
Tips:如果提示:Configuration module could not be loaded!请在../vsomeip/examples/hello_world/build路径下输入以下命令完成链接工作,再执行上述执行命令。
代码 |
sudo ldconfig |
5.3 测试结果:
服务端:
2023-03-16 11:14:47.394718 [info] vSomeIP 3.3.0 | (default)
2023-03-16 11:14:57.400489 [info] vSomeIP 3.3.0 | (default)
2023-03-16 11:14:58.263600 [info] Application/Client 5555 is registering.
2023-03-16 11:14:58.264118 [info] Client [4444] is connecting to [5555] at /tmp/vsomeip-5555
2023-03-16 11:14:58.268696 [info] REGISTERED_ACK(5555)
2023-03-16 11:14:58.376506 [info] REQUEST(5555): [1111.2222:255.4294967295]
2023-03-16 11:14:58.387110 [info] RELEASE(5555): [1111.2222]
2023-03-16 11:14:58.388448 [info] Application/Client 5555 is deregistering.
2023-03-16 11:14:58.399715 [info] receive_cbk local_uds_client_endpoint: connection_reset/EOF/bad_descriptor
2023-03-16 11:14:58.496182 [info] Client [4444] is closing connection to [5555]
2023-03-16 11:15:03.385937 [info] STOP OFFER(4444): [1111.2222:0.0] (true)
2023-03-16 11:15:03.387130 [info] Stopping vsomeip application "hello_world_service" (4444).
客户端:
私人信息脱敏/someipCode/vsomeip/examples/hello_world/build$ env VSOMEIP_CONFIGURATION=./helloworld-local.json \
> VSOMEIP_APPLICATION_NAME=hello_world_client \
> ./hello_world_client
2023-03-16 11:14:58.257083 [info] Using configuration file: "./helloworld-local.json".
2023-03-16 11:14:58.257952 [info] Parsed vsomeip configuration in 0ms
2023-03-16 11:14:58.258019 [info] Configuration module loaded.
2023-03-16 11:14:58.258052 [info] Initializing vsomeip application "hello_world_client".
2023-03-16 11:14:58.258194 [info] Instantiating routing manager [Proxy].
2023-03-16 11:14:58.258368 [info] Client [5555] is connecting to [0] at /tmp/vsomeip-0
2023-03-16 11:14:58.258511 [info] Application(hello_world_client, 5555) is initialized (11, 100).
2023-03-16 11:14:58.258655 [info] Starting vsomeip application "hello_world_client" (5555) using 2 threads I/O nice 255
2023-03-16 11:14:58.259440 [info] shutdown thread id from application: 5555 (hello_world_client) is: 7f516931d700 TID: 78921
2023-03-16 11:14:58.260555 [info] io thread id from application: 5555 (hello_world_client) is: 7f5169bc0000 TID: 78919
2023-03-16 11:14:58.260802 [info] io thread id from application: 5555 (hello_world_client) is: 7f5168b1c700 TID: 78922
2023-03-16 11:14:58.262858 [info] create_local_server: Listening @ /tmp/vsomeip-5555
2023-03-16 11:14:58.263042 [info] Client 5555 (hello_world_client) successfully connected to routing ~> registering..
2023-03-16 11:14:58.263117 [info] Registering to routing manager @ vsomeip-0
2023-03-16 11:14:58.263629 [info] main dispatch thread id from application: 5555 (hello_world_client) is: 7f5169b1e700 TID: 78920
2023-03-16 11:14:58.268148 [info] Application/Client 5555 (hello_world_client) is registered.
2023-03-16 11:14:58.378331 [info] ON_AVAILABLE(5555): [1111.2222:0.0]
Sending: World
2023-03-16 11:14:58.379275 [info] Client [5555] is connecting to [4444] at /tmp/vsomeip-4444
Received: Hello World
2023-03-16 11:14:58.386383 [info] Stopping vsomeip application "hello_world_client" (5555).
2023-03-16 11:14:58.389704 [info] Application/Client 5555 (hello_world_client) is deregistered.
2023-03-16 11:14:58.390784 [info] Client [5555] is closing connection to [4444]