Main Content

配置Autosar客户端-Server Communication

在Si万博1manbetxmulink中®,,,,you can model AUTOSAR client-server communication for simulation and code generation. For information about the Simulink blocks you use and the high-level workflow, see客户端服务器接口

为了建模Autosar服务器和客户端,您可以执行以下任意方法:

  • Import AUTOSAR servers and clients from ARXML code into a model.

  • Configure AUTOSAR servers and clients from Simulink blocks.

此主题提供了从Simulink块开始的AutoSar服务器和客户端配置的示例。万博1manbetx

配置Autosar服务器

This example shows how to configure a万博1manbetxSimulink函数block as an AUTOSAR server. The example uses these files in the foldermatlabroot/help/toolbox/autosar/examples((光盘至folder):

如果you copy the files to a working folder, collocate the MATLAB®file with the model file.

  1. Open a model in which you want to create and configure an AUTOSAR server, or open the example modelmControllerWithInterface_server.slx

  2. 添加一个万博1manbetxSimulink函数block to the model. The example model provides two万博1manbetxSimulink函数blocks,远程andreadData

  3. 配置万博1manbetxSimulink函数block to implement a server function. Configure a function prototype and implement the server function algorithm.

    在里面example model, the contents of the万博1manbetxSimulink函数命名readDataimplement a server function namedreadData

    这contents include:

    • TriggerblockreadData,,,,representing a trigger port for the server function. In theTrigger块属性,触发类型is set to函数呼叫。另外,选项Treat as Simulink function选择。

    • 论点INPORTblockOpand参数外口blocksData,,,,ERR,,,,and负码,,,,corresponding to the function prototype[数据,err,negCode] = readdata(op)

      笔记

      配置服务器函数参数时,您必须在Signal Attributestab of the inport and outport blocks. The AUTOSAR configuration fails validation if signal attributes are absent for server function arguments.

    • Blocks implementing thereadData功能算法。在此示例中,一些简单的块提供Data,,,,ERR,,,,and负码最小操作的输出值。一个Constantblock represents the value of an application error defined for the server function. The value ofOppassed by the caller is ignored. In a real-world application, the algorithm could perform a more complex manipulation, for example, selecting an execution path based on the passed value ofOp,生成应用程序所需的输出数据,并检查是否有错误条件。

  4. When the server function is working in Simulink, set up the万博1manbetxSimulink函数block in a model configured for AUTOSAR. For example, configure the current model for AUTOSAR or copy the block into an AUTOSAR model.

    示例模型是一种汽车模型,在其中万博1manbetxSimulink函数blockreadDatahas been copied. In place of a meaningfulOpinput value for thereadDatafunction, Simulink data transfer line曲线provides an input value that is used in the function algorithm.

  5. 这required elements to configure an AUTOSAR server, in the general order they are created, are:

    • AutoSar客户端服务器(C-S)接口

    • One or more AUTOSAR operations for which the C-S interface handles client requests

    • 一个UTOSAR server port to receive client requests for a server operation

    • 为了each server operation, an AUTOSAR server runnable to execute client requests

    Open the AUTOSAR Dictionary. To view AUTOSAR C-S interfaces in the model, go to theC-S Interfaces看法。示例模型已经包含客户端服务器接口。

    如果a C-S interface does not yet exist in your model, create one.

    1. 在里面C-S interfaces view, click the添加按钮。This action opens the Add Interfaces dialog box.

    2. 在里面dialog box, name the new C-S Interface, and specify the number of operations you intend to associate with the interface. Leave other parameters at their defaults. Click添加。这new interface appears in the C-S interfaces view.

  6. 在下面C-S Interfaces,创建C-S接口处理客户端请求的一个或多个Autosar服务器操作。每个操作对应于模型中的Simulink服务器功能。万博1manbetx

    扩张C-S Interfaces并扩展要添加服务器操作的单个C-S接口。(在示例模型中,展开CsIf1。)要查看接口的操作,请选择操作。这example model already contains AUTOSAR server operations named远程andreadData

    如果a server operation does not yet exist in your model, create one. (If your C-S interface contains a placeholder operation namedOperation1,,,,you can safely delete it.)

    1. 在里面operations view, click the添加按钮。This action opens the Add Operation dialog box.

    2. 在对话框中,输入操作名称。Specify the name of the corresponding Simulink server function.

    3. 如果相应的simulink服务器函数具有参万博1manbetx数,请在万博1manbetxSimulink函数列表。此操作导致AutoSar操作参数是根据Simulink Server函数参数自动创建的。万博1manbetx点击OK。这operation and its arguments appear in the operations view.

  7. Examine the arguments listed for the AUTOSAR server operation. Expand操作,,,,expand the individual operation (for example,readData),然后选择参数。列出的参数对应于Simulink Server函数原型。万博1manbetx

  8. To view AUTOSAR server ports in the model, go to the server ports view. Expand一个至micComponents,,,,expand the individual component that you are configuring, and select服务器港口。这example model already contains an AUTOSAR server port namedsPort

    如果a server port does not yet exist in your model, create one.

    1. 在里面server ports view, click the添加按钮。This action opens the Add Ports dialog box.

    2. 在里面dialog box, name the new server port, and select the C-S interface for which you configured a server operation. Click添加。新端口出现在服务器端口视图中。

  9. 为了each AUTOSAR server operation, configure an AUTOSAR server runnable to execute client requests. To view AUTOSAR runnables in the model, select运行。这example model already contains a server runnable forreadData,,,,named可运行_readData

    如果您的模型中尚不存在合适的服务器,请创建一个。

    1. 在运行可运行的视图中,单击添加按钮。This action adds a table entry for a new runnable.

    2. 选择新的可运行并配置其名称和符号。这象征name specified for the runnable must match the Simulink server function name. (In the example model, the象征名称可运行_readDatais the function namereadData。)

    3. 创建一个操作驱动的事件,以触发服务器运行。(示例模型定义事件event_readDatafor server runnable可运行_readData。)

      1. 在下面Events,,,,click添加Event。Select the new event.

      2. 为了事件类型,,,,selectOperationInvokedEvent

      3. 输入Event Name

      4. 在下面Event Properties,,,,select aTrigger对应于先前为服务器函数创建的服务器端口和C-S操作的值。(在示例模型中,Trigger选择的值可运行_readDataissPort.readData,,,,combining server portsPortwith operationreadData。) 点击申请

    此步骤完成了配置的AutoSar字典视图中AutoSar Server的配置。

  10. 切换到配置的代码映射编辑器视图,然后将Simulink Server函数映射到可运行的AutoSar Server。万博1manbetx

    1. Open the Code Mappings editor. Select the功能标签。

    2. Select the Simulink server function. To map the function to an AUTOSAR runnable, click on the可运行字段并从可用的服务器运行列表中选择相应的运行。在示例模型中,simulink函数万博1manbetxreadDatais mapped to AUTOSAR runnable可运行_readData

  11. 要验证AutoSar组件配置,请单击Validate按钮。如果errors are reported, fix the errors, and retry validation. Repeat until validation succeeds.

  12. 为模型生成C和ARXML代码。

一个fter you configure an AUTOSAR server, configure a corresponding AUTOSAR client invocation, as described in配置Autosar客户端

配置Autosar客户端

配置AutoSar服务器后,如图配置Autosar服务器,,,,configure a corresponding AUTOSAR client invocation. This example shows how to configure aFunction Caller阻止作为Autosar客户端调用。该示例使用文件matlabroot/help/toolbox/autosar/示例/mcontrollerwithinterface_client.slx

  1. Open a model in which you want to create and configure an AUTOSAR client, or open the example modelmcontrollerwithinterface_client.slx

  2. 添加一个Function Callerblock to the model. The example model provides a Simulink Function block namedreadData,,,,which is located inside可运行3_Subsystem

  3. 配置Function Callerblock to call a corresponding万博1manbetxSimulink函数堵塞。双击块以打开它,然后编辑块参数以指定服务器函数原型。

    在里面example model, thereadDataFunction Callerparameters specify a function prototype for thereadDataAutoSar服务器示例中使用的服务器功能,配置Autosar服务器。Here is thereadData服务器示例的功能。

    Function Caller参数包括功能原型和参数规范字段。原型中的功能名称必须与操作名称为相应的服务器操作指定。查看操作创建步骤配置Autosar服务器。这argument types and dimensions also must match the server function arguments.

    笔记

    如果您想模拟函数调用,则必须放置Function Caller与相应的公共模型或测试线束中的阻塞万博1manbetxSimulink函数堵塞。Simulation is not required for this example.

  4. When the function invocation is completely formed in Simulink, set up theFunction Callerblock in a model configured for AUTOSAR. For example, configure the current model for AUTOSAR or copy the block into an AUTOSAR model.

    小费

    如果您创建(或复制)Function Callerblock in a model before you map and configure the AUTOSAR component, you have the option of having the software populate the AUTOSAR operation arguments for you, rather than creating the arguments manually. To have the arguments created for you, along with a fully-configured AUTOSAR client port and a fully mapped Simulink function caller, use the AUTOSAR Component Quick Start to create a default component. For more information, seeCreate AUTOSAR Software Component in Simulink

    示例模型是一种汽车模型,在其中Function CallerblockreadDatahas been copied. The block is connected to inports, outports, and signal lines matching the function argument data types and dimensions.

    笔记

    Whenever you add or change aFunction Callerblock in an AUTOSAR model, update function callers in the AUTOSAR configuration. Open the Code Mappings editor. In the dialog box, click theUpdate按钮。This action loads or updates Simulink data transfers, function callers, and numeric types in your model. After updating, the function caller you added appears in the功能调用器代码映射编辑器的选项卡。

  5. 按照应该创建的一般顺序配置AutoSar客户端的所需元素是:

    • AutoSar客户端服务器(C-S)接口

    • 一个或多个与您在Autosar Server模型中定义的Simulink Server功万博1manbetx能匹配的AutoSar操作

    • AutoSar客户端端口接收C-S接口提供的服务器操作的客户端请求

    Open the AUTOSAR Dictionary. To view AUTOSAR C-S interfaces in the model, go to theC-S Interfaces看法。示例模型已经包含一个名为client-server接口csinterface

    如果a C-S interface does not yet exist in the AUTOSAR configuration, create one.

    1. 在里面C-S interfaces view, click the添加按钮。This action opens the Add Interfaces dialog box.

    2. 在里面dialog box, name the new C-S Interface, and specify the number of operations you intend to associate with the interface. Leave other parameters at their defaults. Click添加。这new interface appears in the C-S interfaces view.

  6. 在下面C-S Interfaces,,,,create one or more AUTOSAR operations matching the Simulink server functions that you defined in the AUTOSAR server model.

    扩张C-S Interfacesand expand the individual C-S interface to which you want to add an AUTOSAR operation. (In the example model, expandCsInterface。)要查看接口的操作,请选择操作。这example model already contains an AUTOSAR operation namedreadData

    如果您的模型中尚不存在AutoSar操作,请创建一个。(如果您的C-S界面包含一个名为的占位符操作Operation1,,,,you can safely delete it.)

    1. 在里面operations view, click the添加按钮。This action opens the Add Operation dialog box.

    2. 在对话框中,输入操作名称。Specify the name of the corresponding Simulink server function. Leave万博1manbetxSimulink函数放至None,,,,because the client model does not contain the Simulink server function block. ClickOK。新操作出现在操作视图中。

  7. 添加AutoSar操作参数。

    1. 扩张操作,,,,expand the individual operation (for example,readData),然后选择参数

    2. 在里面arguments view, click the添加按钮one time for each function argument. For example, forreadData,,,,click the添加按钮four times, for argumentsOp,,,,Data,,,,ERR,,,,and负码。每次点击都会创建一个新的参数条目。

    3. 选择每个参数输入并设置参数姓名andDirection至match the function prototype.

  8. 要查看模型中的AutoSar客户端端口,请转到客户端端口视图。扩张一个至micComponents,,,,expand the individual component that you are configuring, and select客户端港口。这example model already contains an AUTOSAR client port namedcPort

    如果a client port does not yet exist in your model, create one.

    1. 在客户端端口视图中,单击添加按钮。This action opens the Add Ports dialog box.

    2. 在里面dialog box, name the new client port, and select a C-S interface. Click添加。这new port appears in the client ports view.

    此步骤完成了配置的AutoSar字典视图中AutoSar客户端的配置。

  9. 切换到代码映射编辑器视图的反对figuration and map the Simulink function caller to an AUTOSAR client port and C-S operation.

    1. Open the Code Mappings editor. Select the功能调用器标签。

    2. 选择simulink函万博1manbetx数呼叫者。单击ClientPortfield and select a port from the list of available AUTOSAR client ports. Click on theOperationfield and select an operation from the list of available AUTOSAR C-S operations. In the example model, the Simulink function callerreadDatais mapped to AUTOSAR client portcPortand C-S operationreadData

  10. 要验证AutoSar组件配置,请单击Validate按钮。如果errors are reported, fix the errors, and retry validation. Repeat until validation succeeds.

  11. 为模型生成C和ARXML代码。

配置Autosar客户端-Server Error Handling

AUTOSAR定义了一个应用程序错误状态探讨ism for client-server error handling. An AUTOSAR server returns error status, with a value matching a predefined possible error. An AUTOSAR client receives and responds to the error status. An AUTOSAR software component that follows client-server error handling guidelines potentially provides error status to AUTOSAR Basic Software, such as a Diagnostic Event Manager (DEM).

在Si万博1manbetxmulink中,您可以:

  • Import ARXML code that implements client-server error handling.

  • Configure error handling for a client-server interface.

  • Generate C and ARXML code for client-server error handling.

如果导入实现客户端服务器错误处理的ARXML代码,则进口商在相应的服务器调用点上创建错误状态端口(Function Callerblock) locations.

To implement AUTOSAR client-server error handling in Simulink:

  1. 定义AutoSar Server在Simulink数据类型中返回的可能的错误状态值。万博1manbetx在0-63范围内定义一个或多个错误代码,包括。数据类型的基础存储必须是未签名的8位整数。数据范围必须是出口。为了example, define an enumeration typeappErrType

    classDef(枚举)apperrtype 
                    

    笔记

    这Simulink data type that you define to represent possible errors in the model does not directly impact the AUTOSAR possible errors that are imported and exported in ARXML code. To modify the exported possible errors for a C-S interface or C-S operation, use AUTOSAR properties functions. This topic provides examples.

  2. 定义错误状态输出参数万博1manbetxSimulink函数block that models the AUTOSAR server. Configure the error status argument as the only function output or add it to other outputs. For example, here is a万博1manbetxSimulink函数返回输出中错误状态值的块err

    万博1manbetxSimulink函数block implements an algorithm to return error status.

  3. 在模型中引用可能的错误值类型。在里面参数外口block parameters for the error outport, specify the error status data type, in this case,appErrType。SetPort dimensions到1和Signal typereal

  4. 配置一个UTOSAR properties of the error argument in the client-server interface. Open the AUTOSAR Dictionary, expandC-S Interfaces,并导航到参数Autosar操作的视图。要添加参数,请单击添加按钮。配置参数名称并设置DirectionError

  5. 在每个中创建一个错误端口Function Caller阻止对AutoSar客户端调用进行建模。例如,这是一个Function Callerblock that models an invocation offcnwerr

    在里面Function Callerblock parameters, specify the same error status data type.

    配置错误参数的AutoSar属性以匹配AutoSar字典中的信息,参数查看,如步骤4所示。

这generated C code for the function reflects the configured function signature and the logic defined in the model for handling the possible errors.

apperrtype fcnwerr(real_t x1,real_t x2){apperrtype rty_err_0;if(...)== 0.0){rty_err_0 = ...;} else {rty_err_0 = ...;}返回rty_err_0;}

此外,对于本示例中使用的枚举类型类定义,构建生成标头文件apperrtype.h,包含可能的错误类型定义。

这exported ARXML code contains the possible error definitions, and references to them.

<可能的eRrors>  成功  0    ERROR 1 下流  4    VALUE_MOD3  5   

You can use AUTOSAR property functions to programmatically modify the possible errors that are exported in ARXML code, and to set theDirectionproperty of a C-S operation argument toError

这following example adds UNDERFLOW and VALUE_MOD3 to the possible errors for a C-S interface namedfcnwerr

>> arProps = autosar.api.getAUTOSARProperties(bdroot) >> get(arProps,'fcnWErr','PossibleError') ans = 'fcnWErr/SUCCESS' 'fcnWErr/ERROR' 'fcnWErr/COMM_MODE…' 'fcnWErr/OVERFLOW' >> get(arProps,'fcnWErr/OVERFLOW','errorCode') ans = 3 >> add(arProps,'fcnWErr','PossibleError','UNDERFLOW') >> set(arProps,'fcnWErr/UNDERFLOW','errorCode',4) >> add(arProps,'fcnWErr','PossibleError','VALUE_MOD3') >> set(arProps,'fcnWErr/VALUE_MOD3','errorCode',5) >> get(arProps,'fcnWErr','PossibleError') ans = 'fcnWErr/SUCCESS' 'fcnWErr/ERROR' 'fcnWErr/COMM_MODE…' 'fcnWErr/OVERFLOW' 'fcnWErr/UNDERFLOW' 'fcnWErr/VALUE_MOD3'

您还可以在C-S操作上访问可能的错误。以下示例列出了操作的可能错误fcnwerr在C接口上fcnwerr

>> arProps = autosar.api.getAUTOSARProperties(bdroot) >> get(arProps,'fcnWErr/fcnWErr','PossibleError') ans = 'fcnWErr/SUCCESS' 'fcnWErr/ERROR' 'fcnWErr/COMM_MODE…' 'fcnWErr/OVERFLOW'

以下示例设置了C-S操作参数的方向errError

>> arProps = autosar.api.getAUTOSARProperties(bdroot) >> set(arProps,'fcnWErr/fcnWErr/err','Direction','Error') >> get(arProps,'fcnWErr/fcnWErr/err','Direction') ans = Error

Autosar Server运行的并发约束

这following blocks and modeling patterns are incompatible with concurrent execution of an AUTOSAR server runnable.

  • simulink函数中的块:万博1manbetx

    • Blocks with state, such asUnit Delay

    • Blocks with zero-crossing logic, such as触发子系统andEnabled Subsystem

    • Stateflow®图表。

    • 其他万博1manbetxSimulink函数blocks.

    • 非线系子系统。

    • 传统C功能带有副作用。

  • Modeling patterns inside a Simulink function:

    • 写入数据存储存储器(例如,每位记忆)。

    • 写入全局块信号(例如,静态内存)。

To enforce concurrency constraints for AUTOSAR server runnables, use the runnable propertycan beinvokedConcorry。该属性位于运行view in the AUTOSAR Dictionary.

Whencan beinvokedConcorryis set totrue对于可运行的服务器,AutoSar验证检查块和建模模式,这些模式与同时执行服务器可运行的模型。如果Sim万博1manbetxulink函数包含不兼容的块或建模模式,则验证报告错误。如果can beinvokedConcorryis set tofalse,,,,validation does not check for blocks and modeling patterns that are incompatible with concurrent execution of a server runnable.

You can setcan beinvokedConcorrytrue仅对于可运行的autosar服务器 - 即,可运行的OperationInvokedEvent。属性can beinvokedConcorry不支持其他事件万博1manbetx触发器(例如正时事件)的可运行物品。如果can beinvokedConcorryis set totruenonserver runnable, AUTOSAR验证失败。

要编程设置可运行的属性can beinvokedConcorry,,,,use the AUTOSAR property function。这following example sets the runnable propertycan beinvokedConcorrytrue对于可运行的autosar服务器命名可运行_readData

addpath(fullfile(matlabroot,'/help/toolbox/autosar/示例')); open_system('McOntrollerWithInterface_server')arProps = autosar.api.getAUTOSARProperties('McOntrollerWithInterface_server'); SRPath = find(arProps,[],'Runnable',,,,'姓名',,,,'Runnable_readData'
srpath = 1×1个单元格数组{'swc_controller/controllerWithInterface_ar/runnable_readdata'}
InvConc = get(arprops,'swc_controller/contranterwithinterface_ar/runnable_readdata',,,,...'canBeInvokedConcurrently'
InvConc =逻辑0
set(arprops,'swc_controller/contranterwithinterface_ar/runnable_readdata',,,,...'canBeInvokedConcurrently',,,,true) invConc = get(arProps,'swc_controller/contranterwithinterface_ar/runnable_readdata',,,,...'canBeInvokedConcurrently'
InvConc =逻辑1

Configure and Map AUTOSAR Server and Client Programmatically

要编程配置AutoSar客户端服务器接口的AutoSar属性,请使用AutoSar属性功能,例如andget

To programmatically configure Simulink to AUTOSAR mapping information for AUTOSAR clients and servers, use these functions:

为了example scripts that use AUTOSAR property and map functions, see配置Autosar客户端-Server Interfaces

也可以看看

||||

相关示例

更多关于