-
Notifications
You must be signed in to change notification settings - Fork 168
/
generate_xml_without_config.py
95 lines (79 loc) · 3.2 KB
/
generate_xml_without_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""
Generate ARXML from template classes without using config file.
Instead we programatically create namespaces and documents
"""
import os
from demo_system import platform, component
import autosar.xml.element as ar_element
import autosar.xml.workspace as ar_workspace
def create_namespaces(workspace: ar_workspace.Workspace):
"""
Define namespaces
"""
workspace.create_namespace("AUTOSAR_Platform", package_map={
"BaseType": "BaseTypes",
"ImplementationDataType": "ImplementationDataTypes",
"CompuMethod": "CompuMethods",
"DataConstraint": "DataConstrs"
})
workspace.create_namespace("Default", package_map={
"BaseType": "/DataTypes/BaseTypes",
"ImplementationDataType": "/DataTypes/ImplementationDataTypes",
"CompuMethod": "/DataTypes/CompuMethods",
"DataConstraint": "/DataTypes/DataConstrs",
"ModeDeclaration": "/ModeDclrGroups",
"PortInterface": "/PortInterfaces",
"Constant": "/Constants",
"ComponentType": "/ComponentTypes"},
base_ref="/")
def create_behavior_settings(workspace: ar_workspace.Workspace):
"""
Define default event name prefixess
"""
workspace.behavior_settings.update({
"background_event_prefix": "BT_",
"data_receive_error_event_prefix": "DRET_",
"data_receive_event_prefix": "DRT_",
"init_event_prefix": "IT_",
"operation_invoked_event_prefix": "OIT_",
"swc_mode_manager_error_event_prefix": "MMET_",
"swc_mode_switch_event_prefix": "MST_",
"timing_event_prefix": "TMT_"})
def create_documents(workspace: ar_workspace.Workspace) -> None:
"""
Creates documents
"""
workspace.create_document("AUTOSAR_Platform.arxml", packages="/AUTOSAR_Platform")
workspace.create_document("DataTypes.arxml", packages="/DataTypes")
workspace.create_document("Constants.arxml", packages="/Constants")
workspace.create_document("PortInterfaces.arxml", packages=["/ModeDclrGroups", "/PortInterfaces"])
workspace.create_document_mapping(package_ref="/ComponentTypes",
element_types=ar_element.SwComponentType,
suffix_filters=["_Implementation"])
def apply_platform_types(workspace: ar_workspace.Workspace):
"""
Applies platform templates
"""
workspace.apply(platform.ImplementationTypes.boolean)
workspace.apply(platform.ImplementationTypes.uint8)
workspace.apply(platform.ImplementationTypes.uint16)
workspace.apply(platform.ImplementationTypes.uint32)
workspace.apply(platform.ImplementationTypes.uint64)
def apply_component_types(workspace: ar_workspace.Workspace):
"""
Applies component type templates
"""
workspace.apply(component.CompositionComponent)
def main():
"""Main"""
document_root = os.path.join(os.path.dirname(__file__), "generated")
workspace = ar_workspace.Workspace(document_root=document_root)
create_namespaces(workspace)
create_behavior_settings(workspace)
create_documents(workspace)
apply_platform_types(workspace)
apply_component_types(workspace)
workspace.write_documents()
print("Done")
if __name__ == "__main__":
main()