Skip to content

Commit

Permalink
Improved seat massager sample (#99)
Browse files Browse the repository at this point in the history
* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample

* Improved seat massager sample
  • Loading branch information
ashbeitz authored Mar 5, 2024
1 parent c549818 commit 17b94e9
Show file tree
Hide file tree
Showing 72 changed files with 1,861 additions and 656 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/check-spelling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ jobs:
- name: Install spell
run: sudo apt-get install -y spell
- name: Check spelling
# Check the spelling in all README.md files, excluding those in submodules and those in target directories.
run: |
./tools/check_spelling.sh ./README.md
./tools/check_spelling.sh ./container/README.md
./tools/check_spelling.sh ./core/common/README.md
./tools/check_spelling.sh ./dtdl-parser/README.md
./tools/check_spelling.sh ./docs/design/README.md
./tools/check_spelling.sh ./samples/managed_subscribe/README.md
find . -name README.md | grep -v external | grep -v target | xargs -I % ./tools/check_spelling.sh "%" || exit 255
shell: bash
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,6 @@ target/

# VSCodeCounter Extension
.VSCodeCounter/

# VS Code
.vscode
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ members = [
async-std = "^1.5"
bytes = "1.4.0"
config = "0.14.0"
derivative = "2.2.0"
dyn-clone = "1.0.14"
env_logger= "0.11.2"
futures = "0.3.28"
Expand All @@ -56,6 +57,7 @@ paho-mqtt = "0.12"
parking_lot = "0.12.1"
prost = "0.12"
prost-types = "0.12"
rand = "0.8.5"
regex = " 1.9.3"
sdl2 = "0.35.2"
serde = "1.0.160"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ sudo apt install -y libsdl2-dev
You will need to install dotnet-sdk for the dtdl-tools crate. This can be done by executing:

```shell
sudo apt install -y dotnet-sdk-7.0
sudo apt install -y dotnet-sdk-8.0
```

### <a name="install-mqtt-broker">Install MQTT Broker</a>
Expand Down
21 changes: 21 additions & 0 deletions digital-twin-model/.accepted_words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
DTDL
DTDL's
DTMIs
LD
MaxTempSinceLastReset
Structs
TargetTemperature
com
displayName
dtdl
dtmi
github
hasFloor
json
maxMultiplicity
md
metamodel
minMultiplicity
opendigitaltwins
sdv
src
1 change: 1 addition & 0 deletions digital-twin-model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2021"
license = "MIT"

[dependencies]
derivative = { workspace = true }
serde = { workspace = true }
serde_derive = { workspace = true }

Expand Down
91 changes: 91 additions & 0 deletions digital-twin-model/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Digital Twin Model

## Specifying the Digital Twin Model

The digital twin model is specified using the Digital Twin Definition Language ([DTDL V3](https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v3/DTDL.v3.md)). The DTDL is stored under the `digital-twin-model/dtdl` folder and each file defines a DTDL interface.

DTDL's behavior is defined by several metamodel classes. Initially, we will only use the Interface, Property, Command and Relationship metamodel classes.

## DTDL Instance Representation in JSON-LD

Instances of DTDL models are represented as JSON-LD objects. Each instance is a JSON object that includes the `@context`, `@id`, and `@type` fields, as well as any properties defined in the model.

The `@context` field provides the context required for interpreting the JSON-LD document. The `@id` field is a unique identifier for the instance, and the `@type` field specifies the DTDL model that the instance is based on. The properties of the instance are represented as key-value pairs in the JSON object.

Here's an example of a DTDL instance represented in JSON-LD:

```json
{
"@context": "dtmi:dtdl:context;3",
"@id": "dtmi:com:example:Thermostat:device1;1", // Unique identifier for the instance
"@type": "dtmi:com:example:Thermostat;1", // The DTDL model that the instance is based on
"Temperature": 20.0, // Property defined in the model
"TargetTemperature": 22.0, // Property defined in the model
"MaxTempSinceLastReset": 25.0 // Property defined in the model
}
```

In this example, the `@context` field specifies the version of DTDL being used. For DTDL version 3, the appropriate context specifier is `dtmi:dtdl:context;3`. The `@id` field is a unique identifier for the thermostat device instance, and the `@type` field specifies that the instance is based on the `dtmi:com:example:Thermostat;1` model. The `Temperature`, `TargetTemperature`, and `MaxTempSinceLastReset` fields are properties defined in the model, and their values are set for this specific instance.

In DTDL, a **Relationship** is a directional link from a source digital twin to a target digital twin. Relationships are used to create and navigate the graph of digital twins.

Here's an example of how a relationship might be represented in a DTDL model:

```json
{
"@context": "dtmi:dtdl:context;3",
"@id": "dtmi:com:example:Building;1",
"@type": "Interface",
"displayName": "Building",
"contents": [
{
"@type": "Relationship",
"name": "hasFloor",
"minMultiplicity": 0,
"maxMultiplicity": 100,
"target": "dtmi:com:example:Floor;1"
}
]
}
```

In this example, the `hasFloor` relationship represents a link from a `Building` instance to a `Floor` instance. The `minMultiplicity` and `maxMultiplicity` fields specify that a `Building` can have between 0 and 100 `Floor` instances. The `target` field specifies the DTDL model that the target of the relationship is based on.

Here's an example of how a relationship might be represented in a DTDL instance:

```json
{
"@context": "dtmi:dtdl:context;3",
"@id": "dtmi:com:example:Building:building1;1", // Unique identifier for the instance
"@type": "dtmi:com:example:Building;1", // The DTDL model that the instance is based on
"hasFloor": [
"dtmi:com:example:Floor:floor1;1",
"dtmi:com:example:Floor:floor2;1"
]
}
```

In this example, the `hasFloor` field is an array of identifiers for `Floor` instances that are related to the `Building` instance.

## Using the Digital Twin Model in the Code

The digital twin providers and consumers need to reference the Digital Twin Model to perform digital twin interactions. They need the following information from the model:

- the model identifiers (denoted by "@id" in the DTDL) to identify the part of the model that they want to use
- the model names (denoted by "name" in the DTDL) to identify the member of a model part that they want to use
- the property definitions to exchange the associated values
- the command definitions to send and receive the appropriate payloads.

We need to make the digital twin model accessible as code. Each programming language will need its own variant. In this code repository, we will
provide a Rust variant. We will place all of the code for the model's content in a single file named after the model and its version. In
this code repository, that file will be the 'digital-twin-model/src/sdv_v1.rs' file.

The 'sdv_v1.rs' file is based on the model content from the DTDL files located under 'digital-twin-model/dtdl/dtmi/sdv'. A legacy version of this file 'sdv_v0.rs' is also present; it remains to support some of the older samples.

The 'sdv_v1.rs' file will setup namespaces based on the DTMIs used in the DTDL files. These namespaces will allow developers to provide fully
qualified names that look similar to the DTMIs (minus the 'dtmi:sdv:' prefix).

For each namespace, we will define:

- Constants for model ids (“ID”), model descriptions (“DESCRIPTION”), and model member names (“NAME”).
- Structs named “TYPE” to define property values, command request payloads, command response payloads, and schema types.
120 changes: 120 additions & 0 deletions digital-twin-model/dtdl/dtmi/sdv/airbag_seat_massager-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
"@context": ["dtmi:dtdl:context;3"],
"@type": "Interface",
"@id": "dtmi:sdv:airbag_seat_massager;1",
"description": "Airbag Seat Massager Interface.",
"extends": "dtmi:sdv:seat_massager;1",
"contents": [
{
"@type": "Command",
"@id": "dtmi:sdv:airbag_seat_massager:store_sequence;1",
"name": "store_sequence",
"description": "Store a massage sequence.",
"request": {
"name": "request",
"description": "Request.",
"schema": {
"@type": "Object",
"fields": [
{
"name": "sequence_name",
"schema": "string"
},
{
"name": "sequence",
"schema": "dtmi:sdv:massage_sequence;1"
}
]
}
},
"response": {
"name": "response",
"description": "Response.",
"schema": {
"@type": "Object",
"fields": [
{
"name": "status",
"schema": "dtmi:sdv:airbag_seat_massager:status;1"
}
]
}
}
},
{
"@type": "Command",
"@id": "dtmi:sdv:airbag_seat_massager:perform_step;1",
"name": "perform_step",
"description": "Perform a step in the sequence.",
"request": {
"name": "request",
"description": "Request.",
"schema": {
"@type": "Object",
"fields": [
{
"name": "step",
"schema": "dtmi:sdv:massage_step;1"
}
]
}
},
"response": {
"name": "response",
"schema": {
"@type": "Object",
"fields": [
{
"name": "status",
"schema": "dtmi:sdv:airbag_seat_massager:status;1"
}
]
}
}
}
],
"schemas": [
{
"@id": "dtmi:sdv:airbag_seat_massager:status;1",
"@type": "Object",
"fields": [
{
"name": "code",
"schema": "integer"
},
{
"name": "message",
"schema": "string"
}
]
},
{
"@id": "dtmi:sdv:massage_sequence;1",
"@type": "Array",
"elementSchema": "dtmi:sdv:massage_step;1"
},
{
"@id": "dtmi:sdv:massage_step;1",
"@type": "Array",
"elementSchema": "dtmi:sdv:airbag_adjustment;1"
},
{
"@id": "dtmi:sdv:airbag_adjustment;1",
"@type": "Object",
"fields": [
{
"name": "airbag_identifier",
"schema": "integer"
},
{
"name": "inflation_level",
"schema": "integer"
},
{
"name": "inflation_duration_in_seconds",
"schema": "integer"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"@context": ["dtmi:dtdl:context;3"],
"@type": "Interface",
"@id": "dtmi:sdv:basic_airbag_seat_massager;1",
"description": "Basic Airbag Seat Massager Interface.",
"extends": "dtmi:sdv:airbag_seat_massager;1"
}
62 changes: 62 additions & 0 deletions digital-twin-model/dtdl/dtmi/sdv/cabin-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"@context": ["dtmi:dtdl:context;3"],
"@type": "Interface",
"@id": "dtmi:sdv:cabin;1",
"description": "Cabin Interface.",
"contents": [
{
"@type": "Relationship",
"@id": "dtmi:sdv:cabin:has_infotainment;1",
"target": "dtmi:sdv:infotainment;1",
"name": "has_infotainment",
"maxMultiplicity": 1
},
{
"@type": "Relationship",
"@id": "dtmi:sdv:cabin:has_hvac;1",
"target": "dtmi:sdv:hvac;1",
"name": "has_hvac",
"maxMultiplicity": 1
},
{
"@type": "Relationship",
"@id": "dtmi:sdv:cabin:has_seat;1",
"name": "has_seat",
"target": "dtmi:sdv:seat;1",
"properties": [
{
"@type": "Property",
"@id": "dtmi:sdv:seat:seat_row;1",
"name": "seat_row",
"schema": "integer"
},
{
"@type": "Property",
"@id": "dtmi:sdv:Seat:seat_position;1",
"name": "seat_position",
"schema": {
"@type": "Enum",
"valueSchema": "string",
"enumValues": [
{
"name": "left",
"displayName": "left",
"enumValue": "left"
},
{
"name": "center",
"displayName": "center",
"enumValue": "center"
},
{
"name": "right",
"displayName": "right",
"enumValue": "right"
}
]
}
}
]
}
]
}
31 changes: 31 additions & 0 deletions digital-twin-model/dtdl/dtmi/sdv/camera-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"@context": "dtmi:dtdl:context;3",
"@type": "Interface",
"@id": "dtmi:sdv:camera;1",
"description": "Camera Interface.",
"contents": [
{
"@type": "Property",
"@id": "dtmi:sdv:camera:feed;1",
"name": "feed",
"description": "The camera feed.",
"schema": {
"@type": "Object",
"fields": [
{
"name": "media_type",
"schema": "string"
},
{
"name": "media_content",
"description": "An array of bytes (represented by integers here).",
"schema": {
"@type": "Array",
"elementSchema": "integer"
}
}
]
}
}
]
}
Loading

0 comments on commit 17b94e9

Please sign in to comment.