通信易懂唠唠SOME/IP——SOME/IP 协议规范

embedded/2025/2/8 23:26:57/

主要介绍SOME/IP协议中远程过程调用RPC,事件通知Event。

一 Transport Protocol Bindings传输协议绑定

SOME/IP目前支持TCP连接,UDP单播连接,UDP多播连接

1.1 使用UDP还是TCP的指导原则:

• 只有在传输大数据块(>1400bytes),且在出现错误时对延时没有严格要求时使用TCP。

• 如果对延时有严格要求(延时<100ms)时使用UDP。

• 如果要传输的数据块大,同时对延时也有严格要求,可以使用SOME/IP-TP的UDP传输。

同一个insatnce的所有event,method,field应该使用同一个udp单播或者udp多播或者tcp连接,即绑定方式是针对instance的不是针对具体的event或者method的。

而实际上,车辆内部许多应用程序,尤其是智驾相关的应用程序,为了做出快速的响应,对延时有严格的要求,所以UDP传输用的更普遍。虽然UDP不能像TCP那样处理位错误、丢包、分段、网络拥塞等错误,但应用程序本身可以处理 这些不太可能发生的错误。

1.2 支持一个包里传输多个SOME/IP消息

比如下面的例子,一个PDU中包含了2个Subscribe消息和6条Subscribe ACK消息。

1.3 多service instance

一个service可以有多个service instance,不同的service instance用instance id区分。

不同服务的多个instance可以使用相同的端口号,同一个service的多个instance不能使用相同的端口号。

服务发现阶段的报文不包含instance id,可以用socket三元素(ip,port,传输协议)区分不同的instance。

同一个service instance 建议tcp和udp使用相同的端口号。

二 Request/Response Communication 请求应答通信

请求应答通信方式是常见的通信方式之一。通信的Clinet端发出请求消息,通信的Server端作出应答。

2.1 SOME/IP的Request/Response消息Client和Server端分别要做的工作

Client:

• Construct the payload

构造payload。Method的所有参数按照函数签名中的顺序序列化。

• Set the Message ID based on the method the client wants to call。

设置Message ID(SerivceId和MethodID)

• Set the Length field to 8 bytes (for the part of the SOME/IP header after the length field) + length of the serialized payload

设置Length=SOME/IP header length之后的部分的大小+payload大小

• Optionally set the Request ID to a unique number (shall be unique for client only)。

设置RequsetID(Client ID和Session ID)。

• Set the Protocol Version according [PRS_SOMEIP_00052]

设置协议版本号0x01

• Set the Interface Version according to the interface definition

设置Interface版本号

• Set the Message Type to REQUEST (i.e. 0x00)

设置Message Type=0x00

• Set the Return Code to 0x00

设置Return Code=0x00

Server:

• Construct the payload

构造payload。Method的Out和InOut参数按照函数签名中的顺序序列化。

• take over the Message ID from the corresponding request。

从相应的请求中接管Message ID。

• Set the length to the 8 Bytes + new payload size

设置length

• take over the Request ID from the corresponding request

从相应的请求中接管Request ID

Set the Message Type to RESPONSE (i.e. 0x80) or ERROR (i.e. 0x81)

设置MessageType=0x80(正常时)或者0x81(出错时)

• set Return Code to the return code of called method or in case of an Error message to a valid error code.

设置RerurCode。

Return Code的有效值如下

2.2 例子

Client Request消息

Server端Response

三 Fire/Forget Communication请求无影灯的通信

客户端需要做的工作与Request/Response类似,只是MessageType是0x01。服务端不需要应答。

我们通常说的Method就是指Request/Response通信或者Fire/Forget通信。如果Method中有Out或者InOut参数,那么就要使用Request/Response,Server在Response的Payload中携带Out参数。如果Method参数列表中没有Out和InOut参数,那么Method可以设计成Request/Response,这时的Response的 Payload是空的,ReturnCode可以表明执行是否成功。也可以设计成Fire/Forget通信。

四 Notification Events通知事件

通知事件描述了一个通用的发布/订阅概念。 通常,服务器发布客户端订阅的服务。SOME/IP只是发布更新的事件,不做发布订阅的机制,这个机制的实现在SOME/IP-SD中。

4.1 在SOME/IP的通知消息中,服务端需要做的工作

• Construct the payload

构造payload。通知消息的有效载荷应包括事件的序列化数据 。

• Set the Message ID based on the event the server wants to send

根据服务端想发送的event设置Message ID,包括ServiceID和Method ID。

• Set the Length field to 8 bytes (for the part of the SOME/IP header after the length field) + length of the serialized payload

设置Length=SOME/IP header length之后的部分的大小+payload大小

• Set the Client ID to 0x00. Set the Session ID according to [PRS_SOMEIP_00932], [PRS_SOMEIP_00933], and [PRS_SOMEIP_00521]. In case of active Session Handling the Session ID shall be incremented upon each transmission

设置ClientID=0x00,设置Session ID从0x1-0xFFFF循环递增。

. • Set the Protocol Version according [PRS_SOMEIP_00052]

设置协议版本号0x01

• Set the Interface Version according to the interface definition

设置Interface版本号

• Set the Message Type to NOTIFICATION (i.e. 0x02)

设置Message Type=0x02

• Set the Return Code to 0x00

设置ReturnCode=0x00

4.2 例子

4.3 发送通知的三种机制

• Cyclic update — send an updated value in a fixed interval (e.g. every 100 ms for safety relevant messages with Alive)

周期发送

• Update on change — send an update as soon as a "value" changes (e.g. door open)

只在发送变化时发送

• Epsilon change — only send an update when the difference to the last value is greater than a certain epsilon. This concept may be adaptive, i.e. the prediction is based on a history; thus, only when the difference between prediction and current value is greater than epsilon an update is transmitted.

与上一次的值不一样的发送。

五 Fields

字段表示状态并具有有效值。 消费者订阅 获取字段值作为初始事件。

一个Field可以有getter和setter方法,和一个notification event。

即Field是上述Request/Response和Notification Event的结合。getter是一个只有Out参数的Method,其Out的值就是Filed要更新的值,即Request的Payload是空,Response的Payload是返回的Field的值。setter有一个In参数一个Out参数,In参数是期望设置的值,Out参数是返回的FIeld的值。即Request的Payload中是要设置的值,Response的Payload中是返回的filed的值


http://www.ppmy.cn/embedded/160654.html

相关文章

硬件电路基础

目录 1. 电学基础 1.1 原子 1.2 电压 1.3 电流 1.电流方向&#xff1a; 正极->负极,正电荷定向移动方向为电流方向&#xff0c;与电子定向移动方向相反。 2.电荷&#xff08;这里表示负电荷&#xff09;运动方向&#xff1a; 与电流方向相反 1.4 测电压的时候 2. 地线…

Ubuntu22.04操作系统4090显卡电脑本地化部署DeepSeek

操作系统&#xff1a;ubuntu22.04 OpenCV版本&#xff1a;OpenCV4.9 IDE:Visual Studio Code 编程语言&#xff1a;C11 概述 听说最近很火的DeepSeek&#xff0c;就像本地化部署一个看看&#xff0c;发现本地化部署很简单&#xff0c;在这儿记录一下。 下载Ollama 看好多指…

deepseek API 调用-python

【1】创建 API keys 【2】安装openai SDK pip3 install openai 【3】代码&#xff1a; https://download.csdn.net/download/notfindjob/90343352

嵌入式C语言面试常考题(一)

一、嵌入式软件设计中的 volatile 关键字的含义和用法? 1. 什么是 volatile? volatile 是一个告诉编译器不要优化变量的关键字。 它的意思是:“这个变量的值可能会随时变化,所以每次都要重新读取它的最新值。” 如果不加 volatile 会发生什么? 编译器为了让程序运行得…

x64、aarch64、arm与RISC-V64:详解四种处理器架构

x64、aarch64、arm与RISC-V64:详解四种处理器架构 x64架构aarch64架构ARM架构RISC-V64架构总结与展望在计算机科学领域,处理器架构是构建计算机系统的基石,它决定了计算机如何执行指令、管理内存和处理数据。x64、aarch64、arm与RISC-V64是当前主流的四种处理器架构,它们在…

Facebook矩阵营销:多维度布局,精准打击

随着社交媒体的迅猛发展&#xff0c;企业和品牌在数字营销中的竞争愈发激烈。Facebook&#xff0c;作为全球最大的社交平台之一&#xff0c;已成为了品牌推广的关键阵地之一。然而&#xff0c;仅仅依靠单一的Facebook页面进行营销已经无法满足品牌发展的需求&#xff0c;如何通…

谷歌Titans模型论文解析,Transformer迎来变革拐点——DeepSeek能否“接招”?

一、引入 Titans 模型 我们将深入探讨谷歌研究院的一篇新论文《Titans: Learning to Memorize at Test Time》&#xff0c;该论文介绍了一种名为 Titans 的新模型架构。 Titans 在缓解 Transformer 二次方成本问题的同时&#xff0c;展现出了令人期待的成果。Titans 模型的设…

使用 OpenGL ES 渲染一个四边形

使用 OpenGL ES 渲染一个四边形 在 iOS 开发中,OpenGL ES 是一个强大的工具,用于实现高性能的 2D 和 3D 图形渲染。本文将通过一个完整的代码示例,详细解析如何使用 OpenGL ES 渲染一个简单的四边形。我们将从基础概念入手,逐步讲解代码的每个部分,帮助你理解 OpenGL ES …