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';

% Add AUTOSAR service interface mySvcInterface with event mySvcEvent
arProps = autosar.api.getAUTOSARProperties(hModel);

% Add AUTOSAR required port myRPort, associated with mySvcInterface

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

Related Examples

More About