CommonAPI C++(fdepl)介绍

fdepl文件

定义独立于中间件(vSomeIp/D-Bus)的C++ API的一个问题是,需要针对API的各个部分使用不同的配置参数,这部分需要取决于中间件。例如,参数,数组或字符串的最大长度等。

Franca IDL可以根据中间件或特定于平台的部署模型(*.fdepl文件)中使用的中间件来指定部署参数。
一个明确的目标是,针对Common API编写的应用程序可以与不同的Common API IPC后端链接,而无需更改应用程序代码。

因此,有一个重要的隐性限制:Franca IDL(*.fidl文件)中定义的接口只与CommonAPI以及用户调用相关。专用于IPC后端的部署模型(.fdepl)不得影响所生成的API。但是允许使用非特定的部署模型。

fdepl文件的基本构成

类别1 类别2 说明 举例
for interface 对接口进行一些部署,设置ServiceID值,也可以设置枚举支持的类型 *Reliable = false表示使用UDP协议,Reliable = true表示使用TCP协议
attribute 为属性的getter, setter等方法提供ID值 attribute x { SomeIpGetterID = 3000 SomeIpSetterID = 3001 SomeIpNotifierID = 33010 SomeIpEventGroups = { 33010 } SomeIpGetterReliable = false SomeIpSetterReliable = false SomeIpNotifierReliable = false}
method 设置method的ID值,并设置输入输出字符串类型的编码/解码格式;也可以订阅方法调用的超时 method foo { SomeIpMethodID = 30000 SomeIpReliable = false in { x2 { SomeIpStringEncoding = utf16le } } out { y2 {SomeIpStringEncoding =utf16le} } }
broadcast 设置广播事件以及广播事件组的ID值,并设置输出字符串类型的编码/解码格式 broadcast myStatus { SomeIpEventID = 33020 SomeIpEventGroups = { 33020 } }
array 定义数组的长度 SomeIpArrayLengthWidth = 2
enumeration 设置枚举的数据类型 EnumBackingType = UInt64
for provider 提供实例
instance 设置实例名称以及实例ID值,并设置实例的地址和端口号 instance commonapi.mthd.Method { InstanceId = “commonapi.mthd.Method” SomeIpInstanceID = 22136 SomeIpUnicastAddress = “192.168.0.2” SomeIpReliableUnicastPort = 30500 SomeIpUnreliableUnicastPort = 30501 }
for typeCollection 用户自己定义的各种数据类型的集合
array 定义数组的长度 SomeIpArrayLengthWidth = 2
enumeration 设置枚举的数据类型 EnumBackingType = UInt64

使用实例展示:

/* Copyright (C) 2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
import "platform:/plugin/org.genivi.commonapi.someip/deployment/CommonAPI-4-SOMEIP_deployment_spec.fdepl"
import "E01HelloWorld.fidl"

define org.genivi.commonapi.someip.deployment for interface commonapi.examples.E01HelloWorld {
    SomeIpServiceID = 4660

    method sayHello {
        SomeIpMethodID = 30000
        SomeIpReliable = true
        
        in {
            name {
                SomeIpStringEncoding = utf16le
            }
        }
    }
}

define org.genivi.commonapi.someip.deployment for provider as Service {
    instance commonapi.examples.E01HelloWorld {
        InstanceId = "commonapi.examples.HelloWorld"
        
        SomeIpInstanceID = 22136
    
        SomeIpUnicastAddress = "192.168.0.2"
        SomeIpReliableUnicastPort = 30499
        SomeIpUnreliableUnicastPort = 30499
    }
}

for interface

for interface,对应于*.fidl文件中的interface,在这里面主要是配置中间件的ServiceID,以及其他method,broadcast,attribute等使用的methodID,eventID值等。

设置ServiceID:

SomeIpServiceID = 4660

也可以在此定义整个接口的CommonAPI C++级别上定义枚举支持的类型,默认是UInt32:

DefaultEnumBackingType: { UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64 }  (default: UInt32);

例如:

DefaultEnumBackingType = UInt8
attribute

为每个属性所使用的getter, setter等方法设置ID值,并设置这些方法的可靠性。

method

为方法method设置methodID值,并设置可靠性,

也可以为in, out的输入输出参数的字符串类型设置编码/解码格式,也可以不设置,从而使用默认设置。


也可以在此处设置超时:

Timeout : Integer (default: 0);

例如:

Timeout = 1
broadcast

为broadcast事件设置EventID值,Event Groups值(这个是将自己想要划分为一组的事件ID写在一起),设置可靠性,也可以定义out参数里面字符串类型的编码/解码格式。

for typeCollection

array

SomeIpArrayLengthWidth是决定长度字段的大小,表示数组序列化时在数组前面用于表示数组长度的字节数。

即SomeIpArrayLengthWidth =2表示数组在序列化时,前面需要加2个字节,用于表示数组的长度,允许的值是0、1、2、4。

0表示没有长度字段。

array myArray {
SomeIpArrayLengthWidth = 2
}
enumeration

可以在此设置枚举使用的数据类型:

EnumBackingType : {UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64} (optional);

例如:

EnumBackingType = UInt64
for provider

在此提供程序所依赖的所有服务实例(如果有),并为实例设置名称,ID值以及IP地址和端口号。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章