cogu/autosar
소개
AUTOSAR XML 파일을 다루기 위한 Python 모듈 모음
개발 도구측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- -1
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalPython AUTOSAR v0.5
A set of Python modules for working with AUTOSAR XML files.
The primary use case is to enable Python to generate ARXML files for import in other (commercial) AUTOSAR toolchains. It also has some support for parsing AUTOSAR XML files.
Important notes:
- Python AUTOSAR v0.5+ uses a new API and is incompatible with the v0.4 API.
- For Python AUTOSAR v0.4, see the v0.4 maintenance branch.
- There's no offical documentation yet for v0.5. The documentation found at Read the Docs is for v0.4.
Compatibility & Versioning with py-apx
autosar versions align directly with the py-apx package:
autosar Version |
py-apx Version |
Status | Notes |
|---|---|---|---|
| v0.4.x | v0.4.x | Maintenance | Legacy API compatibility maintained on the respective maintenance/0.4 branches. |
| v0.5.x | v0.5.x | In Development | Modernized API redesign & architecture refactoring. |
| v0.6.x | v0.6.x | Planned | Stable modernized release with full py-apx v0.6.x compatibility, published to PyPI. |
Major design changes
AUTOSAR v0.5 has been rewritten and modernized.
Key features:
- New class hierachy
- Follows the structure of the AUTOSAR XML schema where possible.
- Snake-case naming of variables and methods (Follows PEP8 standard).
- Modern type hinting (this unfortunately requires Python 3.10 or later).
- Python Enum classes for enumeration types.
- Improved XML reading and writing using lxml.
- Linting support
- Source code is checked with both Pylint and flake8.
- New unit test suite
- More comprehensive unit tests for XML elements.
- Much faster to run as it uses the new XML reader and writer.
Supported AUTOSAR versions
The implementation tries to follow release R22-11. However, the generated ARXML validates against all versions listed below.
When calling write_documents, use the schema_version parameter to select desired version (integer with value 48-51).
- 48 (R19-11, Classic AUTOSAR 4.5)
- 49 (R20-11, Classic AUTOSAR 4.6)
- 50 (R21-11, Classic AUTOSAR 4.7)
- 51 (R22-11, Classic AUTOSAR 4.8)
Only Clasic AUTOSAR will be supported.
Supported XML elements
For currently supported XML elements, see the XML Index.
If you can't find it in the index it's not implemented.
Usage
import autosar.xml
import autosar.xml.element as ar_element
workspace = autosar.xml.Workspace()
workspace.create_package_map({"ApplicationDataTypes": "DataTypes/ApplicationDataTypes",
"DataConstrs": "DataTypes/DataConstrs"})
data_constraint = ar_element.DataConstraint.make_internal("uint8_ADT_DataConstr", 0, 255)
workspace.add_element("DataConstrs", data_constraint)
sw_data_def_props = ar_element.SwDataDefPropsConditional(data_constraint_ref=data_constraint.ref())
data_type = ar_element.ApplicationPrimitiveDataType("uint8_ADT",
category="VALUE",
sw_data_def_props=sw_data_def_props)
workspace.add_element("ApplicationDataTypes", data_type)
workspace.create_document("datatypes.arxml", packages="/DataTypes")
workspace.write_documents()
Requirements
- Python 3.10+
- lxml
- tomli (Python 3.10 only, tomli is built-in for Python 3.11)
- cfile v0.4.0+
Installation
Manual install required as this version is not yet available on PyPI.
Preparation
Download a compressed source package from GitHub or clone this repo to a local directory.
Installation steps for virtual environment
Start bash (Linux) or PowerShell (Windows).
Create virtual environment
python -m venv .venv
Activate virtual environment
On Windows run:
.\.venv\Scripts\activate
On Linux run:
source .venv/bin/activate
Upgrade toolchain
Once virtual environment is active run:
python -m pip install --upgrade pip setuptools
python -m pip install -r requirements.txt
Developer dependencies (optional)
If you are a package developer, you also need to install additional tools for linting, packaging, and building documentation:
python -m pip install --upgrade flake8 build twine sphinx
Installing the Python module
Your current directory must be either where you unzipped the source package or where you cloned the git repo.
For standard install (users):
pip install .
For editable install (developers):
pip install --editable .
XML Workspace API
The autosar.xml.Workspace class offers two slightly different APIs for creating packages and elements. The main difference between them is the usage of namespaces.
Simple API methods
For small projects, use the simple API.
Methods in the simple API:
- Workspace.create_package_map
- Workspace.add_element
- Workspace.find_element
- Workspace.get_package
For for more information, see the Simple API - User Guide that demonstrates the use of this API.
Advanced API - Requires namespaces
The advanced API is recomended for larger projects. It requires you to write custom template classes in addition to creating namespaces.
Methods in the advanced API:
- Workspace.create_namespace
- Workspace.get_package_ref_by_role
- Workspace.apply
- Workspace.load_config
It can be quite powerful when used the right way but requires some setting up.
There's no user guide yet. See the files under examples/template for reference.
Common methods
A number of methods are common for both APIs. For the advanced API you can skip most of them and instead use config files (.toml) to let the
Workspace class handle both package and document creation automatically.
Common methods:
- Workspace.set_document_root
- Workspace.create_document
- Workspace.create_document_mapping
- Workspace.write_documents
Creating XML elements
The module autosar.xml.element contains all supported elements that you can add to a package. Most often you simply call the constructor for an object you want to create and then add it to a package.
Some elements are quite complicated to create manually. Instead of using the constructor method, some classes offers one or several convenience-methods with names
beginning with either make_ or create_. Exploring these methods is highly recomended.
List of convenience-methods:
MultiLanguageOverviewParagraph.makeComputation.make_value_tableComputation.make_rationalDataConstraint.make_physicalDataConstraint.make_internalValueSpecification.make_value_with_checkValueSpecification.make_valueConstantSpecification.make_constantModeDeclarationGroup.create_mode_declarationSenderReceiverInterface.create_data_elementSenderReceiverInterface.create_invalidation_policyNvDataInterface.create_data_elementParameterInterface.create_parameterClientServerOperation.create_argumentClientServerOperation.create_in_argumentClientServerOperation.create_inout_argumentClientServerOperation.create_out_argumentClientServerOperation.create_possible_error_refClientServerInterface.create_operationClientServerInterface.create_possible_errorModeSwitchInterface.create_mode_groupProvidePortComSpec.make_from_port_interfaceProvidePortComSpec.make_non_queued_sender_com_specRequirePortComSpec.make_from_port_interfaceRequirePortComSpec.make_non_queued_receiver_com_specSwComponentType.create_p_portSwComponentType.create_provide_portSwComponentType.create_r_portSwComponentType.create_require_portSwComponentType.create_pr_portAtomicSoftwareComponentType.create_internal_behaviorCompositionSwComponentType.create_component_prototypeCompositionSwComponentType.create_connectorVariableAccess.make_from_portVariableAccess.make_from_port_with_argsExternalTriggeringPointIdent.make_with_argsModeAccessPointIdent.make_with_argsRunnableEntity.create_port_accessRunnableEntity.create_internal_triggering_pointDataReceiveErrorEvent.makeDataReceivedEvent.makeExternalTriggerOccurredEvent.makeOperationInvokedEvent.makeSwcModeManagerErrorEvent.makeSwcModeSwitchEvent.makeInternalBehavior.create_constant_memoryInternalBehavior.create_exclusive_areaSwcInternalBehavior.create_runnableSwcInternalBehavior.create_background_eventSwcInternalBehavior.create_data_receive_error_eventSwcInternalBehavior.create_data_received_eventSwcInternalBehavior.create_data_send_completed_eventSwcInternalBehavior.create_data_write_completed_eventSwcInternalBehavior.create_init_eventSwcInternalBehavior.create_operation_invoked_eventSwcInternalBehavior.create_swc_mode_manager_error_eventSwcInternalBehavior.create_swc_mode_mode_switch_eventSwcInternalBehavior.create_timing_eventSwcInternalBehavior.create_external_trigger_eventSwcInternalBehavior.create_internal_trigger_eventSwcInternalBehavior.create_port_api_options
Python Module Hierachy
autosar.xml
Packages for handling AUTOSAR XML (ARXML).
autosar.model
Implementation model, an intermediate model between XML and RTE generation.
autosar.generator
RTE generators. Right now it only has a generator for the RTE type header. This part is in early stages of development and is probably not very useful.
Development Roadmap
Below is a rough roadmap of planned releases.
v0.5.0: Data types
v0.5.1: Value specifications and constants
v0.5.2: Port interfaces
v0.5.3: Components and ports
v0.5.4: SwcInternalBehavior - basics
- Runnables
- Events
v0.5.5 SwcInternalBehavior - advanced
- Data type mapping references
- Exclusive areas
- Port access
- Port-API options
v0.5.6 Add some missing elements and functions that wasn't prioritized before.
0.5.7 SwcInternalBehavior - improved
- Fully support the SwcInternalBehavior class.
v0.5.8: Fixes and refactoring
- Fix some early design mistakes.
- Standardize member naming rules across the classes.
- Attempt to break apart large Python files into smaller ones.
- Start documentation work.
v0.5.9: ?
v0.6.0: Stable version, publish to PyPI.
v0.7.0: RTE-generator
- Contract-phase RTE generator
v0.8.0: Stable version, publish to PyPI.
v0.9.0: System description
- System description support
v1.0.0: Stable version, publish to PyPI.
관련 프로젝트 살펴보기
불러오는 중…