app开发定制vsomeip环境搭建及helloworld测试例跑通

SOME/IP开源库vsomeip系列分析

1. 代码拉取

vsomeipapp开发定制相关代码可以直接从github上获取,如下:

git clone https://github.com/COVESA/vsomeip.git

2. app开发定制源码编译及测试例运行

vsomeipapp开发定制工程源码编译方法,app开发定制参考源码中的README文档,内容如下:

  1. ### vsomeip
  2. ##### Copyright
  3. Copyright (C) 2015-2017, Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
  4. ##### License
  5. This Source Code Form is subject to the terms of the Mozilla Public
  6. License, v. 2.0. If a copy of the MPL was not distributed with this
  7. file, You can obtain one at http://mozilla.org/MPL/2.0/.
  8. ##### vsomeip Overview
  9. ----------------
  10. The vsomeip stack implements the http://some-ip.com/ (Scalable service-Oriented
  11. MiddlewarE over IP (SOME/IP)) protocol. The stack consists out of:
  12. * a shared library for SOME/IP (`libvsomeip3.so`)
  13. * a second shared library for SOME/IP's service discovery (`libvsomeip3-sd.so`)
  14. which is loaded during runtime if the service discovery is enabled.
  15. ##### Build Instructions for Linux
  16. ###### Dependencies
  17. - A C++11 enabled compiler like gcc >= 4.8 is needed.
  18. - vsomeip uses CMake as buildsystem.
  19. - vsomeip uses Boost >= 1.55:
  20. Ubuntu 14.04:
  21. `sudo apt-get install libboost-system1.55-dev libboost-thread1.55-dev libboost-log1.55-dev`
  22. Ubuntu 12.04: a PPA is necessary to use version 1.54 of Boost:
  23. -- URL: https://launchpad.net/~boost-latest/+archive/ubuntu/ppa
  24. --`sudo add-apt-repository ppa:boost-latest/ppa`
  25. --`sudo apt-get install libboost-system1.55-dev libboost-thread1.55-dev
  26. libboost-log1.55-dev`
  27. For the tests Google's test framework https://code.google.com/p/googletest/[gtest] in version 1.7.0 is needed.
  28. -- URL: https://googletest.googlecode.com/files/gtest-1.7.0.zip
  29. To build the documentation asciidoc, source-highlight, doxygen and graphviz is needed:
  30. --`sudo apt-get install asciidoc source-highlight doxygen graphviz`
  31. ###### Compilation
  32. For compilation call:
  33. ```bash
  34. mkdir build
  35. cd build
  36. cmake ..
  37. make
  38. ```
  39. To specify a installation directory (like `--prefix=` if you're used to autotools) call cmake like:
  40. ```bash
  41. cmake -DCMAKE_INSTALL_PREFIX:PATH=$YOUR_PATH ..
  42. make
  43. make install
  44. ```
  45. ###### Compilation with predefined unicast and/or diagnosis address
  46. To predefine the unicast address, call cmake like:
  47. ```bash
  48. cmake -DUNICAST_ADDRESS=<YOUR IP ADDRESS> ..
  49. ```
  50. To predefine the diagnosis address, call cmake like:
  51. ```bash
  52. cmake -DDIAGNOSIS_ADDRESS=<YOUR DIAGNOSIS ADDRESS> ..
  53. ```
  54. The diagnosis address is a single byte value.
  55. ###### Compilation with custom default configuration folder
  56. To change the default configuration folder, call cmake like:
  57. ```bash
  58. cmake -DDEFAULT_CONFIGURATION_FOLDER=<DEFAULT CONFIGURATION FOLDER> ..
  59. ```
  60. The default configuration folder is /etc/vsomeip.
  61. ###### Compilation with custom default configuration file
  62. To change the default configuration file, call cmake like:
  63. ```bash
  64. cmake -DDEFAULT_CONFIGURATION_FILE=<DEFAULT CONFIGURATION FILE> ..
  65. ```
  66. The default configuration file is /etc/vsomeip.json.
  67. ###### Compilation with signal handling
  68. To compile vsomeip with signal handling (SIGINT/SIGTERM) enabled, call cmake like:
  69. ```bash
  70. cmake -DENABLE_SIGNAL_HANDLING=1 ..
  71. ```
  72. In the default setting, the application has to take care of shutting down vsomeip in case these signals are received.
  73. ##### Build Instructions for Android
  74. ###### Dependencies
  75. - vsomeip uses Boost >= 1.55. The boost libraries (system, thread and log) must be included in the Android source tree and integrated into the build process with an appropriate Android.bp file.
  76. ###### Compilation
  77. In general for building the Android source tree the instructions found on the pages from the Android Open Source Project (AOSP) apply (https://source.android.com/setup/build/requirements).
  78. To integrate the vsomeip library into the build process, the source code together with the Android.bp file has to be inserted into the Android source tree (by simply copying or by fetching with a custom platform manifest).
  79. When building the Android source tree, the Android.bp file is automatically found and considered by the build system.
  80. In order that the vsomeip library is also included in the Android image, the library has to be added to the PRODUCT_PACKAGES variable in one of a device/target specific makefile:
  81. ```
  82. PRODUCT_PACKAGES += \
  83. libvsomeip \
  84. libvsomeip_cfg \
  85. libvsomeip_sd
  86. ```

 

2.1.安装依赖

由于我的ubuntu版本是18.04,官方文档上的对应包的版本过低,因此这里不需要指定对应的boost包版本号

  1. sudo apt-get install libboost-system-dev libboost-thread-dev libboost-log-dev
  2. sudo apt-get install asciidoc source-highlight doxygen graphviz

若上述安装遇到报错,一般是有对应的编译工具没有安装导致的。通常只需要安装对应的编译工具即可解决,如下:

sudo apt-get install gcc g++ make

2.2 编译vsomeip

进入下载的工程源码根目录,因为vsomeip是通过cmake对工程进行管理的,则新建build目录,进行如下操作:

  1. mkdir build
  2. cd build
  3. cmake ..
  4. make

make之后工程结构:

出现如上工程结构,则说明已经成功编译了源码,相关的库文件如上截图所示。

2.3编译源码自带的测试例——hello_world

分析从也是从源码自带的hello_world程序开始,因此先编译对应的helloworld程序。

hello_world程序的编译方法可以查看其自带的readme文件,内容如下:

  1. # Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
  2. # This Source Code Form is subject to the terms of the Mozilla Public
  3. # License, v. 2.0. If a copy of the MPL was not distributed with this
  4. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. Build instructions for Hello World example
  6. ------------------------------------------
  7. 1. Build whole project at first:
  8. ________________________________
  9. cd <root directory of vSomeIP-Lib>$:
  10. mkdir build
  11. cd build
  12. cmake ..
  13. make
  14. sudo make install
  15. 2. Build hello_world target
  16. ___________________________
  17. cmake --build . --target hello_world
  18. cd ./examples/hello_world/
  19. make
  20. Running Hello World Example
  21. ---------------------------
  22. The Hello World Example should be run on the same host.
  23. The network addresses within the configuration files need to be adapted to match
  24. the devices addresses.
  25. To start the hello world client and service from their build-directory do:
  26. HOST1:
  27. VSOMEIP_CONFIGURATION=../helloworld-local.json \
  28. VSOMEIP_APPLICATION_NAME=hello_world_service \
  29. ./hello_world_service
  30. HOST1:
  31. VSOMEIP_CONFIGURATION=../helloworld-local.json \
  32. VSOMEIP_APPLICATION_NAME=hello_world_client \
  33. ./hello_world_client
  34. Expected output service
  35. -----------------------
  36. 2015-04-01 11:31:13.248437 [info] Using configuration file: ../helloworld-local.json
  37. 2015-04-01 11:31:13.248766 [debug] Routing endpoint at /tmp/vsomeip-0
  38. 2015-04-01 11:31:13.248913 [info] Service Discovery disabled. Using static routing information.
  39. 2015-04-01 11:31:13.248979 [debug] Application(hello_world_service, 4444) is initialized.
  40. 2015-04-01 11:31:22.705010 [debug] Application/Client 5555 got registered!
  41. Expected output client
  42. ----------------------
  43. 2015-04-01 11:31:22.704166 [info] Using configuration file: ../helloworld-local.json
  44. 2015-04-01 11:31:22.704417 [debug] Connecting to [0] at /tmp/vsomeip-0
  45. 2015-04-01 11:31:22.704630 [debug] Listening at /tmp/vsomeip-5555
  46. 2015-04-01 11:31:22.704680 [debug] Application(hello_world_client, 5555) is initialized.
  47. Sending: World
  48. Received: Hello World

相关的编译命令如下:

  1. cmake --build . --target hello_world
  2. cd ./examples/hello_world/
  3. make

3. 测试例运行前准备

通过readme可知,运行程序需要加载指定的配置文件helloworld-local.json, 当前目录下没有该配置文件,需要手动拷贝到当前目录的上一级目录,以当下测试为例:

  • 可执行程序所在目录:/home/nvidia/data/xw/vsomeip/build/examples/hello_world

  • helloworld-local.json配置文件需要拷贝到可执行程序的上一级目录位置:/home/nvidia/data/xw/vsomeip/build/examples

注意:helloworld-local.json配置文件在工程目录:/home/nvidia/data/xw/vsomeip/examples/hello_world位置处可找到,如下:

4. 运行测试:

//server 端

//测试命令,复制如下全部命令,粘贴到终端,按下enter键运行:
  1. VSOMEIP_CONFIGURATION=../helloworld-local.json \
  2. VSOMEIP_APPLICATION_NAME=hello_world_service \
  3. ./hello_world_service

//运行结果如下:

  1. nvidia@nvidia-master:~/data/xw/vsomeip/build/examples/hello_world$ VSOMEIP_CONFIGURATION=../helloworld-local.json \
  2. > VSOMEIP_APPLICATION_NAME=hello_world_service \
  3. > ./hello_world_service
  4. 2022-05-15 14:19:57.214866 [info] Parsed vsomeip configuration in 1ms
  5. 2022-05-15 14:19:57.217071 [info] Using configuration file: "../helloworld-local.json".
  6. 2022-05-15 14:19:57.217994 [info] Configuration module loaded.
  7. 2022-05-15 14:19:57.218612 [info] Initializing vsomeip application "hello_world_service".
  8. 2022-05-15 14:19:57.220857 [info] Instantiating routing manager [Host].
  9. 2022-05-15 14:19:57.221919 [info] create_local_server Routing endpoint at /tmp/vsomeip-0
  10. 2022-05-15 14:19:57.224044 [info] Application(hello_world_service, 4444) is initialized (11, 100).
  11. 2022-05-15 14:19:57.224674 [info] Starting vsomeip application "hello_world_service" (4444) using 2 threads I/O nice 255
  12. 2022-05-15 14:19:57.227687 [info] main dispatch thread id from application: 4444 (hello_world_service) is: 7f8eda11d0 TID: 1348
  13. 2022-05-15 14:19:57.228521 [info] shutdown thread id from application: 4444 (hello_world_service) is: 7f8e5a01d0 TID: 1349
  14. 2022-05-15 14:19:57.232458 [info] Watchdog is disabled!
  15. 2022-05-15 14:19:57.238391 [info] OFFER(4444): [1111.2222:0.0] (true)
  16. 2022-05-15 14:19:57.238942 [info] io thread id from application: 4444 (hello_world_service) is: 7f8fc90010 TID: 1346
  17. 2022-05-15 14:19:57.242660 [info] vSomeIP 3.1.20.3 | (default)
  18. 2022-05-15 14:19:57.239282 [info] io thread id from application: 4444 (hello_world_service) is: 7f8d59e1d0 TID: 1351
  19. 2022-05-15 14:19:57.243613 [info] Listening at /tmp/vsomeip-4444
  20. 2022-05-15 14:19:58.484243 [info] Application/Client 5555 is registering.
  21. 2022-05-15 14:19:58.489425 [info] Client [4444] is connecting to [5555] at /tmp/vsomeip-5555
  22. 2022-05-15 14:19:58.497555 [info] REGISTERED_ACK(5555)
  23. 2022-05-15 14:19:58.601259 [info] REQUEST(5555): [1111.2222:255.4294967295]
  24. 2022-05-15 14:19:58.620860 [info] RELEASE(5555): [1111.2222]
  25. 2022-05-15 14:19:58.624073 [info] Application/Client 5555 is deregistering.
  26. 2022-05-15 14:19:58.729081 [info] Client [4444] is closing connection to [5555]
  27. 2022-05-15 14:20:03.618335 [info] STOP OFFER(4444): [1111.2222:0.0] (true)
  28. 2022-05-15 14:20:03.623931 [info] Stopping vsomeip application "hello_world_service" (4444).

//截图如下

//client 端

//测试命令,复制如下全部命令,enter运行
  1. VSOMEIP_CONFIGURATION=../helloworld-local.json \
  2. VSOMEIP_APPLICATION_NAME=hello_world_client \
  3. ./hello_world_client

//运行结果如下:

  1. nvidia@nvidia-master:~/data/xw/vsomeip/build/examples/hello_world$ VSOMEIP_CONFIGURATION=../helloworld-local.json \
  2. > VSOMEIP_APPLICATION_NAME=hello_world_client \
  3. > ./hello_world_client
  4. 2022-05-15 14:19:58.453265 [info] Parsed vsomeip configuration in 1ms
  5. 2022-05-15 14:19:58.455301 [info] Using configuration file: "../helloworld-local.json".
  6. 2022-05-15 14:19:58.456176 [info] Configuration module loaded.
  7. 2022-05-15 14:19:58.456714 [info] Initializing vsomeip application "hello_world_client".
  8. 2022-05-15 14:19:58.457180 [info] Instantiating routing manager [Proxy].
  9. 2022-05-15 14:19:58.457835 [info] Client [5555] is connecting to [0] at /tmp/vsomeip-0
  10. 2022-05-15 14:19:58.458461 [info] Application(hello_world_client, 5555) is initialized (11, 100).
  11. 2022-05-15 14:19:58.459481 [info] Starting vsomeip application "hello_world_client" (5555) using 2 threads I/O nice 255
  12. 2022-05-15 14:19:58.463607 [info] main dispatch thread id from application: 5555 (hello_world_client) is: 7f8693b1d0 TID: 1353
  13. 2022-05-15 14:19:58.463384 [info] shutdown thread id from application: 5555 (hello_world_client) is: 7f8613a1d0 TID: 1354
  14. 2022-05-15 14:19:58.474254 [info] io thread id from application: 5555 (hello_world_client) is: 7f87029010 TID: 1352
  15. 2022-05-15 14:19:58.474509 [info] io thread id from application: 5555 (hello_world_client) is: 7f7ffff1d0 TID: 1355
  16. 2022-05-15 14:19:58.482142 [info] Listening at /tmp/vsomeip-5555
  17. 2022-05-15 14:19:58.483037 [info] Client 5555 (hello_world_client) successfully connected to routing ~> registering..
  18. 2022-05-15 14:19:58.495687 [info] Application/Client 5555 (hello_world_client) is registered.
  19. 2022-05-15 14:19:58.604220 [info] ON_AVAILABLE(5555): [1111.2222:0.0]
  20. Sending: World
  21. 2022-05-15 14:19:58.607258 [info] Client [5555] is connecting to [4444] at /tmp/vsomeip-4444
  22. Received: Hello World
  23. 2022-05-15 14:19:58.620268 [info] Stopping vsomeip application "hello_world_client" (5555).
  24. 2022-05-15 14:19:58.626685 [info] Application/Client 5555 (hello_world_client) is deregistered.
  25. 2022-05-15 14:19:58.631236 [info] Client [5555] is closing connection to [4444]

//运行截图


过程中遇到的问题记录:

  1. nvidia@nvidia-master:~/data/xw/vsomeip/build/examples$ ./notify-sample
  2. Configuration module could not be loaded!

解决方法:

  1. nvidia@nvidia-master:~/data/xw/vsomeip/build$ sudo make install
  2. nvidia@nvidia-master:~/data/xw/vsomeip/build/examples$ sudo ldconfig

顺利运行:

网站建设定制开发 软件系统开发定制 定制软件开发 软件开发定制 定制app开发 app开发定制 app开发定制公司 电商商城定制开发 定制小程序开发 定制开发小程序 客户管理系统开发定制 定制网站 定制开发 crm开发定制 开发公司 小程序开发定制 定制软件 收款定制开发 企业网站定制开发 定制化开发 android系统定制开发 定制小程序开发费用 定制设计 专注app软件定制开发 软件开发定制定制 知名网站建设定制 软件定制开发供应商 应用系统定制开发 软件系统定制开发 企业管理系统定制开发 系统定制开发