Skip to content

Commit

Permalink
Autosarfactory now respects the order/sequence of elements as specifi…
Browse files Browse the repository at this point in the history
…ed by Autosar schema. The xml serialization is done respecting the schema. Also further improvements made to autosarfactory

* Fixed issue:
- The xml is not serialized according to the order specified in the autosar schema
- Now, it's possible to properly generate the elements SwBaseType, CompuMethod etc.
- Updated example with SwBaseType, CompuMethod, DataConstr creation
- Added a new context menu action in the ui to copy the file path of the respective node

* Fixed issues reported by Christian regarding the broken re-arrangement of elements in the xml node. Now, the file is properly serialized as expected by Autosar schema.

* Added changelog entry wrt xml serialization improvement

* Added unit tests

* Added unit tests for checking order of elements when the model has invisible model elements like BaseTypeDirectDefinition inside SwBaseType

* Fixed issues reported by Christian. Elements are added respecting the order

* the xml elements are now removed when the value is unset or if it's set to None

* Update CHANGELOG.md

* Added support for ordering of elements as specified by Autosar. And now the tool is able to properly manage RoleWrapperElements and normal elements which is added as a list of containment elements. Added additional compu method in the example script for rational coeffs to see if the V are added as per the order

* Updated changelog to modify the date

* Fixed issue with resolving references for the elements of type "roleTypeWrapper"

* Fixed issue wrt processing of elements which are choice eg: SdgContentType inside Sdg. Added unit test and updated example script.

* Fixed issues wrt non-removal of elements when using remove function for containtment elements

* Added support for exporting ColleableElements(ArPackage and all packageableElements) into a file

* Fixed an issue with xml ordering of elements when a same base class is inherited from different levels.

* Fixed issues with reference setting and reading when a parent node of the referenced object has no short-name

* Added autosarfactory implementation for more autosar versions(done since this was requested by many users)

* Fixed issues when the autosar ecore file doesn't have proper references which caused generation of some objects inconsistent

* Fixed issues with respect to processing elements which were of type choice in the schema/ecore model

* Fixed issues with creating nodes on the fly when the insertion order was not respected

* Added proper autosar version to the python implementations of the respective autosar versions.

* Fixed issues with generation of multi-reference nodes

* Doc update for export function

* Update README.md

* Update README.md

* Updated autosarfactory with some minor updates (do not report an error when elements are added to a list which are not Referrable)

* Fixed issues with non-removal of reference elements from arxml if all the elements are removed using the remove api.
Also, fixed issue with reading of elements when there is only concrete sub type available in the autosar metamodel

* Update README.md

* Fixed a small typo in the factory

---------

Co-authored-by: Girish Chandran <[email protected]>
  • Loading branch information
girishchandranc and Girish Chandran authored Nov 17, 2023
1 parent 559010e commit 11f4bd6
Show file tree
Hide file tree
Showing 37 changed files with 3,591,346 additions and 229,189 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ Support for processing the integer attributes configured as hex, binary or octal

## [0.3.1]() - 2023-07-11
- Check if the parent node can have children before getting or adding children

## [0.4.0]() - 2023-11-17
- ARXML elements are now added respecting the sequence order specified by Autosar schema.
- Introduced new API `get_all_instances` to get all the instances of a particular node based on the given class type.
- New feature to export AR-Package or PackageableElement(ApplicationSwComponentType, ISignal etc) to a file.
78 changes: 76 additions & 2 deletions Examples/create_autosar_basic_communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
sys.path.insert(0, mod_path)
from autosarfactory import autosarfactory


def __createCompuScales(compuScales, lowerLimitVal, upperLimitVal, constVal):
compuScale = compuScales.new_CompuScale()
compuScale.new_CompuScaleConstantContents().new_CompuConst().new_CompuConstTextContent().set_vt(constVal)

upperLimit = compuScale.new_UpperLimit()
upperLimit.set(upperLimitVal)
upperLimit.set_intervalType(autosarfactory.IntervalTypeEnum.VALUE_CLOSED)

lowerLimit = compuScale.new_LowerLimit()
lowerLimit.set(lowerLimitVal)
lowerLimit.set_intervalType(autosarfactory.IntervalTypeEnum.VALUE_CLOSED)


generatdDir = os.path.join(os.path.dirname(__file__), 'generated')
dataTypesFile = os.path.join(generatdDir, 'dataTypes.arxml')
interfaceFile = os.path.join(generatdDir, 'interface.arxml')
Expand All @@ -13,10 +27,48 @@
dtPack = autosarfactory.new_file(dataTypesFile, defaultArPackage = 'DataTypes', overWrite = True)
baseTypePack = dtPack.new_ARPackage('baseTypes')
uint8BaseType = baseTypePack.new_SwBaseType('uint8')
baseTypeDef = uint8BaseType.new_BaseTypeDirectDefinition()
baseTypeDef.set_baseTypeEncoding('2C')
baseTypeDef.set_nativeDeclaration('unsigned char')
baseTypeDef.set_memAlignment(8)
baseTypeDef.set_baseTypeSize(16)

compuPack = dtPack.new_ARPackage('compuMethods')
compu1 = compuPack.new_CompuMethod('cm1')
intoPhy = compu1.new_CompuInternalToPhys()
compuScales = intoPhy.new_CompuScales()

__createCompuScales(compuScales=compuScales, lowerLimitVal=0, upperLimitVal=0, constVal='ECU_STATE_STOP')
__createCompuScales(compuScales=compuScales, lowerLimitVal=1, upperLimitVal=1, constVal='ECU_STATE_START')
__createCompuScales(compuScales=compuScales, lowerLimitVal=2, upperLimitVal=2, constVal='ECU_STATE_RUN')

# Create a compu method for rational coeffs
compu2 = compuPack.new_CompuMethod('cm2')
rationalCoeff = compu2.new_CompuInternalToPhys().new_CompuScales().new_CompuScale().new_CompuScaleRationalFormula().new_CompuRationalCoeffs()
num = rationalCoeff.new_CompuNumerator()
num.new_V().set(100)
num.new_V().set(200)
num.new_V().set(300)

dataConstrPack = dtPack.new_ARPackage('dataConstrs')
dataConstr = dataConstrPack.new_DataConstr('dc1')
intConstr = dataConstr.new_DataConstrRule().new_InternalConstrs()

dcLowerLimit = intConstr.new_LowerLimit()
dcLowerLimit.set(-128)
dcLowerLimit.set_intervalType(autosarfactory.IntervalTypeEnum.VALUE_CLOSED)

dcUpperLimit = intConstr.new_UpperLimit()
dcUpperLimit.set(127)
dcUpperLimit.set_intervalType(autosarfactory.IntervalTypeEnum.VALUE_CLOSED)


implTypePack = dtPack.new_ARPackage('ImplTypes')
uint8 = implTypePack.new_ImplementationDataType('uint8')
uint8.new_SwDataDefProps().new_SwDataDefPropsVariant().set_baseType(uint8BaseType)
variant = uint8.new_SwDataDefProps().new_SwDataDefPropsVariant()
variant.set_baseType(uint8BaseType)
variant.set_compuMethod(compu1)
variant.set_dataConstr(dataConstr)

ifPack = autosarfactory.new_file(interfaceFile, defaultArPackage = 'Interfaces', overWrite = True)
srIf = ifPack.new_SenderReceiverInterface('srif1')
Expand Down Expand Up @@ -80,15 +132,23 @@
signalsPack = canNetworkPack.new_ARPackage('signals')
systemsignalsPack = canNetworkPack.new_ARPackage('systemsignals')
syssig1 = systemsignalsPack.new_SystemSignal('syssig1')
syssig1.set_dynamicLength(True)

sig1 = signalsPack.new_ISignal('sig1')
sig1.set_systemSignal(syssig1)
sig1.set_length(4)
sig1.set_dataTypePolicy(autosarfactory.DataTypePolicyEnum.VALUE_LEGACY)
sig1.set_iSignalType(autosarfactory.ISignalTypeEnum.VALUE_PRIMITIVE)
sig1.set_systemSignal(syssig1)

# Adding admin data
sdg = sig1.new_AdminData().new_Sdg()
sdg.set_gid("12")
sdg.new_Sd().set_value("new_sd")

ecuPack = canNetworkPack.new_ARPackage('ecus')
ecu1 = ecuPack.new_EcuInstance('ecu1')
ecu1.set_wakeUpOverBusSupported(True)
ecu1.set_sleepModeSupported(False)

sysPack = canNetworkPack.new_ARPackage('system')
system = sysPack.new_System('CanSystem')
Expand All @@ -109,5 +169,19 @@
swcMap1.add_contextComponent(asw1_proto)
swcMap1.add_contextComponent(asw2_proto)

typesPackage = autosarfactory.new_file(os.path.join(generatdDir, 'array.arxml'), defaultArPackage='types', overWrite=True)

stdImplementationDataType = typesPackage.new_StdCppImplementationDataType('Array')

symbolProps = stdImplementationDataType.new_Namespace('namespace_ns')
symbolProps.set_symbol('ns')

cppTemplateArgument = stdImplementationDataType.new_TemplateArgument()

positiveIntegerValueVariationPoint = stdImplementationDataType.new_ArraySize()
positiveIntegerValueVariationPoint.set(6)
stdImplementationDataType.set_category('ARRAY')
stdImplementationDataType.set_typeEmitter('TYPE_EMITTER_ARA')

autosarfactory.save()
autosarfactory.saveAs(mergedFile, overWrite = True)
25 changes: 14 additions & 11 deletions Examples/generated/CanNetwork.arxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
<AR-PACKAGES>
<AR-PACKAGE>
<SHORT-NAME>Can</SHORT-NAME>
<ELEMENTS/>
<AR-PACKAGES>
<AR-PACKAGE>
<SHORT-NAME>signals</SHORT-NAME>
<ELEMENTS>
<I-SIGNAL>
<SHORT-NAME>sig1</SHORT-NAME>
<ADMIN-DATA>
<SDGS>
<SDG GID="12">
<SD>new_sd</SD>
</SDG>
</SDGS>
</ADMIN-DATA>
<DATA-TYPE-POLICY>LEGACY</DATA-TYPE-POLICY>
<LENGTH>4</LENGTH>
<I-SIGNAL-TYPE>PRIMITIVE</I-SIGNAL-TYPE>
<LENGTH>4</LENGTH>
<SYSTEM-SIGNAL-REF DEST="SYSTEM-SIGNAL">/Can/systemsignals/syssig1</SYSTEM-SIGNAL-REF>
</I-SIGNAL>
</ELEMENTS>
Expand All @@ -22,7 +28,7 @@
<ELEMENTS>
<SYSTEM-SIGNAL>
<SHORT-NAME>syssig1</SHORT-NAME>
<DYNAMIC-LENGTH>false</DYNAMIC-LENGTH>
<DYNAMIC-LENGTH>true</DYNAMIC-LENGTH>
</SYSTEM-SIGNAL>
</ELEMENTS>
</AR-PACKAGE>
Expand All @@ -32,7 +38,7 @@
<ECU-INSTANCE>
<SHORT-NAME>ecu1</SHORT-NAME>
<SLEEP-MODE-SUPPORTED>false</SLEEP-MODE-SUPPORTED>
<WAKE-UP-OVER-BUS-SUPPORTED>false</WAKE-UP-OVER-BUS-SUPPORTED>
<WAKE-UP-OVER-BUS-SUPPORTED>true</WAKE-UP-OVER-BUS-SUPPORTED>
</ECU-INSTANCE>
</ELEMENTS>
</AR-PACKAGE>
Expand All @@ -41,32 +47,29 @@
<ELEMENTS>
<SYSTEM>
<SHORT-NAME>CanSystem</SHORT-NAME>
<SYSTEM-VERSION></SYSTEM-VERSION>
<MAPPINGS>
<SYSTEM-MAPPING>
<SHORT-NAME>Mappings</SHORT-NAME>
<DATA-MAPPINGS>
<SENDER-RECEIVER-TO-SIGNAL-MAPPING>
<SYSTEM-SIGNAL-REF DEST="SYSTEM-SIGNAL">/Can/systemsignals/syssig1</SYSTEM-SIGNAL-REF>
<DATA-ELEMENT-IREF>
<CONTEXT-PORT-REF DEST="P-PORT-PROTOTYPE">/Swcs/asw1/outPort</CONTEXT-PORT-REF>
<TARGET-DATA-PROTOTYPE-REF DEST="VARIABLE-DATA-PROTOTYPE">/Interfaces/srif1/de1</TARGET-DATA-PROTOTYPE-REF>
</DATA-ELEMENT-IREF>
<SYSTEM-SIGNAL-REF DEST="SYSTEM-SIGNAL">/Can/systemsignals/syssig1</SYSTEM-SIGNAL-REF>
</SENDER-RECEIVER-TO-SIGNAL-MAPPING>
</DATA-MAPPINGS>
<SW-MAPPINGS>
<SWC-TO-ECU-MAPPING>
<SHORT-NAME>SwcMapping</SHORT-NAME>
<ECU-INSTANCE-REF DEST="ECU-INSTANCE">/Can/ecus/ecu1</ECU-INSTANCE-REF>
<COMPONENT-IREFS>
<COMPONENT-IREF>
<CONTEXT-COMPOSITION-REF DEST="ROOT-SW-COMPOSITION-PROTOTYPE">/Can/system/CanSystem/rootSwcom</CONTEXT-COMPOSITION-REF>
<CONTEXT-COMPONENT-REFS>
<CONTEXT-COMPONENT-REF DEST="SW-COMPONENT-PROTOTYPE">/Swcs/Comp/asw1_proto</CONTEXT-COMPONENT-REF>
<CONTEXT-COMPONENT-REF DEST="SW-COMPONENT-PROTOTYPE">/Swcs/Comp/asw2_proto</CONTEXT-COMPONENT-REF>
</CONTEXT-COMPONENT-REFS>
<CONTEXT-COMPONENT-REF DEST="SW-COMPONENT-PROTOTYPE">/Swcs/Comp/asw1_proto</CONTEXT-COMPONENT-REF>
<CONTEXT-COMPONENT-REF DEST="SW-COMPONENT-PROTOTYPE">/Swcs/Comp/asw2_proto</CONTEXT-COMPONENT-REF>
</COMPONENT-IREF>
</COMPONENT-IREFS>
<ECU-INSTANCE-REF DEST="ECU-INSTANCE">/Can/ecus/ecu1</ECU-INSTANCE-REF>
</SWC-TO-ECU-MAPPING>
</SW-MAPPINGS>
</SYSTEM-MAPPING>
Expand Down
25 changes: 25 additions & 0 deletions Examples/generated/array.arxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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_00051.xsd">
<AR-PACKAGES>
<AR-PACKAGE>
<SHORT-NAME>types</SHORT-NAME>
<ELEMENTS>
<STD-CPP-IMPLEMENTATION-DATA-TYPE>
<SHORT-NAME>Array</SHORT-NAME>
<CATEGORY>ARRAY</CATEGORY>
<ARRAY-SIZE>6</ARRAY-SIZE>
<NAMESPACES>
<SYMBOL-PROPS>
<SHORT-NAME>namespace_ns</SHORT-NAME>
<SYMBOL>ns</SYMBOL>
</SYMBOL-PROPS>
</NAMESPACES>
<TEMPLATE-ARGUMENTS>
<CPP-TEMPLATE-ARGUMENT/>
</TEMPLATE-ARGUMENTS>
<TYPE-EMITTER>TYPE_EMITTER_ARA</TYPE-EMITTER>
</STD-CPP-IMPLEMENTATION-DATA-TYPE>
</ELEMENTS>
</AR-PACKAGE>
</AR-PACKAGES>
</AUTOSAR>
8 changes: 4 additions & 4 deletions Examples/generated/components.arxml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
<EVENTS>
<TIMING-EVENT>
<SHORT-NAME>te_5ms</SHORT-NAME>
<PERIOD>0.005</PERIOD>
<START-ON-EVENT-REF DEST="RUNNABLE-ENTITY">/Swcs/asw1/beh1/Runnable_1</START-ON-EVENT-REF>
<PERIOD>0.005</PERIOD>
</TIMING-EVENT>
</EVENTS>
<RUNNABLES>
<RUNNABLE-ENTITY>
<SHORT-NAME>Runnable_1</SHORT-NAME>
<SYMBOL>Run1</SYMBOL>
<DATA-SEND-POINTS>
<VARIABLE-ACCESS>
<SHORT-NAME>dsp</SHORT-NAME>
Expand All @@ -37,6 +36,7 @@
</ACCESSED-VARIABLE>
</VARIABLE-ACCESS>
</DATA-SEND-POINTS>
<SYMBOL>Run1</SYMBOL>
</RUNNABLE-ENTITY>
</RUNNABLES>
</SWC-INTERNAL-BEHAVIOR>
Expand All @@ -56,17 +56,16 @@
<EVENTS>
<DATA-RECEIVED-EVENT>
<SHORT-NAME>DRE_Vdp</SHORT-NAME>
<START-ON-EVENT-REF DEST="RUNNABLE-ENTITY">/Swcs/asw2/beh1/Runnable_2</START-ON-EVENT-REF>
<DATA-IREF>
<CONTEXT-R-PORT-REF DEST="R-PORT-PROTOTYPE">/Swcs/asw2/inPort</CONTEXT-R-PORT-REF>
<TARGET-DATA-ELEMENT-REF DEST="VARIABLE-DATA-PROTOTYPE">/Interfaces/srif1/de1</TARGET-DATA-ELEMENT-REF>
</DATA-IREF>
<START-ON-EVENT-REF DEST="RUNNABLE-ENTITY">/Swcs/asw2/beh1/Runnable_2</START-ON-EVENT-REF>
</DATA-RECEIVED-EVENT>
</EVENTS>
<RUNNABLES>
<RUNNABLE-ENTITY>
<SHORT-NAME>Runnable_2</SHORT-NAME>
<SYMBOL>Run2</SYMBOL>
<DATA-RECEIVE-POINT-BY-ARGUMENTS>
<VARIABLE-ACCESS>
<SHORT-NAME>dra</SHORT-NAME>
Expand All @@ -78,6 +77,7 @@
</ACCESSED-VARIABLE>
</VARIABLE-ACCESS>
</DATA-RECEIVE-POINT-BY-ARGUMENTS>
<SYMBOL>Run2</SYMBOL>
</RUNNABLE-ENTITY>
</RUNNABLES>
</SWC-INTERNAL-BEHAVIOR>
Expand Down
72 changes: 71 additions & 1 deletion Examples/generated/dataTypes.arxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,84 @@
<AR-PACKAGES>
<AR-PACKAGE>
<SHORT-NAME>DataTypes</SHORT-NAME>
<ELEMENTS/>
<AR-PACKAGES>
<AR-PACKAGE>
<SHORT-NAME>baseTypes</SHORT-NAME>
<ELEMENTS>
<SW-BASE-TYPE>
<SHORT-NAME>uint8</SHORT-NAME>
<BASE-TYPE-SIZE>16</BASE-TYPE-SIZE>
<BASE-TYPE-ENCODING>2C</BASE-TYPE-ENCODING>
<MEM-ALIGNMENT>8</MEM-ALIGNMENT>
<NATIVE-DECLARATION>unsigned char</NATIVE-DECLARATION>
</SW-BASE-TYPE>
</ELEMENTS>
</AR-PACKAGE>
<AR-PACKAGE>
<SHORT-NAME>compuMethods</SHORT-NAME>
<ELEMENTS>
<COMPU-METHOD>
<SHORT-NAME>cm1</SHORT-NAME>
<COMPU-INTERNAL-TO-PHYS>
<COMPU-SCALES>
<COMPU-SCALE>
<LOWER-LIMIT INTERVAL-TYPE="CLOSED">0</LOWER-LIMIT>
<UPPER-LIMIT INTERVAL-TYPE="CLOSED">0</UPPER-LIMIT>
<COMPU-CONST>
<VT>ECU_STATE_STOP</VT>
</COMPU-CONST>
</COMPU-SCALE>
<COMPU-SCALE>
<LOWER-LIMIT INTERVAL-TYPE="CLOSED">1</LOWER-LIMIT>
<UPPER-LIMIT INTERVAL-TYPE="CLOSED">1</UPPER-LIMIT>
<COMPU-CONST>
<VT>ECU_STATE_START</VT>
</COMPU-CONST>
</COMPU-SCALE>
<COMPU-SCALE>
<LOWER-LIMIT INTERVAL-TYPE="CLOSED">2</LOWER-LIMIT>
<UPPER-LIMIT INTERVAL-TYPE="CLOSED">2</UPPER-LIMIT>
<COMPU-CONST>
<VT>ECU_STATE_RUN</VT>
</COMPU-CONST>
</COMPU-SCALE>
</COMPU-SCALES>
</COMPU-INTERNAL-TO-PHYS>
</COMPU-METHOD>
<COMPU-METHOD>
<SHORT-NAME>cm2</SHORT-NAME>
<COMPU-INTERNAL-TO-PHYS>
<COMPU-SCALES>
<COMPU-SCALE>
<COMPU-RATIONAL-COEFFS>
<COMPU-NUMERATOR>
<V>100</V>
<V>200</V>
<V>300</V>
</COMPU-NUMERATOR>
</COMPU-RATIONAL-COEFFS>
</COMPU-SCALE>
</COMPU-SCALES>
</COMPU-INTERNAL-TO-PHYS>
</COMPU-METHOD>
</ELEMENTS>
</AR-PACKAGE>
<AR-PACKAGE>
<SHORT-NAME>dataConstrs</SHORT-NAME>
<ELEMENTS>
<DATA-CONSTR>
<SHORT-NAME>dc1</SHORT-NAME>
<DATA-CONSTR-RULES>
<DATA-CONSTR-RULE>
<INTERNAL-CONSTRS>
<LOWER-LIMIT INTERVAL-TYPE="CLOSED">-128</LOWER-LIMIT>
<UPPER-LIMIT INTERVAL-TYPE="CLOSED">127</UPPER-LIMIT>
</INTERNAL-CONSTRS>
</DATA-CONSTR-RULE>
</DATA-CONSTR-RULES>
</DATA-CONSTR>
</ELEMENTS>
</AR-PACKAGE>
<AR-PACKAGE>
<SHORT-NAME>ImplTypes</SHORT-NAME>
<ELEMENTS>
Expand All @@ -22,6 +90,8 @@
<SW-DATA-DEF-PROPS-VARIANTS>
<SW-DATA-DEF-PROPS-CONDITIONAL>
<BASE-TYPE-REF DEST="SW-BASE-TYPE">/DataTypes/baseTypes/uint8</BASE-TYPE-REF>
<COMPU-METHOD-REF DEST="COMPU-METHOD">/DataTypes/compuMethods/cm1</COMPU-METHOD-REF>
<DATA-CONSTR-REF DEST="DATA-CONSTR">/DataTypes/dataConstrs/dc1</DATA-CONSTR-REF>
</SW-DATA-DEF-PROPS-CONDITIONAL>
</SW-DATA-DEF-PROPS-VARIANTS>
</SW-DATA-DEF-PROPS>
Expand Down
Loading

0 comments on commit 11f4bd6

Please sign in to comment.