Main Content

Model AUTOSAR Adaptive Service Communication

The AUTOSAR Adaptive Platform defines service-oriented, event-based communication between adaptive software components. Each adaptive software component provides and consumes services, and interconnected components send and receive service events. A component contains:

  • An algorithm that performs tasks in response to received events.

  • Required and provided ports, through which events are received and sent.

  • Service interfaces, which provide the framework for event-based communication.

To model adaptive service communication in Simulink®, you can:

  • Create AUTOSAR required and provided ports, service interfaces, service interface events, and C++ namespaces.

  • Create root-level inports and outports and map them to AUTOSAR required and provided ports and service interface events.

If you have Simulink Coder™ and Embedded Coder® software, you can generate C++ code and ARXML descriptions for AUTOSAR service communication.

To implement adaptive service communication in Simulink:

  1. Open a model configured for the AUTOSAR Adaptive Platform. Displays in this example use model autosar_LaneGuidance.

  2. Open the AUTOSAR Dictionary and select Service Interfaces. To create an AUTOSAR service interface, click the Add button . In the Add Interfaces dialog box, specify the interface name and the number of associated events.

  3. Expand the Service Interfaces node. Expand the new service interface and select Events. In the events view, select each service event and configure its attributes.

  4. Select Namespaces. The namespaces view allows you to define a unique namespace for each service interface. The code generator uses the defined namespace when producing C++ code for the interface. To modify or construct a namespace specification, select a namespace element and edit the name value. For example, this namespaces view defines namespace company::chassis::provided for service interface ProvidedInterface.

  5. At the top level of the AUTOSAR Dictionary, expand AdaptiveApplications and expand the adaptive software component. Use the RequiredPorts and ProvidedPorts views to add AUTOSAR required and provided ports that you want to associate with the new service interface. For each new service port, select the service interface you created.

  6. Optionally, you can configure adaptive service instance identification for AUTOSAR ports. In the RequiredPorts or ProvidedPorts view, select a port and view its Manifest attributes. Based on the service instance form selected in XML options, examine the value for Instance Specifier or Instance Identifier. You can enter a value or accept an existing value. For more information, see Configure AUTOSAR Adaptive Service Instance Identification.

  7. Optionally, for AUTOSAR required ports, you can configure service discovery, which affects how adaptive applications find dynamic services. In the RequiredPorts view, select a port and configure its Service Discovery Mode. Select OneTime or DynamicDiscovery. For more information, see Configure AUTOSAR Adaptive Service Discovery Modes.

  8. In the model widow, to model AUTOSAR adaptive service ports, create root-level inports and outports.

  9. Open the Code Mappings editor. Use the Inports and Outports tabs to map Simulink inports and outports to AUTOSAR required and provided ports. For each inport or outport, select an AUTOSAR required or provided port and an AUTOSAR service interface event.

  10. Optionally, you can configure memory allocation for service data sent from AUTOSAR provided ports. In the Outports tab, select a port and use the code attribute AllocateMemory to configure memory allocation. Specify whether to send event data by reference (the default) or by ara::com allocated memory. To send event data by ara::com allocated memory, select the value true. To send event data by reference, select false. For more information, see Configure Memory Allocation for AUTOSAR Adaptive Service Data.

  11. After validating the adaptive component model configuration, you can simulate or generate code for AUTOSAR service communication.

To programmatically configure AUTOSAR adaptive service communication, use the AUTOSAR property and mapping functions. For example, the following MATLAB® code adds an AUTOSAR service interface, event, and required port to an open model. It then maps a Simulink inport to the AUTOSAR required port.

hModel = 'autosar_LaneGuidance';
addpath(fullfile(matlabroot,'/examples/autosarblockset/main'));
open_system(hModel);

% Add AUTOSAR service interface mySvcInterface with event mySvcEvent
arProps = autosar.api.getAUTOSARProperties(hModel);
addPackageableElement(arProps,'ServiceInterface',...
    '/LaneGuidance_pkg/LaneGuidance_if','mySvcInterface');
add(arProps,'mySvcInterface','Events','mySvcEvent');

% Add AUTOSAR required port myRPort, associated with mySvcInterface
add(arProps,'LaneGuidance','RequiredPorts','myRPort',...
    'Interface','mySvcInterface');

% Map Simulink inport to AUTOSAR port/event pair myRPort and mySvcEvent
slMap = autosar.api.getSimulinkMapping(hModel);
mapInport(slMap,'rightCarInBlindSpot','myRPort','mySvcEvent');

Model Client-Server Communication

Adaptive AUTOSAR allows client-server communication between:

  • Application software components

An AUTOSAR Client-Server Interface defines the interaction between a software component modeled as a server that provides an interface and a software component modeled as a client that requires an interface.

To model AUTOSAR clients and servers in the Simulink environment for simulation and code generation:

  • Model AUTOSAR servers by using Simulink Function blocks at the root level of a model.

  • Model AUTOSAR client calls by using Function Caller blocks.

  • Use an export-function based modeling style to create interconnected Simulink functions, function-calls, and root model inports and outports at the top level of a model.

If you import ARXML definitions of clients or servers, AUTOSAR Blockset creates and configures the components in Simulink and you can directly simulate the component models and export generated C++ code and ARXML.

Configure AUTOSAR Adaptive Servers

A server provides services to clients. To model and simulate an AUTOSAR adaptive server in the Simulink environment, use a Simulink Function block and configure a server interface to respond to clients. Optionally, you can generate C++ code and export ARXML definitions.

  1. Model an AUTOSAR adaptive server. To model a server in Simulink, create a component and use Simulink Function blocks and bus element ports to provide services to clients.

  2. Define the C++ properties of the server interface. Open the AUTOSAR Dictionary and view the properties derived from the component model. Optionally, you can create additional properties:

    1. View or create an interface. To create an AUTOSAR server interface, click the Add button . This interface defines the C++ code properties for the modeled server component.

    2. View or create ProvidedPorts. The ProvidedPorts define the code properties for the ports used in Simulink Function blocks to respond to clients.

    3. View or create the server methods. The AUTOSAR adaptive standard defines Request-Response methods that expect a response to a method call and Fire-Forget methods that do not expect a return value. For the modeled server, you can create and configure the name and method type.

  3. View how the code properties map to the modelled server. Open the Code Mappings editor:

    1. Since servers use functions to communicate, open the Functions tab.

    2. The Source column shows the modeled Function blocks.

    3. The Port column shows that the ports are ProvidedPort.

    4. The Method column shows which method defined in the AUTOSAR Dictionary associates with each port and block.

  4. Validate and simulate the server model. Use the export-function based modeling style to create interconnected Simulink functions, function-calls, and root model inports and outports at the top level of a model

  5. (Optional) Build the component model to generate C++ code and export ARXML definitions.

Alternatively, you can configure and generate this client interface by using the getSimulinkMapping API mapFunction and getFunction methods to map ProvidedPorts and the methods to modelled Simulink Function blocks:

GETFUNCTION(SLFCNNAME) 
MAPFUNCTION(SLFCNNAME, PROVIDEDPORTNAME, METHODNAME)

Configure AUTOSAR clients

Configure AUTOSAR Adaptive Client A client requires a service from a server. To model and simulate an AUTOSAR adaptive client in the Simulink environment, use a Simulink Function Caller block and configure a client interface to call the server. Optionally, you can generate C++ code and export ARXML definitions.

  1. Model an AUTOSAR adaptive client. To model a client in the Simulink, create a component and use Function Caller blocks or bus element ports to call the service provided by the server.

  2. Define the C++ properties of the client interface. Open the AUTOSAR Dictionary and view the properties derived from the component model. Optionally, you can create additional properties:

    1. View or create an interface. To create an AUTOSAR client interface, click the Add button . This interface defines the C++ code properties for the modeled client component.

    2. View or create RequiredPorts. The RequiredPorts define the code properties for the ports used in Simulink Function Caller blocks to call the server.

    3. View or create client methods. The AUTOSAR adaptive standard defines Request-Response methods that expect a response to a method call and Fire-Forget methods that do not expect a return value. For the modeled client, you can create and configure the name and method type.

  3. View how the code properties map to the modelled client. Open the Code Mappings editor:

    1. Since clients use functions to communicate, open the Function Callers tab.

    2. The Source column shows the modeled Function Caller blocks.

    3. The Port column shows that the ports are RequiredPort.

    4. The Method column shows which method defined in the AUTOSAR Dictionary associates with each port and block.

  4. Validate and simulate the client model. Use the export-function based modeling style to create interconnected Simulink functions, function-calls, and root model inports and outports at the top level of a model.

  5. (Optional) Build the component model to generate C++ code and export ARXML definitions

Alternatively, you can configure and generate this client interface by using the getSimulinkMapping API mapFunction and getFunction methods to map RequiredPorts and Methods to modelled Simulink Function blocks:

GETFUNCTION(SLFCNNAME) 
MAPFUNCTION(SLFCNNAME, REQUIREDPORTNAME, METHODNAME) 

Tips and Limitations

  • Global Simulink functions are not supported for Adaptive AUTOSAR.

  • Private scoped Simulink functions are not mapped to methods. They can be used to model behavior internal to the adaptive application component.

See Also

|

Related Examples

More About