Main Content

find

Find AUTOSAR architecture, composition, component, parameter component and elements

Description

archElements = find(archElementOrModel,elementCategory) searches AUTOSAR component, parameter software component, composition, or architecture model represented by archElementOrModel for architecture elements that match the specified elementCategory. The default scope of find is the top level of the specified composition or architecture model, not all levels of the model hierarchy.

example

archElements = find(___,Name=Value) specifies a specific property value applicable for the specified category of elements, narrowing the search.

Examples

collapse all

This example shows how to create AUTOSAR architecture model myArchModel, that contains a composition, components, and corresponding ports. It then shows how to find the individual components, ports, and specific values of those elements using the find function.

The architecture in this example is a simplistic high level model of the basic flow of pedal sensor data and throttle sensor data in AUTOSAR compliant automotive software.

Create Architecture Model, Composition, and Components

1. Create an AUTOSAR architecture model by using autosar.arch.createModel. By default autosar.arch.createModel creates a AUTOSAR Classic Platform architecture model. Using AUTOSAR Adaptive Platform elements is not supported in AUTOSAR Classic Platform models.

modelName = "myArchModel";
archModel = autosar.arch.createModel(modelName);

2. Add a composition to the architecture model by using the addComposition function. Name the composition Sensors.

composition = addComposition(archModel,"Sensors");

3. Add two components representing the behavior for a pedal sensor and a throttle sensor to the composition of the architecture model. Define them as SensorActuator components.

names = {"PedalSnsr","ThrottleSnsr"};
sensorSWCs = addComponent(composition,names,"Kind","SensorActuator");
layout(composition); % Auto-arrange layout

4. At the top level of the architecture model, add a controller and actuator components. For the actuator component, notice you can create an autosar.arch.Component object that you can programmatically interact with at the time of creating the component.

addComponent(archModel,"Controller1");
actuator = addComponent(archModel,"Actuator");
set(actuator,"Kind","SensorActuator");

Add Architecture, Composition, and Component Ports

1. Add architecture ports by using the addPort function. Add ports to the architecture model by passing the architecture model object, archModel.

addPort(archModel,"Receiver",{"TPS_Hw","APP_Hw"});
addPort(archModel,"Sender","ThrCmd_Hw");

2. Add composition ports by using the addPort function, add ports to the composition by passing the composition object, composition.

addPort(composition,"Receiver",{"TPS_Hw","APP_Hw"});
addPort(composition,"Sender",{"TPS_Perc","APP_Perc"});

3. Create an object representing the controller component by using the find function. You can use this function to find components, and other elements in a model by specifying the type and the name of the component. It returns an autosar.arch.Component object in this example.

controller = find(archModel,"Component",Name="Controller1");

4. Similarly, use the addPort function to add ports to the component objects.

addPort(controller,"Receiver",{"TPS_Perc","APP_Perc"});
addPort(controller,"Sender","ThrCmd_Perc");
addPort(actuator,"Receiver","ThrCmd_Perc");
addPort(actuator,"Sender","ThrCmd_Hw");

Create Connections Between Architecture, Composition, Components, and Ports

1. At the top level of the architecture, connect the architecture, composition,and components by using the connect function. The connect function connects Receiver and Sender ports of matching names across the model hierarchy.

connect(archModel,composition,controller);
connect(archModel,controller,actuator);

2. You can use the connect function to explicitly connect specific architecture ports to specific composition and component ports. Simply specify the indices of the ports as they appear in the port arrays of the architecture element objects. In this case the Ports arrays of the architecture and composition objects. For further specificity you can also use the find function to find identifying information of ports.

connect(archModel,archModel.Ports(1),composition.Ports(1));
connect(archModel,...
    find(archModel,"Port",Name="APP_Hw"),...
    find(composition,"Port",Name="APP_Hw"));
connect(archModel,actuator.Ports(2),archModel.Ports(3));

3. Optionally, use the layout function to automatically arrange the components and composition with the architecture.

layout(archModel);

Find Elements and Defining Information in All Levels of the Architecture Model

1. Use the find function to get components in the top level of the architecture model.

components_in_arch_top_level = find(archModel,"Component")
components_in_arch_top_level = 
  2×1 Component array with properties:

    Name
    SimulinkHandle
    Parent
    Kind
    Ports
    ReferenceName

2. You can also use the find function to find components in every level of the modeling hierarchy.

components_in_all_hierarchy = find(archModel,"Component",AllLevels=true)
components_in_all_hierarchy = 
  4×1 Component array with properties:

    Name
    SimulinkHandle
    Parent
    Kind
    Ports
    ReferenceName

3. By using the find function you can also limit the scope of your search to a single component or composition block. For example in this step you can specify that the function only finds ports on the Composition block. You can then query the ports for the identifying information, like their Kind and Name values.

composition_ports = find(composition,"Port")
composition_ports = 
  4×1 CompPort array with properties:

    Name
    Interface
    SimulinkHandle
    Parent
    Kind
    Connected

for ii=1:length(composition_ports)
    Port = composition_ports(ii);
    portName = get(Port,"Name");
    portKind = get(Port,"Kind");
    fprintf('%s port name: %s\n',portKind,portName);
end
Receiver port name: TPS_Hw
Receiver port name: APP_Hw
Sender port name: TPS_Perc
Sender port name: APP_Perc

This example finds the parameter software component in architecture model autosar_swc_parameter and then uses the parameter software component object handle to find the relevant ports of the parameter software component.

Create an AUTOSAR architecture.

arch = autosar.arch.createModel("architecture");

Add a parameter software component and parameter port to the model.

parameterComponent = addComponent(arch,"ParamComponent",...
    Kind="ParameterComponent");
addPort(parameterComponent,"ParameterSender","ParameterPort");

Use the find function to find the parameter software component port.

port = find(parameterComponent,"Port")
port = 

  ParameterPort with properties:

      Name: 'ParameterPort'
    Parent: [1×1 autosar.arch.ParameterComponent]

Input Arguments

collapse all

AUTOSAR component, parameter software component, composition, or architecture model to search.

Example: archModel

Category of AUTOSAR architecture element to find. Valid categories are Component, Composition, Port, ParameterComponent, and Connector.

Parameter software components can only be searched for ports.

Example: 'Component'

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: find(composition,AllLevels=true,Name="OutPort")

Extend the search for AUTOSAR architecture elements to all levels of an AUTOSAR composition or architecture model hierarchy. Specify true to search all levels of an AUTOSAR composition or architecture model hierarchy for the specified architecture elements.

The default scope of find is the top level of the specified composition or architecture model, not all levels of the model hierarchy.

Example: AllLevels=true

Name of element to search for, specified as a character vector string scalar.

Example: Name="TPS_HwIO"

Data Types: char | string

Output Arguments

collapse all

Returns one or more handles for the architecture elements found.

The archElements output argument returns handles for the architecture elements found.

Version History

Introduced in R2020a

expand all