cogu / autosar Goto Github PK
View Code? Open in Web Editor NEWA set of python modules for working with AUTOSAR XML files
License: MIT License
A set of python modules for working with AUTOSAR XML files
License: MIT License
Hello,
Is there a way to create the following structure?
<AR-PACKAGE>
<SHORT-NAME>Constants</SHORT-NAME>
<ELEMENTS>
<CONSTANT-SPECIFICATION UUID="9B2B418A-CA6C-4E3B-9562-D49D1C2695B1">
<SHORT-NAME>CDiagNv_NvMServiceRequestType</SHORT-NAME>
<VALUE-SPEC>
<ARRAY-VALUE-SPECIFICATION>
<ELEMENTS>
<RECORD-VALUE-SPECIFICATION>
<FIELDS>
<NUMERICAL-VALUE-SPECIFICATION>
<SHORT-LABEL>ServiceId</SHORT-LABEL>
<VALUE>0</VALUE>
</NUMERICAL-VALUE-SPECIFICATION>
<NUMERICAL-VALUE-SPECIFICATION>
<SHORT-LABEL>RequestResult</SHORT-LABEL>
<VALUE>0</VALUE>
</NUMERICAL-VALUE-SPECIFICATION>
</FIELDS>
</RECORD-VALUE-SPECIFICATION>
I tried creating array data type, record data type and RECORD-VALUE-SPECIFICATION and ARRAY-VALUE-SPECIFICATION are reversed.
I found a mismatch behavior, for tooling convention like a System Desk from DSpace it's possible to create a description attribute inside Record elements.
So to solve those issue i suggest to add between line 84 and 85 of file datatype_writer.py the following code:
tmp = self.writeDescXML(childElem)
if tmp is not None: lines.extend(self.indent(tmp,3))
This is the same code are used in other classes.
XML parse/write AR 4 port interfaces
Hi all, great package - thank you!
I am updating a script that was at 0.4 with PyCharm. The make_packages call takes a comma separated list of package name strings but the type hint in the function definition says '*refs: list[str]'. This causes PyCharm to flag the call with a warning since I am not passing a list of strings but the comma separated strings themselves.
Let me know if you'd like me to make a pull request with this change.
Thank you.
hi,
i was playing around with autosar and was pretty happy about this nice packages.
But still some element missing.
Question: did i got a wrong version?
e.g.
INCOMPAT_TAGS = [
'LONG-NAME',
'DESC',
'PROVIDER-IREF',
'SDG-CAPTION',
'SDX-REF',
'CATEGORY',
'CLIENT-ID-DEFINITION-SET-REFS',
'CONTAINER-I-PDU-HEADER-BYTE-ORDER',
'ECU-EXTRACT-VERSION',
'FIBEX-ELEMENTS',
'MAPPINGS', # todo for each self.parseSystemMapping?
'PNC-VECTOR-LENGTH',
'PNC-VECTOR-OFFSET',
'ROOT-SOFTWARE-COMPOSITIONS',
'SYSTEM-VERSION',
'REQUESTER-IREF']
Hello cogu,
and greets to Sweden.
Currently I am loading real-world example and came across several NotImplementedErrors, e.g. for:
Then I realized that I was parsing a AUTOSAR_00049 file instead of AUTOSAR_4-2-2
My questions are:
Best regards,
Tom
ComSpec for individual data elements in a port cannot be created
I am reading ARXML we have generated and it is not to the Reader's liking. I have iterated through fixing each raised exception. A nice feature would be a 'parse-only' flag that would return a list of all lines in an ARXML file needing attention and why it is a problem.
Runnables, events etc. for AUTOSAR 4
# record = autosar.constant.RecordValue(label, parent=parent)
change to
record = autosar.constant.RecordValueAR4 (label, parent=parent)
in file b \Lib\site-packages\autosar-0.3.11-py3.9.egg\autosar\writer\component_writer.py:365
应该改为
lines.append(self.indent('{}'.format(self.toBooleanStr(comspec.useEndToEndProtection)), 1))
否则 arxml文件E2E的属性无法正常解析
Hi @cogu
Before starting, I'm big fan of your autosar module and it's very useful for my works.
As far as i know, ImplementationDataTypeElement can have subElement like belows.
<IMPLEMENTATION-DATA-TYPE UUID="ffc534fa-9e89-4a14-82a1-eff8e4acaf50">
<SHORT-NAME>Dt_RECORD_Reaction</SHORT-NAME>
<CATEGORY>STRUCTURE</CATEGORY>
<SUB-ELEMENTS>
<IMPLEMENTATION-DATA-TYPE-ELEMENT UUID="931668fd-65e0-46f9-8768-fc6760c494c1">
<SHORT-NAME>FCA</SHORT-NAME>
<CATEGORY>STRUCTURE</CATEGORY>
<SUB-ELEMENTS>
<IMPLEMENTATION-DATA-TYPE-ELEMENT UUID="b56869c7-2039-4421-ad04-994f7773eebd">
<SHORT-NAME>Ro_Inhibit</SHORT-NAME>
<CATEGORY>TYPE_REFERENCE</CATEGORY>
<SW-DATA-DEF-PROPS>
<SW-DATA-DEF-PROPS-VARIANTS>
<SW-DATA-DEF-PROPS-CONDITIONAL>
<IMPLEMENTATION-DATA-TYPE-REF DEST="IMPLEMENTATION-DATA-TYPE">/AUTOSAR_DataTypes/ImplementationDataTypes/uint8</IMPLEMENTATION-DATA-TYPE-REF>
</SW-DATA-DEF-PROPS-CONDITIONAL>
</SW-DATA-DEF-PROPS-VARIANTS>
</SW-DATA-DEF-PROPS>
</IMPLEMENTATION-DATA-TYPE-ELEMENT>
<IMPLEMENTATION-DATA-TYPE-ELEMENT UUID="20ed6f15-f125-4d10-88db-7346cf01e403">
<SHORT-NAME>Sf2_Inhibit</SHORT-NAME>
<CATEGORY>TYPE_REFERENCE</CATEGORY>
<SW-DATA-DEF-PROPS>
<SW-DATA-DEF-PROPS-VARIANTS>
<SW-DATA-DEF-PROPS-CONDITIONAL>
<IMPLEMENTATION-DATA-TYPE-REF DEST="IMPLEMENTATION-DATA-TYPE">/AUTOSAR_DataTypes/ImplementationDataTypes/uint8</IMPLEMENTATION-DATA-TYPE-REF>
</SW-DATA-DEF-PROPS-CONDITIONAL>
</SW-DATA-DEF-PROPS-VARIANTS>
</SW-DATA-DEF-PROPS>
</IMPLEMENTATION-DATA-TYPE-ELEMENT>
</SUB-ELEMENTS>
</IMPLEMENTATION-DATA-TYPE-ELEMENT>
</SUB-ELEMENTS>
</IMPLEMENTATION-DATA-TYPE>
Is it possible to generate above code by using your module? If not, you have some plans for support? (I hope module had createImplementationDataElement APIs)
Thank you in advance
(major, minor, patch, schema) = parseAutosarVersionAndSchema(xmlroot)
ValueError: not enough values to unpack (expected 4, got 3)
AUTOSAR xmlns="http://autosar.org/schema/r4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://autosar.org/schema/r4.0 AUTOSAR_00044.xsd"
Using collections.Iterable or collections.Mapping direct is deprecated since Python 3.3. In future versions will it stop working.
Change to use collections.abc.Iterable or collections.abc.Mapping will solve this issue.
In the AUTSAR XSD schema the property "BASE-TYPE-SIZE" is optional. In the Python code it is mandatory.
Hi cogu:
I am parai, and I am using this project branch feature/ar4_api for my own AUTOSAR project https://github.com/parai/as which is a study platform of AUTOSAR with python toolchain support for the BSW configuration and CAN COM/DCM/BOOTLOADER tools.
Now I am trying to use your project as RTE configuration and related C source code generator. So I started from the tutorial2, but I failed as below exception, could you help to have a look and how to fix this issue.
And the major feature I want is the RTE C source code generator, can you provide much more demo on this?
D:\repository\as\release\download\autosar\tutorial2\components>python RealTimeClock.py
Traceback (most recent call last):
File "RealTimeClock.py", line 35, in
ws.apply(RealTimeClock)
File "../..\autosar\workspace.py", line 446, in apply
template.apply(self)
File "RealTimeClock.py", line 12, in apply
package = ws.getComponentTypePackage()
File "../..\autosar\workspace.py", line 510, in getComponentTypePackage
packageName = self.defaultPackages["ComponentType"]
AttributeError: 'Workspace' object has no attribute 'defaultPackages'
D:\repository\as\release\download\autosar\tutorial2\components>python RealTimeClock.py
Traceback (most recent call last):
File "RealTimeClock.py", line 36, in
ws.apply(RealTimeClock)
File "../..\autosar\workspace.py", line 446, in apply
template.apply(self)
File "RealTimeClock.py", line 15, in apply
cls.addPorts(swc)
File "RealTimeClock.py", line 21, in addPorts
swc.apply(Signals.RtcHours.Send)
File "../..\autosar\component.py", line 120, in apply
template.apply(self)
File "..\SignalsHelper.py", line 26, in apply
_createProvidePortHelper(swc, cls.name, cls.portInterfaceTemplate, cls.initValueTemplate)
File "..\SignalsHelper.py", line 7, in _createProvidePortHelper
ws.apply(portInterfaceTemplate)
File "../..\autosar\workspace.py", line 446, in apply
template.apply(self)
File "..\PortInterfaces.py", line 10, in apply
package = ws.getPortInterfacePackage()
File "../..\autosar\workspace.py", line 480, in getPortInterfacePackage
package = self.find(self.defaultPackages["PortInterface"])
AttributeError: 'Workspace' object has no attribute 'defaultPackages'
Hi, First thanks to the contributors for this lib. it's very useful.
I have an issue when loading ARXML file. when i use loadpackage the package is correctly loaded but the elements are staying empty. In the same time in the subpackages elements are loaded perfectly.
If somebody know what is my mistake i will be thankfull !
here the simple code that I a use for the loading :
ws = autosar.workspace("4.1.1") ws.openXML("myfile.arxml") for role in ws.listPackages(): ws.loadPackage(role)
I tried with differents files but I have the same issue each time
The current parser incorrectly parses the schema version. Make a fix for this.
Create API methods to allow users to programattically create new AR4 components, data types etc.
the demo always has error,about module 'autosar' has no attribute 'workspace'
Traceback (most recent call last):
File "C:\Users\gz03232\Documents\autosar.py", line 1, in
import autosar
File "C:\Users\gz03232\Documents\autosar.py", line 3, in
ws = autosar.workspace(version='4.2.2')
AttributeError: module 'autosar' has no attribute 'workspace'
demo application as follow:
import autosar
ws = autosar.workspace(version='4.2.2')
ws.createPackage('DataTypes', role='DataType')
ws.createPackage('Constants', role="Constant")
ws.createPackage('PortInterfaces', role="PortInterface")
ws.createPackage('ModeDclrGroups', role="ModeDclrGroup")
ws.createPackage('ComponentTypes', role='ComponentType')
#save the file as XML
ws.saveXML('Workspace.arxml')
ws = autosar.workspace(version='4.2.2')
ws.createPackage('DataTypes', role='DataType')
ws.createPackage('Constants', role="Constant")
ws.createPackage('PortInterfaces', role="PortInterface")
ws.createPackage('ModeDclrGroups', role="ModeDclrGroup")
ws.createPackage('ComponentTypes', role='ComponentType')
#save workspace packages into XML files
ws.saveXML('DataTypes.arxml', filters=['/DataTypes'])
ws.saveXML('Constants.arxml', filters=['/Constants'])
ws.saveXML('PortInterfaces.arxml', filters=['/PortInterfaces', '/ModeDclrGroups'])
ws.saveXML('ComponentTypes.arxml', filters=['/ComponentTypes'])
XML parse/write AR 4 component types (including behavior)
Hi, I use the example like as bellows:
import autosar
#Create some packages and data types
ws = autosar.workspace('4.2.2')
datatypes = ws.createPackage('DataTypes', role='DataType')
basetypes = datatypes.createSubPackage('BaseTypes')
u8Type = basetypes.createSwBaseType('uint8', 8, nativeDeclaration='uint8')
u16Type = basetypes.createSwBaseType('uint16', 16, nativeDeclaration='uint16')
u32Type = basetypes.createSwBaseType('uint32', 32, nativeDeclaration='uint32')
ws.saveXML('basetypes.arxml')
#Print reference and name for the created objects
print('u8Type.name: ' + u8Type.name)
print('u8Type.ref: ' + u8Type.ref)
print('u16Type.name: ' + u16Type.name)
print('u16Type.ref: ' + u16Type.ref)
print('u32Type.name: ' + u32Type.name)
print('u32Type.ref: ' + u32Type.ref)
and it fails with:
d = Decimal(float(version))
ValueError: could not convert string to float: '4.2.2'
Hello @cogu
I am new to the AUTOSAR world and was wondering do you have any plans to support AUTOSAR 4.4.0 version? Many thanks in advance.
First thanks for this great package. For AR 4.x the element name of an complex driver component type shall be "COMPLEX-DEVICE-DRIVER-SW-COMPONENT-TYPE'" instead of "COMPLEX-DEVICE-DRIVER-COMPONENT-TYPE". See /autosar/parser/component_parser.py
there is no api to set swc “DATA-TYPE-MAPPING-REF ”
After I use
pip install autosar.xml and run the code with import autosar.xml, the python says no module name autosar.xml
with below data in arxmls
FIBEX-ELEMENTS
FIBEX-ELEMENT-REF-CONDITIONAL
With a glance of the code, I found you generate the arxml by hand. Is there any plan to port the writer to lxml? I personally use lxml to generate arxml and the pretty_print
can perfectly fit the AUTOSAR indentation standard.
i want to load create RPort in A workspace's componentType, using Port interface in another arxml.
how to create one workspace with multiply arxmls.
how to load multiply arxmls into one workspace.
thanks
XML parse/write AR 4 constants
variantProps needs to be initialized to None, too.
Otherwise, my call to createRequirePort(name, if_name, comspec=comspecs)
results in an error.
Line 29 in cb01395
(Sorry for not providing a PR. I did a dirty hack which makes it work for me w/o any other testing.)
partition_test_disabled.py cause AttributeError: module 'autosar.portinterface' has no attribute 'ModeGroup', partition_test_disabled.py is too old?
Now to implement such a function when writing data to the NVM after shutdown, a wake-up source is detected, and the controller will wake up again at this time the ECU will be reseted again. and the data in NVM is incomplete. At this time, the RAM will reload the previous data in NVM after reset, but at this time we do not want to use Nvm_ReadAll () to read the previously stored data from NVM, but want to keep the last unsaved data in RAM
Hello,
i have to generate an arxml file, which will be imported in a davinci workspace.
I can not find a function to create an NV_DATA_INTERFACE element.
Can someone tell me if this can be done or not, and if it will be implemented in a future version?
Here is a model how it is look like:
Thank you,
Marius
Release v0.3.7 do not work on Python v 3.5 and older.
Tested on Python v 3.4.3
Not able to create the numerical value variation point for PortApi.
i need to create 1)port defined argument value
2)Numerical value specification
3)numerical value variation point
The current parser uses the lightweight standard API xml.etree.ElementTree that support the current needs of the library.
One problem with the current parser is that on an ARXML error there is no feedback on where in the input files the problem is found.
Using the etree module from lxml instead more accurate error information can be printed as the lxml keeps track of xml element file location.
Changing line 1 in base.py to
from lxml import etree as ElementTree
its all that is needed to use lxml. The API is compatible and I tested with the current unit tests and all test passes.
lxml do also support XML schema and schema validation. With lxml as base schema validation can be added.
Getiing Error as follows:
AttributeError: 'Package' object has no attribute 'createImplementationDataType'
Have you considered using pyecore as infrastructure? It looks like a good fit for this project.
I would like to generate a DEXT (Autosar Diagnostic Extract) like file using Python and one library.
Is there an extension to this library or something similar that can help me?
Thank you!
In order to better support what parts of the data model goes into the XML file when saving it we need better control. Currently we have the packages=[] attribute but that is clearly not good enough.
Proposal is to replace packages attributes with a filters attributes where filters attribute can give the user the ability to control even on individual element level (instead of package level) what goes into the XML.
ValueError: could not convert string to float: '4.2.2'
XML parse/write AR 4 data types
I want to read an existing element: ECUC-MODULE-CONFIGURATION-VALUES
with the SHORT-NAME
Dcm but it gives the following error:
[PackageParser] unhandled: ECUC-MODULE-CONFIGURATION-VALUES
.
Does this means this is not supported?
Code snip:
ws = autosar.workspace()
ws.openXML("Dcm.arxml")
ws.loadPackage('shortNameOfPackage')
I also want to be able to create the ECUC-MODULE-CONFIGURATION-VALUES
myself but I also don't see this in the documentation.
Test arxml "Dcm.arxml":
<?xml version="1.0" encoding="utf-8"?>
<AUTOSAR xmlns="http://autosar.org/schema/r4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://autosar.org/schema/r4.0 AUTOSAR_4-0-3.xsd">
<AR-PACKAGES>
<AR-PACKAGE>
<SHORT-NAME>shortNameOfPackage</SHORT-NAME>
<ELEMENTS>
<ECUC-MODULE-CONFIGURATION-VALUES UUID="8e3b6bec-9cd0-4347-b931-ef4a8b022f21">
<SHORT-NAME>Dcm</SHORT-NAME>
<ADMIN-DATA>
</ADMIN-DATA>
<DEFINITION-REF DEST="ECUC-MODULE-DEF">/EcucDefs/Generic/Dcm</DEFINITION-REF>
<IMPLEMENTATION-CONFIG-VARIANT>VARIANT-PRE-COMPILE</IMPLEMENTATION-CONFIG-VARIANT>
<MODULE-DESCRIPTION-REF DEST="BSW-IMPLEMENTATION">/EcucDefs/Generic/Implementations/Dcm</MODULE-DESCRIPTION-REF>
<CONTAINERS>
</CONTAINERS>
</ECUC-MODULE-CONFIGURATION-VALUES>
</ELEMENTS>
</AR-PACKAGE>
</AR-PACKAGES>
</AUTOSAR>
as i want to createConst in my own const package, but the reference implication datatype is in the external arxml
this is an array type ,
the parent implication datatype has no dataType.variantProps , but the subelement has it.
it report errror:
_autosar\builder.py", line 28, in createFromDataTypeInternal
variantProps = dataType.variantProps[0]
IndexError: list index out of range
@cogu how could i solve this problem.
<IMPLEMENTATION-DATA-TYPE UUID="0409b9fa-3809-50bd-7866-18186f47cabd"> <SHORT-NAME>rt_Array_UInt8_6</SHORT-NAME> <CATEGORY>ARRAY</CATEGORY> <ADMIN-DATA> <SDGS> <SDG GID="DV_SDG"> <SD GID="DV_ReadOnly">1</SD> </SDG> </SDGS> </ADMIN-DATA> <SUB-ELEMENTS> <IMPLEMENTATION-DATA-TYPE-ELEMENT UUID="4dc31bd7-14f2-502e-08a6-3eed92b75371"> <SHORT-NAME>rt_Array_UInt8_6</SHORT-NAME> <CATEGORY>TYPE_REFERENCE</CATEGORY> <ARRAY-SIZE>6</ARRAY-SIZE> <ARRAY-SIZE-SEMANTICS>FIXED-SIZE</ARRAY-SIZE-SEMANTICS> <SW-DATA-DEF-PROPS> <SW-DATA-DEF-PROPS-VARIANTS> <SW-DATA-DEF-PROPS-CONDITIONAL> <IMPLEMENTATION-DATA-TYPE-REF DEST="IMPLEMENTATION-DATA-TYPE">/AFA_pkg/AFA_dt/UInt8</IMPLEMENTATION-DATA-TYPE-REF> </SW-DATA-DEF-PROPS-CONDITIONAL> </SW-DATA-DEF-PROPS-VARIANTS> </SW-DATA-DEF-PROPS> </IMPLEMENTATION-DATA-TYPE-ELEMENT> </SUB-ELEMENTS> </IMPLEMENTATION-DATA-TYPE>
CreateRunnable API:
SwcInternalBehavior.createRunnable(name[, portAccess=None][, symbol=None][, concurrent=False][, exclusiveAreas=None][, adminData=None])
I do not see an option for the data access (implicit/explicit).
By default it is taking explicit access.
Can you help me in providing implicit access?
Give the user the ability to attach custom XML writer classes
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.