Skip to content
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

Improved seat massager sample #99

Merged
merged 56 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
2989cf9
Improved seat massager sample
ashbeitz Feb 22, 2024
fad1845
Improved seat massager sample
ashbeitz Feb 27, 2024
7185b81
Improved seat massager sample
ashbeitz Feb 27, 2024
3d752d6
Improved seat massager sample
ashbeitz Feb 27, 2024
5c7e8b2
Improved seat massager sample
ashbeitz Feb 27, 2024
5af8f64
Improved seat massager sample
ashbeitz Feb 27, 2024
b3533c3
Improved seat massager sample
ashbeitz Feb 27, 2024
831b0d9
Improved seat massager sample
ashbeitz Feb 27, 2024
62391fa
Improved seat massager sample
ashbeitz Feb 28, 2024
65e057e
Improved seat massager sample
ashbeitz Feb 28, 2024
aef459c
Improved seat massager sample
ashbeitz Feb 29, 2024
b857560
Improved seat massager sample
ashbeitz Feb 29, 2024
0be6d15
Merge branch 'main' into ashbeitz/improvedSeatMassagerSample
ashbeitz Feb 29, 2024
840e418
Improved seat massager sample
ashbeitz Feb 29, 2024
cb1c71a
Merge branch 'ashbeitz/improvedSeatMassagerSample' of https://github.…
ashbeitz Feb 29, 2024
f33d5b8
Improved seat massager sample
ashbeitz Feb 29, 2024
ba6bfb8
Improved seat massager sample
ashbeitz Feb 29, 2024
5c59b1d
Improved seat massager sample
ashbeitz Feb 29, 2024
b464da1
Improved seat massager sample
ashbeitz Mar 1, 2024
a6e9d2c
Improved seat massager sample
ashbeitz Mar 1, 2024
90b6eed
Improved seat massager sample
ashbeitz Mar 1, 2024
b31d66c
Improved seat massager sample
ashbeitz Mar 1, 2024
cbf2c5b
Improved seat massager sample
ashbeitz Mar 1, 2024
86cd19f
Improved seat massager sample
ashbeitz Mar 1, 2024
c7d2f9e
Improved seat massager sample
ashbeitz Mar 1, 2024
23f307b
Improved seat massager sample
ashbeitz Mar 1, 2024
667baf5
Improved seat massager sample
ashbeitz Mar 1, 2024
c4e048e
Improved seat massager sample
ashbeitz Mar 1, 2024
e4a73d0
Improved seat massager sample
ashbeitz Mar 1, 2024
91b5eb1
Improved seat massager sample
ashbeitz Mar 1, 2024
4484f2f
Improved seat massager sample
ashbeitz Mar 1, 2024
9a3db5e
Improved seat massager sample
ashbeitz Mar 1, 2024
af28d1a
Improved seat massager sample
ashbeitz Mar 1, 2024
d468089
Improved seat massager sample
ashbeitz Mar 1, 2024
5ac1f5e
Improved seat massager sample
ashbeitz Mar 2, 2024
14b4d8b
Improved seat massager sample
ashbeitz Mar 2, 2024
9895860
Improved seat massager sample
ashbeitz Mar 2, 2024
55c96f2
Improved seat massager sample
ashbeitz Mar 2, 2024
3c0938f
Improved seat massager sample
ashbeitz Mar 2, 2024
d69eb89
Improved seat massager sample
ashbeitz Mar 2, 2024
0b6bf7a
Improved seat massager sample
ashbeitz Mar 2, 2024
6376d8e
Improved seat massager sample
ashbeitz Mar 2, 2024
05ad561
Improved seat massager sample
ashbeitz Mar 4, 2024
cd400ea
Improved seat massager sample
ashbeitz Mar 4, 2024
3fefed2
Improved seat massager sample
ashbeitz Mar 4, 2024
9c875de
Improved seat massager sample
ashbeitz Mar 4, 2024
4f4eea3
Improved seat massager sample
ashbeitz Mar 5, 2024
5fe8bbe
Improved seat massager sample
ashbeitz Mar 5, 2024
592d27c
Improved seat massager sample
ashbeitz Mar 5, 2024
000ec33
Improved seat massager sample
ashbeitz Mar 5, 2024
ad04abe
Improved seat massager sample
ashbeitz Mar 5, 2024
15c0c43
Improved seat massager sample
ashbeitz Mar 5, 2024
571c9d2
Improved seat massager sample
ashbeitz Mar 5, 2024
3979a59
Improved seat massager sample
ashbeitz Mar 5, 2024
b729bba
Improved seat massager sample
ashbeitz Mar 5, 2024
be709df
Improved seat massager sample
ashbeitz Mar 5, 2024
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
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 @@
{
ashbeitz marked this conversation as resolved.
Show resolved Hide resolved
"@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
Loading