Skip to content

Commit

Permalink
Static Id Generator
Browse files Browse the repository at this point in the history
Signed-off-by: Adnan Bekan <[email protected]>
Signed-off-by: Niclas Wesemann <[email protected]>
  • Loading branch information
adobekan authored and erikbosch committed Dec 1, 2023
1 parent 152a372 commit d98dee9
Show file tree
Hide file tree
Showing 25 changed files with 1,626 additions and 20 deletions.
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@ Tools in the Obsolete Tools category may be deleted after 12 months.

Examples on tool usage can be found in the [VSS Makefile](https://github.com/COVESA/vehicle_signal_specification/blob/master/Makefile) and in tool-specific documentation, if existing.

Tool | Description | Tool Category | Documentation |
| ------------------ | ----------- | -------------------- |-------------------- |
| [vspec2x.py](vspec2x.py) | Parses and expands VSS into different text based output formats. Currently supports `json`, `yaml`,`csv`,`idl` | Community Supported | Try `./vspec2x --help` or check [vspec2x documentation](docs/vspec2x.md) |
[vspec2csv.py](vspec2csv.py) | Shortcut for [vspec2x.py](vspec2x.py) generating CSV output | Community Supported | Check [vspec2x documentation](docs/vspec2x.md) |
[vspec2ddsidl.py](vspec2ddsidl.py) | Shortcut for [vspec2x.py](vspec2x.py) generating DDS-IDL output | Community Supported | [VSS2DDSIDL Documentation](docs/VSS2DDSIDL.md). For general parameters check [vspec2x documentation](docs/vspec2x.md) |
[vspec2json.py](vspec2json.py) | Shortcut for [vspec2x.py](vspec2x.py) generating JSON output | Community Supported | Check [vspec2x documentation](docs/vspec2x.md) |
[vspec2yaml.py](vspec2yaml.py) | Shortcut for [vspec2x.py](vspec2x.py) generating flattened YAML output | Community Supported | Check [vspec2x documentation](docs/vspec2x.md) |
[vspec2binary.py](vspec2binary.py) | The binary toolset consists of a tool that translates the VSS YAML specification to the binary file format (see below), and two libraries that provides methods that are likely to be needed by a server that manages the VSS tree, one written in C, and one in Go | Community Supported | [vspec2binary Documentation](binary/README.md). For general parameters check [vspec2x documentation](docs/vspec2x.md) |
[vspec2franca.py](vspec2franca.py) | Parses and expands a VSS and generates a Franca IDL specification | Community Supported | Check [vspec2x documentation](docs/vspec2x.md) |
[vspec2c.py](obsolete/vspec2c.py) | The vspec2c tooling allows a vehicle signal specification to be translated from its source YAML file to native C code that has the entire specification encoded in it. | Obsolete (2022-11-01) | [Documentation](obsolete/vspec2c/README.md) |
[vspec2ocf.py](obsolete/ocf/vspec2ocf.py) | Parses and expands a VSS and generates a OCF specification | Obsolete (2022-11-01) | - |
[vspec2protobuf.py](vspec2protobuf.py) | Parses and expands a VSS and generates a Protobuf specification | Contrib | - |
[vspec2ttl.py](contrib/vspec2ttl/vspec2ttl.py) | Parses and expands a VSS and generates a TTL specification | Contrib | - |
[vspec2graphql.py](vspec2graphql.py) | Parses and expands a VSS and generates a GraphQL specification | Community Supported | [Documentation](docs/VSS2GRAPHQL.md) |
Tool | Description | Tool Category | Documentation |
| ------------------ | ----------- |-----------------------|-----------------------------------------------------------------------------------------------------------------------|
| [vspec2x.py](vspec2x.py) | Parses and expands VSS into different text based output formats. Currently supports `json`, `yaml`,`csv`,`idl` | Community Supported | Try `./vspec2x --help` or check [vspec2x documentation](docs/vspec2x.md) |
[vspec2csv.py](vspec2csv.py) | Shortcut for [vspec2x.py](vspec2x.py) generating CSV output | Community Supported | Check [vspec2x documentation](docs/vspec2x.md) |
[vspec2ddsidl.py](vspec2ddsidl.py) | Shortcut for [vspec2x.py](vspec2x.py) generating DDS-IDL output | Community Supported | [VSS2DDSIDL Documentation](docs/VSS2DDSIDL.md). For general parameters check [vspec2x documentation](docs/vspec2x.md) |
[vspec2json.py](vspec2json.py) | Shortcut for [vspec2x.py](vspec2x.py) generating JSON output | Community Supported | Check [vspec2x documentation](docs/vspec2x.md) |
[vspec2yaml.py](vspec2yaml.py) | Shortcut for [vspec2x.py](vspec2x.py) generating flattened YAML output | Community Supported | Check [vspec2x documentation](docs/vspec2x.md) |
[vspec2binary.py](vspec2binary.py) | The binary toolset consists of a tool that translates the VSS YAML specification to the binary file format (see below), and two libraries that provides methods that are likely to be needed by a server that manages the VSS tree, one written in C, and one in Go | Community Supported | [vspec2binary Documentation](binary/README.md). For general parameters check [vspec2x documentation](docs/vspec2x.md) |
[vspec2franca.py](vspec2franca.py) | Parses and expands a VSS and generates a Franca IDL specification | Community Supported | Check [vspec2x documentation](docs/vspec2x.md) |
[vspec2c.py](obsolete/vspec2c.py) | The vspec2c tooling allows a vehicle signal specification to be translated from its source YAML file to native C code that has the entire specification encoded in it. | Obsolete (2022-11-01) | [Documentation](obsolete/vspec2c/README.md) |
[vspec2ocf.py](obsolete/ocf/vspec2ocf.py) | Parses and expands a VSS and generates a OCF specification | Obsolete (2022-11-01) | - |
[vspec2protobuf.py](vspec2protobuf.py) | Parses and expands a VSS and generates a Protobuf specification | Contrib | - |
[vspec2ttl.py](contrib/vspec2ttl/vspec2ttl.py) | Parses and expands a VSS and generates a TTL specification | Contrib | - |
[vspec2graphql.py](vspec2graphql.py) | Parses and expands a VSS and generates a GraphQL specification | Community Supported | [Documentation](docs/VSS2GRAPHQL.md) |
[vspec2id.py](vspec2id.py) | Generates and validates static UIDs for a VSS | WIP | [vspec2id Documentation](./docs/vspec2id.md) |

## Tool Architecture

Expand Down
122 changes: 122 additions & 0 deletions docs/vspec2id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# vspec2id - vspec static UID generator and validator

The vspecID.py script is used to generate and validate static UIDs for all nodes in the tree.
They will be used as unique identifiers to transmit data between nodes. The static UIDs are
implemented to replace long strings like `Vehicle.Body.Lights.DirectionIndicator.Right.IsSignaling`
with a 4-byte identifier.

## General usage

```bash
usage: vspec2id.py [-h] [-I dir] [-e EXTENDED_ATTRIBUTES] [-s] [--abort-on-unknown-attribute] [--abort-on-name-style] [--format format] [--uuid] [--no-expand] [-o overlays] [-u unit_file]
[-vt vspec_types_file] [-ot <types_output_file>] [--json-all-extended-attributes] [--json-pretty] [--yaml-all-extended-attributes] [-v version] [--all-idl-features]
[--gqlfield GQLFIELD GQLFIELD] [--validate-static-uid VALIDATE_STATIC_UID] [--only-validate-no-export]
<vspec_file> <output_file>

Convert vspec to other formats.

positional arguments:
<vspec_file> The vehicle specification file to convert.
<output_file> The file to write output to.

...

IDGEN arguments:

--validate-static-uid VALIDATE_STATIC_UID
Path to validation file.
--only-validate-no-export
For pytests and pipelines you can skip the export of the <output_file>
```

## Example

To initially run this you will need a vehicle signal specification, e.g.
[COVESA Vehicle Signal Specification](https://github.com/COVESA/vehicle_signal_specification). If you are just starting
to use static UIDs the first run is simple. You will only use the static UID generator by running the command below.

```bash
cd path/to/your/vss-tools
./vspec2id.py ../vehicle_signal_specification/spec/VehicleSignalSpecification.vspec ../output_id_v1.vspec
```

Great, you generated your first overlay that will also be used as your validation file as soon as you update your
vehicle signal specification file.

### Generate e.g. yaml file with static UIDs

Now if you just want to generate a new e.g. yaml file including your static UIDs, please use the overlay function of
vspec2x by running the following command:

```bash
cd path/to/your/vss-tools
./vspec2yaml.py ../vehicle_signal_specification/spec/VehicleSignalSpecification.vspec -o ../output_id_v1.vspec -e staticUID vehicle_specification_with_uids.yaml
```

### Validation

In this case you want to validate changes of your vehicle specification. If you are doing a dry run try temporarily
renaming a node or changing the node's datatype, unit, description, or other. You will get warnings depending on your
changes in the vehicle signal specification.

The validation step compares your current changes of the vehicle signal specification to a previously generated file,
here we named it `../output_id_v1.vspec`. There are two types of changes `BREAKING CHANGES` and `NON-BREAKING CHANGES`.
A `BREAKING CHANGE` will generate a new hash for a node. A `NON-BREAKING CHANGE` will throw a warning, but the static
ID will remain the same. A `BREAKING CHANGE` is triggered when you change name/path, unit, type, datatype, enum values
(allowed), or minimum/maximum. These attributes are part of the hash so they a `BREAKING CHANGE` automatically
generates a new hash for a static UID.
In case you want to keep the same ID but rename a node, this we call a `SEMANTIC CHANGE`, you can add an attribute
called `fka` in the vspec (which is a list of strings) and add a list of names to it as shown below for `A.B.NewName`.
The same holds for path changes, if you move a node between layers you can add the `fka` attribute containing the
full path as shown below.

Before renaming `A.B.NewName` its name was `A.B.OldName`.

```
A.B.NewName:
datatype: string
type: actuator
allowed: ["YES", "NO"]
description: A.B.NewName's old name is 'OldName'. And its even older name is 'OlderName'.
fka: ['A.B.OldName', 'A.B.OlderName']
```

As stated if you want to rename the node `A.B.NewName` to `A.NewName` you can also write the `fka` attribute
stating its legacy path.

To summarize these are the `BREAKING CHANGES` that affect the hash and `NON-BREAKING CHANGES` that throw
warnings only:

| BREAKING CHANGES | | NON-BREAKING CHANGES |
|-----------------------|-----|----------------------|
| Qualified name | | Added attribute |
| Data type | | Deprecation |
| Type (i.e. node type) | | Deleted Attribute |
| Unit | | Change description |
| Enum values (allowed) | | |
| Minimum | | |
| Maximum | | |

Now you should know about all possible changes. To run the validation step, please do:

```bash
./vspecID.py ../vehicle_signal_specification/spec/VehicleSignalSpecification.vspec ../output_id_v2.vspec --validate-static-uid ../output_id_v1.vspec
```

Depending on what you changed in the vehicle signal specification the corresponding errors will be triggered.

Now, if the warning logs correspond to what you have changed since the last validation, you can continue to generate
e.g. a yaml file with your validated changes as described in the `Generate e.g. yaml file with static UIDs` step above.

### Tests

If you want to run the tests for the vspec2id implementation, please do

```bash
cd path/to/vss-tools
export PYTHONPATH=${PWD}
pytest tests/vspec/test_static_uids
```

Depending on how you are using the implementation you might have to activate your virtual environment as described on
the top README.
1 change: 1 addition & 0 deletions tests/vspec/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Ignore files produced during testing, if any
**/out.json
**/out.txt
**/out.vspec
Loading

0 comments on commit d98dee9

Please sign in to comment.