SOME/IP-SD -- 协议英文原文讲解2

前言
SOME/IP协议越来越多的用于汽车电子行业中,关于协议详细完全的中文资料却没有,所以我将结合工作经验并对照英文原版协议做一系列的文章。基本分三大块:

1. SOME/IP协议讲解

2. SOME/IP-SD协议讲解

3. python/C++举例调试讲解


5.1.2.2 SOME/IP-SD Header
[PRS_SOMEIPSD_00252]
Upstream requirements: RS_SOMEIPSD_00001
SOME/IP-SD shall be transported using SOME/IP.
SD报文 是基于SOME/IP协议头传输的在其基础上继续叠加SD头

[PRS_SOMEIPSD_00252] can be seen in Figure 5.2.
[PRS_SOMEIPSD_00253]
Upstream requirements: RS_SOMEIPSD_00006
The SOME/IP-SD Header shall start with an 8 Bit field called flags.
See a representation of Flags in Figure 5.3.
SD header 最开始是个8位的flags
如果仅Reboot Flag是 1 则flag字节的值是0x80.
rebootFlag 为 1 表示新的一段 订阅关系的开始

[PRS_SOMEIPSD_00254]
Upstream requirements: RS_SOMEIPSD_00006
The first flag of the SOME/IP-SD Flags field (highest order bit) shall be called Reboot
Flag.
For flags see Figure 5.3.
[PRS_SOMEIPSD_00255]
Upstream requirements: RS_SOMEIPSD_00006
The Reboot Flag of the SOME/IP-SD Header shall be set to one for all messages
after reboot until the Session-ID in the SOME/IP-Header wraps around and thus starts
with 1 again. After this wrap around the Reboot Flag is set to 0.
reboot_flag   sessionID
1             1          --->开机
0             2
0             3
0             4
...   ...
...   ...
...   ...
0             0xffff
1             1         --> sessionID 绕回
0             2
0             3
0             4
...   ...
...   ...

[PRS_SOMEIPSD_00256]
Upstream requirements: RS_SOMEIPSD_00002, RS_SOMEIPSD_00003
The information for the reboot flag and the Session ID shall be kept for multicast and
unicast separately.
(reboot flag and the Session ID )的值 多播和 单播的情况要分开

[PRS_SOMEIPSD_00631]
Upstream requirements: RS_SOMEIPSD_00002, RS_SOMEIPSD_00003
The information for the reboot flag and the Session ID shall be kept for every senderreceiver relation (i.e. source address and destination address) separately.
不通的发送-接收 关系 要分开使用 (reboot flag and the Session ID)
Note:
This means there shall be separate counters for sending and receiving.
Sending

client / server的sessionID 没联系,各自管理,
比如 client sub server的sessionID 和 server suback client的sessionID 不相关。

• There shall be a counter for multicast.(对于发送端来说 多播只配一路
• There shall be a separate counter for each peer for unicast.
Receiving
• There shall be a counter for each peer for multicast.
• There shall be a counter for each peer for unicast.
[PRS_SOMEIPSD_00258]
Upstream requirements: RS_SOMEIPSD_00006
The detection of a reboot shall be done as follows (with the new values of the current
packet from the communication partner and old the last value received before):
if old.reboot==0 and new.reboot==1 then Reboot detected
OR
if old.reboot==1 and new.reboot==1 and old.session_id>=new.session_id then Reboot
detected

reboot_flag   sessionID
1             1          --->开机 reboot
0             2
0             3
0             4
...   ...
...   ...

0             999
1             1000
1             1001 ---> 主动发起reboot (old.reboot==1 and new.reboot==1 and old.session_id>=new.session_id)
0             1002
...   ...
...   ...
0             0xffff
1             1         --> sessionID 绕回 -- reboot
0             2
0             3
0             4
...   ...
...   ...

[PRS_SOMEIPSD_00259]
Upstream requirements: RS_SOMEIPSD_00002
The second flag of the SOME/IP-SD Flags (second highest order bit) shall be called
Unicast Flag.
Flag第二高位 表示 单播标志
For flags see Figure 5.3.

[PRS_SOMEIPSD_00540]
Upstream requirements: RS_SOMEIPSD_00002
The Unicast Flag of the SOME/IP-SD Header shall be set to Unicast (that means 1)
for all SD Messages since this means that receiving using unicast is supported.
Note:
The Unicast Flag is left over from historical SOME/IP versions and is only kept for
compatibility reasons. Its use besides this is very limited.
此标志设置为1 表示支持单播接收 -- 目前都是单播接收 -- 而没移除的原因是 历史版本的兼容保留了下来

For flags see Figure 5.3.
[PRS_SOMEIPSD_00702]
Upstream requirements: RS_SOMEIPSD_00002
Undefined bits within the Flag field shall be set to ’0’ when sending and ignored on
receiving.
发送端flag的其他位要设置为0,接收端要忽略这些位。

[PRS_SOMEIPSD_00261]
Upstream requirements: RS_SOMEIPSD_00006
After the Flags the SOME/IP-SD Header shall have a field of 24 bits called Reserved.
Flag剩下的24位保留 设置为0

[PRS_SOMEIPSD_00262]
Upstream requirements: RS_SOMEIPSD_00006
After the SOME/IP-SD Header the Entries Array(条目数组:提供、订阅的 事件组们) shall follow.
[PRS_SOMEIPSD_00263]
Upstream requirements: RS_SOMEIPSD_00006
The entries shall be processed exactly in the order they arrive.接收端 按接收的顺序 解析处理。
[PRS_SOMEIPSD_00264]
Upstream requirements: RS_SOMEIPSD_00006
After the Entries Array in the SOME/IP-SD Header an Option Array shall follow.
配置组:和上面的 事件组一一对应,是事件组的详细配置 下面有讲
[PRS_SOMEIPSD_00265]
Upstream requirements: RS_SOMEIPSD_00006
The Entries Array and the Options Array of the SOME/IP-SD message shall start with
a length field as uint32 that counts the number of bytes of the following data; i.e. the
entries or the options.
事件组 和 配置组 前都有 4个字节的长度段,描述对应数组的字节数(不包含长度段本身的4个字节)

5.1.2.3 Entry Format
[PRS_SOMEIPSD_00266]
Upstream requirements: RS_SOMEIPSD_00006
The service discovery shall support multiple entries that are combined in one service
discovery message.
一条SD报文中可以有多条 事件组描述 -- 称为聚包。
Note:
The entries are used to synchronize the state of services instances and the Publish/-
Subscribe handling.
这些条目 体现了 发布 和 订阅的实例状态

[PRS_SOMEIPSD_00267]
Upstream requirements: RS_SOMEIPSD_00006
Two types of entries exist: A Service Entry Type for Services and an Eventgroup Entry
Type for Eventgroups.
分两类条目:find/offer/stopoffer是一类条目格式
                      Subscribe (0x06), StopSubscribeEventgroup (0x06), SubscribeAck (0x07) and SubscribeEventgroupNack (0x07) 是一类条目格式

[PRS_SOMEIPSD_00268]
Upstream requirements: RS_SOMEIPSD_00006
A Service Entry Type shall be 16 Bytes of size and include the following fields in this
order:
• Type Field [uint8]: encodes FindService (0x00), OfferService (0x01) and StopOfferService (0x01)
offer 和 stopOffer 都是 0x01 -->TTL为0时表示停止订阅 ,>0 为提供服务
48页 有对find 报文的详解
50页 有对offer报文的详解

• Index First Option Run [uint8]: Index of this runs first option in the option array.
• Index Second Option Run [uint8]: Index of this runs second option in the option
array.
• Number of Options 1 [uint4]: Describes the number of options the first option run
uses.
• Number of Options 2 [uint4]: Describes the number of options the second option
run uses.
833条有解释 作用
5.1.2.4.1节解释了 为啥一条entry可以有多个配置
因为一个服务可以既有ipv4 又有ipv6 ,既有UDP又有TCP,既有ipv4多播又有ipv6多播,还可能有key-value(下面介绍)或者还有负载均衡选项(下面有介绍)
52页有介绍不同类型SD报文 可以使用哪些端点配置。
Option 0: Load Balancing Option
Option 1: IPv4 Endpoint Option
Option 2: IPv6 Endpoint Option
Option 3: Configuration Option
某 Entry 的字段值为:
Index First Option Run: 1
Number of Options 1: 2
Index Second Option Run: 3
Number of Options 2: 1
解析:
第一个 Option Run:

起始位置:Index First Option Run = 1(指向 Option 1)
选项数量:Number of Options 1 = 2(包含 Option 1 和 Option 2)
包含选项:[Option 1, Option 2](IPv4 和 IPv6 Endpoint Option)
第二个 Option Run:

起始位置:Index Second Option Run = 3(指向 Option 3)
选项数量:Number of Options 2 = 1(包含 Option 3)
包含选项:[Option 3](Configuration Option)
4. 重点总结
Index First Option Run 和 Index Second Option Run:

指向选项数组中的起始位置。
用于关联具体的选项数据。
Number of Options 1 和 Number of Options 2:

描述从起始位置开始的连续选项数量。
用于定义关联的 Option Run 长度。
关联关系:

通过这些字段,Entry 和 Option 数组之间建立了灵活的映射。
支持每个 Entry 使用多个不连续的 Option Run。
实际应用:

这套机制允许在服务发现协议中以高效和结构化的方式携带附加信息

为什么有Index1可以指定连续多个options, 还要index2?
因为有时 两个options不一定是连续的,中间隔了几个。

• Service ID [uint16]: Describes the Service ID of the Service or Service Instance
this entry is concerned with.
提供 或 需要 的serviceID

• Instance ID [uint16]: Describes the Service Instance ID of the Service Instance
this entry is concerned with or is set to 0xFFFF if all service instances of a service
are meant.
offer报文中需要指定具体的 instanceID < 0xffff

sub报文中 可指定 订阅具体的instanceID 或者用0xffff 通配订阅所有的instance。

suback报文 响应 具体的instanceID

• Major Version [uint8]: Encodes the major version of the service (instance).
此服务id的 主版本号 -- 表示已有的接口有重大变化,表示不兼容的变化 --- client对比不一致 会拒绝订阅。

另外:一般客户在矩阵表服务更新时,为了减少工作量 不会改变这个版本号,因为会把矩阵表同步更新释放到 所有ECU供应商 


• TTL [uint24]: Describes the lifetime of the entry in seconds.
服务的生存周期 单位是秒

为0的含义:停止offer

推荐值
低频更新场景:

推荐 TTL:60 ~ 120 秒。
应用于较低频的场景,如不频繁变动的配置类服务。
高频实时场景:

推荐 TTL:10 ~ 30 秒。
适用于需要快速检测失效的场景,如实时数据订阅(状态或传感器数据)。
测试或调试场景:

推荐 TTL:5 ~ 15 秒。
短 TTL 用于快速观察服务和订阅行为的变化。
实际设置的考虑
网络延迟:
如果网络延迟较大,应设置较高的 TTL 值,以避免误判服务失效。
服务的动态性:
对动态性较高的服务,TTL 可以短一些,以确保订阅列表保持更新。

4. 如何处理 TTL 到期
客户端:
客户端需要在 TTL 到期前主动续订(发送新的订阅请求)。
续订的时间间隔一般可以略小于 TTL 值,例如 TTL 的 80%。
服务端:
服务端在 TTL 到期后清除对应订阅信息,节省资源。
不会主动通知客户端失效,需要客户端自行维护续订逻辑。

• Minor Version [uint32]: Encodes the minor version of the service
服务id的次版本号 -- 是向后兼容的变化 --- 表示新增了接口 不影响之前的接口使用 -- 可兼容 -- client对比不一致 打印报警信息 可继续订阅

另外:一般客户在矩阵表服务更新时,为了减少工作量 不会改变这个版本号,因为会把矩阵表同步更新释放到 所有ECU供应商

[PRS_SOMEIPSD_00270]
Upstream requirements: RS_SOMEIPSD_00006
dAn Eventgroup Entry (Type 2) shall be 16 Bytes of size and include the following fields
in this order:
• Type Field [uint8]: encodes Subscribe (0x06), StopSubscribeEventgroup (0x06),
SubscribeAck (0x07) and SubscribeEventgroupNack (0x07).
• Index of first option run [uint8]: Index of this runs first option in the option array.
• Index of second option run [uint8]: Index of this runs second option in the option
array.
• Number of Options 1 [uint4]: Describes the number of options the first option run
uses.
• Number of Options 2 [uint4]: Describes the number of options the second option
run uses.
• Service-ID [uint16]: Describes the Service ID of the Service or Service Instance
this entry is concerned with.
这 5 个 字段的含义 同 268条

• Instance ID [uint16]: Describes the Service Instance ID of the Service Instance
this entry is concerned with. The Service Instance ID shall not be set to 0xFFFF
for any Instance.
订阅、订阅回复的 具体instanceID ,不能用0xffff通配

• Major Version [uint8]: Encodes the major version of the service instance this
eventgroup is part of.
• TTL [uint24]: Descibes the lifetime of the entry in seconds.
• Reserved [uint12]: Shall be set to 0x000.
这几个的含义 同 268条

• Counter [uint4]: Is used to differentiate identical Subscribe Eventgroups of the
same subscriber. Set to 0x0 if not used.
最大到15
为0表示不使用。
client发送 1-15 递增表示更新TTL 或是groupID , 或是由于网络问题 导致重发,server端发现counter值未变化 则表示已订阅过 不做处理。

• Eventgroup ID [uint16]: Transports the ID of an Eventgroup.
订阅的serviceID所在的事件组。

[PRS_SOMEIPSD_00845]
Upstream requirements: RS_SOMEIPSD_00006
The Major Version of an entry (according to [PRS_SOMEIPSD_00268] and
[PRS_SOMEIPSD_00270]) shall match the version of the corresponding Service Interface
主版本号要做一致性检查

Note: While SOME/IP-SD defines the Major and Minor version of a service interface,
SOME/IP messages themselves only use the major version in the interface version
field of the SOME/IP header.
sub 仅对比 Major版本号
 

5.1.2.3.1 Referencing Options from Entries
[PRS_SOMEIPSD_00833]
Upstream requirements: RS_SOMEIPSD_00025
Using the following fields of the entries, options are referenced by the entries:
• Index First Option Run: Index into array of options for first option run. Index 0
means first option of this SOME/IP-SD message.
配置项1 位于队列的起始位置 (0表示第一个)
• Index Second Option Run: Index into array of options for second option run. Index
0 means first option of this SOME/IP-SD message.
配置项2 位于队列的起始位置
• Number of Options 1: Length of first option run. Length 0 means no option in
option run.
配置项1 起始位置连续多少项对应全是配置项1 的配置(一般只有 1 项)

• Number of Options 2: Length of second option run. Length 0 means no option in
option run.
配置项2 起始位置连续多少项对应全是配置项2 的配置

Two different option runs exist: First Option Run and Second Option Run.

Rationale for the support of two option runs: Two different types of options are expected: options common between multiple SOME/IP-SD entries and options different
for each SOME/IP-SD entry. Supporting two different options runs is the most efficient
way to support these two types of options, while keeping the wire format highly efficient.
意思这中 位置 加 长度的设计 对序列化来说比较灵活高效

[PRS_SOMEIPSD_00341]
Upstream requirements: RS_SOMEIPSD_00025
Each option run shall reference the first option and the number of options for this run.
每个选项的应用是 从它起始位置起连续 number of options 个

[PRS_SOMEIPSD_00342]
Upstream requirements: RS_SOMEIPSD_00025
If the number of options is set to zero, the option run is considered empty.
如果options的数量设置为0 则option的 index引用可以认为是无效的

[PRS_SOMEIPSD_00343]
Upstream requirements: RS_SOMEIPSD_00025
For empty runs the Index (i.e. Index First Option Run and/or Index Second Option
Run) shall be set to zero.
如果 options number是0 表示无效 则index也需要设置为0

[PRS_SOMEIPSD_00834]
Upstream requirements: RS_SOMEIPSD_00025
Implementations shall accept and process incoming SD messages with option run
length set to zero and option index not set to zero by ignoring this option run
接收端 看到无效的option则可忽略 不要“大惊小怪”报错

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/24344.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C++复习专题——泛型编程(模版),包括模版的全特化和偏特化

1.泛型编程 在未接触模版前&#xff0c;如果我们想实现一个通用的交换函数&#xff0c;那么我们可以通过函数重载来实现 void Swap(int &x,int &y) {int z x;x y;y z; } void Swap(float &x,float &y) {int z x;x y;y z; } void Swap(double &x,dou…

Docker入门

注意&#xff1a; 本文内容于 2025-02-23 01:18:58 创建&#xff0c;可能不会在此平台上进行更新。如果您希望查看最新版本或更多相关内容&#xff0c;请访问原文地址&#xff1a;Docker入门。感谢您的关注与支持&#xff01; 在日常开发中&#xff0c;其实我这里是没有使用 D…

haproxy基本配置详解

一、haproxy基础配置 官方文档&#xff1a;HAProxy version 2.2.22 - Configuration Manual HAProxy 的配置文件haproxy.cfg由两大部分组成&#xff0c;分别是global和proxies部分。 global&#xff1a;全局配置段 进程及安全配置相关的参数性能调整相关参数Debug参数 pro…

nodejs:express + js-mdict 作为后端,vue 3 + vite 作为前端,在线查询英汉词典

向 doubao.com/chat/ 提问&#xff1a; node.js js-mdict 作为后端&#xff0c;vue 3 vite 作为前端&#xff0c;编写在线查询英汉词典 后端部分&#xff08;express js-mdict &#xff09; 1. 项目结构 首先&#xff0c;创建一个项目目录&#xff0c;结构如下&#xff1…

网络原理--TCP的特性

TCP报文的结构&#xff1a; TCP的报头前20字节是固定长度&#xff0c;也可以通过“选项”来增加。 一、用来确保可靠性&#xff0c;最核心的机制&#xff0c;称为“确认应答” 引入一个情景&#xff1a; A向B询问cat和dog的意思&#xff1a; 这种情况是理想情况&#xff0c;…

Java 大视界 -- 深度洞察 Java 大数据安全多方计算的前沿趋势与应用革新(52)

&#x1f496;&#x1f496;&#x1f496;亲爱的朋友们&#xff0c;热烈欢迎你们来到 青云交的博客&#xff01;能与你们在此邂逅&#xff0c;我满心欢喜&#xff0c;深感无比荣幸。在这个瞬息万变的时代&#xff0c;我们每个人都在苦苦追寻一处能让心灵安然栖息的港湾。而 我的…

【HTML— 快速入门】HTML 基础

准备工作 vscode下载 百度网盘 Subline Text 下载 Sublime Text下载 百度网盘 vscode 下载 Sublime Text 是一款轻量好用的文本编辑器&#xff0c;我们在写前端代码时&#xff0c;使用 Sublime Text 打开比使用记事本打开&#xff0c;得到的代码体验更好&#xff0c;比 vscode…

深圳南柯电子|医疗设备EMC测试整改检测:零到一,保障医疗安全

在当今医疗科技飞速发展的时代&#xff0c;医疗设备的电磁兼容性&#xff08;EMC&#xff09;已成为确保其安全、有效运行的关键要素之一。EMC测试整改检测不仅关乎设备的性能稳定性&#xff0c;更是保障患者安全、避免电磁干扰引发医疗事故的重要措施。 一、医疗设备EMC测试整…

Tomcat安装与环境变量配置(图文详解)

一、前置条件 tomcat依赖java环境&#xff0c;需要先安装java环境。 jdk环境变量配置可参考&#xff1a;win7、win10系统JDK环境变量配置-CSDN博客 二、Tomcat的下载与安装 1.进入Tomcat官网&#xff1a; https://tomcat.apache.org/ 2.在该网页左侧栏红框标记的download…

网络安全之Web后端PHP

目录 一、PHP基础语法 1.PHP基础 &#xff08;1&#xff09;php的优点 &#xff08;2&#xff09;PhpStorm的优点 2.PHP基本语法 3.PHP变量 4.PHP运算符 二、PHP流控与数组 1.php流程控制语句以及循环 &#xff08;1&#xff09;if 语句 &#xff08;2&#xff09;if…

Python 批量横屏转竖屏视频处理工具

Python 批量横屏转竖屏视频处理工具 相关资源文件已经打包成EXE文件&#xff0c;可双击直接运行程序&#xff0c;且文章末尾已附上相关源码&#xff0c;以供大家学习交流&#xff0c;博主主页还有更多Python相关程序案例&#xff0c;秉着开源精神的想法&#xff0c;望大家喜欢&…

ESP32S3:解决RWDT无法触发中断问题,二次开发者怎么才能使用内部RTC看门狗中断RWDT呢?

目录 基于ESP32S3:解决RWDT无法触发中断问题引言解决方案1. 查看报错日志2. 分析报错及一步一步找到解决方法3.小结我的源码基于ESP32S3:解决RWDT无法触发中断问题 引言 在嵌入式系统中,RWDT(看门狗定时器)是确保系统稳定性的重要组件。然而,在某些情况下,RWDT可能无法…

在windows下安装windows+Ubuntu16.04双系统(上)

这篇文章的内容主要来源于这篇文章&#xff0c;给文章很详细的介绍了如何从windows下安装windowsubuntu16.04双系统。我刚开始装双系统都是参照这个方法&#xff0c;该作者前后更新了两个版本&#xff0c;在这里对其稍微进行整理一下。 一、准备&#xff1a;&#xff08;这里推…

计算机单位之详解——存储单位Byte 网络传输单位bps 视频码率单位bps

前言&#xff1a; 计算机里面单位有点复杂&#xff0c;容易混淆&#xff0c;很多时候混起来就容易概念不理解&#xff0c;包括一些小问题&#xff0c;比如说&#xff1a;为什么我买了1T硬盘&#xff0c;实际存在虚标。为什么所谓的千兆宽带&#xff0c;下载起来没有1G每秒&…

博客系统完整开发流程

前言 通过前⾯课程的学习, 我们掌握了Spring框架和MyBatis的基本使用, 并完成了图书管理系统的常规功能开发, 接下来我们系统的从0到1完成⼀个项⽬的开发. 企业开发的流程 1. 需求评审(产品经理(PM)会和运营(想口号),UI,测试,开发等沟通) ,会涉及到背景/目标/怎么做,可能会有多…

MFC笔记:本专栏课件

专栏导航 上一篇&#xff1a;在VS2019里面&#xff0c;调整代码字体大小 回到目录 下一篇&#xff1a;无 本节前言 在之前的讲解里面&#xff0c;我讲解了 Visual Studio 软件的一些个基础操作步骤。从本节开始&#xff0c;我们进入预备章。 本节内容&#xff0c;属于是 …

Flutter - 基础Widget

Flutter 中万物皆 Widget&#xff0c;基础Widget 同步对应 Android View. 普通文本 Text /*** 控制文本样式统一使用 style:TextStyle, 例&#xff1a;fontSize(字体大小),color(颜色),shadows(阴影)等等* 控制文本布局需单独设置&#xff1a;* textAlign(文不对齐方式)* te…

蓝桥杯之日期题

文章目录 1.蓝桥杯必备知识点2. 题型13.需求2 1.蓝桥杯必备知识点 蓝桥杯是一个面向全国高校计算机相关专业学生的学科竞赛&#xff0c;涵盖多个赛道&#xff0c;常见的有软件类&#xff08;如 C/C 程序设计、Java 软件开发、Python 程序设计&#xff09;和电子类&#xff08;…

本地部署大模型: LM Studio、Open WebUI 与 Chatbox 全面对比以及选型指南

1. 工具概述 LM Studio 定位&#xff1a;专注于本地化大模型实验与推理的桌面工具&#xff0c;支持多模型并行、Hugging Face集成及离线运行。 核心功能&#xff1a; 图形化界面直接加载GGUF模型文件&#xff0c;支持NVIDIA/AMD GPU加速。 内置OpenAI兼容API&#xff0c;可搭…

springboot实现多文件上传

springboot实现多文件上传 代码 package com.sh.system.controller;import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.PostMap…