Skip to content

Commit 4a53bd2

Browse files
author
Conny Gustafsson
committed
Implement PortApiOption classes
- CommunicationBufferLocking - PortDefinedArgumentValue - PortApiOption
1 parent 3400e3f commit 4a53bd2

File tree

7 files changed

+480
-5
lines changed

7 files changed

+480
-5
lines changed

.pylintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,8 @@ exclude-too-few-public-methods=
516516
ignored-parents=
517517

518518
# Maximum number of arguments for function / method.
519-
max-args=5
519+
max-args=12
520+
max-positional-arguments=12
520521

521522
# Maximum number of attributes for a class (see R0902).
522523
max-attributes=7

CHANGELOG.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
# Changelog
22

3-
The first name in a bullet point below is the Python class name while the second name is the identifier used in the XML schema (XSD file).
3+
The first name in a bullet point below is the Python class name while the second name is the complex type in the AUTOSAR XML schema (XSD file).
44

5-
Elements marked as `collectable` means that they can be added directly to a package.
5+
Elements marked as `collectable` means that they are allowed to be added as sub-elements in a package.
66
Non-collectable elements are various sub-elements to collectable elements.
77

8+
## [Unreleased]
9+
10+
### Added
11+
12+
#### XML - SWC internal behavior elements
13+
14+
* CommunicationBufferLocking | COMMUNICATION-BUFFER-LOCKING
15+
* PortAPIOption | PORT-API-OPTION
16+
* PortDefinedArgumentValue | PORT-DEFINED-ARGUMENT-VALUE
17+
818
## [v0.5.4] - 2024-10-28
919

1020
### Added

src/autosar/xml/element.py

+92-2
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,7 @@ class SwDataDefPropsConditional(ARObject):
16321632
Tag Variants: SW-DATA-DEF-PROPS-CONDITIONAL
16331633
"""
16341634

1635-
def __init__(self,
1635+
def __init__(self, # pylint: disable=R0917
16361636
display_presentation: ar_enum.DisplayPresentation | None = None,
16371637
step_size: float | None = None,
16381638
annotations: Annotation | list[Annotation] | None = None,
@@ -3757,7 +3757,7 @@ class EndToEndTransformationComSpecProps(Describable):
37573757
Tag variants: 'END-TO-END-TRANSFORMATION-COM-SPEC-PROPS'
37583758
"""
37593759

3760-
def __init__(self,
3760+
def __init__(self, # pylint: disable=R0917
37613761
clear_from_valid_to_invalid: bool | None = None,
37623762
disable_e2e_check: bool | None = None,
37633763
disable_e2e_state_machine: bool | None = None,
@@ -5815,6 +5815,7 @@ def __init__(self,
58155815
self.disabled_modes: list[RModeInAtomicSwcInstanceRef] = []
58165816
# .START-ON-EVENT-REF
58175817
self.start_on_event: RunnableEntityRef | None = None
5818+
58185819
if disabled_modes is not None:
58195820
if isinstance(disabled_modes, RModeInAtomicSwcInstanceRef):
58205821
self.append_disabled_mode(disabled_modes)
@@ -6221,12 +6222,101 @@ def __init__(self,
62216222
self._assign_optional("value_type", value_type, ImplementationDataTypeRef)
62226223

62236224

6225+
class SwcSupportedFeature(ARObject):
6226+
"""
6227+
Base class for supported features
6228+
"""
6229+
6230+
6231+
class CommunicationBufferLocking(SwcSupportedFeature):
6232+
"""
6233+
Complex type AR:COMMUNICATION-BUFFER-LOCKING
6234+
Tag variantS: 'COMMUNICATION-BUFFER-LOCKING'
6235+
"""
6236+
6237+
def __init__(self,
6238+
support_buffer_locking: ar_enum.SupportBufferLocking | None = None) -> None:
6239+
super().__init__()
6240+
# .SUPPORT-BUFFER-LOCKING
6241+
self.support_buffer_locking: ar_enum.SupportBufferLocking = None
6242+
6243+
self._assign_optional("support_buffer_locking", support_buffer_locking, ar_enum.SupportBufferLocking)
6244+
6245+
6246+
PortDefinedArgumentValueArgType = PortDefinedArgumentValue | list[PortDefinedArgumentValue] | None
6247+
SwcSupportedFeatureArgType = SwcSupportedFeature | list[SwcSupportedFeature] | None
6248+
6249+
62246250
class PortAPIOption(ARObject):
62256251
"""
62266252
Complex type AR:PORT-API-OPTION
62276253
Tag variants: 'PORT-API-OPTION'
62286254
"""
62296255

6256+
def __init__(self,
6257+
enable_take_address: bool | None = None,
6258+
error_handling: ar_enum.DataTransformationErrorHandling | None = None,
6259+
indirect_api: bool | None = None,
6260+
port_arg_values: PortDefinedArgumentValueArgType = None,
6261+
port: PortPrototypeRef | None = None,
6262+
supported_features: SwcSupportedFeatureArgType = None,
6263+
transformer_status_forwarding: ar_enum.DataTransformationStatusForwarding | None = None
6264+
) -> None:
6265+
super().__init__()
6266+
# .ENABLE-TAKE-ADDRESS
6267+
self.enable_take_address: bool | None = None
6268+
# .ERROR-HANDLING
6269+
self.error_handling: ar_enum.DataTransformationErrorHandling | None = None
6270+
# .INDIRECT-API
6271+
self.indirect_api: bool | None = None
6272+
# .PORT-ARG-VALUES
6273+
self.port_arg_values: list[PortDefinedArgumentValue] = []
6274+
# .PORT-REF
6275+
self.port: PortPrototypeRef | None = port
6276+
# .SUPPORTED-FEATURES
6277+
self.supported_features: list[SwcSupportedFeature] = []
6278+
# .TRANSFORMER-STATUS-FORWARDING
6279+
self.transformer_status_forwarding: ar_enum.DataTransformationStatusForwarding | None = None
6280+
# .VARIATION-POINT not supported
6281+
6282+
self._assign_optional("enable_take_address", enable_take_address, bool)
6283+
self._assign_optional("error_handling", error_handling, ar_enum.DataTransformationErrorHandling)
6284+
self._assign_optional("indirect_api", indirect_api, bool)
6285+
self._assign_optional("port", port, PortPrototypeRef)
6286+
self._assign_optional("transformer_status_forwarding",
6287+
transformer_status_forwarding,
6288+
ar_enum.DataTransformationStatusForwarding)
6289+
if port_arg_values is not None:
6290+
if isinstance(port_arg_values, list):
6291+
for port_arg_value in port_arg_values:
6292+
self.append_port_arg_value(port_arg_value)
6293+
else:
6294+
self.append_port_arg_value(port_arg_values)
6295+
if supported_features is not None:
6296+
if isinstance(supported_features, list):
6297+
for supported_feature in supported_features:
6298+
self.append_supported_feature(supported_feature)
6299+
else:
6300+
self.append_supported_feature(supported_features)
6301+
6302+
def append_port_arg_value(self, port_arg_value: PortDefinedArgumentValue) -> None:
6303+
"""
6304+
Adds PortDefinedArgumentValue to internal list
6305+
"""
6306+
if isinstance(port_arg_value, PortDefinedArgumentValue):
6307+
self.port_arg_values.append(port_arg_value)
6308+
else:
6309+
raise TypeError("port_arg_value must be of type PortDefinedArgumentValue")
6310+
6311+
def append_supported_feature(self, supported_feature: SwcSupportedFeature) -> None:
6312+
"""
6313+
Adds PortDefinedArgumentValue to internal list
6314+
"""
6315+
if isinstance(supported_feature, (CommunicationBufferLocking,)):
6316+
self.supported_features.append(supported_feature)
6317+
else:
6318+
raise TypeError("supported_feature must be of type CommunicationBufferLocking")
6319+
62306320

62316321
class InternalBehavior(Identifiable):
62326322
"""

src/autosar/xml/enumeration.py

+48
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ class DataFilterType(Enum):
104104
ONE_EVERY_N = 7
105105

106106

107+
class DataTransformationErrorHandling(Enum):
108+
"""
109+
DATA-TRANSFORMATION-ERROR-HANDLING-ENUM--SIMPLE
110+
"""
111+
NO_TRANSFORMER_ERROR_HANDLING = 0
112+
TRANSFORMER_ERROR_HANDLING = 1
113+
114+
115+
class DataTransformationStatusForwarding(Enum):
116+
"""
117+
DATA-TRANSFORMATION-STATUS-FORWARDING-ENUM--SIMPLE
118+
"""
119+
NO_TRANSFORMER_STATUS_FORWARDING = 0
120+
TRANSFORMER_STATUS_FORWARDING = 1
121+
122+
107123
class DisplayPresentation(Enum):
108124
"""DISPLAY-PRESENTATION-ENUM"""
109125

@@ -546,6 +562,14 @@ class ServiceKind(Enum):
546562
WATCH_DOG_MANAGER = 17
547563

548564

565+
class SupportBufferLocking(Enum):
566+
"""
567+
SUPPORT-BUFFER-LOCKING-ENUM--SIMPLE
568+
"""
569+
DOES_NOT_SUPPORT_BUFFER_LOCKING = 0
570+
SUPPORTS_BUFFER_LOCKING = 1
571+
572+
549573
class SwCalibrationAccess(Enum):
550574
"""
551575
AR:SW-CALIBRATION-ACCESS-ENUM--SIMPLE
@@ -679,6 +703,14 @@ class VersionedTextValue:
679703
"ONE-EVERY-N": DataFilterType.ONE_EVERY_N
680704

681705
},
706+
"DataTransformationErrorHandling": {
707+
"NO-TRANSFORMER-ERROR-HANDLING": DataTransformationErrorHandling.NO_TRANSFORMER_ERROR_HANDLING,
708+
"TRANSFORMER-ERROR-HANDLING": DataTransformationErrorHandling.TRANSFORMER_ERROR_HANDLING
709+
},
710+
"DataTransformationStatusForwarding": {
711+
"NO-TRANSFORMER-STATUS-FORWARDING": DataTransformationStatusForwarding.NO_TRANSFORMER_STATUS_FORWARDING,
712+
"TRANSFORMER-STATUS-FORWARDING": DataTransformationStatusForwarding.TRANSFORMER_STATUS_FORWARDING
713+
},
682714
"DisplayPresentation": {
683715
"PRESENTATION-CONTINUOUS": DisplayPresentation.CONTINUOUS,
684716
"PRESENTATION-DISCRETE": DisplayPresentation.DISCRETE
@@ -968,6 +1000,10 @@ class VersionedTextValue:
9681000
"USE-ARRAY-BASE-TYPE": ServerArgImplPolicy.USE_ARRAY_BASED_TYPE,
9691001
"USE-VOID": ServerArgImplPolicy.USE_VOID
9701002
},
1003+
"SupportBufferLocking": {
1004+
"DOES-NOT-SUPPORT-BUFFER-LOCKING": SupportBufferLocking.DOES_NOT_SUPPORT_BUFFER_LOCKING,
1005+
"SUPPORTS-BUFFER-LOCKING": SupportBufferLocking.SUPPORTS_BUFFER_LOCKING
1006+
},
9711007
"SwCalibrationAccess": {
9721008
"NOT-ACCESSIBLE": SwCalibrationAccess.NOT_ACCESSIBLE,
9731009
"READ-ONLY": SwCalibrationAccess.READ_ONLY,
@@ -1043,6 +1079,14 @@ def xml_to_enum(enum_type_name: str, xml_text: str, schema_version: int = ar_bas
10431079
"RES-AXIS", # 3
10441080
"STD-AXIS" # 4
10451081
],
1082+
"DataTransformationErrorHandling": [
1083+
"NO-TRANSFORMER-ERROR-HANDLING",
1084+
"TRANSFORMER-ERROR-HANDLING"
1085+
],
1086+
"DataTransformationStatusForwarding": [
1087+
"NO-TRANSFORMER-STATUS-FORWARDING",
1088+
"TRANSFORMER-STATUS-FORWARDING"
1089+
],
10461090
"DataFilterType": [
10471091
"ALWAYS", # 0
10481092
"MASKED-NEW-DIFFERS-MASKED-OLD", # 1
@@ -1343,6 +1387,10 @@ def xml_to_enum(enum_type_name: str, xml_text: str, schema_version: int = ar_bas
13431387
"USE-ARRAY-BASE-TYPE", # 1
13441388
"USE-VOID", # 2
13451389
],
1390+
"SupportBufferLocking": [
1391+
"DOES-NOT-SUPPORT-BUFFER-LOCKING", # 0
1392+
"SUPPORTS-BUFFER-LOCKING" # 1
1393+
],
13461394
"SwCalibrationAccess": [
13471395
"NOT-ACCESSIBLE", # 0
13481396
"READ-ONLY", # 1

src/autosar/xml/reader.py

+67
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ def __init__(self,
318318
'TIMING-EVENT': self._read_timing_event,
319319
'TRANSFORMER-HARD-ERROR-EVENT': self._read_transformer_hard_error_event,
320320
'PORT-DEFINED-ARGUMENT-VALUE': self._read_port_defined_argument_value,
321+
'COMMUNICATION-BUFFER-LOCKING': self._read_communication_buffer_locking,
322+
'PORT-API-OPTION': self._read_port_api_option,
321323
}
322324
self.switcher_all = {}
323325
self.switcher_all.update(self.switcher_collectable)
@@ -5098,6 +5100,71 @@ def _read_port_defined_argument_value(self,
50985100
self._report_unprocessed_elements(child_elements)
50995101
return ar_element.PortDefinedArgumentValue(**data)
51005102

5103+
def _read_communication_buffer_locking(self,
5104+
xml_element: ElementTree.Element
5105+
) -> ar_element.CommunicationBufferLocking:
5106+
"""
5107+
Reads complex type AR:COMMUNICATION-BUFFER-LOCKING
5108+
Tag variantS: 'COMMUNICATION-BUFFER-LOCKING'
5109+
"""
5110+
data = {}
5111+
child_elements = ChildElementMap(xml_element)
5112+
xml_child = child_elements.get("SUPPORT-BUFFER-LOCKING")
5113+
if xml_child is not None:
5114+
data["support_buffer_locking"] = ar_enum.xml_to_enum("SupportBufferLocking", xml_child.text)
5115+
self._report_unprocessed_elements(child_elements)
5116+
return ar_element.CommunicationBufferLocking(**data)
5117+
5118+
def _read_port_api_option(self,
5119+
xml_element: ElementTree.Element
5120+
) -> ar_element.PortAPIOption:
5121+
"""
5122+
Reads complex type AR:PORT-API-OPTION
5123+
Tag variants: 'PORT-API-OPTION'
5124+
"""
5125+
data = {}
5126+
child_elements = ChildElementMap(xml_element)
5127+
self._read_port_api_option_group(child_elements, data)
5128+
self._report_unprocessed_elements(child_elements)
5129+
return ar_element.PortAPIOption(**data)
5130+
5131+
def _read_port_api_option_group(self, child_elements: ChildElementMap, data: dict) -> None:
5132+
"""
5133+
Reads group AR:PORT-API-OPTION
5134+
"""
5135+
xml_child = child_elements.get("ENABLE-TAKE-ADDRESS")
5136+
if xml_child is not None:
5137+
data["enable_take_address"] = self._read_boolean(xml_child.text)
5138+
xml_child = child_elements.get("ERROR-HANDLING")
5139+
if xml_child is not None:
5140+
data["error_handling"] = ar_enum.xml_to_enum("DataTransformationErrorHandling", xml_child.text)
5141+
xml_child = child_elements.get("INDIRECT-API")
5142+
if xml_child is not None:
5143+
data["indirect_api"] = self._read_boolean(xml_child.text)
5144+
xml_child = child_elements.get("PORT-ARG-VALUES")
5145+
if xml_child is not None:
5146+
port_arg_values = []
5147+
for xml_grand_child in xml_child.findall("./PORT-DEFINED-ARGUMENT-VALUE"):
5148+
port_arg_values.append(self._read_port_defined_argument_value(xml_grand_child))
5149+
data["port_arg_values"] = port_arg_values
5150+
xml_child = child_elements.get("PORT-REF")
5151+
if xml_child is not None:
5152+
data["port"] = self._read_port_prototype_ref(xml_child)
5153+
xml_child = child_elements.get("PORT-REF")
5154+
if xml_child is not None:
5155+
data["port"] = self._read_port_prototype_ref(xml_child)
5156+
xml_child = child_elements.get("SUPPORTED-FEATURES")
5157+
if xml_child is not None:
5158+
supported_features = []
5159+
for xml_grand_child in xml_child.findall("./*"):
5160+
if xml_grand_child.tag == "COMMUNICATION-BUFFER-LOCKING":
5161+
supported_features.append(self._read_communication_buffer_locking(xml_grand_child))
5162+
data["supported_features"] = supported_features
5163+
xml_child = child_elements.get("TRANSFORMER-STATUS-FORWARDING")
5164+
if xml_child is not None:
5165+
data["transformer_status_forwarding"] = ar_enum.xml_to_enum("DataTransformationStatusForwarding",
5166+
xml_child.text)
5167+
51015168
def _read_swc_internal_behavior(self, xml_element: ElementTree.Element) -> ar_element.SwcInternalBehavior:
51025169
"""
51035170
Reads complex type AR:SWC-INTERNAL-BEHAVIOR

0 commit comments

Comments
 (0)