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

Add streaming sample #40

Merged
merged 27 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

[workspace]

resolver = "2"
ashbeitz marked this conversation as resolved.
Show resolved Hide resolved

members = [
# core
"core/protobuf_data_access",
Expand All @@ -22,6 +24,7 @@ members = [
"samples/mixed",
"samples/property",
"samples/seat_massager",
"samples/streaming",
]

[workspace.dependencies]
Expand All @@ -30,22 +33,26 @@ config = "0.13.3"
env_logger= "0.10.0"
futures = "0.3"
generic-json = "^0.7"
image = "0.24.3"
iref = "^2.0.3"
lazy_static = "1.4.0"
log = "^0.4"
paho-mqtt = "0.12"
parking_lot = "0.12.1"
prost = "0.11"
prost-types = "0.11"
regex = " 1.9.1"
regex = " 1.9.3"
serde = "1.0.160"
serde_derive = "1.0.163"
serde_json = "^1.0"
show-image = "0.13.1"
strum = "0.25"
strum_macros = "0.25.1"
tokio = "1.29.1"
tokio-stream = "0.1.14"
tonic = "0.9.2"
tonic-build = "0.9.2"
url = "2.3.1"
uuencode = "0.1.5"
uuid = "1.2.2"
yaml-rust = "0.4"
49 changes: 40 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- [Command Sample](#command-sample)
- [Mixed Sample](#mixed-sample)
- [Seat Massager Sample](#seat-massager-sample)
- [Streaming Sample](#streaming-sample)
- [Using Chariott](#using-chariott)
- [Trademarks](#trademarks)

Expand Down Expand Up @@ -110,7 +111,7 @@ demonstrates the mixed use of properties and commands and one that demonstrates

The demos use config files and we have provided a templated version of each config file. These templates can be found in:

- {repo-root-dir}/core/invehicle_digital_twin/template
- {repo-root-dir}/core/invehicle-digital-twin/template
- {repo-root-dir}/samples/common/template

Chariott may be used to discover the in-vehicle digital twin service. We will discuss how to enable this feature.
Expand All @@ -123,7 +124,7 @@ Steps:

1. The best way to run the demo is by using three windows: one running the In-Vehicle Digital Twin, one running the Digital Twin Provider and one running the Digital Twin 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>
The middle window can be used for the Digital Twin Provider. The bottom window can be used for the Digital Twin Consumer.<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}/target/debug`<br>
Expand All @@ -136,7 +137,7 @@ Make sure that you replace "{repo-root-dir}" with the repository root directory
`provider_authority: "0.0.0.0:1883"`<br>
`invehicle_digital_twin_uri: "http://0.0.0.0:5010"`<br><br>
1. In the top window, run:<br><br>
`./in-vehicle-digital-twin`<br>
`./invehicle-digital-twin`<br>
1. In the middle window, run:<br><br>
`./property-provider`<br>
1. In the bottom window, run:<br><br>
Expand All @@ -151,7 +152,7 @@ Steps:

1. The best way to run the demo is by using three windows: one running the In-Vehicle Digital Twin, one running the Digital Twin Provider and one running the Digital Twin 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>
The middle window can be used for the Digital Twin Provider. The bottom window can be used for the Digital Twin Consumer.<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}/target/debug`<br>
Expand All @@ -165,7 +166,7 @@ Make sure that you replace "{repo-root-dir}" with the repository root directory
`provider_authority: "0.0.0.0:4010"`<br>
`invehicle_digital_twin_uri: "http://0.0.0.0:5010"`<br><br>
1. In the top window, run:<br><br>
`./in-vehicle-digital-twin`<br>
`./invehicle-digital-twin`<br>
1. In the middle window, run:<br><br>
`./command-provider`<br>
1. In the bottom window, run:<br><br>
Expand All @@ -180,7 +181,7 @@ Steps:

1. The best way to run the demo is by using three windows: one running the In-Vehicle Digital Twin, one running the Digital Twin Provider and one running the Digital Twin 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>
The middle window can be used for the Digital Twin Provider. The bottom window can be used for the Digital Twin Consumer.<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}/target/debug`<br>
Expand All @@ -194,7 +195,7 @@ Make sure that you replace "{repo-root-dir}" with the repository root directory
`provider_authority: "0.0.0.0:4010"`<br>
`invehicle_digital_twin_uri: "http://0.0.0.0:5010"`<br><br>
1. In the top window, run:<br><br>
`./in-vehicle-digital-twin`<br>
`./invehicle-digital-twin`<br>
1. In the middle window, run:<br><br>
`./mixed-provider`<br>
1. In the bottom window, run:<br><br>
Expand All @@ -209,7 +210,7 @@ Steps:

1. The best way to run the demo is by using three windows: one running the In-Vehicle Digital Twin, one running the Digital Twin Provider and one running the Digital Twin 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>
The middle window can be used for the Digital Twin Provider. The bottom window can be used for the Digital Twin Consumer.<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}/target/debug`<br>
Expand All @@ -223,13 +224,43 @@ Make sure that you replace "{repo-root-dir}" with the repository root directory
`provider_authority: "0.0.0.0:4010"`<br>
`invehicle_digital_twin_uri: "http://0.0.0.0:5010"`<br><br>
1. In the top window, run:<br><br>
`./in-vehicle-digital-twin`<br>
`./invehicle-digital-twin`<br>
1. In the middle window, run:<br><br>
`./seat-massager-provider`<br>
1. In the bottom window, run:<br><br>
`./seat-massager-consumer`<br>
1. Use control-c in each of the windows when you wish to stop the demo.

### <a name="streaming-sample">Streaming Sample</a>

The following instructions are for the demo for streaming.

Steps:

1. The best way to run the demo is by using three windows: one running the In-Vehicle Digital Twin, one running the Digital Twin Provider and one running the Digital Twin Consumer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since much of the setup is copied and pasted for all of these demos, can we move it out into a "common setup" section?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are suttle differences and I expect these to diverge as Ibeji becomes more mature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving as is for now.

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 Digital Twin Provider. The bottom window can be used for the Digital Twin Consumer.<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}/target/debug`<br>
1. Create the three config files with the following contents, if they are not already there:<br><br>
---- streaming_consumer_settings.yaml ----<br>
`invehicle_digital_twin_uri: "http://0.0.0.0:5010"`<br><br>
`number_of_images: 20`<br><br>
---- invehicle_digital_twin_settings.yaml ----<br>
`invehicle_digital_twin_authority: "0.0.0.0:5010"`<br><br>
---- streaming_provider_settings.yaml ----<br>
`provider_authority: "0.0.0.0:4010"`<br>
`invehicle_digital_twin_uri: "http://0.0.0.0:5010"`<br><br>
`image_directory: "<<chariott-repo-root>>/examples/applications/simulated-camera/images"`
1. In the top window, run:<br><br>
`./invehicle-digital-twin`<br>
1. In the middle window, run:<br><br>
`./streaming-provider`<br>
1. In the bottom window, run:<br><br>
`./streaming-consumer`<br>
1. Use control-c in each of the windows when you wish to stop the demo.

### <a name="using-chariott">Using Chariott</a>

If you want the digital twin consumers and digital twin providers for each demo to use Chariott to discover the URI for the In-Vehicle Digital Twin Service,
Expand Down
9 changes: 5 additions & 4 deletions devops/cg/about.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
accepted = [
"MIT",
"Apache-2.0",
"BSD-2-Clause",
"BSD-3-Clause",
"CC0-1.0",
"EPL-1.0",
"EPL-2.0",
"ISC",
"MIT",
"Unicode-DFS-2016",
"BSD-2-Clause",
"BSD-3-Clause",
"Zlib",
"CC0-1.0",
]
17 changes: 17 additions & 0 deletions digital-twin-model/dtdl/v3/spec/sdv/camera.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"@context": "dtmi:dtdl:context;3",
"@type": "Interface",
"@id": "dtmi:sdv:Camera;1",
"description": "Cabin camera.",
"contents": [
{
"@type": "Property",
"@id": "dtmi:sdv:Camera:Feed;1",
"name": "Feed",
"schema": "string",
"description": "The cabin camera's feed for inside the cabin."
ashbeitz marked this conversation as resolved.
Show resolved Hide resolved
}
]
}
]
9 changes: 9 additions & 0 deletions digital-twin-model/src/sdv_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ pub mod airbag_seat_massager {
}
}

pub mod camera {
pub mod feed {
pub const ID: &str = "dtmi:sdv:Camera:Feed;1";
pub const NAME: &str = "Feed";
pub const DESCRIPTION: &str = "The cabin camera's feed for inside the cabin.";
pub type TYPE = String;
}
}

pub mod hmi {
pub mod show_notification {
pub const ID: &str = "dtmi:sdv:HMI:ShowNotification;1";
Expand Down
4 changes: 2 additions & 2 deletions dtdl-parser/src/model_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,9 +1167,9 @@ mod model_parser_tests {
fn find_full_path_test() {
set_dtdl_path();

let find_full_path_result = ModelParser::find_full_path("v3/content/sdv/hvac.json");
let find_full_path_result = ModelParser::find_full_path("v3/spec/sdv/hvac.json");
assert!(find_full_path_result.is_ok());
let full_path = find_full_path_result.unwrap();
assert!(full_path.ends_with("/v3/content/sdv/hvac.json"));
assert!(full_path.ends_with("/v3/spec/sdv/hvac.json"));
}
}
1 change: 1 addition & 0 deletions samples/command/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ serde = { workspace = true }
serde_derive = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
tokio-stream = { workspace = true }
ashbeitz marked this conversation as resolved.
Show resolved Hide resolved
tonic = { workspace = true }
uuid = { workspace = true, features = ["v4", "fast-rng", "macro-diagnostics"] }

Expand Down
18 changes: 18 additions & 0 deletions samples/command/provider/src/provider_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ use samples_protobuf_data_access::sample_grpc::v1::digital_twin_provider::digita
use samples_protobuf_data_access::sample_grpc::v1::digital_twin_provider::{
GetRequest, GetResponse, InvokeRequest, InvokeResponse, SetRequest, SetResponse,
SubscribeRequest, SubscribeResponse, UnsubscribeRequest, UnsubscribeResponse,
StreamRequest, StreamResponse,
};
use serde_derive::{Deserialize, Serialize};
use std::pin::Pin;
use tokio_stream::Stream;
use tonic::{Request, Response, Status};

/// The reponse payload is empty.
Expand All @@ -23,6 +26,8 @@ pub struct ProviderImpl {}

#[tonic::async_trait]
impl DigitalTwinProvider for ProviderImpl {
type StreamStream = Pin<Box<dyn Stream<Item = Result<StreamResponse, Status>> + Send>>;
ashbeitz marked this conversation as resolved.
Show resolved Hide resolved

/// Subscribe implementation.
///
/// # Arguments
Expand Down Expand Up @@ -121,6 +126,19 @@ impl DigitalTwinProvider for ProviderImpl {

Ok(Response::new(response))
}

/// Stream implementation.
///
/// # Arguments
/// * `request` - OpenStream request.
async fn stream(
ashbeitz marked this conversation as resolved.
Show resolved Hide resolved
&self,
request: Request<StreamRequest>,
) -> Result<Response<Self::StreamStream>, Status> {
warn!("Got a stream request: {request:?}");

Err(Status::unimplemented("stream has not been implemented"))
}
}

#[cfg(test)]
Expand Down
1 change: 1 addition & 0 deletions samples/common/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod digital_twin_operation {
pub const SUBSCRIBE: &str = "Subscribe";
pub const UNSUBSCRIBE: &str = "Unsubscribe";
pub const INVOKE: &str = "Invoke";
pub const STREAM: &str = "Stream";
}

// Supported digital twin protocols.
Expand Down
2 changes: 2 additions & 0 deletions samples/common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub async fn discover_digital_twin_provider_using_ibeji(
operations: &[String],
) -> Result<EndpointInfo, String> {
info!("Sending a find_by_id request for entity id {entity_id} to the In-Vehicle Digital Twin Service URI {invehicle_digitial_twin_service_uri}");

let mut client =
InvehicleDigitalTwinClient::connect(invehicle_digitial_twin_service_uri.to_string())
.await
Expand Down Expand Up @@ -216,6 +217,7 @@ mod ibeji_common_utils_tests {
assert!(is_subset(&[], &[]));
assert!(is_subset(&[], &["one".to_string()]));
assert!(is_subset(&[], &["one".to_string(), "two".to_string()]));
assert!(is_subset(&["one".to_string()], &["one".to_string()]));
assert!(is_subset(&["one".to_string()], &["one".to_string(), "two".to_string()]));
assert!(is_subset(
&["one".to_string(), "two".to_string()],
Expand Down
14 changes: 14 additions & 0 deletions samples/common/template/streaming_consumer_settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# Streaming Consumer Settings
#

# The URL that the in-vehicle digital twin service listens on for digital twin requests.
invehicle_digital_twin_url: <<value>>

# The URL that the Chariott service listens on for requests.
# If you wish to use Chariott, then uncomment this setting and comment out the invehicle_digital_twin_url setting.
# chariott_url: <<value>>

# The number of images that we wish to stream.
number_of_images: <<value>>

17 changes: 17 additions & 0 deletions samples/common/template/streaming_provider_settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Streaming Provider Settings
#

# The IP address and port number that the provider listens on for provider requests.
# Example: "0.0.0.0:80"
provider_authority: <<value>>

# The URL that the in-vehicle digital twin service listens on for digital twin requests.
invehicle_digital_twin_url: <<value>>

# The URL that the Chariott service listens on for requests.
# If you wish to use Chariott, then uncomment this setting and comment out the invehicle_digital_twin_url setting.
# chariott_url: <<value>>

# The directory where the images can be found.
image_directory: <<value>>
8 changes: 8 additions & 0 deletions samples/interfaces/sample_grpc/v1/digital_twin_provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ service DigitalTwinProvider {
rpc Get (GetRequest) returns (GetResponse);
rpc Set (SetRequest) returns (SetResponse);
rpc Invoke (InvokeRequest) returns (InvokeResponse);
rpc Stream(StreamRequest) returns (stream StreamResponse);
}

message SubscribeRequest {
Expand Down Expand Up @@ -55,3 +56,10 @@ message InvokeRequest {

message InvokeResponse {
}

message StreamRequest {
ashbeitz marked this conversation as resolved.
Show resolved Hide resolved
}

message StreamResponse {
string content = 1;
}
1 change: 1 addition & 0 deletions samples/mixed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ serde = { workspace = true }
serde_derive = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
tokio-stream = { workspace = true }
tonic = { workspace = true }
uuid = { workspace = true, features = ["v4", "fast-rng", "macro-diagnostics"] }

Expand Down
Loading