diff --git a/zenoh-bridge-ros1/src/main.rs b/zenoh-bridge-ros1/src/main.rs index a956421..38db4f1 100644 --- a/zenoh-bridge-ros1/src/main.rs +++ b/zenoh-bridge-ros1/src/main.rs @@ -138,7 +138,8 @@ r#"--client_bridging_mode=[String] \ .arg(Arg::from_usage( r#"--subscriber_topic_custom_bridging_mode=[JSON] 'A JSON Map describing custom bridging modes for particular topics. Custom bridging mode overrides the global one. -Format: {[topic, mode]} +Format: {"topic", "mode"} +Example: {\"/my/topic1\":\"lazy_auto\",\"/my/topic2\":\"auto\"} where - topic: ROS1 topic name - mode (auto/lazy_auto/disabled) as described above @@ -147,7 +148,8 @@ The default is empty'"# .arg(Arg::from_usage( r#"--publisher_topic_custom_bridging_mode=[JSON] 'A JSON Map describing custom bridging modes for particular topics. Custom bridging mode overrides the global one. -Format: {[topic, mode]} +Format: {"topic", "mode"} +Example: {\"/my/topic1\":\"lazy_auto\",\"/my/topic2\":\"auto\"} where - topic: ROS1 topic name - mode (auto/lazy_auto/disabled) as described above @@ -156,7 +158,8 @@ The default is empty'"# .arg(Arg::from_usage( r#"--service_topic_custom_bridging_mode=[JSON] 'A JSON Map describing custom bridging modes for particular topics. Custom bridging mode overrides the global one. -Format: {[topic, mode]} +Format: {"topic", "mode"} +Example: {\"/my/topic1\":\"lazy_auto\",\"/my/topic2\":\"auto\"} where - topic: ROS1 topic name - mode (auto/lazy_auto/disabled) as described above @@ -165,10 +168,11 @@ The default is empty'"# .arg(Arg::from_usage( r#"--client_topic_custom_bridging_mode=[JSON] 'A JSON Map describing custom bridging modes for particular topics. Custom bridging mode overrides the global one. -Format: {[topic, mode]} +Format: {"topic", "mode"} +Example: {\"/my/topic1\":\"auto\",\"/my/topic2\":\"auto\"} where - topic: ROS1 topic name -- mode (auto/lazy_auto/disabled) as described above +- mode (auto/disabled) as described above The default is empty'"# )) .arg(Arg::from_usage( diff --git a/zenoh-plugin-ros1/src/ros_to_zenoh_bridge/bridging_mode.rs b/zenoh-plugin-ros1/src/ros_to_zenoh_bridge/bridging_mode.rs index 0cadc71..8b75b76 100644 --- a/zenoh-plugin-ros1/src/ros_to_zenoh_bridge/bridging_mode.rs +++ b/zenoh-plugin-ros1/src/ros_to_zenoh_bridge/bridging_mode.rs @@ -20,6 +20,7 @@ use super::{bridge_type::BridgeType, environment::Environment}; #[derive(PartialEq, Eq, EnumString, Clone, Display)] #[strum(serialize_all = "snake_case")] #[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "snake_case")] pub enum BridgingMode { LazyAuto, Auto, diff --git a/zenoh-plugin-ros1/src/ros_to_zenoh_bridge/environment.rs b/zenoh-plugin-ros1/src/ros_to_zenoh_bridge/environment.rs index 23f8188..67f31e0 100644 --- a/zenoh-plugin-ros1/src/ros_to_zenoh_bridge/environment.rs +++ b/zenoh-plugin-ros1/src/ros_to_zenoh_bridge/environment.rs @@ -15,7 +15,6 @@ use duration_string::DurationString; use log::error; use rosrust::api::resolve::*; -use serde_json::Value; use std::collections::HashMap; use std::convert::From; use std::time::Duration; @@ -46,8 +45,9 @@ where pub fn get(&self) -> Tvar { if let Ok(val) = std::env::var(self.name) { - if let Ok(val) = val.parse::() { - return val; + match Tvar::from_str(&val) { + Ok(val) => return val, + Err(_) => error!("Error parsing settings entry {}", self.name), } } self.default.clone() @@ -89,11 +89,7 @@ pub struct CustomBridgingModes { impl ToString for CustomBridgingModes { fn to_string(&self) -> String { - let mut json_map = serde_json::Map::new(); - for (k, v) in &self.modes { - json_map.insert(k.clone(), Value::String(v.to_string())); - } - serde_json::Value::Object(json_map).to_string() + serde_json::to_string(&self.modes).unwrap() } } @@ -101,32 +97,8 @@ impl FromStr for CustomBridgingModes { type Err = serde_json::Error; fn from_str(s: &str) -> Result { - let mut result = CustomBridgingModes::default(); - let parsed: Value = serde_json::from_str(s)?; - match parsed.as_object() { - Some(v) => { - for (topic, mode) in v { - match mode.as_str() { - Some(v) => match BridgingMode::from_str(v) { - Ok(mode) => { - result.modes.insert(topic.clone(), mode); - } - Err(e) => { - error!("Error reading value {v} as Bridging Mode: {e}"); - } - }, - None => { - error!("Error reading non-string as Bridging Mode"); - } - } - } - } - None => { - error!("Error reading custom Bridging Mode map: the value provided is not a map!"); - } - } - - Ok(result) + let modes: HashMap = serde_json::from_str(s)?; + Ok(Self { modes }) } }