diff --git a/Cargo.lock b/Cargo.lock index e3bf55bf2..c6b41595d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3399,6 +3399,15 @@ dependencies = [ "serialport", ] +[[package]] +name = "dora-tcp" +version = "0.3.11" +dependencies = [ + "dora-node-api", + "eyre", + "tokio", +] + [[package]] name = "dora-tracing" version = "0.3.11" @@ -13531,9 +13540,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.44.2" +version = "1.45.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6b88822cbe49de4185e3a4cbf8321dd487cf5fe0c5c65695fef6346371e9c48" +checksum = "75ef51a33ef1da925cea3e4eb122833cb377c61439ca401b770f54902b806779" dependencies = [ "backtrace", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 93f68c335..010137b20 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,7 @@ members = [ "node-hub/dora-rav1e", "node-hub/dora-dav1d", "node-hub/dora-rustypot", + "node-hub/dora-tcp", "libraries/extensions/ros2-bridge", "libraries/extensions/ros2-bridge/msg-gen", "libraries/extensions/ros2-bridge/python", diff --git a/node-hub/dora-tcp/Cargo.toml b/node-hub/dora-tcp/Cargo.toml new file mode 100644 index 000000000..2e9005bdb --- /dev/null +++ b/node-hub/dora-tcp/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "dora-tcp" +version.workspace = true +edition.workspace = true +documentation.workspace = true +description.workspace = true +license.workspace = true +repository.workspace = true + +[dependencies] +dora-node-api = { workspace = true } +tokio = { version = "1.45.0", features = ["full"] } +eyre = "0.6.8" diff --git a/node-hub/dora-tcp/README.md b/node-hub/dora-tcp/README.md new file mode 100644 index 000000000..f8e253332 --- /dev/null +++ b/node-hub/dora-tcp/README.md @@ -0,0 +1,34 @@ +# dora-tcp + +Basic TCP Implementation for streaming data to a TCP Destination. + + +## Getting Started +Copy the node to your dora project and build it + + +Example: +- Streaming drive commands to a Unity simulation hosting a TCP server. + +Example dataflow.yml +```shell +nodes: + - id: drive_director + build: cargo build -p drive_director + path: target/debug/drive_director + inputs: + tick: dora/timer/millis/100 + outputs: + - command + - id: dora-tcp + build: cargo build -p dora-tcp + path: target/debug/dora-tcp + inputs: + command: drive_director/command +``` + +## Input definition + +- command: String + +Note: I used a colon to separate the commands ie drive:10 but you can modify as needed. \ No newline at end of file diff --git a/node-hub/dora-tcp/src/lib.rs b/node-hub/dora-tcp/src/lib.rs new file mode 100644 index 000000000..c86853cbb --- /dev/null +++ b/node-hub/dora-tcp/src/lib.rs @@ -0,0 +1,37 @@ +/* + Basic TCP implementation for streaming events to a TCP Destination +*/ +use dora_node_api::{DoraNode, Event}; +use eyre::Result; +use tokio::io::AsyncWriteExt; +use tokio::net::TcpStream; + +pub async fn lib_main() -> Result<()> { + // NOTE: Hard-coded address + let mut stream = + TcpStream::connect(std::env::var("ADDR").unwrap_or("127.0.0.1:8052".to_string())).await?; + + let (_, mut events) = DoraNode::init_from_env()?; + + while let Some(event) = events.recv() { + match event { + Event::Input { + id, + metadata: _, + data, + } => match id.as_str() { + "text" => { + // Extract the command + let command: &str = (&data).try_into()?; + + // Send the command to the Unity over tcp + stream.write_all(command.as_bytes()).await?; + } + _ => {} + }, + _ => {} + } + } + + Ok(()) +} diff --git a/node-hub/dora-tcp/src/main.rs b/node-hub/dora-tcp/src/main.rs new file mode 100644 index 000000000..031c75aba --- /dev/null +++ b/node-hub/dora-tcp/src/main.rs @@ -0,0 +1,5 @@ +#[tokio::main] + +async fn main() -> Result<(), eyre::Error> { + dora_tcp::lib_main().await +}