armodel 1.2.0__py3-none-any.whl → 1.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- armodel/cli/arxml_dump_cli.py +8 -8
- armodel/cli/connector2xlsx_cli.py +75 -0
- armodel/cli/connector_update_cli.py +70 -0
- armodel/cli/swc_list_cli.py +81 -0
- armodel/lib/__init__.py +3 -0
- armodel/lib/cli_args_parser.py +36 -0
- armodel/lib/data_analyzer.py +34 -0
- armodel/lib/sw_component.py +34 -0
- armodel/models/__init__.py +6 -1
- armodel/models/ar_object.py +40 -1
- armodel/models/ar_package.py +35 -1
- armodel/models/ar_ref.py +12 -2
- armodel/models/bsw_module_template.py +3 -2
- armodel/models/calibration.py +16 -0
- armodel/models/common_structure.py +92 -0
- armodel/models/communication.py +8 -0
- armodel/models/datatype.py +23 -5
- armodel/models/general_structure.py +48 -3
- armodel/models/global_constraints.py +40 -0
- armodel/models/m2_msr.py +76 -2
- armodel/models/port_prototype.py +21 -16
- armodel/models/sw_component.py +49 -18
- armodel/models/unit.py +14 -0
- armodel/parser/arxml_parser.py +595 -151
- armodel/parser/excel_parser.py +0 -0
- armodel/report/__init__.py +1 -0
- armodel/report/connector_xls_report.py +76 -0
- armodel/report/excel_report.py +42 -0
- armodel/tests/__init__.py +0 -0
- armodel/tests/test_armodel/__init__.py +0 -0
- armodel/tests/test_armodel/models/__init__.py +0 -0
- armodel/tests/test_armodel/models/test_ar_package.py +294 -0
- armodel/tests/test_armodel/models/test_ar_ref.py +74 -0
- armodel/tests/test_armodel/models/test_bsw_module_template.py +46 -0
- armodel/tests/test_armodel/models/test_common_structure.py +73 -0
- armodel/tests/test_armodel/models/test_data_dictionary.py +29 -0
- armodel/tests/test_armodel/models/test_data_prototype.py +86 -0
- armodel/tests/test_armodel/models/test_datatype.py +239 -0
- armodel/tests/test_armodel/models/test_general_structure.py +50 -0
- armodel/tests/test_armodel/models/test_m2_msr.py +77 -0
- armodel/tests/test_armodel/models/test_port_interface.py +198 -0
- armodel/tests/test_armodel/models/test_port_prototype.py +14 -0
- armodel/tests/test_armodel/parser/__init__.py +0 -0
- armodel/tests/test_armodel/parser/test_parse_bswmd.py +168 -0
- armodel/writer/__init__.py +1 -0
- armodel/writer/arxml_writer.py +641 -0
- {armodel-1.2.0.dist-info → armodel-1.4.0.dist-info}/METADATA +69 -5
- armodel-1.4.0.dist-info/RECORD +60 -0
- {armodel-1.2.0.dist-info → armodel-1.4.0.dist-info}/WHEEL +1 -1
- armodel-1.4.0.dist-info/entry_points.txt +5 -0
- armodel-1.2.0.dist-info/RECORD +0 -27
- armodel-1.2.0.dist-info/entry_points.txt +0 -3
- {armodel-1.2.0.dist-info → armodel-1.4.0.dist-info}/LICENSE +0 -0
- {armodel-1.2.0.dist-info → armodel-1.4.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import xml.etree.cElementTree as ET
|
|
3
|
+
|
|
4
|
+
from xml.dom import minidom
|
|
5
|
+
from typing import List
|
|
6
|
+
|
|
7
|
+
from ..models.ar_object import ARLiteral
|
|
8
|
+
from ..models import AUTOSAR, ARPackage, ARObject, Identifiable, MultilanguageReferrable, Referrable, AdminData, Sdg, ARElement, SwDataDefProps, MultilanguageLongName
|
|
9
|
+
from ..models import CompositionSwComponentType, SwComponentType, SwComponentPrototype
|
|
10
|
+
from ..models import PortPrototype, PPortPrototype, RPortPrototype
|
|
11
|
+
from ..models import NonqueuedReceiverComSpec, NonqueuedSenderComSpec, ClientComSpec
|
|
12
|
+
from ..models import TRefType
|
|
13
|
+
from ..models import PPortComSpec, RPortComSpec, SenderComSpec, ReceiverComSpec
|
|
14
|
+
from ..models import TransmissionAcknowledgementRequest
|
|
15
|
+
from ..models import ValueSpecification, ApplicationValueSpecification, TextValueSpecification, NumericalValueSpecification, ArrayValueSpecification
|
|
16
|
+
from ..models import ConstantSpecification, RecordValueSpecification, ConstantReference
|
|
17
|
+
from ..models import SwValueCont, SwValues
|
|
18
|
+
from ..models import SwConnector, AssemblySwConnector, DelegationSwConnector, PPortInCompositionInstanceRef, RPortInCompositionInstanceRef
|
|
19
|
+
from ..models import ARBoolean
|
|
20
|
+
from ..models import ApplicationPrimitiveDataType, AutosarDataType, ApplicationDataType, ApplicationRecordDataType, BaseType
|
|
21
|
+
from ..models import CompuMethod, CompuScales, CompuScale, Limit, CompuScaleConstantContents, CompuConstTextContent, CompuScaleRationalFormula, CompuNominatorDenominator
|
|
22
|
+
|
|
23
|
+
from ..models.global_constraints import DataConstr, DataConstrRule, InternalConstrs, PhysConstrs
|
|
24
|
+
|
|
25
|
+
from colorama import Fore
|
|
26
|
+
|
|
27
|
+
class ARXMLWriter:
|
|
28
|
+
def __init__(self, options = None) -> None:
|
|
29
|
+
self.options = {}
|
|
30
|
+
self.options['warning'] = False
|
|
31
|
+
self.options['version'] = "4.2.2"
|
|
32
|
+
self.logger = logging.getLogger()
|
|
33
|
+
|
|
34
|
+
self._processOptions(options=options)
|
|
35
|
+
|
|
36
|
+
self.nsmap = {
|
|
37
|
+
"xmlns": "http://autosar.org/schema/r4.0",
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
def _processOptions(self, options):
|
|
41
|
+
if options:
|
|
42
|
+
if 'warning' in options:
|
|
43
|
+
self.options['warning'] = options['warning']
|
|
44
|
+
|
|
45
|
+
def _raiseError(self, error_msg):
|
|
46
|
+
if (self.options['warning'] == True):
|
|
47
|
+
self.logger.error(Fore.RED + error_msg + Fore.WHITE)
|
|
48
|
+
else:
|
|
49
|
+
raise ValueError(error_msg)
|
|
50
|
+
|
|
51
|
+
def writeElementAttributes(self, element: ET.Element, ar_obj: ARObject):
|
|
52
|
+
if ar_obj.timestamp is not None:
|
|
53
|
+
self.logger.debug("Timestamp: %s" % ar_obj.timestamp)
|
|
54
|
+
element.attrib['T'] = ar_obj.timestamp
|
|
55
|
+
if ar_obj.uuid is not None:
|
|
56
|
+
self.logger.debug("UUID: %s" % ar_obj.uuid)
|
|
57
|
+
element.attrib['UUID'] = ar_obj.uuid
|
|
58
|
+
|
|
59
|
+
def writeChildOptionalElement(self, element: ET.Element, key: str, value: str):
|
|
60
|
+
if value is not None:
|
|
61
|
+
child_element = ET.SubElement(element, key)
|
|
62
|
+
child_element.text = value
|
|
63
|
+
|
|
64
|
+
def writeChildOptionalRefElement(self, parent: ET.Element, child_tag_name: str, ref: TRefType):
|
|
65
|
+
if ref is not None:
|
|
66
|
+
child_tag = ET.SubElement(parent, child_tag_name)
|
|
67
|
+
if ref.dest is not None:
|
|
68
|
+
child_tag.attrib['DEST'] = ref.dest
|
|
69
|
+
if ref.value is not None:
|
|
70
|
+
child_tag.text = ref.value
|
|
71
|
+
|
|
72
|
+
def writeChildOptionalElementFloatValue(self, element: ET.Element, key: str, value: float):
|
|
73
|
+
if value is not None:
|
|
74
|
+
child_element = ET.SubElement(element, key)
|
|
75
|
+
literal = "%g" % value
|
|
76
|
+
if literal == '0':
|
|
77
|
+
literal = "0.0"
|
|
78
|
+
child_element.text = literal
|
|
79
|
+
|
|
80
|
+
def writeChildOptionalElementBooleanValue(self, element: ET.Element, key: str, value: ARBoolean) -> ET.Element:
|
|
81
|
+
child_element = None
|
|
82
|
+
if value is not None:
|
|
83
|
+
child_element = ET.SubElement(element, key)
|
|
84
|
+
self.writeElementAttributes(child_element, value)
|
|
85
|
+
if value.value:
|
|
86
|
+
child_element.text = "true"
|
|
87
|
+
else:
|
|
88
|
+
child_element.text = "false"
|
|
89
|
+
return child_element
|
|
90
|
+
|
|
91
|
+
def writeChildOptionalElementLiteral(self, element: ET.Element, key: str, value: ARLiteral) -> ET.Element:
|
|
92
|
+
child_element = None
|
|
93
|
+
if value is not None:
|
|
94
|
+
child_element = ET.SubElement(element, key)
|
|
95
|
+
self.writeElementAttributes(child_element, value)
|
|
96
|
+
child_element.text = value.value
|
|
97
|
+
return child_element
|
|
98
|
+
|
|
99
|
+
def writeShortName(self, parent: ET.Element, name: str) -> ET.Element:
|
|
100
|
+
sub_element = ET.SubElement(parent, "SHORT-NAME")
|
|
101
|
+
sub_element.text = name
|
|
102
|
+
|
|
103
|
+
return sub_element
|
|
104
|
+
|
|
105
|
+
def writeSd(self, parent: ET.Element, sdg: Sdg):
|
|
106
|
+
for sd in sdg.getSds():
|
|
107
|
+
sd_tag = ET.SubElement(parent, "SD")
|
|
108
|
+
sd_tag.attrib['GID'] = sd.gid
|
|
109
|
+
sd_tag.text = sd.value
|
|
110
|
+
|
|
111
|
+
def writeSdg(self, parent: ET.Element, admin_data: AdminData):
|
|
112
|
+
sdgs = admin_data.getSdgs()
|
|
113
|
+
if len(sdgs) > 0:
|
|
114
|
+
sdgs_tag = ET.SubElement(parent, "SDGS")
|
|
115
|
+
for sdg in sdgs:
|
|
116
|
+
sdg_tag = ET.SubElement(sdgs_tag, "SDG")
|
|
117
|
+
sdg_tag.attrib['GID'] = sdg.gid
|
|
118
|
+
self.writeSd(sdg_tag, sdg)
|
|
119
|
+
|
|
120
|
+
def writeChildLimitElement(self, element: ET.Element, key: str, limit: Limit):
|
|
121
|
+
if limit is not None:
|
|
122
|
+
limit_tag = ET.SubElement(element, key)
|
|
123
|
+
limit_tag.attrib['INTERVAL-TYPE'] = limit.interval_type
|
|
124
|
+
limit_tag.text = limit.value
|
|
125
|
+
|
|
126
|
+
def writeReferable(self, element: ET.Element, referrable: Referrable):
|
|
127
|
+
self.writeElementAttributes(element, referrable)
|
|
128
|
+
self.writeShortName(element, referrable.short_name)
|
|
129
|
+
|
|
130
|
+
def writeMultiLongName(self, element: ET.Element, long_name: MultilanguageLongName):
|
|
131
|
+
self.writeElementAttributes(element, long_name)
|
|
132
|
+
for l4 in long_name.get_l4s():
|
|
133
|
+
l4_tag = ET.SubElement(element, "L-4")
|
|
134
|
+
self.writeElementAttributes(l4_tag, l4)
|
|
135
|
+
if l4.l is not None:
|
|
136
|
+
l4_tag.attrib['L'] = l4.l
|
|
137
|
+
l4_tag.text = l4.value
|
|
138
|
+
|
|
139
|
+
def writeMultilanguageReferrable(self, element: ET.Element, referrable: MultilanguageReferrable):
|
|
140
|
+
self.writeReferable(element, referrable)
|
|
141
|
+
if referrable.long_name is not None:
|
|
142
|
+
long_name_tag = ET.SubElement(element, "LONG-NAME")
|
|
143
|
+
self.writeMultiLongName(long_name_tag, referrable.long_name)
|
|
144
|
+
|
|
145
|
+
def writeAdminData(self, element: ET.Element, admin_data: AdminData):
|
|
146
|
+
element = ET.SubElement(element, "ADMIN-DATA")
|
|
147
|
+
self.writeSdg(element, admin_data)
|
|
148
|
+
|
|
149
|
+
def writeIdentifiable(self, element: ET.Element, identifiable: Identifiable):
|
|
150
|
+
self.writeMultilanguageReferrable(element, identifiable)
|
|
151
|
+
self.writeChildOptionalElement(element, "CATEGORY", identifiable.category)
|
|
152
|
+
if identifiable.admin_data is not None:
|
|
153
|
+
self.writeAdminData(element, identifiable.admin_data)
|
|
154
|
+
|
|
155
|
+
def writeARElement(self, parent: ET.Element, ar_element: ARElement):
|
|
156
|
+
self.writeIdentifiable(parent, ar_element)
|
|
157
|
+
|
|
158
|
+
def writeTransmissionAcknowledgementRequest(self, element: ET.Element, acknowledge: TransmissionAcknowledgementRequest):
|
|
159
|
+
if (acknowledge != None):
|
|
160
|
+
child_element = ET.SubElement(element, "TRANSMISSION-ACKNOWLEDGE")
|
|
161
|
+
self.writeElementAttributes(child_element, acknowledge)
|
|
162
|
+
if acknowledge.timeout != None:
|
|
163
|
+
self.writeChildOptionalElementFloatValue(child_element, "TIMEOUT", acknowledge.timeout)
|
|
164
|
+
|
|
165
|
+
def writeSenderComSpec(self, com_spec_tag: ET.Element, com_spec: SenderComSpec):
|
|
166
|
+
self.writeChildOptionalRefElement(com_spec_tag, "DATA-ELEMENT-REF", com_spec.data_element_ref)
|
|
167
|
+
if com_spec.network_representation is not None:
|
|
168
|
+
network_representation_tag = ET.SubElement(com_spec_tag, "NETWORK-REPRESENTATION")
|
|
169
|
+
self.writeSwDataDefProps(network_representation_tag, com_spec.network_representation)
|
|
170
|
+
self.writeChildOptionalElement(com_spec_tag, "HANDLE-OUT-OF-RANGE", com_spec.handle_out_of_range)
|
|
171
|
+
self.writeTransmissionAcknowledgementRequest(com_spec_tag, com_spec.transmission_acknowledge)
|
|
172
|
+
self.writeChildOptionalElementBooleanValue(com_spec_tag, "USES-END-TO-END-PROTECTION", com_spec.uses_end_to_end_protection)
|
|
173
|
+
|
|
174
|
+
def writeNonqueuedSenderComSpec(self, com_specs_tag: ET.Element, com_spec: NonqueuedSenderComSpec):
|
|
175
|
+
com_spec_tag = ET.SubElement(com_specs_tag, "NONQUEUED-SENDER-COM-SPEC")
|
|
176
|
+
self.writeElementAttributes(com_spec_tag, com_spec)
|
|
177
|
+
self.writeSenderComSpec(com_spec_tag, com_spec)
|
|
178
|
+
|
|
179
|
+
if com_spec.init_value is not None:
|
|
180
|
+
init_value_tag = ET.SubElement(com_spec_tag, "INIT-VALUE")
|
|
181
|
+
if isinstance(com_spec.init_value, NumericalValueSpecification):
|
|
182
|
+
self.writeNumberValueSpecification(init_value_tag, com_spec.init_value)
|
|
183
|
+
elif isinstance(com_spec.init_value, ArrayValueSpecification):
|
|
184
|
+
self.writeArrayValueSpecification(init_value_tag, com_spec.init_value)
|
|
185
|
+
elif isinstance(com_spec.init_value, ConstantReference):
|
|
186
|
+
self.writeConstantReference(init_value_tag, com_spec.init_value)
|
|
187
|
+
else:
|
|
188
|
+
raise NotImplementedError("Unsupported ValueSpecification %s" % type(com_spec.init_value))
|
|
189
|
+
|
|
190
|
+
def writePPortComSpec(self, com_specs_tag: ET.Element, com_spec: PPortComSpec):
|
|
191
|
+
if isinstance(com_spec, NonqueuedSenderComSpec):
|
|
192
|
+
self.writeNonqueuedSenderComSpec(com_specs_tag, com_spec)
|
|
193
|
+
else:
|
|
194
|
+
raise NotImplementedError("Unsupported PPortComSpec")
|
|
195
|
+
|
|
196
|
+
def writeReceiverComSpec(self, com_spec_tag: ET.Element, com_spec: ReceiverComSpec):
|
|
197
|
+
self.writeChildOptionalRefElement(com_spec_tag, "DATA-ELEMENT-REF", com_spec.data_element_ref)
|
|
198
|
+
self.writeChildOptionalElement(com_spec_tag, "HANDLE-OUT-OF-RANGE", com_spec.handle_out_of_range)
|
|
199
|
+
self.writeChildOptionalElementBooleanValue(com_spec_tag, "USES-END-TO-END-PROTECTION", com_spec.uses_end_to_end_protection)
|
|
200
|
+
|
|
201
|
+
def writeSwValues(self, element: ET.Element, values: SwValues):
|
|
202
|
+
if values.v is not None:
|
|
203
|
+
self.writeChildOptionalElement(element, "V", values.v)
|
|
204
|
+
|
|
205
|
+
def writeSwValueCont(self, element: ET.Element, cont: SwValueCont):
|
|
206
|
+
child_element = ET.SubElement(element, "SW-VALUE-CONT")
|
|
207
|
+
self.writeChildOptionalRefElement(child_element, "UNIT-REF", cont.unit_ref)
|
|
208
|
+
if cont.sw_values_phys is not None:
|
|
209
|
+
sw_values_phys_tag = ET.SubElement(child_element, "SW-VALUES-PHYS")
|
|
210
|
+
self.writeSwValues(sw_values_phys_tag, cont.sw_values_phys)
|
|
211
|
+
|
|
212
|
+
def writeValueSpecification(self, element: ET.Element, value_spec: ValueSpecification):
|
|
213
|
+
self.writeElementAttributes(element, value_spec)
|
|
214
|
+
if value_spec.short_label is not None:
|
|
215
|
+
self.writeChildOptionalElement(element, "SHORT-LABEL", value_spec.short_label)
|
|
216
|
+
|
|
217
|
+
def writeApplicationValueSpecification(self, element: ET.Element, value_spec: ApplicationValueSpecification):
|
|
218
|
+
value_spec_tag = ET.SubElement(element, "APPLICATION-VALUE-SPECIFICATION")
|
|
219
|
+
self.writeValueSpecification(value_spec_tag, value_spec)
|
|
220
|
+
self.writeChildOptionalElement(value_spec_tag, "CATEGORY", value_spec.category)
|
|
221
|
+
self.writeSwValueCont(value_spec_tag, value_spec.sw_value_cont)
|
|
222
|
+
|
|
223
|
+
def writeTextValueSpecification(self, element: ET.Element, value_spec: TextValueSpecification):
|
|
224
|
+
value_spec_tag = ET.SubElement(element, "TEXT-VALUE-SPECIFICATION")
|
|
225
|
+
self.writeValueSpecification(value_spec_tag, value_spec)
|
|
226
|
+
self.writeChildOptionalElement(value_spec_tag, "VALUE", value_spec.value)
|
|
227
|
+
|
|
228
|
+
def writeNumberValueSpecification(self, element: ET.Element, value_spec: NumericalValueSpecification):
|
|
229
|
+
value_spec_tag = ET.SubElement(element, "NUMERICAL-VALUE-SPECIFICATION")
|
|
230
|
+
self.writeValueSpecification(value_spec_tag, value_spec)
|
|
231
|
+
self.writeChildOptionalElement(value_spec_tag, "VALUE", value_spec.value)
|
|
232
|
+
|
|
233
|
+
def writeArrayValueSpecification(self, element: ET.Element, value_spec: ArrayValueSpecification):
|
|
234
|
+
value_spec_tag = ET.SubElement(element, "ARRAY-VALUE-SPECIFICATION")
|
|
235
|
+
self.writeValueSpecification(value_spec_tag, value_spec)
|
|
236
|
+
sub_elements = value_spec.get_elements()
|
|
237
|
+
if len(sub_elements) > 0:
|
|
238
|
+
elements_tag = ET.SubElement(value_spec_tag, "ELEMENTS")
|
|
239
|
+
for sub_element in sub_elements:
|
|
240
|
+
if isinstance(sub_element, NumericalValueSpecification):
|
|
241
|
+
self.writeNumberValueSpecification(elements_tag, sub_element)
|
|
242
|
+
else:
|
|
243
|
+
raise NotImplementedError("Unsupported element type of <%s> of ArrayValueSpecification" % type(sub_element))
|
|
244
|
+
|
|
245
|
+
def writeConstantReference(self, element: ET.Element, value_spec: ConstantReference):
|
|
246
|
+
value_spec_tag = ET.SubElement(element, "CONSTANT-REFERENCE")
|
|
247
|
+
self.writeValueSpecification(value_spec_tag, value_spec)
|
|
248
|
+
self.writeChildOptionalRefElement(value_spec_tag, "CONSTANT-REF", value_spec.constant_ref)
|
|
249
|
+
|
|
250
|
+
def writeNonqueuedReceiverComSpec(self, com_specs_tag: ET.Element, com_spec: NonqueuedReceiverComSpec):
|
|
251
|
+
com_spec_tag = ET.SubElement(com_specs_tag, "NONQUEUED-RECEIVER-COM-SPEC")
|
|
252
|
+
self.writeElementAttributes(com_spec_tag, com_spec)
|
|
253
|
+
self.writeReceiverComSpec(com_spec_tag, com_spec)
|
|
254
|
+
self.writeChildOptionalElementFloatValue(com_spec_tag, "ALIVE-TIMEOUT", com_spec.alive_timeout)
|
|
255
|
+
self.writeChildOptionalElementBooleanValue(com_spec_tag, "ENABLE-UPDATE", com_spec.enable_updated)
|
|
256
|
+
self.writeChildOptionalElementBooleanValue(com_spec_tag, "HANDLE-NEVER-RECEIVED", com_spec.handle_never_received)
|
|
257
|
+
self.writeChildOptionalElement(com_spec_tag, "HANDLE-TIMEOUT-TYPE", com_spec.handel_timeout_type)
|
|
258
|
+
if com_spec.init_value is not None:
|
|
259
|
+
init_value_tag = ET.SubElement(com_spec_tag, "INIT-VALUE")
|
|
260
|
+
if isinstance(com_spec.init_value, ApplicationValueSpecification):
|
|
261
|
+
self.writeApplicationValueSpecification(init_value_tag, com_spec.init_value)
|
|
262
|
+
elif isinstance(com_spec.init_value, TextValueSpecification):
|
|
263
|
+
self.writeTextValueSpecification(init_value_tag, com_spec.init_value)
|
|
264
|
+
elif isinstance(com_spec.init_value, ConstantReference):
|
|
265
|
+
self.writeConstantReference(init_value_tag, com_spec.init_value)
|
|
266
|
+
else:
|
|
267
|
+
raise NotImplementedError("Unsupported ValueSpecification %s" % type(com_spec.init_value))
|
|
268
|
+
|
|
269
|
+
def writeClientComSpec(self, com_specs_tag: ET.Element, com_spec: ClientComSpec):
|
|
270
|
+
self.logger.debug("writeClientComSpec")
|
|
271
|
+
|
|
272
|
+
com_spec_tag = ET.SubElement(com_specs_tag, "CLIENT-COM-SPEC")
|
|
273
|
+
self.writeElementAttributes(com_spec_tag, com_spec)
|
|
274
|
+
self.writeChildOptionalRefElement(com_spec_tag, "OPERATION-REF", com_spec.operation_ref)
|
|
275
|
+
|
|
276
|
+
def writeRPortComSpec(self, com_specs_tag: ET.Element, com_spec: RPortComSpec):
|
|
277
|
+
if isinstance(com_spec, NonqueuedReceiverComSpec):
|
|
278
|
+
self.writeNonqueuedReceiverComSpec(com_specs_tag, com_spec)
|
|
279
|
+
elif isinstance(com_spec, ClientComSpec):
|
|
280
|
+
self.writeClientComSpec(com_specs_tag, com_spec)
|
|
281
|
+
else:
|
|
282
|
+
raise ValueError("Unsupported RPortComSpec %s" % type(com_spec))
|
|
283
|
+
|
|
284
|
+
def writePPortPrototype(self, ports_tag: ET.Element, prototype: PPortPrototype):
|
|
285
|
+
prototype_tag = ET.SubElement(ports_tag, "P-PORT-PROTOTYPE")
|
|
286
|
+
|
|
287
|
+
self.writeElementAttributes(prototype_tag, prototype)
|
|
288
|
+
self.writeShortName(prototype_tag, prototype.short_name)
|
|
289
|
+
|
|
290
|
+
self.logger.debug("writePPortPrototype %s" % prototype.short_name)
|
|
291
|
+
|
|
292
|
+
com_specs = prototype.getProvidedComSpecs()
|
|
293
|
+
if len(com_specs):
|
|
294
|
+
com_specs_tag = ET.SubElement(prototype_tag, "PROVIDED-COM-SPECS")
|
|
295
|
+
for com_spec in com_specs:
|
|
296
|
+
self.writePPortComSpec(com_specs_tag, com_spec)
|
|
297
|
+
|
|
298
|
+
self.writeChildOptionalRefElement(prototype_tag, "PROVIDED-INTERFACE-TREF", prototype.provided_interface_tref)
|
|
299
|
+
|
|
300
|
+
def writeRPortPrototype(self, ports_tag: ET.Element, prototype: RPortPrototype):
|
|
301
|
+
prototype_tag = ET.SubElement(ports_tag, "R-PORT-PROTOTYPE")
|
|
302
|
+
|
|
303
|
+
self.writeElementAttributes(prototype_tag, prototype)
|
|
304
|
+
self.writeShortName(prototype_tag, prototype.short_name)
|
|
305
|
+
|
|
306
|
+
self.logger.debug("writeRPortPrototype %s" % prototype.short_name)
|
|
307
|
+
|
|
308
|
+
com_specs = prototype.getRequiredComSpecs()
|
|
309
|
+
if len(com_specs) > 0:
|
|
310
|
+
com_specs_tag = ET.SubElement(prototype_tag, "REQUIRED-COM-SPECS")
|
|
311
|
+
for com_spec in com_specs:
|
|
312
|
+
self.writeRPortComSpec(com_specs_tag, com_spec)
|
|
313
|
+
|
|
314
|
+
self.writeChildOptionalRefElement(prototype_tag, "REQUIRED-INTERFACE-TREF", prototype.required_interface_tref)
|
|
315
|
+
|
|
316
|
+
def writePortPrototypes(self, ports_tag: ET.Element, port_prototypes: List[PortPrototype]):
|
|
317
|
+
for port_prototype in port_prototypes:
|
|
318
|
+
if isinstance(port_prototype, PPortPrototype):
|
|
319
|
+
self.writePPortPrototype(ports_tag, port_prototype)
|
|
320
|
+
elif isinstance(port_prototype, RPortPrototype):
|
|
321
|
+
self.writeRPortPrototype(ports_tag, port_prototype)
|
|
322
|
+
else:
|
|
323
|
+
self._raiseError("Invalid PortPrototype")
|
|
324
|
+
|
|
325
|
+
def writeSwComponentType(self, element: ET.Element, sw_component: SwComponentType):
|
|
326
|
+
ports_tag = ET.SubElement(element, "PORTS")
|
|
327
|
+
self.writePortPrototypes(ports_tag, sw_component.getPortPrototype())
|
|
328
|
+
|
|
329
|
+
def writeSwComponentPrototype(self, element: ET.Element, prototype: SwComponentPrototype):
|
|
330
|
+
prototype_tag = ET.SubElement(element, "SW-COMPONENT-PROTOTYPE")
|
|
331
|
+
self.writeElementAttributes(prototype_tag, prototype)
|
|
332
|
+
self.writeShortName(prototype_tag, prototype.short_name)
|
|
333
|
+
self.writeChildOptionalRefElement(prototype_tag, "TYPE-TREF", prototype.type_tref)
|
|
334
|
+
|
|
335
|
+
def writeSwComponentPrototypes(self, element: ET.Element, sw_component: CompositionSwComponentType):
|
|
336
|
+
components_tag = ET.SubElement(element, "COMPONENTS")
|
|
337
|
+
for prototype in sw_component.getSwComponentPrototypes():
|
|
338
|
+
self.writeSwComponentPrototype(components_tag, prototype)
|
|
339
|
+
|
|
340
|
+
def writeAssemblySwConnector(self, element: ET.Element, sw_connector: AssemblySwConnector):
|
|
341
|
+
connector_tag = ET.SubElement(element, "ASSEMBLY-SW-CONNECTOR")
|
|
342
|
+
self.writeElementAttributes(connector_tag, sw_connector)
|
|
343
|
+
self.writeShortName(connector_tag, sw_connector.short_name)
|
|
344
|
+
|
|
345
|
+
if sw_connector.provider_iref is not None:
|
|
346
|
+
provider_iref_tag = ET.SubElement(connector_tag, "PROVIDER-IREF")
|
|
347
|
+
self.writeElementAttributes(provider_iref_tag, sw_connector.provider_iref)
|
|
348
|
+
self.writeChildOptionalRefElement(provider_iref_tag, "CONTEXT-COMPONENT-REF", sw_connector.provider_iref.context_component_ref)
|
|
349
|
+
self.writeChildOptionalRefElement(provider_iref_tag, "TARGET-P-PORT-REF", sw_connector.provider_iref.target_p_port_ref)
|
|
350
|
+
|
|
351
|
+
if sw_connector.requester_iref is not None:
|
|
352
|
+
requester_iref_tag = ET.SubElement(connector_tag, "REQUESTER-IREF")
|
|
353
|
+
self.writeElementAttributes(requester_iref_tag, sw_connector.requester_iref)
|
|
354
|
+
self.writeChildOptionalRefElement(requester_iref_tag, "CONTEXT-COMPONENT-REF", sw_connector.requester_iref.context_component_ref)
|
|
355
|
+
self.writeChildOptionalRefElement(requester_iref_tag, "TARGET-R-PORT-REF", sw_connector.requester_iref.target_r_port_ref)
|
|
356
|
+
|
|
357
|
+
def writeDelegationSwConnector(self, element: ET.Element, sw_connector: DelegationSwConnector):
|
|
358
|
+
connector_tag = ET.SubElement(element, "DELEGATION-SW-CONNECTOR")
|
|
359
|
+
self.writeElementAttributes(connector_tag, sw_connector)
|
|
360
|
+
self.writeShortName(connector_tag, sw_connector.short_name)
|
|
361
|
+
|
|
362
|
+
if sw_connector.inner_port_iref is not None:
|
|
363
|
+
inner_port_iref_tag = ET.SubElement(connector_tag, "INNER-PORT-IREF")
|
|
364
|
+
if isinstance(sw_connector.inner_port_iref, PPortInCompositionInstanceRef):
|
|
365
|
+
instance_ref_tag = ET.SubElement(inner_port_iref_tag, "P-PORT-IN-COMPOSITION-INSTANCE-REF")
|
|
366
|
+
self.writeChildOptionalRefElement(instance_ref_tag, "CONTEXT-COMPONENT-REF", sw_connector.inner_port_iref.context_component_ref)
|
|
367
|
+
self.writeChildOptionalRefElement(instance_ref_tag, "TARGET-P-PORT-REF", sw_connector.inner_port_iref.target_p_port_ref)
|
|
368
|
+
elif isinstance(sw_connector.inner_port_iref, RPortInCompositionInstanceRef):
|
|
369
|
+
instance_ref_tag = ET.SubElement(inner_port_iref_tag, "R-PORT-IN-COMPOSITION-INSTANCE-REF")
|
|
370
|
+
self.writeChildOptionalRefElement(instance_ref_tag, "CONTEXT-COMPONENT-REF", sw_connector.inner_port_iref.context_component_ref)
|
|
371
|
+
self.writeChildOptionalRefElement(instance_ref_tag, "TARGET-R-PORT-REF", sw_connector.inner_port_iref.target_r_port_ref)
|
|
372
|
+
else:
|
|
373
|
+
self._raiseError("Invalid inner port of DelegationSwConnector <%s>" % sw_connector.short_name)
|
|
374
|
+
|
|
375
|
+
if sw_connector.outer_port_ref is not None:
|
|
376
|
+
self.writeChildOptionalRefElement(connector_tag, "OUTER-PORT-REF", sw_connector.outer_port_ref)
|
|
377
|
+
#self.writeChildOptionalRefElement(requester_iref_tag, "TARGET-R-PORT-REF", sw_connector.requester_iref.target_r_port_ref)
|
|
378
|
+
|
|
379
|
+
def writeSwConnector(self, element: ET.Element, sw_connector: SwConnector):
|
|
380
|
+
if isinstance(sw_connector, AssemblySwConnector):
|
|
381
|
+
self.writeAssemblySwConnector(element, sw_connector)
|
|
382
|
+
elif isinstance(sw_connector, DelegationSwConnector):
|
|
383
|
+
self.writeDelegationSwConnector(element, sw_connector)
|
|
384
|
+
else:
|
|
385
|
+
raise NotImplementedError("Unsupported Sw Connector %s")
|
|
386
|
+
|
|
387
|
+
def writeSwConnectors(self, element: ET.Element, sw_component: CompositionSwComponentType):
|
|
388
|
+
connectors_tag = ET.SubElement(element, "CONNECTORS")
|
|
389
|
+
for sw_connector in sw_component.getSwConnectors():
|
|
390
|
+
self.writeSwConnector(connectors_tag, sw_connector)
|
|
391
|
+
|
|
392
|
+
def writeDataTypeMappingSet(self, element: ET.Element, parent: CompositionSwComponentType):
|
|
393
|
+
data_type_mappings = parent.getDataTypeMappings()
|
|
394
|
+
if len(data_type_mappings) > 0:
|
|
395
|
+
child_element = ET.SubElement(element, "DATA-TYPE-MAPPING-REFS")
|
|
396
|
+
self.logger.debug("writeDataTypeMappingSet")
|
|
397
|
+
for data_type_mapping in data_type_mappings:
|
|
398
|
+
self.writeChildOptionalRefElement(child_element, "DATA-TYPE-MAPPING-REF", data_type_mapping)
|
|
399
|
+
|
|
400
|
+
def writeCompositionSwComponentType(self, parent: ET.Element, sw_component: CompositionSwComponentType):
|
|
401
|
+
child_element = ET.SubElement(parent, "COMPOSITION-SW-COMPONENT-TYPE")
|
|
402
|
+
|
|
403
|
+
self.writeIdentifiable(child_element, sw_component)
|
|
404
|
+
self.writeSwComponentType(child_element, sw_component)
|
|
405
|
+
self.writeSwComponentPrototypes(child_element, sw_component)
|
|
406
|
+
self.writeSwConnectors(child_element, sw_component)
|
|
407
|
+
self.writeDataTypeMappingSet(child_element, sw_component)
|
|
408
|
+
|
|
409
|
+
def writeCompositionSwComponentTypes(self, element: ET.Element, ar_package: ARPackage):
|
|
410
|
+
for sw_component in ar_package.getCompositionSwComponentTypes():
|
|
411
|
+
self.writeCompositionSwComponentType(element, sw_component)
|
|
412
|
+
|
|
413
|
+
def writeSwDataDefProps(self, element: ET.Element, sw_data_def_props: SwDataDefProps):
|
|
414
|
+
sw_data_def_props_tag = ET.SubElement(element, "SW-DATA-DEF-PROPS")
|
|
415
|
+
sw_data_def_props_variants_tag = ET.SubElement(sw_data_def_props_tag, "SW-DATA-DEF-PROPS-VARIANTS")
|
|
416
|
+
sw_data_def_props_conditional_tag = ET.SubElement(sw_data_def_props_variants_tag, "SW-DATA-DEF-PROPS-CONDITIONAL")
|
|
417
|
+
if sw_data_def_props.sw_calibration_access is not None:
|
|
418
|
+
self.writeChildOptionalElement(sw_data_def_props_conditional_tag, "SW-CALIBRATION-ACCESS", sw_data_def_props.sw_calibration_access)
|
|
419
|
+
if sw_data_def_props.compu_method_ref is not None:
|
|
420
|
+
self.writeChildOptionalRefElement(sw_data_def_props_conditional_tag, "COMPU-METHOD-REF", sw_data_def_props.compu_method_ref)
|
|
421
|
+
if sw_data_def_props.data_constr_ref is not None:
|
|
422
|
+
self.writeChildOptionalRefElement(sw_data_def_props_conditional_tag, "DATA-CONSTR-REF", sw_data_def_props.data_constr_ref)
|
|
423
|
+
|
|
424
|
+
def writeAutosarDataType(self, parent: ET.Element, data_type: AutosarDataType):
|
|
425
|
+
self.writeARElement(parent, data_type)
|
|
426
|
+
if data_type.sw_data_def_props is not None:
|
|
427
|
+
self.writeSwDataDefProps(parent, data_type.sw_data_def_props)
|
|
428
|
+
|
|
429
|
+
def writeApplicationDataType(self, parent: ET.Element, data_type: ApplicationDataType):
|
|
430
|
+
self.writeAutosarDataType(parent, data_type)
|
|
431
|
+
|
|
432
|
+
def writeApplicationPrimitiveDataType(self, element: ET.Element, data_type: ApplicationPrimitiveDataType):
|
|
433
|
+
data_type_tag = ET.SubElement(element, "APPLICATION-PRIMITIVE-DATA-TYPE")
|
|
434
|
+
self.writeApplicationDataType(data_type_tag, data_type)
|
|
435
|
+
|
|
436
|
+
def writeApplicationRecordElements(self, element: ET.Element, data_type: ApplicationRecordDataType):
|
|
437
|
+
record_elements = data_type.getApplicationRecordElements()
|
|
438
|
+
if len(record_elements) > 0:
|
|
439
|
+
elements_tag = ET.SubElement(element, "ELEMENTS")
|
|
440
|
+
for record_element in record_elements:
|
|
441
|
+
record_element_tag = ET.SubElement(elements_tag, "APPLICATION-RECORD-ELEMENT")
|
|
442
|
+
self.writeIdentifiable(record_element_tag, record_element)
|
|
443
|
+
self.writeChildOptionalRefElement(record_element_tag, "TYPE-TREF", record_element.type_tref)
|
|
444
|
+
|
|
445
|
+
def writeApplicationRecordDataType(self, element: ET.Element, data_type: ApplicationRecordDataType):
|
|
446
|
+
data_type_tag = ET.SubElement(element, "APPLICATION-RECORD-DATA-TYPE")
|
|
447
|
+
self.writeApplicationDataType(data_type_tag, data_type)
|
|
448
|
+
self.writeApplicationRecordElements(data_type_tag, data_type)
|
|
449
|
+
|
|
450
|
+
def writeApplicationDataTypes(self, parent: ET.Element, ar_package: ARPackage):
|
|
451
|
+
for data_type in ar_package.getApplicationDataType():
|
|
452
|
+
if isinstance(data_type, ApplicationPrimitiveDataType):
|
|
453
|
+
self.writeApplicationPrimitiveDataType(parent, data_type)
|
|
454
|
+
elif isinstance(data_type, ApplicationRecordDataType):
|
|
455
|
+
self.writeApplicationRecordDataType(parent, data_type)
|
|
456
|
+
else:
|
|
457
|
+
raise NotImplementedError("Unsupported ApplicationDataType <%s>" % type(data_type))
|
|
458
|
+
|
|
459
|
+
def writeBaseTypeDirectDefinition(self, element: ET.Element, base_type: BaseType):
|
|
460
|
+
self.writeChildOptionalElement(element, "BASE-TYPE-SIZE", str(base_type.base_type_definition.base_type_size))
|
|
461
|
+
self.writeChildOptionalElementLiteral(element, "BASE-TYPE-ENCODING", base_type.base_type_definition.base_type_encoding)
|
|
462
|
+
self.writeChildOptionalElementLiteral(element, "NATIVE-DECLARATION", base_type.base_type_definition.native_declaration)
|
|
463
|
+
|
|
464
|
+
def writeSwBaseTypes(self, element: ET.Element, ar_package: ARPackage):
|
|
465
|
+
for base_type in ar_package.getSwBaseTypes():
|
|
466
|
+
data_type_tag = ET.SubElement(element, "SW-BASE-TYPE")
|
|
467
|
+
self.writeIdentifiable(data_type_tag, base_type)
|
|
468
|
+
self.writeBaseTypeDirectDefinition(data_type_tag, base_type)
|
|
469
|
+
|
|
470
|
+
def writeCompuScaleConstantContents(self, element: ET.Element, contents: CompuScaleConstantContents):
|
|
471
|
+
compu_const_tag = ET.SubElement(element, "COMPU-CONST")
|
|
472
|
+
if isinstance(contents.compu_const.compu_const_content_type, CompuConstTextContent):
|
|
473
|
+
self.writeChildOptionalElement(compu_const_tag, "VT", contents.compu_const.compu_const_content_type.vt)
|
|
474
|
+
|
|
475
|
+
def writeCompuNominatorDenominator(self, element: ET.Element, key: str, parent: CompuNominatorDenominator):
|
|
476
|
+
child_element = ET.SubElement(element, key)
|
|
477
|
+
for v in parent.get_vs():
|
|
478
|
+
v_tag = ET.SubElement(child_element, "V")
|
|
479
|
+
v_tag.text = v
|
|
480
|
+
|
|
481
|
+
def writeCompuScaleRationalFormula(self, element: ET.Element, contents: CompuScaleRationalFormula):
|
|
482
|
+
if contents.compu_rational_coeffs is not None:
|
|
483
|
+
coeffs_tag = ET.SubElement(element, "COMPU-RATIONAL-COEFFS")
|
|
484
|
+
if contents.compu_rational_coeffs.compu_numerator:
|
|
485
|
+
self.writeCompuNominatorDenominator(coeffs_tag, "COMPU-NUMERATOR", contents.compu_rational_coeffs.compu_numerator)
|
|
486
|
+
if contents.compu_rational_coeffs.compu_denominator:
|
|
487
|
+
self.writeCompuNominatorDenominator(coeffs_tag, "COMPU-DENOMINATOR", contents.compu_rational_coeffs.compu_denominator)
|
|
488
|
+
|
|
489
|
+
def writeCompuScaleContents(self, element: ET.Element, compu_scale: CompuScale):
|
|
490
|
+
if isinstance(compu_scale.compu_scale_contents, CompuScaleConstantContents):
|
|
491
|
+
self.writeCompuScaleConstantContents(element, compu_scale.compu_scale_contents)
|
|
492
|
+
elif isinstance(compu_scale.compu_scale_contents, CompuScaleRationalFormula):
|
|
493
|
+
self.writeCompuScaleRationalFormula(element, compu_scale.compu_scale_contents)
|
|
494
|
+
else:
|
|
495
|
+
raise NotImplementedError("Unsupported CompuScaleContents %s" % type(compu_scale.compu_scale_contents))
|
|
496
|
+
|
|
497
|
+
def writeCompuScales(self, element: ET.Element, compu_scales: CompuScales):
|
|
498
|
+
compu_scales_tag = ET.SubElement(element, "COMPU-SCALES")
|
|
499
|
+
for compu_scale in compu_scales.getCompuScales():
|
|
500
|
+
compu_scale_tag = ET.SubElement(compu_scales_tag, "COMPU-SCALE")
|
|
501
|
+
self.writeChildLimitElement(compu_scale_tag, "LOWER-LIMIT", compu_scale.lower_limit)
|
|
502
|
+
self.writeChildLimitElement(compu_scale_tag, "UPPER-LIMIT", compu_scale.upper_limit)
|
|
503
|
+
self.writeCompuScaleContents(compu_scale_tag, compu_scale)
|
|
504
|
+
|
|
505
|
+
def writeCompuInternalToPhys(self, element: ET.Element, compu_method: CompuMethod):
|
|
506
|
+
if compu_method.compu_internal_to_phys is not None:
|
|
507
|
+
compu_internal_to_phys_tag = ET.SubElement(element, "COMPU-INTERNAL-TO-PHYS")
|
|
508
|
+
self.writeElementAttributes(compu_internal_to_phys_tag, compu_method.compu_internal_to_phys)
|
|
509
|
+
if isinstance(compu_method.compu_internal_to_phys.compu_content, CompuScales):
|
|
510
|
+
self.writeCompuScales(compu_internal_to_phys_tag, compu_method.compu_internal_to_phys.compu_content)
|
|
511
|
+
|
|
512
|
+
def writeCompuMethods(self, element: ET.Element, parent: ARPackage):
|
|
513
|
+
for compu_method in parent.getCompuMethods():
|
|
514
|
+
compu_method_tag = ET.SubElement(element, "COMPU-METHOD")
|
|
515
|
+
self.logger.debug("writeCompuMethods %s" % compu_method.short_name)
|
|
516
|
+
self.writeIdentifiable(compu_method_tag, compu_method)
|
|
517
|
+
self.writeChildOptionalRefElement(compu_method_tag, "UNIT-REF", compu_method.unit_ref)
|
|
518
|
+
self.writeCompuInternalToPhys(compu_method_tag, compu_method)
|
|
519
|
+
|
|
520
|
+
def writeApplicationValueSpecification(self, element: ET.Element, spec: ApplicationValueSpecification):
|
|
521
|
+
spec_tag = ET.SubElement(element, "APPLICATION-VALUE-SPECIFICATION")
|
|
522
|
+
self.writeChildOptionalElement(spec_tag, "SHORT-LABEL", spec.short_label)
|
|
523
|
+
self.writeChildOptionalElement(spec_tag, "CATEGORY", spec.category)
|
|
524
|
+
self.writeSwValueCont(spec_tag, spec.sw_value_cont)
|
|
525
|
+
|
|
526
|
+
def writeRecordValueSpecification(self, element: ET.Element, spec: RecordValueSpecification):
|
|
527
|
+
spec_tag = ET.SubElement(element, "RECORD-VALUE-SPECIFICATION")
|
|
528
|
+
fields = spec.get_fields()
|
|
529
|
+
if len(fields) > 0:
|
|
530
|
+
fields_tag = ET.SubElement(spec_tag, "FIELDS")
|
|
531
|
+
for field in fields:
|
|
532
|
+
if isinstance(field, ApplicationValueSpecification):
|
|
533
|
+
self.writeApplicationValueSpecification(fields_tag, field)
|
|
534
|
+
else:
|
|
535
|
+
raise NotImplementedError("Unsupported Field <%s>" % type(field))
|
|
536
|
+
|
|
537
|
+
def writeConstantSpecifications(self, element: ET.Element, parent: ARPackage):
|
|
538
|
+
for spec in parent.getConstantSpecifications():
|
|
539
|
+
spec_tag = ET.SubElement(element, "CONSTANT-SPECIFICATION")
|
|
540
|
+
self.writeIdentifiable(spec_tag, spec)
|
|
541
|
+
|
|
542
|
+
if spec.value_spec is not None:
|
|
543
|
+
value_spec_tag = ET.SubElement(spec_tag, "VALUE-SPEC")
|
|
544
|
+
if isinstance(spec.value_spec, ApplicationValueSpecification):
|
|
545
|
+
self.writeApplicationValueSpecification(value_spec_tag, spec.value_spec)
|
|
546
|
+
elif isinstance(spec.value_spec, RecordValueSpecification):
|
|
547
|
+
self.writeRecordValueSpecification(value_spec_tag, spec.value_spec)
|
|
548
|
+
else:
|
|
549
|
+
raise NotImplementedError("Unsupported ConstantSpecification %s" % type(spec.value_spec))
|
|
550
|
+
|
|
551
|
+
def writeInternalConstrs(self, element: ET.Element, parent: InternalConstrs):
|
|
552
|
+
constrs_tag = ET.SubElement(element, "INTERNAL-CONSTRS")
|
|
553
|
+
if parent.lower_limit is not None:
|
|
554
|
+
self.writeChildLimitElement(constrs_tag, "LOWER-LIMIT", parent.lower_limit)
|
|
555
|
+
if parent.upper_limit is not None:
|
|
556
|
+
self.writeChildLimitElement(constrs_tag, "UPPER-LIMIT", parent.upper_limit)
|
|
557
|
+
|
|
558
|
+
def writePhysConstrs(self, element: ET.Element, parent: PhysConstrs):
|
|
559
|
+
constrs_tag = ET.SubElement(element, "PHYS-CONSTRS")
|
|
560
|
+
if parent.lower_limit is not None:
|
|
561
|
+
self.writeChildLimitElement(constrs_tag, "LOWER-LIMIT", parent.lower_limit)
|
|
562
|
+
if parent.upper_limit is not None:
|
|
563
|
+
self.writeChildLimitElement(constrs_tag, "UPPER-LIMIT", parent.upper_limit)
|
|
564
|
+
self.writeChildOptionalRefElement(constrs_tag, "UNIT-REF", parent.unit_ref)
|
|
565
|
+
|
|
566
|
+
def writeDataConstrRules(self, element: ET.Element, parent: DataConstr):
|
|
567
|
+
rules = parent.getDataConstrRules()
|
|
568
|
+
if len(rules) > 0:
|
|
569
|
+
rules_tag = ET.SubElement(element, "DATA-CONSTR-RULES")
|
|
570
|
+
for rule in rules:
|
|
571
|
+
rule_tag = ET.SubElement(rules_tag, "DATA-CONSTR-RULE")
|
|
572
|
+
if rule.internal_constrs is not None:
|
|
573
|
+
self.writeInternalConstrs(rule_tag, rule.internal_constrs)
|
|
574
|
+
if rule.phys_constrs is not None:
|
|
575
|
+
self.writePhysConstrs(rule_tag, rule.phys_constrs)
|
|
576
|
+
|
|
577
|
+
def writeDataConstr(self, element: ET.Element, parent: ARPackage):
|
|
578
|
+
for constr in parent.getDataConstrs():
|
|
579
|
+
child_element = ET.SubElement(element, "DATA-CONSTR")
|
|
580
|
+
self.writeIdentifiable(child_element, constr)
|
|
581
|
+
self.writeDataConstrRules(child_element, constr)
|
|
582
|
+
|
|
583
|
+
def writeUnit(self, element: ET.Element, parent: ARPackage):
|
|
584
|
+
for unit in parent.getUnits():
|
|
585
|
+
self.logger.debug("writeUnit %s" % unit.short_name)
|
|
586
|
+
child_element = ET.SubElement(element, "UNIT")
|
|
587
|
+
self.writeIdentifiable(child_element, unit)
|
|
588
|
+
self.writeChildOptionalElementLiteral(child_element, "DISPLAY-NAME", unit.display_name)
|
|
589
|
+
|
|
590
|
+
def writeARPackages(self, element: ET.Element, pkgs: List[ARPackage]):
|
|
591
|
+
if len(pkgs) > 0:
|
|
592
|
+
pkgs_tag = ET.SubElement(element, "AR-PACKAGES")
|
|
593
|
+
|
|
594
|
+
for pkg in pkgs:
|
|
595
|
+
pkg_tag = ET.SubElement(pkgs_tag, "AR-PACKAGE")
|
|
596
|
+
|
|
597
|
+
self.writeElementAttributes(pkg_tag, pkg)
|
|
598
|
+
self.writeShortName(pkg_tag, pkg.short_name)
|
|
599
|
+
self.logger.debug("writeARPackage %s" % pkg.full_name)
|
|
600
|
+
|
|
601
|
+
if pkg.getTotalElement() > 0:
|
|
602
|
+
elements_tag = ET.SubElement(pkg_tag, "ELEMENTS")
|
|
603
|
+
|
|
604
|
+
self.writeApplicationDataTypes(elements_tag, pkg)
|
|
605
|
+
self.writeCompositionSwComponentTypes(elements_tag, pkg)
|
|
606
|
+
self.writeSwBaseTypes(elements_tag, pkg)
|
|
607
|
+
self.writeCompuMethods(elements_tag, pkg)
|
|
608
|
+
self.writeConstantSpecifications(elements_tag, pkg)
|
|
609
|
+
self.writeDataConstr(elements_tag, pkg)
|
|
610
|
+
self.writeUnit(elements_tag, pkg)
|
|
611
|
+
|
|
612
|
+
self.writeARPackages(pkg_tag, pkg.getARPackages())
|
|
613
|
+
|
|
614
|
+
def patch_xml(self, xml: str) -> str:
|
|
615
|
+
xml = xml.replace("<SW-DATA-DEF-PROPS-CONDITIONAL/>","<SW-DATA-DEF-PROPS-CONDITIONAL></SW-DATA-DEF-PROPS-CONDITIONAL>")
|
|
616
|
+
xml = xml.replace("<ELEMENTS/>","")
|
|
617
|
+
return xml
|
|
618
|
+
|
|
619
|
+
def saveToFile(self, filename, root: ET.Element):
|
|
620
|
+
xml = ET.tostring(root, encoding = "UTF-8", xml_declaration = True, short_empty_elements = False)
|
|
621
|
+
|
|
622
|
+
dom = minidom.parseString(xml.decode())
|
|
623
|
+
xml = dom.toprettyxml(indent = " ", encoding = "UTF-8")
|
|
624
|
+
|
|
625
|
+
text = self.patch_xml(xml.decode())
|
|
626
|
+
|
|
627
|
+
with open(filename, "w") as f_out:
|
|
628
|
+
#f_out.write(xml.decode())
|
|
629
|
+
f_out.write(text)
|
|
630
|
+
|
|
631
|
+
def save(self, filename, document: AUTOSAR):
|
|
632
|
+
self.logger.info("Save %s ..." % filename)
|
|
633
|
+
|
|
634
|
+
root = ET.Element("AUTOSAR", self.nsmap)
|
|
635
|
+
root.attrib["xmlns:xsi"] = "http://www.w3.org/2001/XMLSchema-instance"
|
|
636
|
+
root.attrib["xsi:schemaLocation"] = "http://autosar.org/schema/r4.0 AUTOSAR_4-2-2.xsd"
|
|
637
|
+
|
|
638
|
+
self.writeARPackages(root, document.getARPackages())
|
|
639
|
+
|
|
640
|
+
self.saveToFile(filename, root)
|
|
641
|
+
|