BSWMD Model
The AutomationInterface contains a generated BswmdModel. The BswmdModel provides classes for all Ecuc elements of the AUTOSAR model (ModuleConfigurations, Containers, Parameter, References). The BswmdModel is automatically generated from the SIP of the DaVinci Configurator.
You should use the BswmdModel whenever possible to access Ecuc elements of the AUTOSAR model. For accessing the Ecuc elements with the BswmdModel, see chapter BswmdModelRead.
For a detailed description of the BswmdModel, see chapter BswmdModel.
BswmdModel Package and Class Names
com.vector.cfg.automation.model.ecuc. Every Module has its own
sub packages with the name:
com.vector.cfg.automation.model.ecuc.<AUTOSAR-PKG>.<SHORTNAME>- e.g.
com.vector.cfg.automation.model.ecuc.microsar.dio - e.g.
com.vector.cfg.automation.model.ecuc.autosar.ecucdefs.can
- e.g.
The packages then contain the class of the element like Dio for the module. The full path would
be com.vector.cfg.automation.model.ecuc.microsar.dio.Dio.
For the container DioGeneral it would be:
com.vector.cfg.automation.model.ecuc.microsar.dio.diogeneral.DioGeneral
To use the BswmdModel in script files, you have to write an import, when accessing the class:
//The required BswmdModel import of the class Dio
import com.vector.cfg.automation.model.ecuc.microsar.dio.Dio
scriptTask("TaskName"){
code{
Dio.DefRef //Usage of the class Dio
}
}
Reading with BswmdModel
The bswmdModel() methods provide entry points to start navigation through the ActiveEcuc. Client code can use the Action/groovy.lang.Closure overloads to navigate into the
content of the found bswmd objects. Inside the called code the related bswmd object is available as closure parameter.
The following types of entry points are provided here:
bswmdModel(WrappedTypedDefRef)searches all objects with the specified definition and returns the BswmdModel instances.searches all objects with the specified class and returns the BswmdModel instances. Finds the same elements as above. - <code>bswmdModel(MIHasDefinition, WrappedTypedDefRef)searches all objects with the specified class and returns the BswmdModel instances. Finds the same elements as above.bswmdModel(MIHasDefinition, WrappedTypedDefRef)returns the BswmdModel instance for the provided MDF model instance.IMdfModelApi#mdfModel(String)searches all objects with the specified class and the matching path, seeIMdfModelApi#mdfModel(String)or chapter mdfModel_String for details.
When a closure is being used, the object found by bswmdModel() is provided as parameter when the closure is called.
The bswmdModel() method itself returns the found objects too. Retrieving the objects member and children (Container,
Parameter) as properties or methods are then possible directly using the returned object.
Examples:
code {
// Gets the ecuc module configuration
EcuC ecuc = bswmdModel(EcuC).single
}
DefRef instead of a Class:
code {
// Gets the ecuc module configuration
EcuC ecuc = bswmdModel(EcuC.DefRef).single
}
For more usage samples please see chapter GettingStartedReadActiveEcuc.
Writing with BswmdModel
bswmdModel() methods.
There has to be at least one existing element in the ActiveEcuc from which the navigation can be started. For the most
cases the entry point for writing the ActiveEcuc is the module configuration.
Example:
code {
transaction {
// Gets the ecuc module configuration
EcuC ecuc = bswmdModel(EcuC).single
//Gets the EcucGeneral container or create one if it is missing
EcucGeneral ecucGeneral = ecuc.ecucGeneralOrCreate
}
saveProject()
}
For more usage samples please see chapter GettingStartedWriteActiveEcuc.
The model is in read-only state by default, so no objects could be created. For this reason all calls which creates or
deletes elements has to be executed within a transaction() block.
See BswmdModelWriteAccess for more details about the BswmdModel write API.
Declaration with BswmdModel
The BswmdModel supports declaration API to declare an AUTOSAR ECU configuration structure in code, which is then synchronized with the existing structure to create elements in a declarative way.
The model is in read-only state by default, so no objects could be created. For this reason all calls which creates or
deletes elements has to be executed within a transaction() block.
Example:
code {
transaction {
EcuC ecuc = bswmdModel(EcuC).single
ecuc.declare {
EcucGeneral {
EcuCSafeBswChecks(true)
}
}
}
}
See BswmdModelDeclarationAPI for more details about the BswmdModel Declaration API.
Bsw DefRefs
The sipDefRef API provides access to retrieve generated DefRef instances from the SIP without knowing the correct
Java/Groovy imports. This is mainly useful in script files, where no IDE helps with the imports.
If you are using an Automation Script Project you can ignore this API and use the DefRefs provided by the generated classes, which is superior to this API,
because they are typesafe and compile time checked.
The listing show the usage of the bswDefRef API with short names and definition paths.
code{
def theDefRef
// You can call bswDefRef.<ShortName>
theDefRef = bswDefRef.EcucGeneral
theDefRef = bswDefRef.Dio
theDefRef = bswDefRef.DioPort
// Or you can use the [] notation
theDefRef = bswDefRef["Dio"]
theDefRef = bswDefRef["DioChannelGroup"]
// If the DefRef is not unique you have to specify the full definition
theDefRef = bswDefRef["/MICROSAR/EcuC/EcucGeneral"]
theDefRef = bswDefRef["/MICROSAR/Dio"]
theDefRef = bswDefRef["/MICROSAR/Dio/DioConfig/DioPort"]
//Wildcards are also allowed
theDefRef = bswDefRef["/[ANY]/Adc"]
}
You can also check if a certain DefRef exists in the currently loaded SIP. The method hasDefRef(String) returns
true, if the definition exists. This is helpful to check for existence of the definition before using it to prevent e.g. LinkageErrors.
if(bswDefRef.hasDefRef("Dio")){
// Now we know the Dio module exists in the SIP
def theDefRef = bswDefRef.Dio
}
BswmdModel DefRefs
DefRef instances for each definition element (Modules, Containers,
Parameters). You should always prefer this API over the Sip DefRefs, because this is type safe and checked during
compile time.
You can use the DefRefs by calling <ModelClassName>.DefRef. The literal DefRef is a static constant in the
generated classes.
For simple parameters like Strings, Integer there is no generated class, so you have to call the method on its parent
container like <ParentContainerClass>.<ParameterShortName>DefRef.
There exist generated classes for Parameters of type Enumeration and References to Container and therefore you have
both ways to access the DefRef:
<ModelClassName>.DefRefor<ParentContainerClass>.<ParameterShortName>DefRef
To use the DefRefs of the classes you have to add imports in script files, see chapter BswmdModelPackages for required import names.
// Required imports
import com.vector.cfg.automation.model.ecuc.microsar.ecuc.ecucgeneral.EcucGeneral
import com.vector.cfg.automation.model.ecuc.microsar.ecuc.ecucgeneral.cputype.CPUType
scriptTask("TaskName"){
code {
def theDefRef
//DefRef from EcucGeneral container
theDefRef = EcucGeneral.DefRef
//DefRef from generated parameter
theDefRef = CPUType.DefRef
//Or the same
theDefRef = EcucGeneral.CPUTypeDefRef
//DefRef from simple parameter
theDefRef = EcucGeneral.AtomicBitAccessInBitfieldDefRef
theDefRef = EcucGeneral.DummyFunctionDefRef
}
}
Untyped Model with the DefRef API
DefRefs. There are NO generated
classes for the Definition structure.
To use the untyped Model, the BswDefRefs can be used:
// Required imports
import com.vector.cfg.gen.core.bswmdmodel.GIModuleConfiguration
import com.vector.cfg.gen.core.bswmdmodel.GIContainer
import com.vector.cfg.gen.core.bswmdmodel.GIParameter
scriptTask("TaskName"){
code {
GIModuleConfiguration ecuc = bswmdModel(bswDefRef.EcuC).single
// If the short name is not unique, you can use the full definition as string (DefRef wildcards are allowed, e.g. [/ANY])
GIContainer ecucPduCollection = ecuc.getSubContainer(bswDefRef["/MICROSAR/EcuC/EcucPduCollection"])
List<GIContainer> pdus = ecucPduCollection.getSubContainers(bswDefRef["/MICROSAR/EcuC/EcucPduCollection/Pdu"])
GIContainer pdu = pdus.get(0)
GIParameter<Integer> pduLength = pdu.getParameter(bswDefRef["/MICROSAR/EcuC/EcucPduCollection/Pdu/PduLength"])
"PduLength: " + pduLength.getValueMdf().intValue()
}
}
See chapter BswmdModelDefRefGetterMethods for more details.
Switching from Domain Models to BswmdModel
You can switch from domain models to the BswmdModel, if the domain model is backed by ActiveEcuC elements. Please read the documentation of the different domain models, for whether this is possible for a certain domain model.
To switch from a domain model to the BswmdModel, you can call one of the methods for IHasModelObjects like, bswmdModel(IHasModelObject, WrappedTypedDefRef).
But you need a DefRef to get the type safe BswmdModel object. The domain model documents, which DefRef must be used for the certain domain model object.
// Domain model object of the communication domain
ICanController canDomainModel = ...
def canControllerBswmd = canDomainModel.bswmdModel(CanController.DefRef)
// Or use a closure
canDomainModel.bswmdModel(CanController.DefRef){ canControllerBswmd ->
//Use the bswmd object
}