-
-
Save district10/7284191c905034bdcc173eb661e5ba32 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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