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
Clone the repository.
Manually install the package.
$ python setup.py install
use
python3
if you have bothpython2
andpython3
installed.
Import the package autosarfactory
to your python script.
And, finally have fun with modelling AUTOSAR.
#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.
newPack = autosarfactory.new_file('newFile.arxml', defaultArPackage = 'NewPack')
Creates a new arxml file with the given package name and returns the ARPackage object.
Model elements have get_<attribute/reference>
methods to access existing attribute and reference value.
For multi-references, the method returns a list of values
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>
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')
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')
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.
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')
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)
autosarfactory.read(['component.arxml'])
swc = autosarfactory.get_node('/Swcs/swc1')
swc.export_to_file('swc1Export.arxml', overWrite = True)
autosarfactory.read(['component.arxml'])
swc = autosarfactory.get_node('/Swcs/swc1')
autosarfactory.export_to_file(swc, 'swc1Export.arxml', overWrite = True)
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.
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).
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
.