girishchandranc / autosarfactory

AutosarFactory is a python package which helps user to read/create/modify AUTOSAR standard arxml files.
MIT License
87 stars 28 forks source link
arxml automotive autosar autosar-adaptive autosar-classic modelling-autosar modelling-tool python software-engineering

Build Actions Status

Autosar Modelling Tool

AutosarFactory provides nice methods to read/create/modify AUTOSAR compliant arxml files. The folder autosarfactory contains the autosarfactory implementation with respect to the schema corresponding to the latest AUTOSAR release. Please check the folder autosar_releases for previous AUTOSAR releases

How to use

Reading file

#Read a list of files
files = ['component.arxml', 'datatypes.arxml']
root, status = autosarfactory.read(files)

#Read a list of folders
folders = ['folder1', 'folder2']
root, status = autosarfactory.read(folders)

The read method processes the input files/folders and return the root node(with merged info of all the files). If folder is provided, the method does a deep search for the arxml files and reads in all the files in the folder. The status gives an info if the file/folder reading was successful.

Creating new file

newPack = autosarfactory.new_file('newFile.arxml', defaultArPackage = 'NewPack')

Creates a new arxml file with the given package name and returns the ARPackage object.

Accessing attributes and references

Model elements have get_<attribute/reference> methods to access existing attribute and reference value.

For multi-references, the method returns a list of values

Modifying attributes/references

All the elements have set_<attribute/reference>methods to modify the attribute or reference value.

For multi-references, there also exists methods add_<reference>, remove_<reference>

Adding new model elements

All the parent classes have new_<element> methods to create an element.

rootPack = autosarfactory.new_file('newFile.arxml', defaultArPackage = 'RootPack')
newPack = rootPack.new_ARPackage('NewPack')
#new applicaton component
asw1 = newPack.new_ApplicationSwComponentType('asw1')
asw1.new_PPortPrototype('outPort')

#new senderRecever interface
srIf = newPack.new_SenderReceiverInterface('srif1')
srIf.new_DataElement('de1')

Accessing elements by path

Once the file is read by the tool, its possible to access elements by path.

files = ['component.arxml', 'datatypes.arxml']
autosarfactory.read(files)
swc = autosarfactory.get_node('/Swcs/asw1')
uint8DataType = autosarfactory.get_node('/DataTypes/baseTypes/uint8')

Saving options

Save

The tool provides save method to save the changes made to the model.

files = ['component.arxml', 'datatypes.arxml']
autosarfactory.read(files)

rootPack = autosarfactory.new_file('newFile.arxml', defaultArPackage = 'RootPack')
newPack = rootPack.new_ARPackage('NewPack')

#new applicaton component
newcomp = newPack.new_ApplicationSwComponentType('newcomponent')
newcomp.new_PPortPrototype('outPort')

#new senderRecever interface
srIf = newPack.new_SenderReceiverInterface('srif1')
srIf.new_DataElement('de1')

#save changes
autosarfactory.save(['newFile.arxml'])

The save method accepts a list of file which needs to be saved. If no argument is provided, all the files(input, newly created) will be saved.

SaveAs

The tool provides saveAs method to save the changes made to the model into a single arxml file.

files = ['component.arxml', 'datatypes.arxml']
autosarfactory.read(files)

rootPack = autosarfactory.new_file('newFile.arxml', defaultArPackage = 'RootPack')
newPack = rootPack.new_ARPackage('NewPack')

#new applicaton component
newcomp = newPack.new_ApplicationSwComponentType('newcomponent')
newcomp.new_PPortPrototype('outPort')

#new senderRecever interface
srIf = newPack.new_SenderReceiverInterface('srif1')
srIf.new_DataElement('de1')

#save changes
autosarfactory.saveAs('mergedFile.arxml')

Export element

The tool provides export_to_file method to export a specific element to a file including it's AR-Package hierarchy. This is only supported for CollectableElements(which means AP-Package as well as all PackageableElements which includes ApplicationSwComponentType, SR interface, Signals etc etc- precisely any elements which directly fall under an AR-Package)

Autosar visualizer

The package also includes a graphical visualizer for the Autosar models which can be simply opened by passing the autosar root to the method show_in_ui. For example:

files = ['component.arxml', 'datatypes.arxml']
root,status = autosarfactory.read(files)
autosar_ui.show_in_ui(root)

Please see below a screenshot of the visualizer.

AutosarVisualizer-2021-01-26 130700

The visualizer mainly consists of 4 views and a menu bar.

The menu bar allows to switch the theme applied to the application at runtime and to exit the application. (This is planned to be extended with new menu options added in the future).

Examples

Please check the script inside the Examples folder which creates a basic communication matrix.

For more information on the usage, please refer tests/test_autosarmodel.py.