【AUTOSAR.相关】

阅读: 评论:0

【AUTOSAR.相关】

【AUTOSAR.相关】

介绍

AUTOSAR (AUTomotive Open System ARchitecture) is a worldwide development partnership of vehicle manufacturers, suppliers, service providers and companies from the automotive electronics, semiconductor and software industry.
这是一个由整车厂,零配件供应商,以及软件、电子、半导体公司合起来成立的组织,从2003年以来, 致力于汽车电子行业提供一个开放、标准的软件架构
核心成为有9个,分别为:博世,大陆,大众,丰田,通用,PSA,福特,宝马,奔驰。

SOMEIP

SOMEIP : Scalable service-Oriented MiddlewarE over IP

SOMEIP 通信单元理解:

  • SOMEIP 面向 service ,和service 相对的就是需要申请服务和订阅需求的client。
  • 提供service 服务的 是一个个 servcie instance ,每个servcie instance 有一个 servcie id , 和 instanceId 相对应。
  • service interface 包括提供的method,field 和 event服务。 event服务通过eventgroup 进行组订阅,避免event 服务碎片化。
  • Field 有 setter 、gettter、notifier 可选组成,至少有一个。
  • Setter 、getter 以及 method ,notifier 和一组 message 相对应。
  • 一组 messages 里边 对应notifier 只提供单项的event 服务。 setter ,getter 消息组 包括request 和 response message。
  • message 中 包括 some/ip header 和 payload。 payload 根据具体情况进行区分。

SOMEIP 协议已经有开源实现, ghub 项目地址 : 。

重要概念:
单播(unitcast): 点对点通信。在client 接受offer 中如果有对应的instance 和 servcie id。在后边subscribe eventgroup的时候使用 单播点对点发送消息,server side 回ACK 或者NACK 消息也是点对点的单播。 event 的发送也是点对点的单播。单播使用的不是SD_PORT, 而是用offer 中提供的 servive 端口, service 发送给 client 的单播消息,也是通过 subscribe eventgroup 带的 endpoint 的 optional 信息中的ip 和端口来发送。

# offer 消息中带的service instance 对应通信方式。 
Frame 69: 110 bytes on wire (880 bits), 110 bytes captured (880 bits)
Ethernet II, Src: c2:48:39:c4:d2:15 (c2:48:39:c4:d2:15), Dst: IPv4mcast_01 (01:00:5e:00:00:01)
Internet Protocol Version 4, Src: 192.168.225.1, Dst: 224.0.0.1
User Datagram Protocol, Src Port: 30490, Dst Port: 30490
SOME/IP Protocol (Service ID: 0xffff, Method ID: 0x8100, Length: 60)Service ID: 0xffffMethod ID: 0x8100Length: 60Client ID: 0x0000Session ID: 0x00d2SOME/IP Version: 0x01Interface Version: 0x01Message Type: 0x02 (Notification)Return Code: 0x00 (Ok)
SOME/IP Service Discovery ProtocolFlags: 0xc0, Reboot Flag,  .... = Reboot Flag: Session ID did not roll over since last reboot.1.. .... = Unicast Flag: Unicast messages support..0. .... = Explicit Initial Events Flag: Explicit Initial Event control not supportedReserved: 0x000000Length of Entries Array: 16Entries ArrayOffer Service Entry (Service ID 0x6002, Instance ID 0x0101, Version 0.0)Type: 0x01 (Offer Service)Index 1: 0x00Index 2: 0x000010 .... = Number of Opts 1:  0000 = Number of Opts 2: 0x0[Options referenced: 0-1]Service ID: 0x6002Instance ID: 0x0101Major Version: 0TTL: 3Minor Version: 0Length of Options Array: 24Options Array0: IPv4 Endpoint Option (192.168.225.1:30001 (UDP))Length: 9Type: 4Reserved: 00IPv4 Address: 192.168.225.1Reserved 2: 00Protocol: 17 (UDP)Port: 300011: IPv4 Endpoint Option (192.168.225.1:30002 (TCP))Length: 9Type: 4Reserved: 00IPv4 Address: 192.168.225.1Reserved 2: 00Protocol: 6 (TCP)Port: 30002# subscribe 中带的client 的通信方式 
Frame 402: 110 bytes on wire (880 bits), 110 bytes captured (880 bits)
Ethernet II, Src: AsixElec_dc:36:40 (00:0e:c6:dc:36:40), Dst: e2:ac:68:27:74:62 (e2:ac:68:27:74:62)
Internet Protocol Version 4, Src: 192.168.225.24, Dst: 192.168.225.1
User Datagram Protocol, Src Port: 30490, Dst Port: 30490
SOME/IP Protocol (Service ID: 0xffff, Method ID: 0x8100, Length: 60)Service ID: 0xffffMethod ID: 0x8100Length: 60Client ID: 0x0000Session ID: 0x0001SOME/IP Version: 0x01Interface Version: 0x01Message Type: 0x02 (Notification)Return Code: 0x00 (Ok)
SOME/IP Service Discovery ProtocolFlags: 0xc0, Reboot Flag,  .... = Reboot Flag: Session ID did not roll over since last reboot.1.. .... = Unicast Flag: Unicast messages support..0. .... = Explicit Initial Events Flag: Explicit Initial Event control not supportedReserved: 0x000000Length of Entries Array: 16Entries ArraySubscribe Eventgroup Entry (Service ID 0x6002, Instance ID 0x0101, Eventgroup ID 0x7002, Version 0)Type: 0x06 (Subscribe Eventgroup)Index 1: 0x00Index 2: 0x000010 .... = Number of Opts 1:  0000 = Number of Opts 2: 0x0[Options referenced: 0-1]Service ID: 0x6002Instance ID: 0x0101Major Version: 0TTL: 3Reserved:  .... = Initial Event Request: False.000 .... = Reserved:  0000 = Counter: 0x0Eventgroup ID: 0x7002Length of Options Array: 24Options Array0: IPv4 Endpoint Option (192.168.225.24:37252 (UDP))Length: 9Type: 4Reserved: 00IPv4 Address: 192.168.225.24Reserved 2: 00Protocol: 17 (UDP)Port: 372521: IPv4 Endpoint Option (192.168.225.24:45303 (TCP))Length: 9Type: 4Reserved: 00IPv4 Address: 192.168.225.24Reserved 2: 00Protocol: 6 (TCP)Port: 45303

组播(multicast): offer 和 find 这类SD 消息通过组播发送。

SOME/IP Header

PayLoad 根据不同的应用场景再进行区分。
针对各个字段理解如下:

Message ID

MessageID 是一个笼统的概念,因为 SOMEIP 是面向service 的, 一般 MessageID 会进一步分解为 service ID 和 method ID 或者 event ID。 如图所示:

Length

Length field shall contain the length in Byte starting from Request ID/Client ID until the end of the SOME/IP message.

Request ID

PRS_SOMEIP_00043: The Request ID shall be unique for a provider- and subscriber-combination ,这一句应该是说对于 provider,针对同一个 subscriber 针对不通的method 类请求,要使用不同的 request ID,这个ID 是 subscriber 自己生成的。 包括请求里边的session ID 也是 subscriber 自己生成的。 对于 subscriber 它不关系 这个request ID,response的时候,直接copy 对应的字段,填进去即可。
那么 有没有 可能provider 收到两个 request_ID 是一样的消息呢? 有可能, 收到,反正它也不关注。 PRS_SOMEIP_00704 做了response 的说明。只是copy 过来,填进去。 区分不同的client 实体,是通过 udp 或tcp 的通信协议地址来的。 针对同一个client 中不通进程的请求,应该是通过udp或 tcp 的port 进去分析, 不同线程的请求,是通过 client_id 来区分的。 我是这样理解的。

Request ID 是 Client 用来请求 method 时区分不通的 method ,同时也要能区分不同的 client.
在 AUTOSAR 中 将Request ID 分成两部分。

Protocol Version

The Protocol Version identifies the used SOME/IP Header format
针对SOMEIP 头的版本定义,方便对头进行解析。

Interface version

针对 Service 做的版本定义,一般应该都是1。用来做,针对service 的的向后兼容。
Interface Version shall be an 8 Bit field that contains the Major
Version of the Service Interface

Message Type

用来定义不通的Message ,如是Request 还是 Response,是正常response 还是异常 Response。Request 是否需要 Response等。


SOME/IP-TP: 非tcp 的 在SOMEIP 栈解决的分段协议, 全称: Transporting large SOME/IP messages of UDP.
TP header OFFSET 的理解

TP header ,放在 SOMEIP header之后, payload 之前, 包括 一个 offerset value, 由于offset 占用的是高28位,第二个字节的高四位协议要求填0, 所以 第一个字节 的值的单位 是 16个字节 。 比如 协议上列举的1392 ,第一个字节 是 0x57. 加上第二个字节高四位 ,就是 “0101 0111 0000” 。 0x57 就是 协议上说的 87。

PayLoad

PayLoad 最大不超过1400字节, 是为了后续 header 变化做了预留。
The size of the SOME/IP payload field depends on the transport protocol used. With UDP the SOME/IP payload shall be between 0 and 1400 Bytes. The limitation to 1400 Bytes is needed in order to allow for future changes to protocol stack (e.g. changing to IPv6 or adding security means).

PayLoad 主要是解决parameter的序列化问题。核心就是序列化的规则(要考虑到解析效率,所以一般都需要进行对齐)。
对齐的意义:
There are processor architectures which can access data more efficiently (i.e. master) when they start at addresses which are multiples of a certain number (e.g multiples of 32 Bit).
要对齐进行 Padding,padding的东西一般都要丢弃,解析一般只管自己要的,其他都丢弃(前提是message 相关字段检查没问题)。
Paramter 可以分为 固定长度考虑和非固定长度考虑,固定长度的,可以考虑不用长度前缀,非固定长度的必须要有长度前缀,方便进行数据分割解析。

The serialization of a struct shall be close to the in-memory layout. This means, only the parameters shall be serialized sequentially into the buffer. Especially for structs it is important to consider the correct memory alignment.
Struct 由于嵌套存在嵌套,尤其是内部有array 或者 strings 类型的,长度不固定。 当前也有固定长度的struct ,但是大部分可能不太固定。

  • 正常struct 序列化

    Data ID,其实就是TAG,类似于 asn.1 TLV结构中的T值。序列化的时候考虑T值,方便后续向后兼容(因为以前的内容可以按照T值去检索,而不用考虑在struct中的位置)。那么 Data ID 如何解析呢? Data ID 长度固定,为两个字节(PRS_SOMEIP_00202)。 TAG 16bit 结构如下:
  • reserved (Bit 7 of the first byte)
  • wire type (Bit 6-4 of the first byte)
  • Data ID (Bit 3-0 of the first byte and bit 7-0 of the second byte)

    Wire Type: include whether use length ,and length of length if length field exist.

Wire Type 协议描述如下:
wire type 4 ensures the compatibility with the current approach where the size of length fields is statically configured. This approach has the drawback that changing the size of the length field during evolution of interfaces is always incompatible. Thus, wire types 5, 6 and 7 allow to encode the size of the used length field in the transferred byte stream. A serializer may use this, if the statically configured size of the length field is not sufficient to hold the current size of the data struct.

String

String 分为 fixed 和 dynamic 的。 String 一般序列化结构是 BOM(Byte order Mark)+ content + 结束符。 结束符根据是否 UTF-8 可以分为 “” 或者 “”,动态的String 需要在BOM 之前加上 length 字段。

Array

Array 不管是否fixed ,都要带 length 。

Enumerate

枚举定义使用 unsigned int 序列化。

Bitfield

Bitfield 转化为 UNIT8,UNIT16,UNIT32等完成。

Union

Union 结构如下:

  1. Length field [32 bit] //使用configuration 规定字段长度。
  2. Type field [32 bit]
  3. Data including padding [sizeof(padding) = length - sizeof(data)]

Pading Like this:

SOMEIP-SD

Someip-SD 是SOMEIP 的一个子协议,是在SOMEIP 协议层实现的一个 Discover 协议,主要解决 service 发现 ,事件订阅管理等服务区。 有了SD 协议, SOMEIP的应用场景更加灵活。

SOMEIP-SD Header


Flags 字段定义:

  • RebootFlag: 表示Service 的一个状态 , 当Sevice session id 出现整体切换的时候,rebootFlag 要配合进行切换。 比如 Service Initial 后 sessionID 从最小开始不断增加,这些消息默认rebootflag为1, 如果session 到最大,进行wrap 重新counter,就需要rebootflag =0 .
  • Unicast Flag 应用场景有限?

Entry format

Entry 可以分为两类,一类是 Service Entry ,另外一类是 EventGroup 订阅。

  • Service Entry:

Type: 用来区分 ServiceEntry 类型; encodes FindService (0x00), OfferService (0x01) and StopOfferService (0x01) 。
Index of 1st options:这个值表示的是后续options 中的索引。

service entry 中包含的主要是一些ID 管理和识别类消息,其他entry content 需要通过options 进行存放。 这个是用来描述1st 在options 中的位置。 不用看,options 也是一个数据,数据长度通过option 中的length来控制。(entry 大小固定为16个字节,所以前边+length 就可以知道 optional 的起始位置)。

#of opt 1: 定义 index of 1st options index 以后用了多少个option。0 表示没有option。 and Index of 1st Options 要设置为0。
TTL: entry 的 lifetime ,不是太理解?

  • EventGroup Entry

    Type : encodes Subscribe (0x06), StopSubscribeEventgroup (0x06),SubscribeAck (0x07) and SubscribeEventgroupNack (0x07)
    Counter:Is used to differentiate identical Subscribe Eventgroups of the same subscriber. Set to 0x0 if not used.

Optional Array

Optional Format:
  • Length [uint16]: Specifies the length of the option in Bytes.
  • Type [uint8]: Specifying the type of the option.
ValueType Name
1Configuration Option
2Load Balancing Option
4IPv4 Endpoint Option
6IPv6 Endpoint Option
  • Discardable Flag [1 bit]: Specifies if the option can be discarded.
  • Bit 1 to bit 7 are reserved and shall be 0.
Configuration Option

Load Balance option

IPv4 Endpoint Option

IPv4 Endpoint Option

VSOMEIP

VSOMEIP 是一套 GENIVI 倡导实现的开源 SOME/IP 协议栈,GENIVI 是一个联盟组织,由BMW倡导,是 COVESA(Connected Vehicle Systems Alliance) 的前身。COMMONAPI 也是 这个组织倡导实现的的开源项目,用来通过工具化生成 VSOMEIP 使用框架。

VSOMEIP 分析

COMMONAPI分析

COMMONAPI 使用FrancaIDL对服务接口进行定义。 fidl 文件是用IDL写的,用来描述服务提供的接口信息,比如method,attribute等。 文件后缀 fidl.

amplesinterface E01HelloWorld {version { major 0 minor 1 } method sayHello {in {String name}   out {String message}   }   method sendBuff {in {ByteBuffer dataBuff}   }   
}

fdepl 文件描述服务的部署信息,包括service id,instance id,method id,event id .

import "platform:/ivimonapi.someip/deployment/CommonAPI-4-SOMEIP_deployment_spec.fdepl"
import "E01HelloWorld.fidl"ivimonapi.someip.deployment for amples.E01HelloWorld {SomeIpServiceID = 4660method sayHello {SomeIpMethodID = 30000in {name {SomeIpStringEncoding = utf16le      }}} method sendBuff {              SomeIpMethodID = 30001     }   
}ivimonapi.someip.deployment for provider as Service {amples.E01HelloWorld {InstanceId = &#amples.HelloWorld"SomeIpInstanceID = 22136   } 
}

COMMONAPI 代码生成工具使用:

    $WORK_DIR/commonapi_core_generator/commonapi-core-generator-linux-`uname -m` -sk fidl/$TEST_APP_NAME.fidl -d src-gen/core$WORK_DIR/commonapi_someip_generator/commonapi-someip-generator-linux-`uname -m` ./fidl/$TEST_APP_NAME-SomeIP.fdepl -d src-gen/someip

VSOMEIP 的使用可以通过 C

参考及连接

AutoSAR 官网连接:
wireshark SOMEIP: .html

vsomeip:

Git hub 地址

vsomeip 例子(比较好的):
=MzUzNDYxOTA1NA==&mid=2247527763&idx=1&sn=958a10a87546f53d9ec8f1ddffc7f2e1&chksm=fa93db92cde452842b8d3df6d7d33216621d3d5a57e43924403f645c0d64369c4427214c867c&scene=27

windows: doxygen+graphviz生成工程中的类继承树及函数调用图
.html
graphviz 下载:
/
doxygen 下载:
.html
COMMONIP 相关介绍

本文发布于:2024-01-31 03:15:55,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170664215824956.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:AUTOSAR
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23