Skip to content

Commit

Permalink
Various fixes before relesae
Browse files Browse the repository at this point in the history
- Change term "DataDictionary" to "Data type"
- Removed 's'-suffix on unit test file names
- Fix name PhysicalDimentionRef -> PhysicalDimensionRef
- Reorganized and updated CHANGELOG
  • Loading branch information
cogu committed Oct 25, 2023
1 parent 8a554ee commit d0bcfbb
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 101 deletions.
106 changes: 69 additions & 37 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,83 @@
# Changelog

Notable changes.
Elements marked as `collectable` means that they can be added directly to a package.
Non-collectable elements are various sub-elements to collectable elements.

## [Unreleased]
The name in the parenthesis after each element is the name used in the XML schema (XSD file).

### XML - Collectable elements
## [v0.5.0]

* ApplicationArrayDataType
* ApplicationPrimitiveDataType
* ApplicationRecordDataType
* CompuMethod
* DataConstraint
* ImplementationDataType
* SwBaseType
* Unit
* DataTypeMappingSet
### Added

### XML - Documentation elements
#### XML - Documentation elements

* DocumentationBlock
* EmphasisText
* MultiLanguageLongName
* MultiLanguageOverviewParagraph
* MultiLanguageParagraph
* MultiLanguageVerbatim
* Subscript
* Superscript
* TechnicalTerm
* DocumentationBlock | DOCUMENTATION-BLOCK
* EmphasisText | EMPHASIS-TEXT
* MultilanguageLongName | MULTILANGUAGE-LONG-NAME
* MultiLanguageOverviewParagraph | MULTI-LANGUAGE-OVERVIEW-PARAGRAPH
* MultiLanguageParagraph | MULTI-LANGUAGE-PARAGRAPH
* MultiLanguageVerbatim | MULTI-LANGUAGE-VERBATIM
* Subscript | SUPSCRIPT (This not a typo)
* Superscript | SUPSCRIPT
* TechnicalTerm | TT

### XML - DataDictionary elements
#### XML - Data type elements

* ApplicationArrayElement
* ApplicationRecordElement
* AutosarDataType
* ImplementationDataTypeElement
* SwBitRepresentation
* SwDataDefProps
* SwDataDefPropsConditional
* SwPointerTargetProps
* SwTextProps
* SymbolProps
* ApplicationArrayDataType | APPLICATION-ARRAY-DATA-TYPE | `collectable`
* ApplicationPrimitiveDataType | APPLICATION-PRIMITIVE-DATA-TYPE | `collectable`
* ApplicationRecordDataType | APPLICATION-RECORD-DATA-TYPE | `collectable`
* DataTypeMappingSet | DATA-TYPE-MAPPING-SET | `collectable`
* ImplementationDataType | IMPLEMENTATION-DATA-TYPE | `collectable`
* SwBaseType | SW-BASE-TYPE | `collectable`
* ApplicationArrayElement | APPLICATION-ARRAY-ELEMENT
* ApplicationRecordElement | APPLICATION-RECORD-ELEMENT
* AutosarDataType | AUTOSAR-DATA-TYPE
* DataTypeMap | DATA-TYPE-MAP
* ImplementationDataTypeElement | IMPLEMENTATION-DATA-TYPE-ELEMENT
* SwBitRepresentation | SW-BIT-REPRESENTATION
* SwDataDefProps | SW-DATA-DEF-PROPS
* SwDataDefPropsConditional | SW-DATA-DEF-PROPS-CONDITIONAL + SW-DATA-DEF-PROPS-CONTENT
* SwPointerTargetProps | SW-POINTER-TARGET-PROPS
* SwTextProps | SW-TEXT-PROPS
* SymbolProps | SYMBOL-PROPS

### XML - Datatype elements
#### XML - Unit elements

* DataTypeMap
* Unit | UNIT | `collectable`

### Implementation Model - Elements
#### XML - Computation and constraint elements

* CompuMethod | COMPU-METHOD | `collectable`
* DataConstraint | DATA-CONSTR | `collectable`
* CompuConst | COMPU-CONST
* CompuRational | COMPU-RATIONAL-COEFFS
* CompuScale | COMPU-SCALE
* Computation | COMPU
* DataConstraintRule | DATA-CONSTR-RULE
* InternalConstraint | INTERNAL-CONSTRS
* PhysicalConstraint | PHYS-CONSTRS
* ScaleConstraint | SCALE-CONSTR

#### XML - Reference elements

These elements exist in Python only. They are returned as objects when calling
the `ref` method on various XML elements.

Only a handful of XML element classes have their corresponding `ref` method implemented (will be fixed later).

* ApplicationDataTypeRef
* AutosarDataTypeRef
* CompuMethodRef
* DataConstraintRef
* FunctionPtrSignatureRef
* ImplementationDataTypeRef
* IndexDataTypeRef
* PhysicalDimensionRef
* SwAddrMethodRef
* SwBaseTypeRef
* UnitRef

#### Implementation Model - Elements

* ArrayType
* BaseType
Expand All @@ -54,7 +86,7 @@ Notable changes.
* RefType
* ScalarType

### RTE Data Type Generator
#### RTE Data Type Generator

* ArrayType
* BaseType
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ When saving, use the `schema_version` parameter to select desired version (integ

Only Clasic AUTOSAR will be supported.

## Supported XML elements

For currently supported XML elements, see the [CHANGELOG](CHANGELOG.md) file.

## Requirements

* Python 3.10+
Expand Down
71 changes: 35 additions & 36 deletions src/autosar/xml/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def _accepted_subtypes(self) -> set[ar_enum.IdentifiableSubTypes]:
return {ar_enum.IdentifiableSubTypes.DATA_CONSTR}


class PhysicalDimentionRef(BaseRef):
class PhysicalDimensionRef(BaseRef):
"""
PhysicalDimension reference
"""
Expand Down Expand Up @@ -1548,11 +1548,11 @@ def __init__(self, name: str,
display_name: str | SingleLanguageUnitNames | None = None,
factor: float | None = None,
offset: float | None = None,
physical_dimension_ref: str | PhysicalDimentionRef | None = None,
physical_dimension_ref: str | PhysicalDimensionRef | None = None,
**kwargs: dict) -> None:
super().__init__(name, **kwargs)
self.display_name: SingleLanguageUnitNames | None = None # .DISPLAY-NAME
self.physical_dimension_ref: PhysicalDimentionRef | None = None # .PHYSICAL-DIMENSION-REF
self.physical_dimension_ref: PhysicalDimensionRef | None = None # .PHYSICAL-DIMENSION-REF
self.factor: float | None = None # .FACTOR-SI-TO-UNIT
self.offset: float | None = None # .OFFSET-SI-TO-UNIT
if display_name is not None:
Expand All @@ -1564,16 +1564,16 @@ def __init__(self, name: str,
raise TypeError(f"display_name: Invalid type '{str(type(display_name))}'")
if physical_dimension_ref is not None:
if isinstance(physical_dimension_ref, str):
self.physical_dimension_ref = PhysicalDimentionRef(display_name)
elif isinstance(physical_dimension_ref, PhysicalDimentionRef):
self.physical_dimension_ref = PhysicalDimensionRef(display_name)
elif isinstance(physical_dimension_ref, PhysicalDimensionRef):
self.physical_dimension_ref = physical_dimension_ref
else:
raise TypeError(f"physical_dimension_ref: Invalid type '{str(type(physical_dimension_ref))}'")
self._assign_optional('factor', factor, float)
self._assign_optional('offset', offset, float)


# Data dictionary elements
# Data type elements


class BaseType(ARElement):
Expand Down Expand Up @@ -1947,7 +1947,7 @@ def append(self, elem: "ImplementationDataTypeElement") -> None:

class ImplementationDataType(AutosarDataType):
"""
IMPLEMENTATION-DATA-TYPE
AR: IMPLEMENTATION-DATA-TYPE
Type: Concrete
Tag Variants: 'IMPLEMENTATION-DATA-TYPE'
"""
Expand Down Expand Up @@ -2229,35 +2229,6 @@ def ref(self) -> ApplicationDataTypeRef | None:
value = '/'.join(reversed(ref_parts))
return ApplicationDataTypeRef(value, ar_enum.IdentifiableSubTypes.APPLICATION_RECORD_DATA_TYPE)

# Software address method (partly implemented)


class SwAddrMethod(ARElement):
"""
Complex-type AR:SW-ADDR-METHOD
Type: Concrete:
Tag Variants: SW-ADDR-METHOD
"""

def __init__(self, name: str, **kwargs) -> None:
super().__init__(name, **kwargs)
self.memory_allocation_keyword_policy = None # .MEMORY-ALLOCATION-KEYWORD-POLICY
self.options = [] # .OPTIONS
self.section_initialization_policy = None # .SECTION-INITIALIZATION-POLICY
self.section_type = None # .SECTION-TYPE

def ref(self) -> SwAddrMethodRef:
"""
Reference
"""
assert self.parent is not None
ref_parts: list[str] = [self.name]
self.parent.update_ref_parts(ref_parts)
value = '/'.join(reversed(ref_parts))
return SwAddrMethodRef(value)

# Datatype elements


class DataTypeMap(ARObject):
"""
Expand Down Expand Up @@ -2308,6 +2279,34 @@ def append(self, element: DataTypeMap) -> None:
else:
raise TypeError(f'Unexpected type: "{str(type(element))}"')


# Software address method (partly implemented)


class SwAddrMethod(ARElement):
"""
Complex-type AR:SW-ADDR-METHOD
Type: Concrete:
Tag Variants: SW-ADDR-METHOD
"""

def __init__(self, name: str, **kwargs) -> None:
super().__init__(name, **kwargs)
self.memory_allocation_keyword_policy = None # .MEMORY-ALLOCATION-KEYWORD-POLICY
self.options = [] # .OPTIONS
self.section_initialization_policy = None # .SECTION-INITIALIZATION-POLICY
self.section_type = None # .SECTION-TYPE

def ref(self) -> SwAddrMethodRef:
"""
Reference
"""
assert self.parent is not None
ref_parts: list[str] = [self.name]
self.parent.update_ref_parts(ref_parts)
value = '/'.join(reversed(ref_parts))
return SwAddrMethodRef(value)

# !!UNFINISHED!! Port Interfaces


Expand Down
19 changes: 7 additions & 12 deletions src/autosar/xml/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,14 @@ def __init__(self,
# CompuMethod
'COMPU-METHOD': self._read_compu_method,

# Data Dictionary
# Data type elements
'APPLICATION-ARRAY-DATA-TYPE': self._read_application_array_data_type,
'APPLICATION-RECORD-DATA-TYPE': self._read_application_record_data_type,
'APPLICATION-PRIMITIVE-DATA-TYPE': self._read_application_primitive_data_type,
'SW-BASE-TYPE': self._read_sw_base_type,
'SW-ADDR-METHOD': self._read_sw_addr_method,
'IMPLEMENTATION-DATA-TYPE': self._read_implementation_data_type,
'DATA-TYPE-MAPPING-SET': self._read_data_type_mapping_set,

# Constraint elements
'DATA-CONSTR': self._read_data_constraint,
Expand All @@ -111,9 +112,6 @@ def __init__(self,

# Unit elements
'UNIT': self._read_unit,

# Datatype elements
'DATA-TYPE-MAPPING-SET': self._read_data_type_mapping_set,
}
self.switcher_non_collectable = { # Non-collectable, used only for unit testing
# Documentation elements
Expand Down Expand Up @@ -143,7 +141,7 @@ def __init__(self,
'INTERNAL-CONSTRS': self._read_internal_constraint,
'PHYS-CONSTRS': self._read_physical_constraint,
'DATA-CONSTR-RULE': self._read_data_constraint_rule,
# DataDictionary elements
# Data type elements
'BASE-TYPE-REF': self._read_sw_base_type_ref,
'SW-BIT-REPRESENTATION': self._read_sw_bit_representation,
'SW-DATA-DEF-PROPS-CONDITIONAL': self._read_sw_data_def_props_conditional,
Expand All @@ -152,11 +150,10 @@ def __init__(self,
'SYMBOL-PROPS': self._read_symbol_props,
'IMPLEMENTATION-DATA-TYPE-ELEMENT': self._read_implementation_data_type_element,
'APPLICATION-RECORD-ELEMENT': self._read_application_record_element,
'DATA-TYPE-MAP': self._read_data_type_map,
# Reference elements
'PHYSICAL-DIMENSION-REF': self._read_physical_dimension_ref,
'APPLICATION-DATA-TYPE-REF': self._read_application_data_type_ref,
# Datatype elements
'DATA-TYPE-MAP': self._read_data_type_map,
}
self.switcher_all = {}
self.switcher_all.update(self.switcher_collectable)
Expand Down Expand Up @@ -1264,7 +1261,7 @@ def _read_unit_group(self, child_elements: ChildElementMap, data: dict) -> None:
if xml_child is not None:
data["physical_dimension_ref"] = self._read_physical_dimension_ref(xml_child)

# DataDictionary elements
# Data type elements

def _read_sw_addr_method(self, xml_element: ElementTree.Element) -> ar_element.SwAddrMethod:
"""
Expand Down Expand Up @@ -1894,7 +1891,7 @@ def _read_unit_ref(self, xml_elem: ElementTree.Element):
self._raise_parse_error(xml_elem, f"Invalid DEST attribute '{dest_text}'. Expected 'UNIT'")
return ar_element.UnitRef(xml_elem.text)

def _read_physical_dimension_ref(self, xml_elem: ElementTree.Element) -> ar_element.PhysicalDimentionRef:
def _read_physical_dimension_ref(self, xml_elem: ElementTree.Element) -> ar_element.PhysicalDimensionRef:
"""
Reads PHYSICAL-DIMENSION-REF
Type: Concrete
Expand All @@ -1904,7 +1901,7 @@ def _read_physical_dimension_ref(self, xml_elem: ElementTree.Element) -> ar_elem
dest_enum = ar_enum.xml_to_enum('IdentifiableSubTypes', dest_text, self.schema_version)
if dest_enum != ar_enum.IdentifiableSubTypes.PHYSICAL_DIMENSION:
self._raise_parse_error(xml_elem, f"Invalid DEST attribute '{dest_text}'. Expected 'PHYSICAL-DIMENSION'")
return ar_element.PhysicalDimentionRef(xml_elem.text)
return ar_element.PhysicalDimensionRef(xml_elem.text)

def _read_index_data_type_ref(self, xml_elem: ElementTree.Element) -> ar_element.IndexDataTypeRef:
"""
Expand Down Expand Up @@ -1949,8 +1946,6 @@ def _read_base_ref_attributes(self, attr: dict, data: dict) -> None:
if data['dest'] is None:
raise ar_exception.ParseError("Missing required attribute 'DEST'")

# DataType elements

def _read_data_type_map(self, xml_element: ElementTree.Element) -> ar_element.DataTypeMap:
"""
Reads AR:DATA-TYPE-MAP
Expand Down
Loading

0 comments on commit d0bcfbb

Please sign in to comment.