【vsomeip】如何让vsomeip在双系统运行起来----(一)


前言

验证vsomeip可以在Host Linux和LXC 里面的Guest Linux之间进行通信。

  1. 验证vsomeip自带helloworld例程
  2. 创建helloworld的Service和client的配置文件
  3. 验证双机情况下vsomeip通信
  4. 验证LXC 内外系统的vsomeip通信

一、验证vsomeip自带helloworld例程

{
    "unicast":"127.0.0.1",
    "logging":
    {
        "level":"debug",
        "console":"true"
    },

    "applications":
    [
        {
            "name":"hello_world_service",
            "id":"0x4444"
        },

        {
            "name":"hello_world_client",
            "id":"0x5555"
        }
    ],

    "services":
    [
        {
            "service":"0x1111",
            "instance":"0x2222",
            "unreliable":"30509"
        }
    ],

    "routing":"hello_world_service",
    "service-discovery":
    {
        "enable":"false"
    }
}

unicast的地址要更换成127.0.0.1,说明是在本机内部运行。

will@will-OptiPlex-7050:~/work/vsomeip/examples/hello_world/build$ VSOMEIP_CONFIGURATION=../helloworld-local.json \
> VSOMEIP_APPLICATION_NAME=hello_world_client \
> ./hello_world_client
1 Configuration module could not be loaded!


Error fix:
will@will-OptiPlex-7050:~/work/vsomeip/examples/hello_world/build$ sudo ldconfig

按照readme的说明,直接copy执行命令来运行,要说明的是
1.vsomeip的配置需要import自己的JSON文件,否则会用到系统自带的default配置;
2.第一执行的时候会遇到配置模块无法加载的问题,执行一下 sudo ldconfig就能解决

1. 先运行服务端的APP

Run vsompip server side first:
will@will-OptiPlex-7050:~/work/vsomeip/examples/hello_world/build$ VSOMEIP_CONFIGURATION=../helloworld-local.json \
> VSOMEIP_APPLICATION_NAME=hello_world_service \
> ./hello_world_service

log会有 如下打印

2023-11-01 11:11:42.288696 [info] Using configuration file: "../helloworld-local.json".
2023-11-01 11:11:42.289278 [info] Parsed vsomeip configuration in 0ms
2023-11-01 11:11:42.289336 [info] Configuration module loaded.
2023-11-01 11:11:42.289392 [info] Security disabled!
2023-11-01 11:11:42.289424 [info] Initializing vsomeip (3.4.9.1) application "hello_world_service".
2023-11-01 11:11:42.289804 [info] Instantiating routing manager [Host].
2023-11-01 11:11:42.290299 [info] create_routing_root: Routing root @ /tmp/vsomeip-0
2023-11-01 11:11:42.290997 [info] Application(hello_world_service, 4444) is initialized (11, 100).
2023-11-01 11:11:42.291277 [info] Starting vsomeip application "hello_world_service" (4444) using 2 threads I/O nice 255
2023-11-01 11:11:42.291740 [info] Client [4444] routes unicast:134.86.56.94, netmask:255.255.255.0
2023-11-01 11:11:42.291761 [info] shutdown thread id from application: 4444 (hello_world_service) is: 7f2b3b98d700 TID: 19691
2023-11-01 11:11:42.291696 [info] main dispatch thread id from application: 4444 (hello_world_service) is: 7f2b3c18e700 TID: 19690
2023-11-01 11:11:42.293976 [info] Watchdog is disabled!
2023-11-01 11:11:42.294551 [info] io thread id from application: 4444 (hello_world_service) is: 7f2b3d234ec0 TID: 19687
2023-11-01 11:11:42.294549 [info] io thread id from application: 4444 (hello_world_service) is: 7f2b3a98b700 TID: 19693
2023-11-01 11:11:42.295082 [info] vSomeIP 3.4.9.1 | (default)
2023-11-01 11:11:42.295539 [info] create_local_server: Listening @ /tmp/vsomeip-4444
2023-11-01 11:11:42.295753 [info] OFFER(4444): [1111.2222:0.0] (true)
2023-11-01 11:11:52.297733 [info] vSomeIP 3.4.9.1 | (default)
2023-11-01 11:11:54.804669 [info] Application/Client 5555 is registering.
2023-11-01 11:11:54.805463 [info] Client [4444] is connecting to [5555] at /tmp/vsomeip-5555
2023-11-01 11:11:54.806854 [info] REGISTERED_ACK(5555)
2023-11-01 11:11:54.909201 [info] REQUEST(5555): [1111.2222:255.4294967295]
2023-11-01 11:11:54.924016 [info] RELEASE(5555): [1111.2222]
2023-11-01 11:11:54.925872 [info] Application/Client 5555 is deregistering.
2023-11-01 11:11:54.937450 [info] local_uds_client_endpoint_impl::receive_cbk Error: End of file
2023-11-01 11:11:54.029515 [info] Client [4444] is closing connection to [5555]
2023-11-01 11:11:59.923047 [info] STOP OFFER(4444): [1111.2222:0.0] (true)
2023-11-01 11:11:59.924874 [info] Stopping vsomeip application "hello_world_service" (4444).

2. 再运行客户端APP

Run vsompip client side :
will@will-OptiPlex-7050:~/work/vsomeip/examples/hello_world/build$ VSOMEIP_CONFIGURATION=../helloworld-local.json VSOMEIP_APPLICATION_NAME=hello_world_client ./hello_world_client

对应的log如下

2023-11-01 15:53:15.523921 [info] Using configuration file: "../helloworld-local.json".
2023-11-01 15:53:15.524468 [info] Parsed vsomeip configuration in 0ms
2023-11-01 15:53:15.524524 [info] Configuration module loaded.
2023-11-01 15:53:15.524576 [info] Security disabled!
2023-11-01 15:53:15.524608 [info] Initializing vsomeip (3.4.9.1) application "hello_world_client".
2023-11-01 15:53:15.524642 [info] Instantiating routing manager [Proxy].
2023-11-01 15:53:15.524799 [info] Client [5555] is connecting to [0] at /tmp/vsomeip-0
2023-11-01 15:53:15.524844 [info] Application(hello_world_client, 5555) is initialized (11, 100).
2023-11-01 15:53:15.524954 [info] Starting vsomeip application "hello_world_client" (5555) using 2 threads I/O nice 255
2023-11-01 15:53:15.526023 [info] main dispatch thread id from application: 5555 (hello_world_client) is: 7fb002dab700 TID: 23920
2023-11-01 15:53:15.526727 [info] io thread id from application: 5555 (hello_world_client) is: 7fb002e50000 TID: 23919
2023-11-01 15:53:15.526179 [info] shutdown thread id from application: 5555 (hello_world_client) is: 7fb0025aa700 TID: 23921
2023-11-01 15:53:15.526751 [info] io thread id from application: 5555 (hello_world_client) is: 7faffbfff700 TID: 23922
2023-11-01 15:53:15.528288 [info] create_local_server: Listening @ /tmp/vsomeip-5555
2023-11-01 15:53:15.528654 [info] Client 5555 (hello_world_client) successfully connected to routing  ~> registering..
2023-11-01 15:53:15.528712 [info] Registering to routing manager @ vsomeip-0
2023-11-01 15:53:15.530923 [info] Application/Client 5555 (hello_world_client) is registered.
2023-11-01 15:53:15.634773 [info] ON_AVAILABLE(5555): [1111.2222:0.0]
Sending: World
2023-11-01 15:53:15.635725 [info] Client [5555] is connecting to [4444] at /tmp/vsomeip-4444
Received: Hello World
2023-11-01 15:53:15.639340 [info] Stopping vsomeip application "hello_world_client" (5555).
2023-11-01 15:53:15.641279 [info] Application/Client 5555 (hello_world_client) is deregistered.
2023-11-01 15:53:15.641723 [info] local_uds_client_endpoint_impl::receive_cbk Error: Operation canceled
2023-11-01 15:53:15.641806 [info] Client [5555] is closing connection to [4444]
2023-11-01 15:53:15.641830 [info] local_uds_client_endpoint_impl::receive_cbk Error: Operation canceled

log后端有出现一些error, “local_uds_client_endpoint_impl::receive_cbk Error: Operation canceled”,找了很久也没 找到原因,但是应该不影响验证vsomeip的验证。

二、创建helloworld的Service和client的配置文件

在这里插入图片描述

1. 修改代码

  1. hello_world_service.hpp
bool init(){
        
        setenv("VSOMEIP_CONFIGURATION", "../helloworld-service.json", 1);
        setenv("VSOMEIP_APPLICATION_NAME", "hello_world_service", 1);
  1. hello_world_client.hpp
bool init(){
        
        setenv("VSOMEIP_CONFIGURATION", "../helloworld-client.json", 1);
        setenv("VSOMEIP_APPLICATION_NAME", "hello_world_client", 1);

2. 运行测试APP

4. Rebuild vsomeip source code and the run service side in advanced
will@will-OptiPlex-7050:~/work/vsomeip/examples/hello_world/build$ make clean
will@will-OptiPlex-7050:~/work/vsomeip/examples/hello_world/build$ make
Scanning dependencies of target hello_world_client
[ 25%] Building CXX object CMakeFiles/hello_world_client.dir/hello_world_client_main.cpp.o
[ 50%] Linking CXX executable hello_world_client
[ 50%] Built target hello_world_client
Scanning dependencies of target hello_world_service
[ 75%] Building CXX object CMakeFiles/hello_world_service.dir/hello_world_service_main.cpp.o
[100%] Linking CXX executable hello_world_service
[100%] Built target hello_world_service
will@will-OptiPlex-7050:~/work/vsomeip/examples/hello_world/build$ ./hello_world_service
5. Run client side app.
will@will-OptiPlex-7050:~/work/vsomeip/examples/hello_world/build$ ./hello_world_client 
2023-11-01 18:08:23.197728 [info] Using configuration file: "../helloworld-client.json".
2023-11-01 18:08:23.198257 [info] Parsed vsomeip configuration in 0ms
2023-11-01 18:08:23.198311 [info] Configuration module loaded.
2023-11-01 18:08:23.198388 [info] Security disabled!
2023-11-01 18:08:23.198420 [info] Initializing vsomeip (3.4.9.1) application "hello_world_client".
2023-11-01 18:08:23.198451 [info] Instantiating routing manager [Proxy].
2023-11-01 18:08:23.198662 [info] Client [5555] is connecting to [0] at /tmp/vsomeip-0
2023-11-01 18:08:23.198743 [info] Application(hello_world_client, 5555) is initialized (11, 100).
2023-11-01 18:08:23.198853 [info] Starting vsomeip application "hello_world_client" (5555) using 2 threads I/O nice 255
2023-11-01 18:08:23.199727 [info] shutdown thread id from application: 5555 (hello_world_client) is: 7fae936bf700 TID: 27766
2023-11-01 18:08:23.199711 [info] main dispatch thread id from application: 5555 (hello_world_client) is: 7fae93ec0700 TID: 27765
2023-11-01 18:08:23.200185 [info] io thread id from application: 5555 (hello_world_client) is: 7fae93f65000 TID: 27764
2023-11-01 18:08:23.200226 [info] io thread id from application: 5555 (hello_world_client) is: 7fae8bfff700 TID: 27767
2023-11-01 18:08:23.202116 [info] create_local_server: Listening @ /tmp/vsomeip-5555
2023-11-01 18:08:23.202279 [info] Client 5555 (hello_world_client) successfully connected to routing  ~> registering..
2023-11-01 18:08:23.202326 [info] Registering to routing manager @ vsomeip-0
2023-11-01 18:08:23.204803 [info] Application/Client 5555 (hello_world_client) is registered.
2023-11-01 18:08:23.308749 [info] ON_AVAILABLE(5555): [1111.2222:0.0]
Sending: World
2023-11-01 18:08:23.309505 [info] Client [5555] is connecting to [4444] at /tmp/vsomeip-4444
Received: Hello World
2023-11-01 18:08:23.313131 [info] Stopping vsomeip application "hello_world_client" (5555).
2023-11-01 18:08:23.315530 [info] Application/Client 5555 (hello_world_client) is deregistered.
2023-11-01 18:08:23.316107 [info] Client [5555] is closing connection to [4444]
2023-11-01 18:08:23.316457 [info] local_uds_client_endpoint_impl::receive_cbk Error: Operation canceled

总结

vsomeip的学习,只能靠自己在网上搜集一些资料,由于对于配置的说明不够详细,或者说很难解释我的困惑,所以花了很多时间研究和尝试。由于篇幅有限,决定把学习过程一分为二写成两篇文章来分享给大家。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值