Contenu principal

Configure C++ Namespaces for AUTOSAR Adaptive Interfaces and Data Types

R2026b

For component models configured for the AUTOSAR Adaptive Platform, generate C++ code with individual C++ namespaces for architectural data types and export the individual C++ namespaces as namespace symbols in exported ARXML files. To generate and export the individual C++ namespaces of data types, you configure the C++ Namespace code generation property of data types defined in the Architectural Data section of a linked data dictionary.

To configure individual C++ namespaces of interfaces defined in the Architectural Data section of a data dictionary:

  1. Open the Architectural Data Editor by entering archdataeditor in the MATLAB® Command Window and open the PortInterfaces data dictionary.

  2. In the Interfaces tab, select SensorInterface.

  3. In the right pane of the Architectural Data Editor, expand the Code Generation tab.

  4. Set C++ Namespace to company::chassis::perception.

  5. In the Interfaces tab, select HazardInterface.

  6. Set C++ Namespace to company::chassis::actuation.

  7. For each interface set Header file to impl_type_interfaces.h.

    Architectural Data Editor. PortInterfaces data dictionary is open showing Code Generation settings with the C++ Namespace and Header file properties set. .

  8. Save and close the data dictionary.

  9. Save the model.

To configure individual C++ namespaces of data types defined in the Architectural Data section of a data dictionary:

  1. Open the Architectural Data Editor and create a new data dictionary by selecting New in the File section of the editor toolstrip. Name the data dictionary ArchDataTypes.

  2. In the Architectural Data Editor, in the Create section of the toolstrip, add an alias data type to the data dictionary by selecting Alias Type.

  3. Select the alias data type, and expand the Code Generation section in the Details pane.

    1. Specify the Header file as impl_type_aliastype.h.

    2. Specify the C++ Namespace as alias::ns.

      Architectural Data Editor Data Types tab and Details pane. Header file and C++ Namespace are specified for AliasType.

  4. Create a component model configured for the AUTOSAR Adaptive Platform. This example uses the Software Component (Adaptive) model template from the Simulink® Start Page. For steps to create the model used in this example, see Create Mapped AUTOSAR Component with Simulink Start Page.

  5. On the Modeling tab, expand the Design section and click Link to Data Dictionary. In the Model Properties dialog box, browse for and select the ArchDataTypes data dictionary file. Click Apply, and then click OK.

  6. In the model canvas, double-click the RequiredPort.In1 bus element port to open the port properties dialog box.

  7. On the Signal tab set Data type to AliasType.

    Properties of input port: RequiredPort. Signal tab data type menu is displayed AliasType is highlighted.

  8. Save the model and data dictionary. Export ARXML and generate C++ code.

  9. Inspect the generated C++ code.

    Header file impl_types_aliastype.h defines the architectural alias data type including the assigned C++ namespace alias::ns.

    #ifndef ALIAS_NS_IMPL_TYPE_ALIASTYPE_H_
    #define ALIAS_NS_IMPL_TYPE_ALIASTYPE_H_
    #include <cstdint>
    
    namespace alias
    {
      namespace ns
      {
        using AliasType = double;
      }                                    /* namespace ns */
    }                                      /* namespace alias */
    
    #endif                                 //ALIAS_NS_IMPL_TYPE_ALIASTYPE_H_

    In the exported ARXML file modelname_datatype.arxml, the assigned namespace appears in NAMESPACES tagging.

    ...
    <ELEMENTS>
    <STD-CPP-IMPLEMENTATION-DATA-TYPE UUID="...">
        <SHORT-NAME>AliasType</SHORT-NAME>
        <CATEGORY>TYPE_REFERENCE</CATEGORY>
        <NAMESPACES>
            <SYMBOL-PROPS>
                <SHORT-NAME>alias</SHORT-NAME>
                <SYMBOL>alias</SYMBOL>
            </SYMBOL-PROPS>
            <SYMBOL-PROPS>
                <SHORT-NAME>ns</SHORT-NAME>
                <SYMBOL>ns</SYMBOL>
            </SYMBOL-PROPS>
        </NAMESPACES>
        <TEMPLATE-ARGUMENTS>
            <CPP-TEMPLATE-ARGUMENT>
                <TEMPLATE-TYPE-REF DEST="STD-CPP-IMPLEMENTATION-DATA-TYPE">/DataTypes/SwBaseTypes/double</TEMPLATE-TYPE-REF>
            </CPP-TEMPLATE-ARGUMENT>
        </TEMPLATE-ARGUMENTS>
    </STD-CPP-IMPLEMENTATION-DATA-TYPE>
    </ELEMENTS>
    ...

See Also

Topics