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

New demo for dog mode props and cmds #18

Merged
merged 34 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f9a135f
New demo for dog mode props and cmds
ashbeitz Feb 3, 2023
b3be214
New demo for dog mode props and cmds
ashbeitz Feb 4, 2023
e44e4d1
Add command support
ashbeitz Feb 5, 2023
c11ccb6
Add command support
ashbeitz Feb 5, 2023
40cd47a
Add command support
ashbeitz Feb 5, 2023
252db30
New demo for dog mode props and cmds
ashbeitz Feb 5, 2023
c270ea8
New demo for dog mode props and cmds
ashbeitz Feb 5, 2023
beedbbc
New demo for dog mode props and cmds
ashbeitz Feb 6, 2023
a5b7f00
New demo for dog mode props and cmds
ashbeitz Feb 6, 2023
5a10556
New demo for dog mode props and cmds
ashbeitz Feb 6, 2023
b120a72
New demo for dog mode props and cmds
ashbeitz Feb 7, 2023
83da34a
New demo for dog mode props and cmds
ashbeitz Feb 8, 2023
67d9efd
New demo for dog mode props and cmds
ashbeitz Feb 9, 2023
90929cc
New demo for dog mode props and cmds
ashbeitz Feb 10, 2023
e284aa8
New demo for dog mode props and cmds
ashbeitz Feb 10, 2023
591b337
New demo for dog mode props and cmds
ashbeitz Feb 11, 2023
196cf5d
New demo for dog mode props and cmds
ashbeitz Feb 11, 2023
3970f0c
New demo for dog mode props and cmds
ashbeitz Feb 11, 2023
4baf1b5
New demo for dog mode props and cmds
ashbeitz Feb 11, 2023
402ae8c
New demo for dog mode props and cmds
ashbeitz Feb 11, 2023
684e887
New demo for dog mode props and cmds
ashbeitz Feb 14, 2023
3010f40
New demo for dog mode props and cmds
ashbeitz Feb 14, 2023
8f08de5
New demo for dog mode props and cmds
ashbeitz Feb 14, 2023
0f00076
New demo for dog mode props and cmds
ashbeitz Feb 14, 2023
3c6980d
New demo for dog mode props and cmds
ashbeitz Feb 15, 2023
ff3017c
New demo for dog mode props and cmds
ashbeitz Feb 16, 2023
06a3f87
New demo for dog mode props and cmds
ashbeitz Feb 16, 2023
245ba37
New demo for dog mode props and cmds
ashbeitz Feb 16, 2023
bd946ac
New demo for dog mode props and cmds
ashbeitz Feb 16, 2023
2051e04
New demo for dog mode props and cmds
ashbeitz Feb 17, 2023
002dd75
New demo for dog mode props and cmds
ashbeitz Feb 17, 2023
33ec3c9
New demo for dog mode props and cmds
ashbeitz Feb 17, 2023
501374a
New demo for dog mode props and cmds
ashbeitz Feb 17, 2023
1ac4436
New demo for dog mode props and cmds
ashbeitz Feb 17, 2023
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
6 changes: 3 additions & 3 deletions .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Install nightly Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
toolchain: nightly-2022-08-11
default: true
override: true
components: clippy, rustfmt
Expand Down Expand Up @@ -61,12 +61,12 @@ jobs:
- name: Install nightly Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
toolchain: nightly-2022-08-11
default: true
override: true
- name: Cache Dependencies
uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build
- name: Test
run: cargo test
run: cargo test
23 changes: 22 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,32 @@
members = [
"common",
"common-test",
"dt-model/dt-model-identifiers",
"proto",
"dtdl-parser",
"in-vehicle-digital-twin",
"samples/command/consumer",
"samples/command/provider",
"samples/mixed/consumer",
ashbeitz marked this conversation as resolved.
Show resolved Hide resolved
"samples/mixed/provider",
"samples/property/consumer",
"samples/property/provider"
]
]

[workspace.dependencies]
async-std = "^1.5"
env_logger= "0.10.0"
futures = "0.3"
generic-json = "^0.7"
iref = "^2.0.3"
lazy_static = "1.4.0"
log = "^0.4"
prost = "0.11"
regex = " 1.7.1"
tokio = "1.0"
tonic = "0.8.2"
tonic-build = "0.8.2"
serde_json = "^1.0"
strum = "0.24"
strum_macros = "0.24"
uuid = "1.2.2"
44 changes: 37 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ sudo apt install gcc

### <a name="install-rust">Install Rust</a>

At this point in time, you will need to use the nightly release of Rust. While it is not ideal to rely on a nightly release, we should be able to rely on the
At this point in time, you will need to use a nightly release of Rust. While it is not ideal to rely on a nightly release, we should be able to rely on the
stable release of Rust sometime in the not too distant future when some of the Rust crates that we use can all rely on it as well. To install Rust, do the following:

```shell
sudo apt update
sudo apt install -y snapd
sudo snap install rustup --classic
rustup toolchain install nightly
rustup default nightly
rustup toolchain install nightly-2022-08-11
rustup default nightly-2022-08-11
```

If you have already installed Rust, but you are using another release, then you can switch to the nightly release by running the following commands:
If you have already installed Rust, but you are using another release, then you can switch to the nightly-2022-08-11 release by running the following commands:

```shell
rustup toolchain install nightly
rustup default nightly
rustup toolchain install nightly-2022-08-11
rustup default nightly-2022-08-11
```

### <a name="install-protobuf-compiler">Install Protobuf Compiler</a>
Expand Down Expand Up @@ -102,7 +102,8 @@ Currently, we have no integration tests or end-to-end tests.

## <a name="running-the-demo">Running the Demo</a>

There are currently two demos: one that demonstrates the use of a property and one that demonstrates the use of a command.
There are currently three demos: one that demonstrates the use of a property, one that demonstrates the use of a command and one that
demonstrates the mixed use of properties and command.

The following instructions are for the demo for the use of a property.

Expand Down Expand Up @@ -153,3 +154,32 @@ trademarks or logos is subject to and must follow
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
Any use of third-party trademarks or logos are subject to those third-party's policies.

The following instructions are for the demo for the mixed use of commands and properties.

Steps:

1. The best way to run the demo is by using three windows: one running the In-Vehicle Digital Twin, one running the Provider and one running a Consumer.
Orientate the three windows so that they are lined up in a column. The top window can be used for the In-Vehicle Digital Twin.
The middle window can be used for the Provider. The bottom window can be used for a Consumer.<br>
1. In each window run the following command too set the DTDL_PATH environment variable.
ashbeitz marked this conversation as resolved.
Show resolved Hide resolved
Make sure that you replace "{repo-root-dir}" with the repository root directory on the machine where you are running the demo.<br><br>
`export DTDL_PATH="{repo-root-dir}/ibeji/opendigitaltwins-dtdl/DTDL;{repo-root-dir}/ibeji/dtdl;{repo-root-dir}/ibeji/samples/mixed/dtdl"`<br>
1. In each window change directory to the directory containing the build artifacts.
Make sure that you replace "{repo-root-dir}" with the repository root directory on the machine where you are running the demo.<br><br>
`cd {repo-root-dir}/ibeji/target/debug`<br>
1. In the top window, run:<br><br>
`./in-vehicle-digital-twin`<br>
1. In the middle window, run:<br><br>
`./mixed-provider`<br>
1. In the bottom window, run:<br><br>
`./mixed-consumer`<br>
1. Use control-c in each of the windows when you wish to stop the demo.

## <a name="trademarks">Trademarks</a>

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
trademarks or logos is subject to and must follow
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
Any use of third-party trademarks or logos are subject to those third-party's policies.
2 changes: 1 addition & 1 deletion common-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ edition = "2021"
license = "MIT"

[dependencies]
log = "0.4.17"
log = { workspace = true}
4 changes: 2 additions & 2 deletions common-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ pub fn set_dtdl_path() {
"{repo_dir}/opendigitaltwins-dtdl/DTDL;{repo_dir}/iot-plugandplay-models;{repo_dir}/dtdl"
);
env::set_var(DTDL_PATH, &value);
trace!("{}={}", DTDL_PATH, &value);
trace!("{DTDL_PATH}={value}");
} else {
warn!("Unable to set {}, as repo directory could not be determined.", DTDL_PATH);
warn!("Unable to set {DTDL_PATH}, as repo directory could not be determined.");
}
}

Expand Down
14 changes: 14 additions & 0 deletions dt-model/dt-model-identifiers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT license.

[package]
name = "dt-model-identifiers"
version = "0.1.0"
edition = "2021"
license = "MIT"

[dependencies]

[lib]
path = "src/lib.rs"
crate-type = ["lib"]
11 changes: 11 additions & 0 deletions dt-model/dt-model-identifiers/src/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT license.

[package]
name = "model-identifiers"
version = "0.1.0"
edition = "2021"
license = "MIT"

[dependencies]

4 changes: 4 additions & 0 deletions dt-model/dt-model-identifiers/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

pub mod sdv_v1;
36 changes: 36 additions & 0 deletions dt-model/dt-model-identifiers/src/sdv_v1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

// Note: In the future this code could be auto-generated from a DTDL spec.

pub mod vehicle {
pub mod cabin {
pub mod hvac {
pub mod ambient_air_temperature {
pub const ID: &str = "dtmi:sdv:Vehicle:Cabin:HVAC:AmbientAirTemperature;1";
}
pub mod is_air_conditioning_active {
pub const ID: &str = "dtmi:sdv:Vehicle:Cabin:HVAC:IsAirConditioningActive;1";
}
}
pub mod infotainment {
pub mod hmi {
pub mod show_notification {
pub const ID: &str =
"dtmi:sdv:Vehicle:Cabin:Infotainment:HMI:ShowNotification;1";
}
}
}
}
pub mod obd {
pub mod hybrid_battery_remaining {
pub const ID: &str = "dtmi:sdv:Vehicle:OBD:HybridBatteryRemaining;1";
}
}
}

pub mod property {
pub mod uri {
pub const ID: &str = "dtmi:sdv:property:uri;1";
}
}
20 changes: 10 additions & 10 deletions dtdl-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ edition = "2021"
license = "MIT"

[dependencies]
async-std = { version = "^1.5", features = ["attributes"] }
async-std = { workspace = true, features = ["attributes"] }
ibeji-common = { path = "../common" }
ibeji-common_test = { path = "../common-test" }
generic-json = { version = "^0.7", features = ["serde_json-impl"] }
iref = "^2.0.3"
futures = { workspace = true }
generic-json = { workspace = true, features = ["serde_json-impl"] }
iref = { workspace = true }
json-ld = { git = "https://github.com/blast-hardcheese/json-ld", branch = "resolve-issue-40" }
# json-ld = { git = "https://github.com/timothee-haudebourg/json-ld", tag = "0.9.1-beta" }
lazy_static = "1.4.0"
log = "^0.4"
regex = " 1.7.1"
serde_json = "1.0.88"
strum = "0.24"
strum_macros = "0.24"
lazy_static = { workspace = true }
log = { workspace = true }
regex = { workspace = true }
serde_json = { workspace = true }
strum = { workspace = true }
strum_macros = { workspace = true }

[lib]
path = "src/lib.rs"
Expand Down
6 changes: 3 additions & 3 deletions dtdl-parser/src/dtmi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Dtmi {

let fragment = match iri.fragment() {
Some(fragment) => String::from(fragment.as_str()),
None => String::from(""),
None => String::new(),
ashbeitz marked this conversation as resolved.
Show resolved Hide resolved
};

Ok(Self {
Expand Down Expand Up @@ -152,13 +152,13 @@ impl fmt::Display for Dtmi {
/// * `value` - The IRI to copy from.
pub fn create_dtmi(value: &str) -> Option<Dtmi> {
if !DTMI_REGEX.is_match(value) {
warn!("The value '{}' does not represent a valid DTMI", value);
warn!("The value '{value}' does not represent a valid DTMI");
return None;
}

let new_dtmi_result = Dtmi::new(value);
if let Err(error) = new_dtmi_result {
warn!("{}", error);
warn!("{error}");
return None;
}

Expand Down
31 changes: 11 additions & 20 deletions dtdl-parser/src/model_parser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

use async_std::task;
use futures::executor::block_on;
use ibeji_common::find_full_path;
use json_ld::{context, Document, NoLoader, Node, Object};
use log::warn;
Expand Down Expand Up @@ -93,13 +93,10 @@ impl ModelParser {
self.preprocess(&mut doc)?;

let mut loader = NoLoader::<Value>::new();
let dtdl_doc = match task::block_on(doc.expand::<context::Json<Value>, _>(&mut loader))
{
Ok(expanded_doc) => expanded_doc,
Err(error) => {
return Err(format!("Failed to expand one of the JSON texts due to: {error:?}"))
}
};
let dtdl_doc =
ashbeitz marked this conversation as resolved.
Show resolved Hide resolved
block_on(doc.expand::<context::Json<Value>, _>(&mut loader)).map_err(|error| {
format!("Failed to expand one of the JSON texts due to: {error:?}")
})?;

for item in dtdl_doc.iter() {
let object: &Object<serde_json::Value> = item;
Expand Down Expand Up @@ -163,7 +160,7 @@ impl ModelParser {
Ok(json) => json,
Err(error) => {
return Err(format!(
"Unable to pasrse the context located at {} due to: {:?}",
"Unable to parse the context located at {} due to: {:?}",
filepath.display(),
error
))
Expand Down Expand Up @@ -321,7 +318,6 @@ impl ModelParser {

if let Some(entity_kind) = entity_kind_option {
if is_primitive_schema_kind(entity_kind) {
println!("entity_kind is_primitive_entity_kind");
let id: Option<Dtmi> = self.generate_id(parent_id, "test");
if id.is_none() {
return Err(String::from(
Expand All @@ -337,7 +333,6 @@ impl ModelParser {
entity_kind,
)))
} else {
println!("entity_kind is_NOT primitive_entity_kind");
Err(format!("expected a primitive schema, found {entity_kind}"))
}
} else {
Expand Down Expand Up @@ -461,7 +456,6 @@ impl ModelParser {
}

if entity_kind_option.is_none() {
println!("Complex schema has no associated type. It must have one.");
return Err(String::from("Complex schema has no associated type. It must have one."));
}

Expand All @@ -470,7 +464,6 @@ impl ModelParser {
if entity_kind == EntityKind::Object {
self.get_object_schema(node, model_dict, parent_id)
} else {
println!("Unsupported complex object: {entity_kind:?}.");
Err(format!("Unsupported complex object: {entity_kind:?}."))
}
}
Expand Down Expand Up @@ -902,8 +895,6 @@ impl ModelParser {
// name - optional
let name = self.get_property_value(node, "dtmi:dtdl:property:name;2")?;

println!("Command: {}", name.clone().unwrap());

let mut id: Option<Dtmi> = None;
if node.id().is_some() {
id = create_dtmi(node.id().unwrap().as_str());
Expand Down Expand Up @@ -1107,8 +1098,8 @@ mod model_parser_tests {
);
}

#[rustfmt::skip]
#[test]
# [rustfmt::skip]
fn demo_validation_test() {
set_dtdl_path();

Expand All @@ -1129,12 +1120,12 @@ mod model_parser_tests {
);
let model_dict = model_dict_result.unwrap();
assert!(
model_dict.len() == 14,
"expected length was 14, actual length is {}",
model_dict.len() == 13,
"expected length was 13, actual length is {}",
model_dict.len()
);

let ambient_air_temperature_id: Option<Dtmi> = create_dtmi("dtmi:org:eclipse:sdv:property:cabin:AmbientAirTemperature;1");
let ambient_air_temperature_id: Option<Dtmi> = create_dtmi("dtmi:sdv:Vehicle:Cabin:HVAC:AmbientAirTemperature;1");
assert!(ambient_air_temperature_id.is_some());
let ambient_air_temperature_entity_result =
model_dict.get(&ambient_air_temperature_id.unwrap());
Expand All @@ -1149,7 +1140,7 @@ mod model_parser_tests {
assert!(ambient_air_temperature_uri_property_value_result.is_some());
assert!(ambient_air_temperature_uri_property_value_result.unwrap() == "http://[::1]:40010"); // Devskim: ignore DS137138

let send_notification_id: Option<Dtmi> = create_dtmi("dtmi:org:eclipse:sdv:command:HVAC:send_notification;1");
let send_notification_id: Option<Dtmi> = create_dtmi("dtmi:sdv:Vehicle:Cabin:HVAC:SendNotification;1");
assert!(send_notification_id.is_some());
let send_notification_entity_result = model_dict.get(&send_notification_id.unwrap());
assert!(send_notification_entity_result.is_some());
Expand Down
2 changes: 1 addition & 1 deletion dtdl-parser/src/primitive_schema_info_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::entity_kind::EntityKind;
use crate::primitive_schema_info::PrimitiveSchemaInfo;
use crate::schema_info::SchemaInfo;

#[derive(Clone, PartialEq)]
#[derive(Clone, PartialEq, Eq)]
pub struct PrimitiveSchemaInfoImpl {
// EntitytInfo
dtdl_version: i32,
Expand Down
Loading