Skip to content

Commit

Permalink
Merge pull request #20 from melodypapa/feature/19
Browse files Browse the repository at this point in the history
Issue 19: ARXML writer
  • Loading branch information
melodypapa authored Jul 14, 2024
2 parents 3236fcf + 136aafc commit fca8eff
Show file tree
Hide file tree
Showing 40 changed files with 4,016 additions and 807 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ __pycache__
*.log
docs/py-armodel.und
data
src/armodel/tests/test_files/backup.arxml
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"cSpell.words": [
"ADDRMETHOD",
"appl",
"armodel",
"ARXML",
Expand All @@ -18,13 +19,17 @@
"nsmap",
"openpyxl",
"Packageable",
"Possbile",
"PPORT",
"pypi",
"pytest",
"reentrancy",
"Referrable",
"RPORT",
"Schedulable",
"sdgs",
"sdist",
"sheetnames",
"swcs"
],
"python.formatting.autopep8Args": [
Expand Down
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ And more details can be found at https://packaging.python.org/
- ParameterInterface
- SenderReceiverInterface
- BswModuleEntry
- EndToEndProtectionSet
- Implementation
- BswImplementation
- AtpFeature
Expand Down Expand Up @@ -127,9 +128,18 @@ $arxml-swc --format long --filter CompositionSwComponent <arxml_folder>
**Export all the SwConnector (AssemblySwConnector, DelegationSwConnector) to excel file**

```
$connector2xlsx <arxml_folder> connector.xlsx
$connector2xlsx src/armodel/tests/test_files/SimpleTest.arxml data/SimpleTest.xlsx
```

### 1.8.4. connector-update

**Update all the SwConnector (AssemblySwConnector, DelegationSwConnector) from excel file**

```
$connector-update src/armodel/tests/test_files/SimpleTest.arxml data/SimpleTest.xlsx data/Test.arxml
```


## 1.9. API

### 1.9.1. Constructor
Expand Down Expand Up @@ -192,4 +202,14 @@ Fix the attribute intervalType of **Limit** is empty issue.
2. Support to read the AUTOSAR model from arxml file (Issue #17)
* ConstantSpecification
* DataConstr
* Unit
* Unit

**Version 1.4.1**

1. Support to write the AUTOSAR model to arxml file (Issue #19)
* ServerComSpec
* PerInstanceMemory
2. Support to read the AUTOSAR model from arxml file (Issue #19)
* ServerComSpec
* PerInstanceMemory
3. Move the ARPackage from the Elements.
26 changes: 26 additions & 0 deletions docs/com_spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Allowed combinations of a specific Type of PortInterface, a specific Type of PortPrototype, and a specific Type of ComSpec

| Type of PortPrototype | Type of ComSpec | Role of Element | Type of PortInterface | Role of Type-Ref |
| --------------------- | ------------------------- | --------------- | ----------------------- | ------------------------- |
| PPortPrototype | NonqueuedSenderComSpec | dataElement | SenderReceiverInterface | providedInterface |
| PPortPrototype | QueuedSenderComSpec | dataElement | SenderReceiverInterface | providedInterface |
| RPortPrototype | NonqueuedReceiverComSpec | dataElement | SenderReceiverInterface | requiredInterface |
| RPortPrototype | QueuedReceiverComSpec | dataElement | SenderReceiverInterface | requiredInterface |
| PRPortPrototype | NonqueuedSenderComSpec | dataElement | SenderReceiverInterface | providedRequiredInterface |
| PRPortPrototype | NonqueuedReceiverComSpec | dataElement | SenderReceiverInterface | providedRequiredInterface |
| PRPortPrototype | QueuedReceiverComSpec | dataElement | SenderReceiverInterface | providedRequiredInterface |
| PRPortPrototype | QueuedSenderComSpec | dataElement | SenderReceiverInterface | providedRequiredInterface |
| PPortPrototype | NvProvideComSpec | nvData | NvDataInterface | providedInterface |
| RPortPrototype | NvRequireComSpec | nvData | NvDataInterface | requiredInterface |
| PRPortPrototype | NvProvideComSpec | nvData | NvDataInterface | providedRequiredInterface |
| PRPortPrototype | NvRequireComSpec | nvData | NvDataInterface | providedRequiredInterface |
| PPortPrototype | ModeSwitchSenderComSpec | modeGroup | ModeSwitchInterface | providedInterface |
| RPortPrototype | ModeSwitchReceiverComSpec | modeGroup | ModeSwitchInterface | requiredInterface |
| PRPortPrototype | ModeSwitchSenderComSpec | modeGroup | ModeSwitchInterface | providedRequiredInterface |
| PRPortPrototype | ModeSwitchReceiverComSpec | modeGroup | ModeSwitchInterface | providedRequiredInterface |
| PPortPrototype | ParameterProvideComSpec | parameter | ParameterInterface | providedInterface |
| RPortPrototype | ParameterRequireComSpec | parameter | ParameterInterface | requiredInterface |
| PPortPrototype | ServerComSpec | operation | ClientServerInterface | providedInterface |
| RPortPrototype | ClientComSpec | operation | ClientServerInterface | requiredInterface |
| PRPortPrototype | ServerComSpec | operation | ClientServerInterface | providedRequiredInterface |
| PRPortPrototype | ClientComSpec | operation | ClientServerInterface | providedRequiredInterface |
Binary file added docs/figure_3_4_overview_of_component_types.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docs/sw_components.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Component Types

![Figure 3.4: Overview of Component Types](figure_3_4_overview_of_component_types.png)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='armodel',
version='1.4.0',
version='1.4.1',
description='the python arxml parser',

url='http://github.com/melodypapa/py-armodel',
Expand Down
2 changes: 1 addition & 1 deletion src/armodel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .models import *
from .parser import ARXMLParser
from .parser import *
2 changes: 2 additions & 0 deletions src/armodel/cli/arxml_dump_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def show_bsw_module_description(indent: int, description: BswModuleDescription):
def show_ar_package(indent: int, ar_package: ARPackage):
print("%s-%s (Pkg)" % (" " * indent, ar_package.short_name))

for sub_package in ar_package.getARPackages():
show_ar_package(indent + 2, sub_package)
#for data_type in ar_package.getImplementationDataTypes():
# show_type(indent + 2, data_type)
#for mapping_set in ar_package.getDataTypeMappingSets():
Expand Down
11 changes: 9 additions & 2 deletions src/armodel/cli/connector_update_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import sys
import os.path

from armodel import AUTOSAR
from armodel.parser import ARXMLParser

from ..models.ar_package import AUTOSAR
from ..parser.arxml_parser import ARXMLParser
from ..parser.connector_xlsx_parser import ConnectorXlsReader

from ..lib import InputFileParser
from ..writer import ARXMLWriter
Expand Down Expand Up @@ -59,11 +61,16 @@ def main():
parser = ARXMLParser(options)
parser.load(args.INPUT, document)

reader = ConnectorXlsReader()
reader.read(args.MAPPING)
reader.update(document)

writer = ARXMLWriter()
writer.save(args.OUTPUT, document)

except Exception as e:
#print(e)
logger.error(e)
raise e

if __name__ == "__main__":
Expand Down
File renamed without changes.
22 changes: 22 additions & 0 deletions src/armodel/data_models/sw_connector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class SwConnectorData:
def __init__(self) -> None:
self.short_name = ""

class DelegationSwConnectorData(SwConnectorData):
def __init__(self) -> None:
super().__init__()

self.inner_swc = ""
self.inner_pport = ""
self.inner_rport = ""
self.outer_pport = ""
self.outer_rport = ""

class AssemblySwConnectorData(SwConnectorData):
def __init__(self) -> None:
super().__init__()

self.provider_swc= ""
self.pport = ""
self.requester_swc = ""
self.rport = ""
2 changes: 1 addition & 1 deletion src/armodel/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .general_structure import *
from .common_structure import *
from .sw_component import *
from .ar_package import ARPackage, AUTOSAR
from .ar_package import *
from .ar_ref import *
from .datatype import *
from .port_prototype import *
Expand Down
18 changes: 18 additions & 0 deletions src/armodel/models/annotation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

from abc import ABCMeta
from .ar_object import ARObject, MultilanguageLongName


class GeneralAnnotation(ARObject, metaclass=ABCMeta):
def __init__(self):
if type(self) == ARObject:
raise NotImplementedError("GeneralAnnotation is an abstract class.")

self.label = None # type: MultilanguageLongName

super().__init__()

class Annotation(GeneralAnnotation):
def __init__(self):
super().__init__()

58 changes: 49 additions & 9 deletions src/armodel/models/ar_package.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from typing import List
from typing import Dict, List

from .end_to_end_protection import EndToEndProtectionSet
from .unit import Unit
from .general_structure import Identifiable, ARObject, Referrable, CollectableElement, SwcBswMapping
from .port_interface import SenderReceiverInterface, ClientServerInterface
from .sw_component import SwComponentType, EcuAbstractionSwComponentType, AtomicSwComponentType, ApplicationSwComponentType, ServiceSwComponentType, CompositionSwComponentType, SensorActuatorSwComponentType
from .sw_component import SwComponentType, EcuAbstractionSwComponentType, AtomicSwComponentType, ApplicationSwComponentType
from .sw_component import ServiceSwComponentType, CompositionSwComponentType, SensorActuatorSwComponentType, ComplexDeviceDriverSwComponentType
from .datatype import ImplementationDataType, ApplicationDataType, DataTypeMappingSet, DataTypeMap, SwBaseType, ApplicationPrimitiveDataType, ApplicationRecordDataType
from .m2_msr import CompuMethod
from .common_structure import ConstantSpecification
Expand All @@ -16,14 +18,28 @@ def __init__(self, parent: ARObject, short_name: str):
Identifiable.__init__(self, parent, short_name)
CollectableElement.__init__(self)

self._ar_packages = {} # type: Dict[str, ARPackage]

def getARPackages(self): # type: (...) -> List[ARPackage]
return list(filter(lambda e: isinstance(e, ARPackage), self.elements.values()))
return list(sorted(self._ar_packages.values(), key= lambda a: a.short_name))
#return list(filter(lambda e: isinstance(e, ARPackage), self.elements.values()))

def createARPackage(self, short_name: str):
'''
if (short_name not in self.elements):
ar_package = ARPackage(self, short_name)
self.elements[short_name] = ar_package
return self.elements[short_name]
'''
if short_name not in self._ar_packages:
ar_package = ARPackage(self, short_name)
self._ar_packages[short_name] = ar_package
return self._ar_packages[short_name]

def getElement(self, short_name: str) -> Referrable:
if (short_name in self._ar_packages):
return self._ar_packages[short_name]
return CollectableElement.getElement(self, short_name)

def createEcuAbstractionSwComponentType(self, short_name: str) -> EcuAbstractionSwComponentType:
if (short_name not in self.elements):
Expand All @@ -32,10 +48,16 @@ def createEcuAbstractionSwComponentType(self, short_name: str) -> EcuAbstraction
return self.elements[short_name]

def createApplicationSwComponentType(self, short_name: str) -> ApplicationSwComponentType:
if (short_name not in self.elements):
if short_name not in self.elements:
sw_component = ApplicationSwComponentType(self, short_name)
self.elements[short_name] = sw_component
return self.elements[short_name]

def createComplexDeviceDriverSwComponentType(self, short_name: str) -> ComplexDeviceDriverSwComponentType:
if short_name not in self.elements:
sw_component = ComplexDeviceDriverSwComponentType(self, short_name)
self.elements[short_name] = sw_component
return self.elements[short_name]

def createServiceSwComponentType(self, short_name: str) -> ServiceSwComponentType:
if (short_name not in self.elements):
Expand Down Expand Up @@ -150,6 +172,12 @@ def createUnit(self, short_name: str) -> Unit:
spec = Unit(self, short_name)
self.elements[short_name] = spec
return self.elements[short_name]

def createEndToEndProtectionSet(self, short_name: str) -> EndToEndProtectionSet:
if (short_name not in self.elements):
spec = EndToEndProtectionSet(self, short_name)
self.elements[short_name] = spec
return self.elements[short_name]

def getApplicationPrimitiveDataTypes(self) -> List[ApplicationPrimitiveDataType]:
return list(filter(lambda a: isinstance(a, ApplicationPrimitiveDataType), self.elements.values()))
Expand All @@ -174,6 +202,9 @@ def getAtomicSwComponentTypes(self) -> List[AtomicSwComponentType]:

def getCompositionSwComponentTypes(self) -> List[CompositionSwComponentType]:
return list(filter(lambda a : isinstance(a, CompositionSwComponentType), self.elements.values()))

def getComplexDeviceDriverSwComponentTypes(self) -> List[ComplexDeviceDriverSwComponentType]:
return list(sorted(filter(lambda a : isinstance(a, ComplexDeviceDriverSwComponentType), self.elements.values()), key = lambda a: a.short_name))

def getSenderReceiverInterfaces(self) -> List[SenderReceiverInterface]:
return list(filter(lambda a : isinstance(a, SenderReceiverInterface), self.elements.values()))
Expand Down Expand Up @@ -228,26 +259,35 @@ def __init__(self):
raise Exception("The AUTOSAR is singleton!")
CollectableElement.__init__(self)

self.version = "4.3.0"
self.schema_location = ""
self._appl_impl_type_maps = {}
self._impl_appl_type_maps = {}
AUTOSAR.__instance = self

self._ar_packages = {} # type: Dict[str, ARPackage]

@property
def full_name(self):
return ""

def clear(self):
self._ar_packages = {}
self.elements = {}

def getElement(self, short_name: str) -> Referrable:
if (short_name in self._ar_packages):
return self._ar_packages[short_name]
return CollectableElement.getElement(self, short_name)

def getARPackages(self) -> List[ARPackage]:
return list(filter(lambda e: isinstance(e, ARPackage), self.elements.values()))
#return list(filter(lambda e: isinstance(e, ARPackage), self.elements.values()))
return list(sorted(self._ar_packages.values(), key= lambda a: a.short_name))

def createARPackage(self, short_name: str) -> ARPackage:
if (short_name not in self.elements):
if (short_name not in self._ar_packages):
ar_package = ARPackage(self, short_name)
self.elements[short_name] = ar_package
return self.elements[short_name]
self._ar_packages[short_name] = ar_package
return self._ar_packages[short_name]

def find(self, referred_name: str) -> Referrable:
short_name_list = referred_name.split("/")
Expand Down
23 changes: 17 additions & 6 deletions src/armodel/models/ar_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,27 @@ def __init__(self):
class AutosarVariableRef(ARObject):
def __init__(self):
super().__init__()
self.autosar_variable_iref = None
self.autosar_variable_in_impl_datatype = None # type: ArVariableInImplementationDataInstanceRef
self.autosar_variable_iref = None # type: VariableInAtomicSWCTypeInstanceRef
self.autosar_variable_in_impl_datatype = None # type: ArVariableInImplementationDataInstanceRef
self.local_variable_ref = None

class AtpInstanceRef(ARObject, metaclass=ABCMeta):
def __init__(self):
if type(self) == AtpInstanceRef:
raise NotImplementedError("AtpInstanceRef is an abstract class.")

super().__init__()

class VariableInAtomicSWCTypeInstanceRef(AtpInstanceRef):
def __init__(self):
super().__init__()

self.base_ref = None # type: RefType
self.context_data_prototype_ref = None # type: RefType
self.port_prototype_ref = None # type: RefType
self.root_variable_data_prototype_ref = None # type: RefType
self.target_data_prototype_ref = None # type: RefType

class PortInCompositionTypeInstanceRef(AtpInstanceRef, metaclass=ABCMeta):
def __init__(self):
if type(self) == PortInCompositionTypeInstanceRef:
Expand Down Expand Up @@ -95,7 +106,7 @@ class RModeInAtomicSwcInstanceRef(AtpInstanceRef):
def __init__(self):
super().__init__()

self.base_ref = None # type: RefType
self.context_mode_declaration_group_prototype = None # type: RefType
self.context_port = None # type: RefType
self.target_mode_declaration = None # type: RefType
self.base_ref = None # type: RefType
self.context_mode_declaration_group_prototype_ref = None # type: RefType
self.context_port_ref = None # type: RefType
self.target_mode_declaration_ref = None # type: RefType
Loading

0 comments on commit fca8eff

Please sign in to comment.