一、下载
注:需要记住以下安装的三个库的路径!!!
1、安装boost库:https://sourceforge.net/projects/boost/files/boost-binaries/
2、安装3.4.10vsomeip库:https://github.com/COVESA/vsomeip
3、 安装pybind11库、numpy 库:python使用c++的库
pybind11的使用:
【Pybind11】pybind11在visual studio中的配置_如何在vs中使用pybind11-CSDN博客
4、VS安装:Thank You for Downloading Visual Studio Community Edition
5、安装python-3.9.13-amd64.exe(必须安装这个版本!!!)
二、前提条件
下载VS2022,以下执行的指令均在VS的终端里执行
三、安装步骤:
1、安装boost库:
- 下载boost_1_65_0-msvc-14.1-64.exe
- 双击boost_1_65_0-msvc-14.1-64.exe安装(记住安装路径)
2、安装3.4.10vsomeip库:
(1)修改根目录CMakeLists.txt,加入hello_world文件,
(2)在E:\vsomeip-master下创建build目录,打开命令行进入E:\vsomeip-master\build执行:
将指令中的-DBOOST_ROOT改为所安装的boost库的路径
cmake -G “Visual Studio 17 2022” .. -DBOOST_ROOT=E:\Boost-Vsomeip\boost_1_65_0 -DBoost_USE_STATIC_LIBS=ON
(3)点击vsomeip.sln打开工程,右键ALL_BUILD和example->生成,等待编译完成
(4)生成的vsomeip库:
3、 安装pybind11库
pip install pybind11 -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com
如果安装不上可能是python的setuptools出问题了 卸载一下再安装
pip uninstall setuptools
pip install setuptools -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com
4、安装numpy
pip install numpy -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com
5、查看pybind11安装目录:
pip uninstall pybind11(不要输入y)
四、域间通信
1、Ubuntu
(1)修改vsomeip.json
- 修改IP:本机地址
- 修改routing:my_first_adaptive_service_provider_process
{
"unicast": "192.168.186.148",
"netmask": "255.255.255.0",
"logging":
{
"level": "debug",
"console": "false",
"file":
{
"enable": "false",
"path": "/var/log/vsomeip.log"
},
"dlt": "false"
},
"applications":
[
{
"name": "my_first_adaptive_service_provider_process",
"id": "0x1129"
},
{
"name": "my_first_adaptive_service_consumer_process",
"id": "0xf610"
}
],
"services":
[
{
"service": "0x0",
"name": "my_first_adaptive_service_interface",
"instance": "0x1",
"unreliable": "31402",
"methods":
[
{
"name":"MyMethodReadFile",
"id":"0x1",
"is_reliable": "false"
},
{
"name":"MyMethodWriteFile",
"id":"0x2",
"is_reliable": "false"
},
{
"name":"my_field",
"id":"0x3",
"is_reliable": "false"
}
],
"events":
[
{
"event": "0xfff8",
"event_name": "my_event",
"is_field": "false",
"is_reliable": "false"
},
{
"event": "0xfff9",
"event_name": "my_field",
"is_field": "true",
"is_reliable": "false"
}
],
"eventgroups":
[
{
"eventgroup": "0x1",
"events":
[
"0xfff8",
"0xfff9"
]
}
]
}
],
"clients":
[
{
"service": "0x0",
"name": "my_first_adaptive_service_interface",
"instance": "0x1",
"unreliable": "31403",
"methods":
[
{
"name":"MyMethodReadFile",
"id":"0x1",
"is_reliable": "false"
},
{
"name":"MyMethodWriteFile",
"id":"0x2",
"is_reliable": "false"
},
{
"name":"my_field",
"id":"0x3",
"is_reliable": "false"
}
],
"events":
[
{
"event": "0xfff8",
"event_name": "my_event",
"is_field": "false",
"is_reliable": "false"
},
{
"event": "0xfff9",
"event_name": "my_field",
"is_field": "true",
"is_reliable": "false"
}
],
"eventgroups":
[
{
"eventgroup": "0x1",
"events":
[
"0xfff8",
"0xfff9"
]
}
]
}
],
"routing": "my_first_adaptive_service_provider_process",
"service-discovery":
{
"enable" : "true",
"multicast" : "224.0.0.11",
"port" : "12330",
"protocol" : "udp",
"initial_delay_min" : "10",
"initial_delay_max" : "100",
"repetitions_base_delay" : "200",
"repetitions_max" : "3",
"ttl" : "3",
"cyclic_offer_delay" : "2000",
"request_response_delay" : "1500"
}
}
2、Windows
(1)将目录下的文件vsomeip-master\examples\hello_world\helloworld-local.json复制到hello_world_service.exe所在目录,修改json文件
{
"unicast": "192.168.186.1",
"logging" :
{
"level" : "debug",
"console" : "true",
"file" : { "enable" : "false", "path" : "/tmp/vsomeip.log" },
"dlt" : "false"
},
"applications": [
{
"name": "hello_world_client",
"id": "0x5555"
}
],
"services": [
{
"service": "0x0",
"instance": "0x1",
"unreliable": "31402"
}
],
"routing": "hello_world_client",
"service-discovery" :
{
"enable" : "true",
"multicast" : "224.0.0.11",
"port" : "12330",
"protocol" : "udp",
"initial_delay_min" : "10",
"initial_delay_max" : "100",
"repetitions_base_delay" : "200",
"repetitions_max" : "3",
"ttl" : "3",
"cyclic_offer_delay" : "2000",
"request_response_delay" : "1500"
}
}
(2)修改源码,改完源码后 一定记得重新编译!!!
文件hello_world_client.hpp中的service_id、service_instance_id 、service_method_id 改为服务端对应值
(3)起hello_world_client.exe,当前目录启动VS终端,执行如下bat(使用时,去掉注释内容)
#设置环境变量
@ECHO OFF
SETLOCAL
#添加boost和vsomeip库路径
set PATH=%PATH%;E:\Boost-Vsomeip\vsomeip-master\build\Debug;E:\Boost-Vsomeip\boost_1_65_0\lib64-msvc-14.1
set VSOMEIP_CONFIGURATION=E:\Boost-Vsomeip\vsomeip-master\build\examples\hello_world\Debug\helloworld-local.json
set VSOMEIP_APPLICATION_NAME=hello_world_client
#启动程序
hello_world_client.exe
五、Xcp代码的使用
(一)服务端
1、添加对应的etc文件和exampel.jsion文件
2、修改vsomeip.json的IP
(二)客户端
1、example文件
(1)更改文件example.cpp中的.py文件的路径,重新生成example.pyd,将重新生成的pyd替换Pytest文件中的example.pyd
2、Pytest文件
(1)修改jsion文件的IP
(2)修改路径client.bat脚本中vsomeip库、boost库、helloworld-local.json的路径
(3)将vsomeip和boost的动态库放到.py同级路径
(三)联调
启动服务端:执行可执行文件
启动客户端:执行client.bat脚本