Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions docs/vhal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# VHAL Exporter

The VHAL exporter maps the VSS tree to Android VHAL properties by creating or modifying given map file and generating
needed Java and AIDL sources.

The Android VHAL property ID is composed of 4 parts (0xGATTDDDD):

- [Group](https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/automotive/vehicle/aidl_property/android/hardware/automotive/vehicle/VehiclePropertyGroup.aidl): 1 nibble
- [Area](https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/automotive/vehicle/aidl_property/android/hardware/automotive/vehicle/VehicleArea.aidl): 1 nibble
- [Type](https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/automotive/vehicle/aidl_property/android/hardware/automotive/vehicle/VehiclePropertyType.aidl): 1 byte
- iDentifier: 2 bytes - as sequence (max 65535)

This mapper can create all group of properties defined in
[VehiclePropertyGroup](https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/automotive/vehicle/aidl_property/android/hardware/automotive/vehicle/VehiclePropertyGroup.aidl)
and one additional we call VSS to demonstrate the possibility of a VSS specific scope (group).

## Property Change Mode

Each VHAL property has one of the following change modes:

STATIC
: used to VSS node types ATTRIBUTE.

ON_CHANGE
: used for VSS node types ACTUATOR and SENSOR.

CONTINUOUS
: used for VSS node types ACTUATOR and SENSOR if the path of that VSS node is present in JSON file provided by `--continuous-change-mode`.

### Continuous Change Mode List Example

`vss_continuous.json`:
```json
[
"Vehicle.Speed",
"Vehicle.TraveledDistance",
"Vehicle.Powertrain.Range",
"Vehicle.Powertrain.CombustionEngine.Speed",
"Vehicle.OBD.EngineSpeed",
"Vehicle.Powertrain.ElectricMotor.Speed",
"Vehicle.Powertrain.CombustionEngine.EOT",
"Vehicle.Powertrain.CombustionEngine.EngineOil.Temperature",
"Vehicle.Powertrain.TractionBattery.StateOfCharge.CurrentEnergy",
"Vehicle.Powertrain.FuelSystem.AbsoluteLevel",
"Vehicle.Chassis.Axle.Row1.SteeringAngle",
"Vehicle.Chassis.Axle.Row2.SteeringAngle",
"Vehicle.Exterior.AirTemperature",
"Vehicle.Powertrain.CombustionEngine.ECT",
"Vehicle.Powertrain.CombustionEngine.EngineCoolant.Temperature",
"Vehicle.Powertrain.ElectricMotor.CoolantTemperature",
"Vehicle.Powertrain.ElectricMotor.EngineCoolant.Temperature",
"Vehicle.Powertrain.TractionBattery.StateOfCharge.Current",
"Vehicle.Powertrain.TractionBattery.StateOfCharge.Displayed",
"Vehicle.Powertrain.TractionBattery.Charging.ChargeCurrent.DC",
"Vehicle.Powertrain.TractionBattery.Charging.ChargeCurrent.Phase1",
"Vehicle.Powertrain.TractionBattery.Charging.ChargeCurrent.Phase2",
"Vehicle.Powertrain.TractionBattery.Charging.ChargeCurrent.Phase3",
"Vehicle.Powertrain.TractionBattery.Charging.ChargeVoltage.DC",
"Vehicle.Powertrain.TractionBattery.Charging.ChargeVoltage.Phase1",
"Vehicle.Powertrain.TractionBattery.Charging.ChargeVoltage.Phase2",
"Vehicle.Powertrain.TractionBattery.Charging.ChargeVoltage.Phase3",
"Vehicle.Powertrain.TractionBattery.Charging.ChargeRate",
"Vehicle.Powertrain.TractionBattery.Charging.TimeToComplete",
"Vehicle.Powertrain.TractionBattery.Temperature.Average",
"Vehicle.Chassis.Axle.Row1.Wheel.Left.Tire.Pressure",
"Vehicle.Chassis.Axle.Row1.Wheel.Right.Tire.Pressure",
"Vehicle.Chassis.Axle.Row2.Wheel.Left.Tire.Pressure",
"Vehicle.Chassis.Axle.Row2.Wheel.Right.Tire.Pressure"
]
```

## Examples

To generate SYSTEM properties use the following command. With SYSTEM properties we need to make sure not to conflict
with existing ones in the platform, therefore the use of `--min-property-id` is needed when generating the map file
for the first time:

```bash
vspec export vhal \
--vspec /path/to/vehicle_signal_specification/spec/VehicleSignalSpecification.vspec \
--min-property-id 32768 \
--vhal-map vss_to_android_property_map.json \
--continuous-change-mode vss_continuous.json \
--output-dir /path/to/output
```

To only update SYSTEM properties, i.e. ignore all newly added VSS nodes to the spec add `--no-extend-new` argument:

```bash
vspec export vhal \
--vspec /path/to/vehicle_signal_specification/spec/VehicleSignalSpecification.vspec \
--vhal-map vss_to_android_property_map.json \
--continuous-change-mode vss_continuous.json \
--output-dir /path/to/output \
--no-extend-new
```

To generate VENDOR properties use the argument `--property-group 2`:

```bash
vspec export vhal \
--vspec /path/to/vehicle_signal_specification/spec/VehicleSignalSpecification.vspec \
--property-group 2 \
--vhal-map vss_to_android_property_map.json \
--continuous-change-mode vss_continuous.json \
--output-dir /path/to/output
```

To generate VHAL properties in custom VSS group use the argument `--property-group 4`:

```bash
vspec export vhal \
--vspec /path/to/vehicle_signal_specification/spec/VehicleSignalSpecification.vspec \
--property-group 4 \
--vhal-map vss_to_android_property_map.json \
--continuous-list-change-mode vss_continuous.json \
--output-dir /path/to/output/
```
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ readme = "README.md"
requires-python = ">=3.10"
dependencies = [
"anytree>=2.12.1",
"bump2version>=1.0.1", # x
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be in dev dependencies but I guess that's what the x is for?

"click>=8.1.7",
"dataclasses-json>=0.6.7",
"deprecation>=2.1.0", # x
"graphql-core>=3.2.5",
"importlib-metadata>=8.5.0", # x
"jsonschema>=4.23.0",
"pydantic>=2.9.2",
"pyyaml>=6.0.2",
"rdflib>=7.1.1",
"rich-click>=1.8.3",
"rich>=13.9.4",
"ruff>=0.7.3", # x
"graphene>=3.4.3",
"pandas>=2.2.3",
]
Expand Down
1 change: 1 addition & 0 deletions src/vss_tools/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def cli(ctx: click.Context, log_level: str, log_file: Path):
"tree": "vss_tools.exporters.tree:cli",
"samm": "vss_tools.exporters.samm:cli",
"go": "vss_tools.exporters.go:cli",
"vhal": "vss_tools.exporters.vhal:cli",
},
)
@click.pass_context
Expand Down
128 changes: 128 additions & 0 deletions src/vss_tools/exporters/vhal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Copyright (c) 2025 Contributors to COVESA
#
# This program and the accompanying materials are made available under the
# terms of the Mozilla Public License 2.0 which is available at
# https://www.mozilla.org/en-US/MPL/2.0/
#
# SPDX-License-Identifier: MPL-2.0

from pathlib import Path

import rich_click as click

import vss_tools.cli_options as clo
from vss_tools import log
from vss_tools.main import get_trees
from vss_tools.utils.vhal.vhal_mapper import VhalMapper


@click.command()
@clo.vspec_opt
@click.option(
"--vhal-map",
type=click.Path(dir_okay=False, readable=True, path_type=Path, exists=False),
required=True,
help="""
Read a json file with mapping of VSS property names to Android vehicle property ids.
The file containing json list of all VSS properties (leaves) mappings by vss_tools generated VHAL IDs.
""",
)
@click.option(
"--continuous-change-mode",
type=click.Path(dir_okay=False, readable=True, path_type=Path, exists=True),
required=False,
help="Read a json file list of VSS paths which should be considered as continuous change mode.",
)
@click.option(
"--output-dir",
type=click.Path(dir_okay=True, readable=True, path_type=Path, exists=True),
required=True,
help="Output directory, where vhal specific generated files are saved into.",
)
@click.option(
"--property-group",
type=int,
required=False,
default=1,
show_default=True,
help="""
Group of generated VHAL properties: 1 = SYSTEM, 2 = VENDOR, 3 = BACKPORTED, 4 = VSS.
See https://cs.android.com/android/platform/superproject/main/+/main:hardware/interfaces/automotive/vehicle/aidl_property/android/hardware/automotive/vehicle/VehiclePropertyGroup.aidl
""",
)
@click.option(
"--min-property-id",
type=int,
required=False,
default=1,
show_default=True,
help="Stating ID for newly generated properties. This considers only the last 2 bytes of the VHAL property ID.",
)
@click.option(
"--extend-new/--no-extend-new",
help="""
Whether to extend the map with new VSS nodes from the spec not present in the map file or only update
existing VHAL properties and ignores all new VSS nodes.
""",
default=True,
show_default=True,
)
@click.option(
"--override-vhal-units/--no-override-vhal-units",
help="Overrides previously generated VHAL units.",
default=False,
show_default=True,
)
@click.option(
"--override-vhal-datatype/--no-override-vhal-datatype",
help="Overrides previously generated VHAL datatypes.",
default=False,
show_default=True,
)
def cli(
vspec: Path,
vhal_map: Path,
continuous_change_mode: Path | None,
output_dir: Path,
extend_new: bool,
property_group: int,
min_property_id: int,
override_vhal_units: bool,
override_vhal_datatype: bool,
):
"""
Export as VSS as VHAL mapping file, Java and AIDL sources.
"""
tree, datatype_tree = get_trees(
vspec=vspec,
include_dirs=(),
aborts=(),
strict=False,
extended_attributes=(),
quantities=(),
units=(),
types=(),
overlays=(),
expand=True,
)

log.info("Generating JSON output for VHAL Mapper...")
mapper = VhalMapper(
group=property_group,
include_new=extend_new,
starting_id=min_property_id,
override_units=override_vhal_units,
override_datatype=override_vhal_datatype,
)

if continuous_change_mode is not None:
mapper.load_continuous_list(continuous_change_mode)
mapper.load(vhal_map, tree)
mapper.safe(vhal_map)

java_output = output_dir / "VehiclePropertyIdsVss.java"
permissions_output = output_dir / "VssPermissions.java"
mapper.generate_java_files(java_output, permissions_output)

aidl_output = output_dir / "VehiclePropertyVss.aidl"
mapper.generate_aidl_file(aidl_output)
7 changes: 7 additions & 0 deletions src/vss_tools/utils/vhal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) 2025 Contributors to COVESA
#
# This program and the accompanying materials are made available under the
# terms of the Mozilla Public License 2.0 which is available at
# https://www.mozilla.org/en-US/MPL/2.0/
#
# SPDX-License-Identifier: MPL-2.0
Loading