Skip to content

Commit d0843fd

Browse files
committed
Implement RunnableEntity and ExecutableEntity
- ExecutableEntity should be fully Implement - RunnableEntity is just a place-holder/wrapper
1 parent 66cd412 commit d0843fd

File tree

6 files changed

+1062
-57
lines changed

6 files changed

+1062
-57
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""
2+
Application data type examples
3+
"""
4+
import autosar.xml.element as ar_element
5+
6+
ref = ar_element.ExclusiveAreaRef("/Areas/Area1")
7+
print(str(ref))

src/autosar/xml/element.py

+199-3
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,16 @@ class BaseRef(ARObject, abc.ABC):
530530

531531
def __init__(self,
532532
value: str,
533-
dest: ar_enum.IdentifiableSubTypes) -> None:
533+
dest: ar_enum.IdentifiableSubTypes = None) -> None:
534534
self.value = value
535535
self.dest: ar_enum.IdentifiableSubTypes = None
536+
if dest is None:
537+
if len(self._accepted_subtypes()) == 1:
538+
dest = list(self._accepted_subtypes())[0]
539+
else:
540+
msg_part1 = "Value of dest cannot be None. Accepted values are: "
541+
msg_part2 = ",".join([str(x) for x in sorted(list(self._accepted_subtypes()))])
542+
raise ValueError(msg_part1 + msg_part2)
536543
if dest in self._accepted_subtypes():
537544
self.dest = dest
538545
else:
@@ -999,6 +1006,26 @@ def _accepted_subtypes(self) -> set[ar_enum.IdentifiableSubTypes]:
9991006
"""Acceptable values for dest"""
10001007
return {ar_enum.IdentifiableSubTypes.SWC_IMPLEMENTATION}
10011008

1009+
1010+
class ExclusiveAreaRef(BaseRef):
1011+
"""
1012+
EXCLUSIVE-AREA--SUBTYPES-ENUM
1013+
"""
1014+
1015+
def _accepted_subtypes(self) -> set[ar_enum.IdentifiableSubTypes]:
1016+
"""Acceptable values for dest"""
1017+
return {ar_enum.IdentifiableSubTypes.EXCLUSIVE_AREA}
1018+
1019+
1020+
class ExclusiveAreaNestingOrderRef(BaseRef):
1021+
"""
1022+
AR:EXCLUSIVE-AREA-NESTING-ORDER--SUBTYPES-ENUM
1023+
"""
1024+
1025+
def _accepted_subtypes(self) -> set[ar_enum.IdentifiableSubTypes]:
1026+
"""Acceptable values for dest"""
1027+
return {ar_enum.IdentifiableSubTypes.EXCLUSIVE_AREA_NESTING_ORDER}
1028+
10021029
# --- Documentation Elements
10031030

10041031

@@ -2437,8 +2464,7 @@ def __init__(self,
24372464

24382465
class ImplementationProps(Referrable):
24392466
"""
2440-
Complex type AR:IMPLEMENTATION-PROPS
2441-
Type: Abstract
2467+
Group AR:IMPLEMENTATION-PROPS
24422468
"""
24432469

24442470
def __init__(self,
@@ -6016,3 +6042,173 @@ def ref(self) -> SwcImplementationRef | None:
60166042
if ref_str is None:
60176043
return None
60186044
return SwcImplementationRef(ref_str)
6045+
6046+
6047+
class ExecutableEntityActivationReason(ImplementationProps):
6048+
"""
6049+
Complex type AR:EXECUTABLE-ENTITY-ACTIVATION-REASON
6050+
Tag variants: 'EXECUTABLE-ENTITY-ACTIVATION-REASON'
6051+
"""
6052+
6053+
def __init__(self,
6054+
name: str,
6055+
bit_position: int | None = None,
6056+
**kwargs) -> None:
6057+
super().__init__(name, **kwargs)
6058+
self.bit_position: int | None = None
6059+
self._assign_optional_positive_int("bit_position", bit_position)
6060+
6061+
6062+
class ExclusiveAreaRefConditional(ARObject):
6063+
"""
6064+
Complex type AR:EXCLUSIVE-AREA-REF-CONDITIONAL
6065+
Tag variants: 'EXCLUSIVE-AREA-REF-CONDITIONAL'
6066+
"""
6067+
6068+
def __init__(self,
6069+
exclusive_area_ref: ExclusiveAreaRef | str | None = None) -> None:
6070+
self.exclusive_area_ref: ExclusiveAreaRef | None = None # .EXCLUSIVE-AREA-REF
6071+
self._assign_optional("exclusive_area_ref", exclusive_area_ref, ExclusiveAreaRef)
6072+
6073+
6074+
ActivationReasonArgumentType = ExecutableEntityActivationReason | list[ExecutableEntityActivationReason] | None
6075+
CanEnterLeaveArgumentType = Union[ExclusiveAreaRefConditional,
6076+
list[ExclusiveAreaRefConditional],
6077+
ExclusiveAreaRef,
6078+
list[ExclusiveAreaRef],
6079+
str,
6080+
None]
6081+
6082+
ExclusiveAreaNestingOrderArgumentType = ExclusiveAreaNestingOrderRef | list[ExclusiveAreaNestingOrderRef] | None
6083+
RunsInsidesArgumentType = Union[ExclusiveAreaRefConditional,
6084+
list[ExclusiveAreaRefConditional],
6085+
ExclusiveAreaRef,
6086+
list[ExclusiveAreaRef],
6087+
str,
6088+
None]
6089+
6090+
ExclusiveAreaElementArgumentType = ExclusiveAreaRefConditional | ExclusiveAreaRef | str
6091+
6092+
6093+
class ExecutableEntity(Identifiable):
6094+
"""
6095+
Group AR:EXECUTABLE-ENTITY
6096+
"""
6097+
6098+
def __init__(self,
6099+
name: str,
6100+
activation_reasons: ActivationReasonArgumentType = None,
6101+
can_enter_leave: CanEnterLeaveArgumentType = None,
6102+
exclusive_area_nesting_order: ExclusiveAreaNestingOrderArgumentType = None,
6103+
minimum_start_interval: float | None = None,
6104+
reentrancy_level: ar_enum.ReentrancyLevel | None = None,
6105+
runs_insides: RunsInsidesArgumentType = None,
6106+
sw_addr_method: str | SwAddrMethodRef | None = None,
6107+
**kwargs) -> None:
6108+
super().__init__(name, **kwargs)
6109+
self.activation_reasons: list[ExecutableEntityActivationReason] = [] # .ACTIVATION-REASONS
6110+
# .CAN-ENTERS or CAN-ENTER-EXCLUSIVE-AREA-REFS depending on schema version
6111+
self.can_enter_leave: list[ExclusiveAreaRefConditional] = []
6112+
self.exclusive_area_nesting_order: list[ExclusiveAreaNestingOrderRef] = [] # .EXCLUSIVE-AREA-NESTING-ORDER-REFS
6113+
self.minimum_start_interval: float | None = None # .MINIMUM-START-INTERVAL
6114+
self.reentrancy_level: ar_enum.ReentrancyLevel | None = None # .REENTRANCY-LEVEL
6115+
# .RUNS-INSIDES or .RUNS-INSIDE-EXCLUSIVE-AREA-REFS depending on schema version
6116+
self.runs_insides: list[ExclusiveAreaRefConditional] = []
6117+
self.sw_addr_method: str | SwAddrMethodRef | None = None # .SW-ADDR-METHOD-REF
6118+
6119+
if activation_reasons is not None:
6120+
if isinstance(activation_reasons, list):
6121+
for activation_reason in activation_reasons:
6122+
self.append_activation_reason(activation_reason)
6123+
else:
6124+
self.append_activation_reason(activation_reasons)
6125+
if can_enter_leave is not None:
6126+
if isinstance(can_enter_leave, list):
6127+
for elem in can_enter_leave:
6128+
self.append_can_enter_leave(elem)
6129+
else:
6130+
self.append_can_enter_leave(can_enter_leave)
6131+
if exclusive_area_nesting_order is not None:
6132+
if isinstance(exclusive_area_nesting_order, ExclusiveAreaNestingOrderRef):
6133+
self.append_exclusive_area_nesting_order(exclusive_area_nesting_order)
6134+
elif isinstance(exclusive_area_nesting_order, list):
6135+
for elem in exclusive_area_nesting_order:
6136+
self.append_exclusive_area_nesting_order(elem)
6137+
self._assign_optional("minimum_start_interval", minimum_start_interval, float)
6138+
self._assign_optional("reentrancy_level", reentrancy_level, ar_enum.ReentrancyLevel)
6139+
if runs_insides is not None:
6140+
if isinstance(runs_insides, list):
6141+
for elem in runs_insides:
6142+
self.append_runs_insides(elem)
6143+
else:
6144+
self.append_runs_insides(runs_insides)
6145+
self._assign_optional('sw_addr_method', sw_addr_method, SwAddrMethodRef)
6146+
6147+
def append_activation_reason(self, activation_reason: ExecutableEntityActivationReason) -> None:
6148+
"""
6149+
Appends activation_reason to internal list of activation reasons
6150+
"""
6151+
if isinstance(activation_reason, ExecutableEntityActivationReason):
6152+
self.activation_reasons.append(activation_reason)
6153+
else:
6154+
raise TypeError("activation_reason must be of type ExecutableEntityActivationReason")
6155+
6156+
def append_can_enter_leave(self, value: ExclusiveAreaElementArgumentType) -> None:
6157+
"""
6158+
Tthe executable entity can enter/leave the referenced exclusive area through explicit API calls
6159+
"""
6160+
if isinstance(value, ExclusiveAreaRefConditional):
6161+
self.can_enter_leave.append(value)
6162+
elif isinstance(value, (ExclusiveAreaRef, str)):
6163+
self.can_enter_leave.append(ExclusiveAreaRefConditional(value))
6164+
else:
6165+
raise TypeError("value: Invalid type. Expected one of ExclusiveAreaRefConditional, ExclusiveAreaRef, str.")
6166+
6167+
def append_exclusive_area_nesting_order(self, exclusive_area_nesting_order: ExclusiveAreaNestingOrderRef) -> None:
6168+
"""
6169+
Appends exclusive area reference to internal can_enter_leave list
6170+
"""
6171+
if isinstance(exclusive_area_nesting_order, ExclusiveAreaNestingOrderRef):
6172+
self.exclusive_area_nesting_order.append(exclusive_area_nesting_order)
6173+
else:
6174+
raise TypeError("exclusive_area_nesting_order must be of type ExclusiveAreaRefConditional")
6175+
6176+
def append_runs_insides(self, value: ExclusiveAreaElementArgumentType) -> None:
6177+
"""
6178+
The executable entity runs completely inside the referenced exclusive area
6179+
"""
6180+
if isinstance(value, ExclusiveAreaRefConditional):
6181+
self.runs_insides.append(value)
6182+
elif isinstance(value, (ExclusiveAreaRef, str)):
6183+
self.runs_insides.append(ExclusiveAreaRefConditional(value))
6184+
else:
6185+
raise TypeError("value: Invalid type. Expected one of ExclusiveAreaRefConditional, ExclusiveAreaRef, str.")
6186+
6187+
6188+
class RunnableEntity(ExecutableEntity):
6189+
"""
6190+
Complex type AR:RUNNABLE-ENTITY
6191+
Tag variants: 'RUNNABLE-ENTITY'
6192+
Only implements base class features for now.
6193+
"""
6194+
6195+
def __init__(self,
6196+
name: str,
6197+
**kwargs) -> None:
6198+
super().__init__(name, **kwargs)
6199+
6200+
6201+
# --- Future stuff
6202+
6203+
6204+
class RModeInAtomicSwcInstanceRef(ARObject):
6205+
"""
6206+
Complex type AR:R-MODE-IN-ATOMIC-SWC-INSTANCE-REF
6207+
Tag variants: 'DISABLED-MODE-IREF' | 'MODE-IREF'
6208+
"""
6209+
6210+
6211+
class RTEEvent(Identifiable):
6212+
"""
6213+
Group AR:RTE-EVENT
6214+
"""

0 commit comments

Comments
 (0)