Ark
Loading...
Searching...
No Matches
comm_handler.subscriber.Subscriber Class Reference

A subscriber for listening to messages on a communication channel. More...

Inheritance diagram for comm_handler.subscriber.Subscriber:
comm_handler.comm_handler.CommHandler

Public Member Functions

None __init__ (self, LCM lcm, str channel_name, type channel_type, Callable[[int, str, object], None] callback, list[object] callback_args=[])
 Initializes the subscriber with the necessary parameters for subscribing to a communication channel and setting up the callback function.
None subscriber_callback (self, str channel_name, bytes data)
 Callback function to handle incoming messages on the subscribed channel.
 subscribe (self)
 Subscribe to the configured channel.
 restart (self)
 Reconnect the subscriber to its channel.
None suspend (self)
 Suspends the subscriber by unsubscribing from the communication channel.
 get_info (self)
 Return a dictionary describing this subscriber.
Public Member Functions inherited from comm_handler.comm_handler.CommHandler
 __init__ (self, LCM lcm, str channel_name, type channel_type)
 Initializes the communication handler with an LCM instance, a channel name, and a channel type.
str __repr__ (self)
 Returns a string representation of the communication handler, showing the channel name and the type of message it handles.

Public Attributes

str comm_type = "Subscriber"
Public Attributes inherited from comm_handler.comm_handler.CommHandler
str channel_name = channel_name
type channel_type = channel_type
bool active = True

Protected Attributes

Callable[[int, str, object], None] _user_callback = callback
list[object] _callback_args = callback_args
 _sub = self._lcm.subscribe(self.channel_name, self.subscriber_callback)
Protected Attributes inherited from comm_handler.comm_handler.CommHandler
LCM _lcm = lcm
 Initializes the communication handler with an LCM instance, a channel name, and a channel type.

Detailed Description

A subscriber for listening to messages on a communication channel.

This class subscribes to a specified communication channel and calls a user-defined callback function whenever a new message is received. The message data is passed to the callback along with the timestamp and channel name.

Note
: This class is a subclass of CommHandler and requires an LCM instance, a channel name, and a channel type to function correctly.

Constructor & Destructor Documentation

◆ __init__()

None comm_handler.subscriber.Subscriber.__init__ ( self,
LCM lcm,
str channel_name,
type channel_type,
Callable[[int, str, object], None] callback,
list[object] callback_args = [] )

Initializes the subscriber with the necessary parameters for subscribing to a communication channel and setting up the callback function.

Parameters
lcmThe LCM instance used for communication.
channel_nameThe name of the communication channel.
channel_typeThe type of the message expected for this communication channel.
callbackThe user-defined callback function to be called with the message data.
callback_argsAdditional arguments to be passed to the callback function.

Member Function Documentation

◆ get_info()

comm_handler.subscriber.Subscriber.get_info ( self)

Return a dictionary describing this subscriber.

Reimplemented from comm_handler.comm_handler.CommHandler.

◆ restart()

comm_handler.subscriber.Subscriber.restart ( self)

Reconnect the subscriber to its channel.

Reimplemented from comm_handler.comm_handler.CommHandler.

◆ subscribe()

comm_handler.subscriber.Subscriber.subscribe ( self)

Subscribe to the configured channel.

Returns
: None

◆ subscriber_callback()

None comm_handler.subscriber.Subscriber.subscriber_callback ( self,
str channel_name,
bytes data )

Callback function to handle incoming messages on the subscribed channel.

This method decodes the message data, records the timestamp, and calls the user-defined callback function with the timestamp, channel name, and message.

Parameters
channel_nameThe name of the communication channel the message was received from.
dataThe raw byte data of the message.

◆ suspend()

None comm_handler.subscriber.Subscriber.suspend ( self)

Suspends the subscriber by unsubscribing from the communication channel.

This method releases the subscription and logs that the subscriber has been unsubscribed.

Reimplemented from comm_handler.comm_handler.CommHandler.

Member Data Documentation

◆ _callback_args

comm_handler.subscriber.Subscriber._callback_args = callback_args
protected

◆ _sub

comm_handler.subscriber.Subscriber._sub = self._lcm.subscribe(self.channel_name, self.subscriber_callback)
protected

◆ _user_callback

Callable[[int, str, object], None] comm_handler.subscriber.Subscriber._user_callback = callback
protected

◆ comm_type

str comm_handler.subscriber.Subscriber.comm_type = "Subscriber"

The documentation for this class was generated from the following file: