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

Replaced message filler/reader in utils to work with newer stuff.. #77

Open
wants to merge 1 commit into
base: ros2
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions mqtt_bridge/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def _callback_ros(self, msg):
self._last_published = now

def _publish(self, msg):
values = extract_values(msg)
#self.ros_node.get_logger().info(f"EXTRACT VALUES -- \nmsg:{msg}\nvalues:{values}\n---")
payload = self._serialize(extract_values(msg))
self._mqtt_client.publish(topic=self._topic_to, payload=payload)

Expand Down Expand Up @@ -101,6 +103,8 @@ def _create_ros_message(self, mqtt_msg: mqtt.MQTTMessage):
msg_dict = self._deserialize(mqtt_msg.payload, raw=False)
else:
msg_dict = self._deserialize(mqtt_msg.payload)

#self.ros_node.get_logger().info(f"--- POPULATE INSTANCE\nmsg_dict:\n{msg_dict}\n\nmsg_type:{self._msg_type()}\n\npopulate:\n{populate_instance(msg_dict, self._msg_type())}")
return populate_instance(msg_dict, self._msg_type())


Expand Down
15 changes: 12 additions & 3 deletions mqtt_bridge/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from importlib import import_module
from typing import Any, Callable, Dict

from rosbridge_library.internal import message_conversion
# does not do lists... replaced with rosidl_runtime_py stuff!
#from rosbridge_library.internal import message_conversion
from rosidl_runtime_py.set_message import set_message_fields
from rosidl_runtime_py.convert import message_to_ordereddict

def lookup_object(object_path: str, package: str='mqtt_bridge') -> Any:
""" lookup object from a some.module:object_name specification. """
Expand All @@ -10,8 +13,14 @@ def lookup_object(object_path: str, package: str='mqtt_bridge') -> Any:
obj = getattr(module, obj_name)
return obj

def populate_instance(msg_dict, msg_type):
set_message_fields(msg_type, msg_dict)
return msg_type

extract_values = message_conversion.extract_values
populate_instance = message_conversion.populate_instance
def extract_values(msg):
return message_to_ordereddict(msg)

#extract_values = message_conversion.extract_values
#populate_instance = message_conversion.populate_instance

__all__ = ['lookup_object', 'extract_values', 'populate_instance']