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

more bugfixes for roscore compatibility #6

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/client_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl ClientApi {
caller_id: &str,
key: &str,
value: &Value,
) -> anyhow::Result<()> {
) -> anyhow::Result<Value> {
let request = Call::new("paramUpdate", (caller_id, key, value));
let result = self.client.call(request).await;
Ok(result?)
Expand Down
36 changes: 16 additions & 20 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,8 @@ impl Handler for RegisterSubscriberHandler {
let topic = resolve(&caller_id, &topic);

if let Some(known_topic_type) = self.data.topics.read().unwrap().get(&topic.clone()) {
if known_topic_type != &topic_type {
let err_msg = format!(
"{} for topic {} does not match {}",
topic_type, topic, known_topic_type
);
return Ok((0, err_msg, "").try_to_value()?);
if known_topic_type != &topic_type && topic_type != "*" {
log::warn!("Topic '{topic}' was initially published as '{known_topic_type}', but subscriber '{caller_id}' wants it as '{topic_type}'.");
}
}

Expand Down Expand Up @@ -376,8 +372,7 @@ impl Handler for RegisterPublisherHandler {

if let Some(v) = self.data.topics.read().unwrap().get(&topic.clone()) {
if v != &topic_type {
let err_msg = format!("{} for topic {} does not match {}", topic_type, topic, v);
return Ok((0, err_msg, Vec::<String>::default()).try_to_value()?);
log::warn!("New publisher for topic '{topic}' has type '{topic_type}', but it is already published as '{v}'.");
}
}

Expand Down Expand Up @@ -846,15 +841,16 @@ async fn update_client_with_new_param_value(
subscribing_node_id: String,
param_name: String,
new_value: Value,
) -> Result<(), anyhow::Error> {
) -> Result<Value, anyhow::Error> {
let client_api = ClientApi::new(&client_api_url);
let request = client_api.param_update(&updating_node_id, &param_name, &new_value);
let res = request.await;
match res {
Ok(()) => log::debug!(
"Sent new value for param '{}' to node '{}'.",
Ok(ref v) => log::debug!(
"Sent new value for param '{}' to node '{}'. response: {:?}",
param_name,
subscribing_node_id
subscribing_node_id,
&v
),
Err(ref e) => log::debug!(
"Error sending new value for param '{}' to node '{}': {:?}",
Expand All @@ -864,7 +860,7 @@ async fn update_client_with_new_param_value(
),
}

res
Ok(res?)
}

/// Handler for setting a ROS parameter.
Expand Down Expand Up @@ -934,8 +930,8 @@ impl Handler for SetParamHandler {

while let Some(res) = update_futures.join_next().await {
match res {
Ok(Ok(())) => {
log::debug!("a subscriber has been updated");
Ok(Ok(v)) => {
log::debug!("a subscriber has been updated (res: {:#?})", &v);
}
Ok(Err(err)) => {
log::warn!(
Expand Down Expand Up @@ -986,13 +982,13 @@ impl Handler for GetParamHandler {
log::debug!("GetParamHandler {:?} ", params);
type Request = (String, String);
let (caller_id, key) = Request::try_from_params(params)?;
let key = resolve(&caller_id, &key);
let key_full = resolve(&caller_id, &key);
let params = self.data.parameters.read().unwrap();
let key = key.strip_prefix('/').unwrap_or(&key).split('/');
let key_path = key_full.strip_prefix('/').unwrap_or(&key_full).split('/');

Ok(match params.get(key) {
Some(value) => (1, "", value.to_owned()),
None => (0, "", Value::string("".to_owned())),
Ok(match params.get(key_path) {
Some(value) => (1, "".to_owned(), value.to_owned()),
None => (-1, format!("Parameter [{key_full}] is not set"), Value::i4(0)),
}
.try_to_value()?)
}
Expand Down
Loading