Skip to content

Commit

Permalink
Update packet_printer (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
sktometometo authored Jan 25, 2024
1 parent fd6da41 commit 824a8c1
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions node_scripts/sdp_v2_packet_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@
import rospy

from smart_device_protocol.smart_device_protocol_interface import SDPInterface
from smart_device_protocol.utils import address_tuple_to_str, address_str_to_tuple


def callback(src_address, frame):
print("{} Packet from {}".format(type(frame), src_address))
print("{}".format(frame))
class Node:

def __init__(self, target_address_str = None):
self.target_address = address_str_to_tuple(target_address_str) if target_address_str is not None else None
self.interface = SDPInterface(callback_data=self.callback, callback_meta=self.callback)

def callback(self, src_address, frame):
if self.target_address is not None:
if src_address == self.target_address:
print("{} Packet from {}".format(type(frame), address_tuple_to_str(src_address)))
print("{}".format(frame))
else:
print("{} Packet from {}".format(type(frame), address_tuple_to_str(src_address)))
print("{}".format(frame))


if __name__ == "__main__":
rospy.init_node("smart_device_protocol_packet_printer")
interface = SDPInterface(callback_data=callback, callback_meta=callback)
target_address = rospy.get_param('~target_address', None)
node = Node(target_address_str=target_address)
rospy.spin()

0 comments on commit 824a8c1

Please sign in to comment.