Skip to content

Commit 29dba7c

Browse files
committed
Implement ModeSwitchInterface
- Implement ModeSwitchInterface - Refactor reference utility methods
1 parent 950d36c commit 29dba7c

11 files changed

+1259
-113
lines changed

CHANGELOG.md

+20-4
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,37 @@ Non-collectable elements are various sub-elements to collectable elements.
99

1010
### Added
1111

12+
#### XML - Data type elements
13+
14+
* ArgumentDataPrototype | ARGUMENT-DATA-PROTOTYPE
15+
* ParameterDataPrototype | PARAMETER-DATA-PROTOTYPE
16+
* VariableDataPrototype | VARIABLE-DATA-PROTOTYPE
17+
18+
#### Mode declaration elements
19+
20+
* ModeDeclarationGroup | MODE-DECLARATION-GROUP | `collectable`
21+
* ModeDeclaration | MODE-DECLARATION
22+
* ModeDeclarationGroupPrototype | MODE-DECLARATION-GROUP-PROTOTYPE
23+
* ModeErrorBehavior | MODE-ERROR-BEHAVIOR
24+
* ModeTransition | MODE-TRANSITION
25+
1226
#### XML Port interface elements
1327

1428
* ClientServerInterface | CLIENT-SERVER-INTERFACE | `collectable`
29+
* ModeSwitchInterface | MODE-SWITCH-INTERFACE | `collectable`
1530
* NvDataInterface | NV-DATA-INTERFACE | `collectable`
1631
* ParameterInterface | PARAMETER-INTERFACE | `collectable`
1732
* SenderReceiverInterface | SENDER-RECEIVER-INTERFACE | `collectable`
1833
* ApplicationError | APPLICATION-ERROR
1934
* ClientServerOperation | CLIENT-SERVER-OPERATION
2035
* InvalidationPolicy | INVALIDATION-POLICY
2136

22-
#### XML - Data type elements
37+
#### XML - Reference elements
2338

24-
* ArgumentDataPrototype | ARGUMENT-DATA-PROTOTYPE
25-
* ParameterDataPrototype | PARAMETER-DATA-PROTOTYPE
26-
* VariableDataPrototype | VARIABLE-DATA-PROTOTYPE
39+
* ApplicationErrorRef
40+
* ModeDeclarationGroupRef
41+
* ModeDeclarationRef
42+
* VariableDataPrototypeRef
2743

2844
## [v0.5.1] - 2023-11-09
2945

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<AUTOSAR xsi:schemaLocation="http://autosar.org/schema/r4.0 AUTOSAR_00051.xsd" xmlns="http://autosar.org/schema/r4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3+
<AR-PACKAGES>
4+
<AR-PACKAGE>
5+
<SHORT-NAME>ModeDeclarations</SHORT-NAME>
6+
<ELEMENTS>
7+
<MODE-DECLARATION-GROUP>
8+
<SHORT-NAME>VehicleMode</SHORT-NAME>
9+
<INITIAL-MODE-REF DEST="MODE-DECLARATION">/ModeDeclarations/VehicleMode/OFF</INITIAL-MODE-REF>
10+
<MODE-DECLARATIONS>
11+
<MODE-DECLARATION>
12+
<SHORT-NAME>OFF</SHORT-NAME>
13+
</MODE-DECLARATION>
14+
<MODE-DECLARATION>
15+
<SHORT-NAME>ACCESSORY</SHORT-NAME>
16+
</MODE-DECLARATION>
17+
<MODE-DECLARATION>
18+
<SHORT-NAME>RUNNING</SHORT-NAME>
19+
</MODE-DECLARATION>
20+
<MODE-DECLARATION>
21+
<SHORT-NAME>CRANKING</SHORT-NAME>
22+
</MODE-DECLARATION>
23+
</MODE-DECLARATIONS>
24+
</MODE-DECLARATION-GROUP>
25+
</ELEMENTS>
26+
</AR-PACKAGE>
27+
</AR-PACKAGES>
28+
</AUTOSAR>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<AUTOSAR xsi:schemaLocation="http://autosar.org/schema/r4.0 AUTOSAR_00051.xsd" xmlns="http://autosar.org/schema/r4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3+
<AR-PACKAGES>
4+
<AR-PACKAGE>
5+
<SHORT-NAME>PortInterfaces</SHORT-NAME>
6+
<ELEMENTS>
7+
<MODE-SWITCH-INTERFACE>
8+
<SHORT-NAME>VehicleMode_I</SHORT-NAME>
9+
<IS-SERVICE>false</IS-SERVICE>
10+
<MODE-GROUP>
11+
<SHORT-NAME>mode</SHORT-NAME>
12+
<TYPE-TREF DEST="MODE-DECLARATION-GROUP">/ModeDeclarations/VehicleMode</TYPE-TREF>
13+
</MODE-GROUP>
14+
</MODE-SWITCH-INTERFACE>
15+
</ELEMENTS>
16+
</AR-PACKAGE>
17+
</AR-PACKAGES>
18+
</AUTOSAR>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""
2+
Sender-receiver port interface examples
3+
"""
4+
import os
5+
import autosar
6+
import autosar.xml.element as ar_element
7+
8+
9+
def create_mode_declaration_groups(packages: dict[str, ar_element.Package]):
10+
"""
11+
Creates mode declarations
12+
"""
13+
vehicle_mode = ar_element.ModeDeclarationGroup("VehicleMode", ["OFF",
14+
"ACCESSORY",
15+
"RUNNING",
16+
"CRANKING"])
17+
packages["ModeDeclarations"].append(vehicle_mode)
18+
vehicle_mode.initial_mode_ref = vehicle_mode.find("OFF").ref()
19+
20+
21+
def create_mode_switch_interface(packages: dict[str, ar_element.Package]):
22+
"""
23+
Creates mode switch interface
24+
"""
25+
mode_declaration = packages["ModeDeclarations"].find("VehicleMode")
26+
portinterface = ar_element.ModeSwitchInterface("VehicleMode_I", is_service=False)
27+
portinterface.create_mode_group("mode", mode_declaration.ref())
28+
packages["PortInterfaces"].append(portinterface)
29+
30+
31+
def save_xml_files(workspace: autosar.xml.Workspace):
32+
"""
33+
Saves workspace as XML documents
34+
"""
35+
interface_document_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
36+
'data',
37+
'mode_switch_interface.arxml'))
38+
mode_declaration_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
39+
'data',
40+
'mode_declarations.arxml'))
41+
workspace.create_document(interface_document_path, packages="/PortInterfaces")
42+
workspace.create_document(mode_declaration_path, packages="/ModeDeclarations")
43+
workspace.write_documents()
44+
45+
46+
def main():
47+
"""
48+
Main
49+
"""
50+
workspace = autosar.xml.Workspace()
51+
packages = dict(zip(["ModeDeclarations", "PortInterfaces"],
52+
workspace.make_packages("ModeDeclarations", "PortInterfaces")))
53+
create_mode_declaration_groups(packages)
54+
create_mode_switch_interface(packages)
55+
save_xml_files(workspace)
56+
57+
58+
if __name__ == "__main__":
59+
main()

run_examples.cmd

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ python examples\xml\port_interface\nv_data_interface.py
1212
python examples\xml\port_interface\parameter_interface.py
1313
python examples\xml\port_interface\sender_receiver_interface.py
1414
python examples\xml\port_interface\client_server_interface.py
15+
python examples\xml\port_interface\mode_switch_interface.py
1516
python examples\generator\data_types\gen_type_defs_scalar.py
1617
python examples\generator\data_types\gen_type_defs_array.py
1718
python examples\generator\data_types\gen_type_defs_record.py

0 commit comments

Comments
 (0)