前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[081]AI教你快速入门someip

[081]AI教你快速入门someip

作者头像
王小二
发布2023-05-23 10:46:15
6380
发布2023-05-23 10:46:15
举报

一、问:someip是什么

SOME/IP (Scalable service-Oriented MiddlewarE over IP) 是一种用于汽车电子系统和其他嵌入式系统的网络通信协议,它的设计旨在为分布式系统中的服务发现、通信和管理提供标准化的解决方案。SOME/IP 协议可以用于不同的物理层网络,包括以太网、CAN、FlexRay等,其目标是在这些网络之间提供互操作性。

SOME/IP 协议采用了面向服务的架构,通过将系统划分为服务提供者和服务使用者两个角色,实现了服务的发布、发现、绑定和调用。协议还提供了安全性和可靠性保障的机制,支持多种数据类型的传输,具有可扩展性和灵活性等优点。

在汽车领域,SOME/IP 协议已经被广泛应用于车辆网络和汽车电子系统的通信中,它使得不同的电子控制单元(ECUs)能够相互通信,从而实现了更加智能和高效的汽车系统。

二、问:比较一下Binder和SomeIP的相同点和不同点

Binder和SomeIP都是用于实现进程间通信的协议,它们有以下相同点和不同点:

相同点:

1. 都是用于实现进程间通信的协议。

2. 都提供了类似于RPC(远程过程调用)的机制,使得进程可以通过调用远程接口来实现数据的交换和处理。

3. 都支持在底层使用TCP/IP协议栈来实现数据传输。

4. 都具有可扩展性和灵活性,可以根据需要进行定制和配置。

不同点:

1. Binder主要用于Android系统中的进程间通信,而SomeIP则可以应用于各种不同的系统和场景中。

2. Binder使用了基于共享内存的进程间通信机制,而SomeIP则使用了基于网络协议栈的通信机制。

3. Binder提供了更强的安全机制,可以对数据进行加密和签名,以保证通信的安全性。SomeIP的安全机制相对较弱,需要用户自行实现安全措施。

4. Binder提供了更高的性能和更低的延迟,因为它是专门为Android系统设计的。SomeIP则更注重可扩展性和通用性,可以应用于不同的系统和场景中。

三、问:SomeIP有没有类似Binder AIDL的机制

SomeIP没有像Binder AIDL(Android Interface Definition Language)那样的机制,但是它提供了类似于RPC(远程过程调用)的机制,使得进程可以通过调用远程接口来实现数据的交换和处理。具体来说,SomeIP定义了消息格式和编解码方式,可以通过指定服务ID和方法ID来调用远程服务。

SomeIP使用了基于网络协议栈的通信机制,它通过传输层协议(如TCP、UDP或IP)来实现进程间的通信,而不像Binder使用共享内存等机制来实现。SomeIP的通信机制相对于Binder更加通用和灵活,可以在不同平台和系统之间使用。

虽然SomeIP没有AIDL这样的接口描述语言,但是可以使用IDL(Interface Definition Language)来定义接口和方法。IDL是一种标准的接口描述语言,可以定义接口、方法、参数、返回值和异常等信息。使用IDL可以在不同的语言之间共享接口定义,以便实现跨平台和跨语言的通信。

四、问:用vsomeip写一个简单的demo

AI的回答有点问题,我决定运行vsomeip的helloworld

五、vsomeip的hello world

5.1 下载代码

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

5.2 编译代码并安装

mkdir build
cd build
cmake ..
make
sudo make install

5.3 编译hello world

kobe@41001005-26-0:~/study/vsomeip/examples/hello_world/build$ cmake ..
-- Configuring done
-- Generating done
-- Build files have been written to: /home/kobe/study/vsomeip/examples/hello_world/build
kobe@41001005-26-0:~/study/vsomeip/examples/hello_world/build$ make
[ 50%] Built target hello_world_client
[100%] Built target hello_world_service

5.4 运行hello world

修改examples/hello_world/helloworld-local.json中IP为本机的IP,其实不改也没事,如果要两个设备之间运行就得改了。

5.4.1 server端

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

运行的结果

kobe@41001005-26-0:~/study/vsomeip/examples/hello_world/build$ VSOMEIP_CONFIGURATION=../helloworld-local.json \
> VSOMEIP_APPLICATION_NAME=hello_world_service \
/hello_> ./hello_world_service
2023-05-11 10:30:07.931895 [info] Using configuration file: "../helloworld-local.json".
2023-05-11 10:30:07.932418 [info] Parsed vsomeip configuration in 0ms
2023-05-11 10:30:07.932491 [info] Configuration module loaded.
2023-05-11 10:30:07.932557 [info] Initializing vsomeip application "hello_world_service".
2023-05-11 10:30:07.932930 [info] Instantiating routing manager [Host].
2023-05-11 10:30:07.933651 [info] create_routing_root: Routing root @ /tmp/vsomeip-0
2023-05-11 10:30:07.934118 [info] Application(hello_world_service, 4444) is initialized (11, 100).
2023-05-11 10:30:07.934376 [info] Starting vsomeip application "hello_world_service" (4444) using 2 threads I/O nice 255
2023-05-11 10:30:07.935706 [info] Client [4444] routes unicast:172.31.68.132, netmask:255.255.255.0
2023-05-11 10:30:07.935720 [info] main dispatch thread id from application: 4444 (hello_world_service) is: 7f2651916700 TID: 480
2023-05-11 10:30:07.936521 [info] shutdown thread id from application: 4444 (hello_world_service) is: 7f2651115700 TID: 481
2023-05-11 10:30:07.937274 [info] Watchdog is disabled!
2023-05-11 10:30:07.938821 [info] OFFER(4444): [1111.2222:0.0] (true)
2023-05-11 10:30:07.939884 [info] io thread id from application: 4444 (hello_world_service) is: 7f2654b7d740 TID: 477
2023-05-11 10:30:07.940103 [info] io thread id from application: 4444 (hello_world_service) is: 7f264bfff700 TID: 483
2023-05-11 10:30:07.939991 [info] create_local_server: Listening @ /tmp/vsomeip-4444
2023-05-11 10:30:07.941220 [info] Network interface "eth0" state changed: up
2023-05-11 10:30:07.941826 [info] Service Discovery disabled. Using static routing information.
2023-05-11 10:30:07.942377 [info] udp_server_endpoint_impl: SO_RCVBUF is: 212992 (1703936) local port:30509
2023-05-11 10:30:07.942499 [info] SOME/IP routing ready.
2023-05-11 10:30:07.940854 [info] vSomeIP 3.3.0 | (default)
2023-05-11 10:30:07.942903 [warning] Route "default route (0.0.0.0/0) if: eth0 gw: 172.31.64.1" state changed: up
2023-05-11 10:30:17.943506 [info] vSomeIP 3.3.0 | (default)
2023-05-11 10:30:27.944112 [info] vSomeIP 3.3.0 | (default)
2023-05-11 10:30:37.945107 [info] vSomeIP 3.3.0 | (default)
2023-05-11 10:30:41.325295 [info] Application/Client 5555 is registering.
2023-05-11 10:30:41.327004 [info] Client [4444] is connecting to [5555] at /tmp/vsomeip-5555
2023-05-11 10:30:41.331377 [info] REGISTERED_ACK(5555)
2023-05-11 10:30:41.434295 [info] REQUEST(5555): [1111.2222:255.4294967295]
2023-05-11 10:30:41.442904 [info] RELEASE(5555): [1111.2222]
2023-05-11 10:30:41.443599 [info] Application/Client 5555 is deregistering.
2023-05-11 10:30:41.456640 [info] receive_cbk local_uds_client_endpoint: connection_reset/EOF/bad_descriptor
2023-05-11 10:30:41.546013 [info] Client [4444] is closing connection to [5555]
2023-05-11 10:30:46.442785 [info] STOP OFFER(4444): [1111.2222:0.0] (true)
2023-05-11 10:30:46.443757 [info] Stopping vsomeip application "hello_world_service" (4444).

5.4.2 client端

VSOMEIP_CONFIGURATION=../helloworld-local.json \
VSOMEIP_APPLICATION_NAME=hello_world_client \
./hello_world_client

运行的结果,可以看到关键的Sending: WorldReceived: Hello World,证明两者就通了。

kobe@41001005-26-0:~/study/vsomeip/examples/hello_world/build$ VSOMEIP_CONFIGURATION=../helloworld-local.json \
PPLI> VSOMEIP_APPLICATION_NAME=hello_world_client \
hello_world_cl> ./hello_world_client
2023-05-11 10:30:41.316299 [info] Using configuration file: "../helloworld-local.json".
2023-05-11 10:30:41.316950 [info] Parsed vsomeip configuration in 0ms
2023-05-11 10:30:41.317019 [info] Configuration module loaded.
2023-05-11 10:30:41.317239 [info] Initializing vsomeip application "hello_world_client".
2023-05-11 10:30:41.317442 [info] Instantiating routing manager [Proxy].
2023-05-11 10:30:41.317602 [info] Client [5555] is connecting to [0] at /tmp/vsomeip-0
2023-05-11 10:30:41.317810 [info] Application(hello_world_client, 5555) is initialized (11, 100).
2023-05-11 10:30:41.318359 [info] Starting vsomeip application "hello_world_client" (5555) using 2 threads I/O nice 255
2023-05-11 10:30:41.319383 [info] main dispatch thread id from application: 5555 (hello_world_client) is: 7fda3262b700 TID: 485
2023-05-11 10:30:41.319900 [info] shutdown thread id from application: 5555 (hello_world_client) is: 7fda31e2a700 TID: 486
2023-05-11 10:30:41.320597 [info] io thread id from application: 5555 (hello_world_client) is: 7fda34890740 TID: 484
2023-05-11 10:30:41.320686 [info] io thread id from application: 5555 (hello_world_client) is: 7fda31629700 TID: 487
2023-05-11 10:30:41.323761 [info] create_local_server: Listening @ /tmp/vsomeip-5555
2023-05-11 10:30:41.324015 [info] Client 5555 (hello_world_client) successfully connected to routing  ~> registering..
2023-05-11 10:30:41.324078 [info] Registering to routing manager @ vsomeip-0
2023-05-11 10:30:41.330196 [info] Application/Client 5555 (hello_world_client) is registered.
2023-05-11 10:30:41.435897 [info] ON_AVAILABLE(5555): [1111.2222:0.0]
Sending: World
2023-05-11 10:30:41.437515 [info] Client [5555] is connecting to [4444] at /tmp/vsomeip-4444
Received: Hello World
2023-05-11 10:30:41.442398 [info] Stopping vsomeip application "hello_world_client" (5555).
2023-05-11 10:30:41.444793 [info] Application/Client 5555 (hello_world_client) is deregistered.
2023-05-11 10:30:41.446893 [info] Client [5555] is closing connection to [4444]

六、总结

首先someip是一个基于IP的跨进程跨设备的通信协议,协议说白了只是规范,但是并没有实现,vsomeip就是对这个协议的C++实现,并提供API,不同的实现库的API可以不同,但是他们却可以通信。

Binder中是通过AIDL生成使用Binder API的模板代码,someip的很多实现库也提供了类似的功能,方便开发者可以专注于接口的设计,忽略一下不同someip实现库的使用差异。

尾巴

最后再问AI一个问题,如何学习someip?

学习 SOME/IP 需要掌握以下几个方面:

1. 网络协议的基础知识:了解计算机网络的基本概念和通信协议的基础知识,包括 OSI 参考模型、TCP/IP 协议栈等。

2. SOME/IP 协议的规范:深入学习 SOME/IP 协议的消息格式、消息传输、服务发现等方面的规范,可以通过 AUTOSAR 官网、Vector 官网等网站查找相关资料。

3. 编程语言和工具的应用:使用一些流行的编程语言和工具,如 C/C++、Python、Wireshark 等,实现 SOME/IP 协议的通信和调试。

以下是一些学习 SOME/IP 的建议:

1. 学习网络协议的基础知识:在学习 SOME/IP 协议之前,需要了解计算机网络的基础知识,理解 OSI 参考模型和 TCP/IP 协议栈等。

2. 深入了解 SOME/IP 协议的规范:通过阅读 SOME/IP 协议的规范文档,可以深入了解协议的各个方面,包括消息格式、消息传输、服务发现等。

3. 练习使用工具和编程语言:可以使用 Wireshark 等工具进行 SOME/IP 协议的抓包和分析,使用 C/C++、Python 等编程语言实现 SOME/IP 协议的通信和调试。

4. 参与相关的开源项目:参与一些开源项目,如 Eclipse Iceoryx,可以深入了解 SOME/IP 协议的实现和应用。

总之,学习 SOME/IP 需要结合理论和实践,深入了解协议规范,同时掌握一些编程语言和工具的使用。

参考文献 https://github.com/COVESA/vsomeip/

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2023-05-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、问:someip是什么
  • 二、问:比较一下Binder和SomeIP的相同点和不同点
  • 三、问:SomeIP有没有类似Binder AIDL的机制
  • 四、问:用vsomeip写一个简单的demo
  • 五、vsomeip的hello world
    • 5.1 下载代码
      • 5.2 编译代码并安装
        • 5.3 编译hello world
          • 5.4 运行hello world
            • 5.4.1 server端
              • 5.4.2 client端
              • 六、总结
              • 尾巴
                • 最后再问AI一个问题,如何学习someip?
                领券
                问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档