diff --git a/Cargo.lock b/Cargo.lock index 0b7bb07..ee9e4b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -464,6 +464,7 @@ dependencies = [ "tokio-util", "tracing", "tungstenite", + "url", "wiremock", ] @@ -1948,9 +1949,9 @@ checksum = "1865806a559042e51ab5414598446a5871b561d21b6764f2eabb0dd481d880a6" [[package]] name = "url" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" +checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" dependencies = [ "form_urlencoded", "idna", diff --git a/Cargo.toml b/Cargo.toml index c206a97..455d931 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ parsit = "0.2.0" graphviz-rust = "0.6.2" logos = "0.13.0" itertools = "0.11.0" -strum = "0.25.0" +strum = { version = "0.25.0", features = [] } strum_macros = "0.25.1" log = "0.4" env_logger = "0.10.0" @@ -30,6 +30,7 @@ chrono = "0.4.26" quick-xml = "0.31.0" tungstenite = "0.20.1" +url = "2.4.1" [dev-dependencies] wiremock = "0.5.19" diff --git a/src/runtime.rs b/src/runtime.rs index 4f76324..643c2c4 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -16,7 +16,6 @@ use std::str::ParseBoolError; use std::string::FromUtf8Error; use std::sync::{MutexGuard, PoisonError}; use quick_xml::events::attributes::AttrError; -use rustdds::dds::CreateError; /// The major type of every result in Forester. pub type RtResult = Result; diff --git a/src/runtime/builder/ros_core.rs b/src/runtime/builder/ros_core.rs index 456304a..381b986 100644 --- a/src/runtime/builder/ros_core.rs +++ b/src/runtime/builder/ros_core.rs @@ -13,6 +13,6 @@ pub fn ros_actions_file() -> String { // The actions are accessible using the import 'import "ros::core"' // Publish message to the topic -impl publish(topic:string, type:string, value:any, qos_policy:object); +impl publish(topic:string, value:any, url:string); "#) } diff --git a/src/runtime/dds.rs b/src/runtime/dds.rs index 0c76f4f..cca96dd 100644 --- a/src/runtime/dds.rs +++ b/src/runtime/dds.rs @@ -1,5 +1,5 @@ //! Provide a DDS implementation for the runtime. - +// ros2 launch rosbridge_server rosbridge_websocket_launch.xml pub mod ws_client; use crate::runtime::action::{Impl, Tick}; diff --git a/src/runtime/dds/ws_client.rs b/src/runtime/dds/ws_client.rs index e69de29..235fe4d 100644 --- a/src/runtime/dds/ws_client.rs +++ b/src/runtime/dds/ws_client.rs @@ -0,0 +1,49 @@ +use serde::{Deserialize, Serialize}; +use tungstenite::{connect, Message}; +use url::Url; + + +#[derive(Serialize, Deserialize)] +pub struct PubMes { + pub topic: String, + pub msg: D, +} + +impl PubMes { + pub fn new(topic: String, msg: D) -> Self { + Self { topic, msg } + } +} + +pub fn publish(mes: PubMes, url: String) { + let (mut socket, response) = + connect(Url::parse(url.as_str()).unwrap()).expect("Can't connect"); + println!("Connected to the server"); + println!("Response HTTP code: {}", response.status()); + println!("Response contains the following headers:"); + for (ref header, _value) in response.headers() { + println!("* {}", header); + } + let js = serde_json::to_string_pretty(&mes).unwrap(); + socket.send(Message::text(js)).unwrap(); +} + + +#[cfg(test)] +mod tests { + use std::collections::HashMap; + use crate::runtime::args::RtValue; + use crate::runtime::dds::ws_client::{publish, PubMes}; + + #[test] + fn smoke() { + let value = RtValue::Object(HashMap::from_iter(vec![("a".to_string(), RtValue::int(10))])); + publish(PubMes::new( + "test".to_string(), + value, + ), "ws://localhost:9090".to_string()); + } +} + + + diff --git a/tree/tests/flow/parallel/simple_w_retry/main.tree b/tree/tests/flow/parallel/simple_w_retry/main.tree index b0fa17f..92505fd 100644 --- a/tree/tests/flow/parallel/simple_w_retry/main.tree +++ b/tree/tests/flow/parallel/simple_w_retry/main.tree @@ -1,7 +1,7 @@ import "std::actions" cond fail_before_tick(); -cond incr(key:string,default:num); +cond incr(key:string,default:any); root main repeat(3) parallel { r_fallback {