-
Notifications
You must be signed in to change notification settings - Fork 71
VSS to VHAL mapper. #441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jankubovy
wants to merge
6
commits into
COVESA:master
Choose a base branch
from
jankubovy:vhal-generator
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
VSS to VHAL mapper. #441
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2ebb8cc
VSS to VHAL mapper.
jankubovy 710a42d
Update reviews
jankubovy e59223b
Test coverage
jankubovy c524848
Improve documentation.
jankubovy ae9a510
Change jsonvhal -> vhal in README.md
jankubovy 14cd5b7
Change Actuator's changeMode to ON_CHANGE or CONTINUOUS.
jankubovy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/ | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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), | ||
jankubovy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
xis for?