Git Product home page Git Product logo

autosarfactory's Introduction

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

  • Clone the repository.

  • Manually install the package.

    $ python setup.py install

use python3 if you have both python2 and python3 installed.

  • Import the package autosarfactory to your python script.
  • And, finally have fun with modelling AUTOSAR.

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.

  • If package name is not provided, default package name 'RootPackage' is used.
  • The method raises FileExistsError if the given file already exist. To avoid this, please pass the argument overWrite as True.

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)

  • option1(using export function available in the node itself)
autosarfactory.read(['component.arxml'])
swc = autosarfactory.get_node('/Swcs/swc1')
swc.export_to_file('swc1Export.arxml', overWrite = True)
  • option2(using export function where the node is passed)
autosarfactory.read(['component.arxml'])
swc = autosarfactory.get_node('/Swcs/swc1')
autosarfactory.export_to_file(swc, 'swc1Export.arxml', overWrite = True)

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.

  • Autosar Explorer - A simple tree which shows all elements in the model.
  • Property view - Info about property and its corresponding values of the selected element in autosar explorer.
  • Referenced by view - This views list elements which references the selected element in autosar explorer.
  • Search view - Provision to search any elements in the model. The type of search can be selected through a combobox at the top of the view. There are 3 different types of search available: by the element short name, by a regular expression applied to the name of the element or by the Autosar type of the element.

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.

autosarfactory's People

Contributors

adb9fe avatar ausdach avatar girishchandranc avatar popadrian1981 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

autosarfactory's Issues

ARXML checker/checking

Is there any checking/validation that is done during export or import of ARXML? I am looking to create DEXT ARXML file and would like to ensure that the files i create are in-line with the AUTOSAR DEXT specification document.

PS: Sorry to highlight this as an issue. Didn't find the 'discussions' option for this repo.

AUTOSAR schema version

Hi girishchandranc,
This is really a good tool to read and write arxml.
Which AUTOSAR schema version is supported currently?
Is there a way to support different versions?
I use it to read an arxml of autosar-00048.xsd and get an error that PROCESS-DESIGN-TO-MACHINE-DESIGN-MAPPING-SET is not supported.
I would like to understand how autosarfactory.py is organized/coded so that I can make changes to let it support autosar-00048.xsd.

Thanks for your support.

python setup.py install

after i running “python setup.py install”, i got info as bellow, could you kindly help?

running install
/home/magic/.local/lib/python3.12/site-packages/setuptools/_distutils/cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated.
!!

    ********************************************************************************
    Please avoid running ``setup.py`` directly.
    Instead, use pypa/build, pypa/installer or other
    standards-based tools.

    See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
    ********************************************************************************

!!
self.initialize_options()
/home/magic/.local/lib/python3.12/site-packages/setuptools/_distutils/cmd.py:66: EasyInstallDeprecationWarning: easy_install command is deprecated.
!!

    ********************************************************************************
    Please avoid running ``setup.py`` and ``easy_install``.
    Instead, use pypa/build, pypa/installer or other
    standards-based tools.

    See https://github.com/pypa/setuptools/issues/917 for details.
    ********************************************************************************

!!
self.initialize_options()
error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

[Errno 13] Permission denied: '/usr/local/lib/python3.12/site-packages/test-easy-install-56135.write-test'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

/usr/local/lib/python3.12/site-packages/

Perhaps your account does not have write access to this directory? If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account. If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.

For information on other options, you may wish to consult the
documentation at:

https://setuptools.pypa.io/en/latest/deprecated/easy_install.html

Please make the appropriate changes for your system and try again.

Export referenced elements or export multiple packages.

This is extension to the arxml export support provided previously.

For example, there are three packages.

  1. AUTOSAR Platform Package- which has all datatype, constraints, units etc
  2. SWCs package- where all the SWC are defined
  3. An other package- may be consisting of compu methods, init values etc

Now, when i export a SWC arxml, it contains only the SWC and not the referrenced elements. When this arxml is imported in a tool like simulink, the model will load with errors.

It would be beneficial, while exporting a component in an arxml, if all the referenced elements are also exported or if we can export multiple packages together in one arxml.

etree.parse Error

Thank you foremost for providing the library.
After installing and trying to execute some code from the examples I ran into the following problem:

Traceback (most recent call last):
  File "c:\Users\user123\Desktop\AutosarFactory2\autosarfactory\autosarFactoryTest.py", line 22, in <module>
    root, status = autosarfactory.read(input_files)
  File "c:\Users\user123\Desktop\AutosarFactory2\autosarfactory\autosarfactory\autosarfactory.py", line 39, in read    
    tree = etree.parse(file, etree.XMLParser(remove_blank_text=True))
  File "src\lxml\etree.pyx", line 3521, in lxml.etree.parse
  File "src\lxml\parser.pxi", line 1859, in lxml.etree._parseDocument
  File "src\lxml\parser.pxi", line 1885, in lxml.etree._parseDocumentFromURL
  File "src\lxml\parser.pxi", line 1789, in lxml.etree._parseDocFromFile
  File "src\lxml\parser.pxi", line 1177, in lxml.etree._BaseParser._parseDocFromFile
  File "src\lxml\parser.pxi", line 615, in lxml.etree._ParserContext._handleParseResultDoc
  File "src\lxml\parser.pxi", line 725, in lxml.etree._handleParseResult
  File "src\lxml\parser.pxi", line 652, in lxml.etree._raiseParseError
OSError: Error reading file 'c:\Users\user123\Desktop\AutosarFactory2\autosarfactory\resources\components.arxml': failed to load external entity "file:/c:/Users/user123/Desktop/AutosarFactory2/autosarfactory/resources/components.arxml"   
PS C:\Users\user123\Desktop\AutosarFactory2>

Triggering reference Issue

Hello,

I have come across the following issue.

when a FrameTriggering is created, there needs to be a PduTrigerringRef and similarly when a PduTrigerring is created, there needs to be a SignalTrigerringRef .
I am doing as shown below:

canFramTrig.new_PduTriggering().set_pduTriggering(newPduTrig)
or
pduTrig.new_ISignalTriggering(sigName).set_iSignalTriggering(newISignalTrig)

The generated arxml shall be:

/CANCatalog/Cluster/CAN_Bus_Cluster/ClusterVariant/CAN_Bus_Channel/Message1_PduTrig

this is path in the generated arxml: /CANCatalog/Cluster/CAN_Bus_Cluster/ClusterVariant/CAN_Bus_Channel/Message1_PduTrig
but the required path is : /CANCatalog/Cluster/CAN_Bus_Cluster/CAN_Bus_Channel/Message1_PduTrig

The extra "ClusterVariant" is generated in the path. This gives an error in Artop and Tresos.

SHORT-NAME creation

Hello,

I would like to address the following problem:

When creating a new EcucNumericalParamValue, I want to add a short name.
Currently however when running the function "new_EcucNumericalParamValue()" from the class "EcucContainerValue", it does only create the yellow marked output, without a SHORT-NAME node.
image
By default I would expect a SHORT-NAME to be created if I enter a value inside "new_EcucNumericalParamValue(value)".
Is there a way to add a short name to this EcucNumericalParamValue like in the other ECUC-NUMERICAL-PARAM-VALUE?

Updating model from UI

Check for the possibility to update(modify existing properties, creating new nodes etc) the loaded arxml using the ui provided with autosarfactory.

Issue while parsing arxml with schema 00048

I have tried parsing arxml with schema 00048, using the autosarfactory library. But I was facing KeyError while reading the file. The error is due to unavailability of few nodes in autosarfactory library:
TRANSFORMATION-PROPS-TO-SERVICE-INTERFACE-ELEMENT-MAPPING-SET
SECURE-COM-PROPS-SET
STARTUP-CONFIG-SET
PROCESS-DESIGN-TO-MACHINE-DESIGN-MAPPING-SET
Is there any latest version of autosarfactory available to solve this issue?

Attribute Error

Hey sorry, this maybe a dumb question,

When I run this

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

I get this error:
root, status = autosarfactory.read(files)
AttributeError: module 'autosarfactory' has no attribute 'read'

What am I doing wrong here?

I cloned the repo correctly and also checked if setup.py was installed properly too - both are proper.

Thanks :)

provide method to return the root model object while creating a new file

Currently, autosarfactory requires user to pass a default arpckage name while creating a new file and the api returns the created arpackage object. There is no provision for the user to add another package in the root level. And hence, there is a need for a new method to just create the file and return the root model object and allow user to create any number of packages under the root node

Export Ar-Package support

Export a particular Ar-package maintaining its tree structure along with the parent packages in to a new arxml file.
The exported arxml shall be importable in tools like Matlab/Simulink/TargetLink

swBasetype without shortname

Hello Girish,

I took the latest delivery.

I am trying to generate arxmls are i checked ur examples too.
The SwBaseTypes are generating without shortnames. Is this an intended change?

Regards,
Punith

Issue with Xml serialization

The xml elements are created on the fly whenever the api's are used and this isn't ideal and could lead to schema violations. This needs a rework on the way xml is serialized.

Issue with identifying which element a value belongs in the GUI

Hi @girishchandranc ,

Thanks again for your support on the previous issues,

I am just facing another issue, when I read in the files and try to visualise the tree using the GUI,

I am trying to visualize the numerical values in the arxml files, this shows up in the GUI tree as a NumercicalValueVariation Poiint and then on cicking that shows the properties and the Value for that path,

This is the problem I'm facing:

How do I understand as to which element the value belongs under?

For example in the below structure, under Elekemnt1a SHORT-NAME, there are two different paths, first one ending with ID1 and the second ending with ID2 with two different values 0,1 (its different here but some cases values are same too!) but these are not shown in the GUI, it just shows parameterValues_@1 and below that NumercialValueVariationPoint and then it shows the value, similarly for the next one parameterValues_@2 and below that NumercialValueVariationPoint and then it shows the value - but it doesnt mention where this value comes from or where it belongs even in the Type column (which should show the Path) on the right in the GUI,

Could you please suggest a solution for this?

Thanks

GitHub doubt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.