Skip to content

Commit d23c553

Browse files
committed
Update reviews
Signed-off-by: Jan Kubovy <jan.kubovy@bmw.de>
1 parent c8df463 commit d23c553

File tree

8 files changed

+161
-142
lines changed

8 files changed

+161
-142
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dependencies = [
88
"anytree>=2.12.1",
99
"bump2version>=1.0.1",
1010
"click>=8.1.7",
11+
"dataclasses-json>=0.6.7",
1112
"deprecation>=2.1.0",
1213
"graphql-core>=3.2.5",
1314
"importlib-metadata>=8.5.0",

src/vss_tools/cli_options.py

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -158,72 +158,3 @@ def validate_attribute(value):
158158
)
159159

160160
pretty_print_opt = option("--pretty/--no-pretty", help="Pretty print.", default=False, show_default=True)
161-
162-
vhal_map_opt = option(
163-
"--vhal-map",
164-
type=click.Path(dir_okay=False, readable=True, path_type=Path, exists=False),
165-
required=True,
166-
help="""
167-
Read a json file with mapping of VSS property names to Android vehicle property ids.
168-
The file containing json list of all VSS properties (leaves) mappings by vss_tools generated VHAL IDs.
169-
""",
170-
)
171-
172-
continuous_change_mode_opt = option(
173-
"--continuous-change-mode",
174-
type=click.Path(dir_okay=False, readable=True, path_type=Path, exists=True),
175-
required=False,
176-
help="Read a json file list of VSS paths which should be considered as continuous change mode.",
177-
)
178-
179-
output_dir_opt = option(
180-
"--output-dir",
181-
type=click.Path(dir_okay=True, readable=True, path_type=Path, exists=True),
182-
required=True,
183-
help="Output directory, where vhal specific generated files are saved into.",
184-
)
185-
186-
property_group_opt = option(
187-
"--property-group",
188-
type=int,
189-
required=False,
190-
default=1,
191-
show_default=True,
192-
help="""
193-
Group of generated VHAL properties: 1 = SYSTEM, 2 = VENDOR, 3 = BACKPORTED, 4 = VSS.
194-
See https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/automotive/vehicle/aidl_property/android/hardware/automotive/vehicle/VehiclePropertyGroup.aidl
195-
""",
196-
)
197-
198-
min_property_id_opt = option(
199-
"--min-property-id",
200-
type=int,
201-
required=False,
202-
default=1,
203-
show_default=True,
204-
help="Stating ID for newly generated properties. This considers only the last 2 bytes of the VHAL property ID.",
205-
)
206-
207-
extend_new_opt = option(
208-
"--extend-new/--no-extend-new",
209-
help="""
210-
Whether to extend the map with new VSS nodes from the spec not present in the map file or only update
211-
existing VHAL properties and ignores all new VSS nodes.
212-
""",
213-
default=True,
214-
show_default=True,
215-
)
216-
217-
override_vhal_units_opt = option(
218-
"--override-vhal-units/--no-override-vhal-units",
219-
help="Overrides previously generated VHAL units.",
220-
default=False,
221-
show_default=True,
222-
)
223-
224-
override_vhal_datatype_opt = option(
225-
"--override-vhal-datatype/--no-override-vhal-datatype",
226-
help="Overrides previously generated VHAL datatypes.",
227-
default=False,
228-
show_default=True,
229-
)

src/vss_tools/exporters/vhal.py

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,67 @@
1818

1919
@click.command()
2020
@clo.vspec_opt
21-
@clo.vhal_map_opt
22-
@clo.continuous_change_mode_opt
23-
@clo.output_dir_opt
24-
@clo.extend_new_opt
25-
@clo.property_group_opt
26-
@clo.min_property_id_opt
27-
@clo.override_vhal_units_opt
28-
@clo.override_vhal_datatype_opt
21+
@click.option(
22+
"--vhal-map",
23+
type=click.Path(dir_okay=False, readable=True, path_type=Path, exists=False),
24+
required=True,
25+
help="""
26+
Read a json file with mapping of VSS property names to Android vehicle property ids.
27+
The file containing json list of all VSS properties (leaves) mappings by vss_tools generated VHAL IDs.
28+
""",
29+
)
30+
@click.option(
31+
"--continuous-change-mode",
32+
type=click.Path(dir_okay=False, readable=True, path_type=Path, exists=True),
33+
required=False,
34+
help="Read a json file list of VSS paths which should be considered as continuous change mode.",
35+
)
36+
@click.option(
37+
"--output-dir",
38+
type=click.Path(dir_okay=True, readable=True, path_type=Path, exists=True),
39+
required=True,
40+
help="Output directory, where vhal specific generated files are saved into.",
41+
)
42+
@click.option(
43+
"--property-group",
44+
type=int,
45+
required=False,
46+
default=1,
47+
show_default=True,
48+
help="""
49+
Group of generated VHAL properties: 1 = SYSTEM, 2 = VENDOR, 3 = BACKPORTED, 4 = VSS.
50+
See https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/automotive/vehicle/aidl_property/android/hardware/automotive/vehicle/VehiclePropertyGroup.aidl
51+
""",
52+
)
53+
@click.option(
54+
"--min-property-id",
55+
type=int,
56+
required=False,
57+
default=1,
58+
show_default=True,
59+
help="Stating ID for newly generated properties. This considers only the last 2 bytes of the VHAL property ID.",
60+
)
61+
@click.option(
62+
"--extend-new/--no-extend-new",
63+
help="""
64+
Whether to extend the map with new VSS nodes from the spec not present in the map file or only update
65+
existing VHAL properties and ignores all new VSS nodes.
66+
""",
67+
default=True,
68+
show_default=True,
69+
)
70+
@click.option(
71+
"--override-vhal-units/--no-override-vhal-units",
72+
help="Overrides previously generated VHAL units.",
73+
default=False,
74+
show_default=True,
75+
)
76+
@click.option(
77+
"--override-vhal-datatype/--no-override-vhal-datatype",
78+
help="Overrides previously generated VHAL datatypes.",
79+
default=False,
80+
show_default=True,
81+
)
2982
def cli(
3083
vspec: Path,
3184
vhal_map: Path,

src/vss_tools/utils/vhal/property_constants.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ class VhalAreaType(Enum):
2626
VEHICLE_AREA_TYPE_VENDOR = 7 # VehicleAreaType.VENDOR java
2727
VEHICLE_AREA_TYPE_VENDOR_AIDL = int(0x08000000) # VehicleArea.VENDOR aidl
2828

29-
def __str__(self):
30-
if self.name == VhalAreaType.VEHICLE_AREA_TYPE_VENDOR_AIDL.name:
31-
return "VehicleArea.VENDOR"
32-
elif self.name == VhalAreaType.VEHICLE_AREA_TYPE_GLOBAL_AIDL.name:
33-
return "VehicleArea.GLOBAL"
34-
else:
35-
return f"VehicleAreaType.{self.name}"
29+
def __str__(self) -> str:
30+
d = {
31+
self.VEHICLE_AREA_TYPE_GLOBAL: "VehicleArea.GLOBAL",
32+
self.VEHICLE_AREA_TYPE_VENDOR: "VehicleArea.VENDOR",
33+
}
34+
return d.get(self, f"VehicleAreaType.{self.name}")
3635

3736

3837
class VhalPropertyGroup(Enum):
@@ -61,16 +60,13 @@ def get(group: int):
6160
sys.exit(1)
6261

6362
def __str__(self):
64-
if self.name == VhalPropertyGroup.VEHICLE_PROPERTY_GROUP_SYSTEM.name:
65-
return "VehiclePropertyGroup.SYSTEM"
66-
if self.name == VhalPropertyGroup.VEHICLE_PROPERTY_GROUP_VENDOR.name:
67-
return "VehiclePropertyGroup.VENDOR"
68-
if self.name == VhalPropertyGroup.VEHICLE_PROPERTY_GROUP_BACKPORTED.name:
69-
return "VehiclePropertyGroup.BACKPORTED"
70-
if self.name == VhalPropertyGroup.VEHICLE_PROPERTY_GROUP_VSS.name:
71-
return "VehiclePropertyGroup.VSS"
72-
else:
73-
return "VehiclePropertyGroup.SYSTEM"
63+
d = {
64+
self.VEHICLE_PROPERTY_GROUP_SYSTEM: "VehiclePropertyGroup.SYSTEM",
65+
self.VEHICLE_PROPERTY_GROUP_VENDOR: "VehiclePropertyGroup.VENDOR",
66+
self.VEHICLE_PROPERTY_GROUP_BACKPORTED: "VehiclePropertyGroup.BACKPORTED",
67+
self.VEHICLE_PROPERTY_GROUP_VSS: "VehiclePropertyGroup.VSS",
68+
}
69+
return d.get(self, "VehiclePropertyGroup.SYSTEM")
7470

7571

7672
class VSSDatatypesToVhal:
@@ -135,8 +131,7 @@ def get_property_type_repr(cls, datatype_id: int) -> str:
135131
"""
136132
datatype_name = VSSDatatypesToVhal.VHAL_TO_VSS_TYPE_MAP.get(datatype_id)
137133
if not datatype_name:
138-
logging.error(f"Invalid property type id {datatype_id}, must be one of IDs listed in VSSDataTypeToVhal")
139-
sys.exit()
134+
raise Exception(f"Invalid property type id {datatype_id}, must be one of IDs listed in VSSDataTypeToVhal")
140135

141136
return f"VehiclePropertyType.{datatype_name}"
142137

src/vss_tools/utils/vhal/vehicle_mapping.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,58 +7,61 @@
77
# SPDX-License-Identifier: MPL-2.0
88

99
from dataclasses import dataclass
10-
from typing import List, Optional
10+
from typing import List, Optional, Union
1111

12+
from dataclasses_json import LetterCase, dataclass_json
1213

13-
@dataclass
14+
15+
@dataclass_json(letter_case=LetterCase.CAMEL)
16+
@dataclass(frozen=True)
1417
class VehicleMappingItem:
1518
"""
1619
Represents a single vehicle mapping item.
1720
"""
1821

1922
name: str
20-
propertyId: int
21-
areaId: int
23+
property_id: int
24+
area_id: int
2225
access: int
23-
changeMode: int
26+
change_mode: int
2427
unit: str
2528
source: str
2629
formula: Optional[str] = None
2730
comment: Optional[str] = None
28-
configString: Optional[str] = None
31+
config_string: Optional[str] = None
2932

3033
datatype: Optional[str] = None
3134
type: Optional[str] = None
3235
min: Optional[int] = None
3336
max: Optional[int] = None
3437
allowed: Optional[List[str]] = None
35-
default: Optional[int] = None
38+
default: Optional[Union[Union[int, str], Union[List[int], List[str]]]] = None
3639
deprecation: Optional[str] = None
3740

3841
@property
39-
def vhalGroup(self):
42+
def vhal_group(self):
4043
"""
4144
VHAL group component of the property ID.
4245
"""
43-
return (self.propertyId & 0xF0000000) >> 28
46+
return (self.property_id & 0xF0000000) >> 28
4447

4548
@property
46-
def vhalArea(self):
49+
def vhal_area(self):
4750
"""
4851
VHAL area component of the property ID.
4952
"""
50-
return (self.propertyId & 0x0F000000) >> 24
53+
return (self.property_id & 0x0F000000) >> 24
5154

5255
@property
53-
def vhalType(self):
56+
def vhal_type(self):
5457
"""
5558
VHAL type component of the property ID.
5659
"""
57-
return (self.propertyId & 0x00FF0000) >> 16
60+
return (self.property_id & 0x00FF0000) >> 16
5861

5962
@property
60-
def vhalId(self):
63+
def vhal_id(self):
6164
"""
6265
VHAL unique ID component of the property ID.
6366
"""
64-
return self.propertyId & 0x0000FFFF
67+
return self.property_id & 0x0000FFFF

0 commit comments

Comments
 (0)