SOME/IP--协议英文原文讲解7

ops/2025/2/20 19:51:24/

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

1. SOME/IP协议讲解

2. SOME/IP-SD协议讲解

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


4.1.5 De-serialization of Data Structures
The de-serialization process need to inspect the payload (serialized byte stream) of
the received SOME/IP message. Thereby the de-serialization process need to identify
the elements within the received byte stream and compare the identified elements with
the configured data type(s) of the corresponding service interface (please note, the
data type is derived from the interface specification, which defines the exact position
of all data structures in a SOME/IP message). The possibility to identify elements in a
dedicated SOME/IP serialized byte stream depend on the interface specification and
the serialization properties. The serialization properties define among others:
• if structured data types are serialized with a length field in front
• if tag-length-value are used for encoding, which include data ids and the possibility specify optional data members
The de-serialization process of a SOME/IP messages need to consider the received
message length and deal with a message length which may be larger or less then expected according the interface specification. This is needed to support backward compatible communication, where ECUs of a heterogeneous in-vehicle network (re-used
ECUs and new developed ECUs) communicate via SOME/IP serialized byte streams.
The subsequential chapters describe the expected behavior of the de-serialization process.
4.1.5 数据结构的反序列化

SOME/IP(Scalable service-Oriented MiddlewarE over IP)消息的反序列化过程需要检查接收到的消息的有效载荷(序列化的字节流)。在此过程中,反序列化需要识别接收到的字节流中的元素,并将这些已识别的元素与相应服务接口配置的数据类型进行比较(请注意,数据类型是从接口规范中派生的,该规范定义了SOME/IP消息中所有数据结构的精确位置)。在专用的SOME/IP序列化字节流中识别元素的可能性取决于接口规范和序列化属性。

序列化属性定义了多种内容,其中包括:

结构化数据类型是否在前面有一个长度字段进行序列化。
是否使用标签-长度-值(TLV)进行编码,这包括数据标识符以及指定可选数据成员的可能性。
SOME/IP消息的反序列化过程需要考虑接收到的消息长度,并处理可能大于或小于接口规范所预期的消息长度。这是为了支持向后兼容的通信,在这种通信中,异构车载网络(包括重新使用的电子控制单元ECU和新开发的ECU)通过SOME/IP序列化的字节流进行通信。

后续的章节将描述反序列化过程的预期行为。这包括但不限于如何处理不同长度的消息、如何根据TLV编码解析数据、以及如何确保数据类型的正确匹配,以确保在异构车辆网络中实现可靠和兼容的通信。

总结:了解前面章节描述序列化的规则,则就可以反向解析出数据了。

4.1.5.1 Structured DataTypes (structs)
If more data then expected was received, then the de-serialization process should accept all received elements of the SOME/IP message payload which correspond to the
configured service interface data type and skip the unknown identified elements of the
de-serialized SOME/IP message payload. If less data then expected was received,
then the de-serialization should accept all know elements of the SOME/IP message
payload which correspond to the configured service interface data type and fill the
missing elements of the configured service interface data type with an specified complementary default value (e.g. initial value).
4.1.5.1 结构化数据类型(结构体)

如果接收到的数据比预期的多,那么反序列化过程应该接受SOME/IP消息有效载荷中所有与配置的服务接口数据类型相对应的元素,并跳过反序列化后的SOME/IP消息有效载荷中未知的已识别元素。如果接收到的数据比预期的少,那么反序列化过程应该接受SOME/IP消息有效载荷中所有与配置的服务接口数据类型相对应的已知元素,并用指定的补充默认值(例如初始值)填充配置的服务接口数据类型中缺失的元素。

在处理这种情况时,重要的是要确保系统的稳定性和向后兼容性。当接收到比预期更多的数据时,跳过未知元素可以防止解析错误或数据损坏,同时仍然能够利用可用的有效数据。当接收到比预期更少的数据时,使用默认值填充缺失的元素可以确保服务能够继续运行,尽管可能以某种受限或降级模式运行。

这种处理策略是设计用于在异构和不断演变的车辆网络中实现灵活的通信。在这样的环境中,不同的电子控制单元(ECU)可能具有不同的软件版本和功能集,因此它们之间的通信可能会遇到数据不匹配的情况。通过采用上述策略,可以确保即使在这种情况下,系统也能够以尽可能高的可靠性和效率运行。

[PRS_SOMEIP_00371]
Upstream requirements: RS_SOMEIP_00033
If the length is greater than the length of the struct as specified in the data type definition only the bytes specified in the data type shall be interpreted and the other bytes shall be skipped based on the length field.
如果⻓度⼤于数据类型定义中指定的结构⻓度,则仅应解释数据类型中指定的字节,并根
据⻓度字段跳过其他字节

[PRS_SOMEIP_00900]
Upstream requirements: RS_SOMEIP_00033
If the length is less than the sum of the lengths of all struct members and no complementary 
default value for the missing data can be provided locally by the receiver, the
deserialization shall be aborted and the message shall be treated as malformed.

如果⻓度⼩于所有结构成员的⻓度之和,并且接收器⽆法在本地提供缺失数据的补充默认
值,则应中⽌反序列化并将消息视为格式错误
4.1.5.2 Structured Datatypes and Arguments with Identifier and optional members (’TLV’)
If the de-serialization process detect an unkown optional member according the configured
service interface data type, then the de-serialization process should ignore this
member. If the de-serialization process detect a missing member/argument, which is
required according the configured service interface data type and a complementary
default value (e.g. initial value) is available, then the de-serialization process should
use the complementary default value for this missing member/argument. Otherwise
the SOME/IP message is treated as malformed.

4.1.5.2 带有标识符和可选成员的结构化数据类型和参数(’TLV’)

在反序列化过程中,如果检测到根据配置的服务接口数据类型未知的可选成员,则反序列化过程应忽略该成员。如果反序列化过程检测到根据配置的服务接口数据类型必需的成员/参数缺失,但存在补充默认值(例如初始值),则反序列化过程应使用此补充默认值来填充缺失的成员/参数。否则,该SOME/IP消息将被视为格式错误。

[PRS_SOMEIP_00223]
Upstream requirements: RS_SOMEIP_00050
The deserializer shall ignore optional members/arguments which are not available in
the serialized byte stream.

反序列化器应忽略序列化字节流中不存在的可选成员/参数。


[PRS_SOMEIP_00217]
Upstream requirements: RS_SOMEIP_00050
If the deserializer reads an unknown Data ID (i.e. not contained in its data definition),
it shall skip the unknown member/argument by using the information of the wire type
and length field.

如果反序列化器读取到未知的数据标识符(即不在其数据定义中),则它应使用线型信息和长度字段来跳过未知的成员/参数。

[PRS_SOMEIP_00380] Behaviour if a required member/argument is missing in
the received SOME/IP message
Upstream requirements: RS_SOMEIP_00050
If the deserializer cannot find a required (i.e. non-optional) member/argument defined
in its data definition in the serialized byte stream and a complementary default value for
this missing member/argument is available, then the available complementary default
value shall be used for this missing member/argument. Ohterwise the deserialization
shall be aborted and the message shall be treated as malformed.
[PRS_SOMEIP_00380] 接收到的SOME/IP消息中缺少必需成员/参数时的行为

如果反序列化器在序列化字节流中找不到其数据定义中定义的必需(即非可选)成员/参数,并且为该缺失的成员/参数提供了补充默认值,则应使用此可用的补充默认值来填充该缺失的成员/参数。否则,应中止反序列化过程,并将消息视为格式错误。

这条需求强调了SOME/IP通信中数据完整性的重要性。在SOME/IP消息中,如果缺少了根据接口规范定义的必需成员/参数,这可能会影响到消息的正确解析和后续处理。因此,系统需要有一定的容错机制来处理这种情况。

当遇到缺少必需成员/参数的情况时,如果系统能够提供一个合理的默认值来填充这个缺失的部分,那么这可以确保系统的稳定运行,并减少因数据不完整而导致的通信失败。然而,如果没有可用的默认值,或者默认值不足以保证系统的正确运行,那么系统应该中止反序列化过程,并将该消息视为格式错误,以避免潜在的问题。

这种处理策略有助于在异构的车辆网络中实现可靠的SOME/IP通信,并确保系统能够灵活地适应不同的数据配置和通信场景。

4.1.5.3 Strings

Strings could be configured with a fixed length or dynamic length. Independent a string has fixed length or dynamic length configured, a serialized string, which is received with a larger length than expected according the configured service interface data type, should be treated as malformed. For strings with fixed length and received with a length which is less than expected and this string is correctly terminated, the string should be processed. Otherwise the message shall be treated as malformed.

对于变长 定长 字符串:
接收的长度 大于 配置的长度(没看到结束符)则视为 格式错误 
对于定长字串:
接收到小于配置的长度 可根据需要 处理 或是报错

4.1.5.3.1 Strings (fixed length)
[PRS_SOMEIP_00911]
Upstream requirements: RS_SOMEIP_00038
If the length of a string with fixed length is greater than expected (expectation shall
be based on the data type definition), the deserialization shall be aborted and the
message shall be treated as malformed.
定长字串 接收到比预期长的字串 则应终止反序列化 并报错

[PRS_SOMEIP_00912]
Upstream requirements: RS_SOMEIP_00038
If the length of a string with fixed length is less than expected (expectation shall be
based on the data type definition) and it is correctly terminated using "\0", it shall be
accepted.
定长字串 接收到比预期少的长度(但后面有结束符) 可以接收

[PRS_SOMEIP_00913]
Upstream requirements: RS_SOMEIP_00038
If the length of a string with fixed length is less than expected (expectation shall be
based on the data type definition) and it is not correctly terminated using "\0", the
deserialization shall be aborted and the message shall be treated as malformed.
定长字串 收到比预期少的长度 并且后面结束符用的不对 (比如utf-16需要两个结束符 但是只收到1个)则应终止反序列化 并报错---认为时丢数据了 或者对方程序出错了     

Instead of transferring application strings as SOME/IP strings with BOM and "\0" termination,
strings can also be transported as plain dynamic length arrays without BOM
and "\0" termination (see chapter 4.1.4.5.2). Please note that this requires the full string
handling (e.g. endianness conversion) to be done in the applications.
可用用动态数组替代 string 达到不带BOM和结束符的目的,但需要做字节顺序转换

4.1.5.3.2 Strings (dynamic length)
[PRS_SOMEIP_00914]
Upstream requirements: RS_SOMEIP_00039
If the length of a string with variable length is greater than expected (expectation
shall be based on the data type definition), the deserialization shall be aborted and the
message shall be treated as malformed.
如果动态数组长度 长于 期待的(客户定义的最大长度)则应终止反序列化 并报错

规范中未定义的点:
有些客户也会定义动态string的最小长度,接收的长度小于这个 也应该终止反序列化 并报错

4.1.5.4 Arrays
Arrays could be configured with a fixed length or dynamic length. Independent if an
array has fixed length or dynamic length configured, if a serialized array was received
with a larger length than expected according the configured service interface data type,
then all known elements according the configured service interface data type should
be considered and the remaining elements should be skipped by the de-serialization
process.
For arrays with fixed length and the de-serialization process detect a missing element,
which is required according the configured service interface data type and a complementary default value (e.g. initial value) is available, then the de-serialization process
should use the complementary default value for this missing member/argument. Otherwise the SOME/IP message is treated as malformed.
定长、变长数组
如果收到长度 大于 预期的长度 则跳过 或 忽略这些多余的元素

什么情况?
1. 数组嵌套 外层指定了元素长度 内层也有长度 会有不一致的情况
2. SOME/IP header中的payload指示的定长数组长度 大于 客户规范中规定的定长长度
2. 客户会指定 动态长度的最大值
3. 客户 为了版本兼容 可能会配置开启定长前面的长度字段


对于具有固定长度的数组,如果反序列化过程检测到缺少元素(根据配置的服务接⼝数据
类型,该元素是必需的),并且有可⽤的补充默认值(例如初始值),则反序列化过程应
使⽤此缺失成员/参数的补充默认值。否则,SOME/IP 消息将被视为格式错误。

4.1.5.4.1 Arrays (fixed length)
[PRS_SOMEIP_00917]
Upstream requirements: RS_SOMEIP_00036
If the length of a fixed length array is greater than expected (expectation shall be
based on the data type definition) only the elements specified in the data type shall be
interpreted and the other bytes shall be skipped based on the length field.
[PRS_SOMEIP_00381] Behaviour if a required element is missing in the received
SOME/IP message
Upstream requirements: RS_SOMEIP_00036
dIf the length of a fixed length array is less than expected (expectation shall be based
on the data type definition) and a complementary default value (e.g. initial value) for the
missing data can be provided locally by the receiver, then the deserialization consider
this complementary default value as value for the missing data. Otherwise the deserialization process shall be aborted and the message shall be treated as malformed.c
Note: Overruns of fixed-size arrays can only be detected with a length field.
定长数组:
接收到过少的长度元素 如果没有默认值填充 则可终止解析 并报错。

4.1.5.4.2 Arrays (dynamic length)

[PRS_SOMEIP_00919] Upstream requirements: RS_SOMEIP_00037

If the length of a variable length array is greater than expected (expectation shall be based on the data type definition) only the elements specified in the data type shall be interpreted and the other bytes shall be skipped based on the length field.

注意点和定长一样:跳过多余的

4.1.5.5 Enumeration

No further requirements considered for the deserialization.

4.1.5.6 Bitfield

No further requirements considered for the deserialization

上面俩 没啥特别说的

4.1.5.7 Union / Variant
[PRS_SOMEIP_00915]
Upstream requirements: RS_SOMEIP_00034
If the length of a union is greater than expected (expectation shall be based on the
data type definition) only the bytes specified in the data type shall be interpreted and
the other bytes shall be skipped based on the length field.
联合体收到的 多余 客户自己定义的最大长度 则应该根据 联合体头中数据类型 指定的字节数 解析需要的 ,,多余的跳过即可

[PRS_SOMEIP_00916]
Upstream requirements: RS_SOMEIP_00034
If the length of a union is less than expected (expectation shall be based on the
data type definition) it shall depend on the inner data type whether valid data can be
deserialized or the deserialization shall be aborted and the message shall be treated
as malformed.
联合体收到过少的情况,如果够头部中类型指定的数据类型长度(因为有可能多余的是填充)则直接用就行,否则终止解析 并报错


http://www.ppmy.cn/ops/159697.html

相关文章

什么是平面环形无影光源

平面环形无影光源是一种特殊设计的光源,主要用于消除阴影,提供均匀照明,常见于摄影、显微镜、工业检测等领域。以下是其关键特点和应用: 关键特点 环形设计:光源呈环形,光线从四周均匀照射,减少…

MME-CoT:专为评估大型多模态模型CoT推理能力的基准测试。涵盖了数学、科学、OCR、逻辑、时空和一般场景6个领域。

2025-02-09 ,由CUHK MMLab、CUHK MulLab、字节跳动、、东北大学等机构联合发布MME-CoT数据集,该数据集目的评估大型多模态模型(LMMs)中的思维链(CoT)推理能力,涵盖数学、科学、OCR、逻辑、时空和…

功能测试-黑盒测试

黑盒测试是一种功能测试方法,它将软件视为一个“黑盒”,即测试人员不关心软件的内部结构和实现,细节只关注软件的输入和输出是否符合预期。以下是黑盒测试方法的详细解释: 1. 黑盒测试的核心理念 黑盒测试的核心在于验证软件的功…

【DeepSeek-R1】满血版免费网页端使用(不卡顿,支持联网搜索)

DeepSeek-R1-671B 平台汇总 序号平台名称网址特点使用建议1DeepSeek 官方chat.deepseek.com提供R1和V3满血版,支持联网功能,但高峰期可能卡顿上午使用较流畅,下午和晚上可能卡顿,建议错峰使用2腾讯元宝yuanbao.tencent.com完整版…

Flutter 状态管理库-----GetX(一)

Flutter 状态管理库-----GetX(一) 一、GetX特点 状态管理: GetX 提供了非常简洁的 API 来管理 Flutter 中的状态。它可以通过 GetX() 或 Obx() 来监听和更新界面。通过响应式编程,GetX 可以在数据变化时自动更新 UI。它避免了传统的 Flutter 状态管理方…

Nat. Genet | 单细胞多组回归模型识别功能和疾病相关增强子,并实现染色质潜力分析

Nat. Genet | 单细胞多组回归模型识别功能和疾病相关增强子,并实现染色质潜力分析 本文提出了一种名为SCARlink的基因调控模型,通过结合单细胞RNA测序(scRNA-seq)和单细胞开放染色质测序(scATAC-seq)数据&…

图论- 经典最小生成树算法

最小生成树算法 什么是最小生成树Kruskal算法关键代码实现 Prim 最小生成树算法Kruskal 和 Prim 算法的区别为什么Prim算法不需要判断成环,但Kruskal需要 什么是最小生成树 在图中找一棵包含图中所有节点的树, 且权重和最小的那棵树就叫最小生成树. 如下:右侧生成树的权重和显…

应用案例 | uaGate SI助力汽车零部件工厂将生产数据传输到MES

一、背景和挑战 (图1 汽车零部件工厂生产车间) 随着汽车工业的不断发展,新能源汽车市场的竞争日益激烈,这对汽车零部件供应商提出了更高的要求,包括提升产品精度、增强可靠性、节能环保以及控制成本等多个方面。某国际…