Skip to content

Instantly share code, notes, and snippets.

@district10
Created April 1, 2021 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save district10/7284191c905034bdcc173eb661e5ba32 to your computer and use it in GitHub Desktop.
Save district10/7284191c905034bdcc173eb661e5ba32 to your computer and use it in GitHub Desktop.
import rospy
from std_msgs.msg import String
def chunks(lst, n):
"""Yield successive n-sized chunks from lst."""
for i in range(0, len(lst), n):
yield lst[i:i + n]
def callback(data):
rospy.loginfo(f'\n\ninput string: (#bytes: {len(data.data):,})')
# rospy.loginfo(data.data)
rospy.loginfo('hex:')
for idx, line in enumerate(chunks(data.data, 10)):
print(f'#{idx * 10:3d}\t\t\t{", ".join(f"{ord(c):02x}" for c in line)}')
def listener(topics):
rospy.init_node('node_name')
for topic in topics:
rospy.Subscriber(topic, String, callback)
# spin() simply keeps python from exiting until this node is stopped
rospy.spin()
print('listening...')
listener(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment