Frame Listener Module
- class mtf.network_port._frame_listener.FrameListener
This class manages the listening and handling of frames on a specific communication channel like CAN, LIN and FlexRay.
- __init__(channel_name: str, frame_id: str)
- get_queue() Queue[BusEvent]
This method returns the queue that stores the frames received by the FrameListener.
- Returns:
Queue: The queue that holds the frames received by the FrameListener.
- reset()
This method clears the listener’s event queue.
- Returns:
This method does not return anything.
- start_listening(keep_cache: bool = False, silent_mode: bool = True, direction: Direction = Direction.Rx, mode: PublishingMode = PublishingMode.Always, include_null_frames: bool = False, callback: Callable[[MtfDataFrameEvent], None] | None = None)
This method starts listening for bus events and uses an optional callback function to handle the captured events.
- Args:
- silent_mode(bool): A flag that sets whether the listener is in silent mode.
Defaults to False. When silent_mode is False, both the MTF-Pyapi and MTF-Core callbacks are active. When silent_mode is True, only the MTF-Core callback is triggered.
- direction(Direction): The Frames direction (either receive: Rx or
transmit: Tx). In this case, the frames are received.
- mode(PublishingMode): An enumeration indicating that
“OnChange” is always occurring.
- include_null_frames(bool): A flag that determines whether null frames are included.
This option is only applicable to flexray channels. Defaults to False.
callback(Union[FrameCallback, None]): An optional callback function.
- Returns:
Union[None, bool]: Returns None if no callback is provided, or True if listening started successfully.
- stop_listening()
This method stops the listening process (captured events remain and the queue is not cleared).
- Returns:
bool: True if the listener was successfully stopped.
- register_callback(callback_fnc)
- Parameters:
callback_fnc – callback function with parameter of type BusEvent
Setting a callback# ... from mtf.mtf_types import BusEvent # ... def my_callback(msg: BusEvent): # do things # ... creating listener # register our callback listener.register_callback(my_callback)
Warning
The callback function should be lightweight without logs. Otherwise, it will reduce the performance dramatically. The object that is passed to callback functions is mutable. So the user must be careful. In case of silent mode, the callback functions will be invoked only when getting the queue.
- unregister_callback(callback_fnc)
- Parameters:
callback_fnc – callback function with parameter of type BusEvent, which has been registered
:Example def frame_listener_callabck(vent :BusEvent)
- static __new__(cls, *args, **kwargs)
Initializes a new instance of the ControllerBase.
The instance will be automatically added to the list of controllers to be cleaned up later. It guarantees that all the controller instances are followed up and cleaned up when the associate method ‘controllers_cleanup(cls)’ is called.
- Note:
Do not override this method in subclasses to maintain this functionality.
- Args:
*args: Suitable arguments passed to the constructor of the ControllerBase class. **kwargs: keywords passed to the constructor of the ControllerBase class.
- Returns:
instance(ControllerBase): The new instance of the class that has been created.
- clean_up()
This method cleans up resources used by the listener by stopping any ongoing operations and resetting the listener’s internal state to ensure it is in a clean and ready state for future use.
- Returns:
bool: Returns True if the cleanup is successfully done. False if an exception occurs.
- classmethod controllers_cleanup()
Cleans up all controller instances.
It Calls the clean_up() method for each instance, since it iterates through the list of controllers to realize any needed cleanup which can fail so an error will be raised. Then, the remaining instances will continue processing.
- Returns:
bool: True indicating that all the controllers are successfully cleaned up, otherwise False when an error occurred during the operation of the cleanup.
- class mtf.network_port._frame_listener.FlexrayFrameListener
This class extends the FrameListerner class to manage FlexRay frames.
- __init__(channel_name: str, frame_id: str)
- static __new__(cls, *args, **kwargs)
Initializes a new instance of the ControllerBase.
The instance will be automatically added to the list of controllers to be cleaned up later. It guarantees that all the controller instances are followed up and cleaned up when the associate method ‘controllers_cleanup(cls)’ is called.
- Note:
Do not override this method in subclasses to maintain this functionality.
- Args:
*args: Suitable arguments passed to the constructor of the ControllerBase class. **kwargs: keywords passed to the constructor of the ControllerBase class.
- Returns:
instance(ControllerBase): The new instance of the class that has been created.
- clean_up()
This method cleans up resources used by the listener by stopping any ongoing operations and resetting the listener’s internal state to ensure it is in a clean and ready state for future use.
- Returns:
bool: Returns True if the cleanup is successfully done. False if an exception occurs.
- classmethod controllers_cleanup()
Cleans up all controller instances.
It Calls the clean_up() method for each instance, since it iterates through the list of controllers to realize any needed cleanup which can fail so an error will be raised. Then, the remaining instances will continue processing.
- Returns:
bool: True indicating that all the controllers are successfully cleaned up, otherwise False when an error occurred during the operation of the cleanup.
- get_queue() Queue[BusEvent]
This method returns the queue that stores the frames received by the FrameListener.
- Returns:
Queue: The queue that holds the frames received by the FrameListener.
- register_callback(callback_fnc)
- Parameters:
callback_fnc – callback function with parameter of type BusEvent
Setting a callback# ... from mtf.mtf_types import BusEvent # ... def my_callback(msg: BusEvent): # do things # ... creating listener # register our callback listener.register_callback(my_callback)
Warning
The callback function should be lightweight without logs. Otherwise, it will reduce the performance dramatically. The object that is passed to callback functions is mutable. So the user must be careful. In case of silent mode, the callback functions will be invoked only when getting the queue.
- reset()
This method clears the listener’s event queue.
- Returns:
This method does not return anything.
- start_listening(keep_cache: bool = False, silent_mode: bool = True, direction: Direction = Direction.Rx, mode: PublishingMode = PublishingMode.Always, include_null_frames: bool = False, callback: Callable[[MtfDataFrameEvent], None] | None = None)
This method starts listening for bus events and uses an optional callback function to handle the captured events.
- Args:
- silent_mode(bool): A flag that sets whether the listener is in silent mode.
Defaults to False. When silent_mode is False, both the MTF-Pyapi and MTF-Core callbacks are active. When silent_mode is True, only the MTF-Core callback is triggered.
- direction(Direction): The Frames direction (either receive: Rx or
transmit: Tx). In this case, the frames are received.
- mode(PublishingMode): An enumeration indicating that
“OnChange” is always occurring.
- include_null_frames(bool): A flag that determines whether null frames are included.
This option is only applicable to flexray channels. Defaults to False.
callback(Union[FrameCallback, None]): An optional callback function.
- Returns:
Union[None, bool]: Returns None if no callback is provided, or True if listening started successfully.
- stop_listening()
This method stops the listening process (captured events remain and the queue is not cleared).
- Returns:
bool: True if the listener was successfully stopped.
- unregister_callback(callback_fnc)
- Parameters:
callback_fnc – callback function with parameter of type BusEvent, which has been registered
:Example def frame_listener_callabck(vent :BusEvent)
- class mtf.network_port._frame_listener.LinFrameListener
This class extends the FrameListerner class to manage LIN frames.
- __init__(channel_name: str, frame_id: str)
- static __new__(cls, *args, **kwargs)
Initializes a new instance of the ControllerBase.
The instance will be automatically added to the list of controllers to be cleaned up later. It guarantees that all the controller instances are followed up and cleaned up when the associate method ‘controllers_cleanup(cls)’ is called.
- Note:
Do not override this method in subclasses to maintain this functionality.
- Args:
*args: Suitable arguments passed to the constructor of the ControllerBase class. **kwargs: keywords passed to the constructor of the ControllerBase class.
- Returns:
instance(ControllerBase): The new instance of the class that has been created.
- clean_up()
This method cleans up resources used by the listener by stopping any ongoing operations and resetting the listener’s internal state to ensure it is in a clean and ready state for future use.
- Returns:
bool: Returns True if the cleanup is successfully done. False if an exception occurs.
- classmethod controllers_cleanup()
Cleans up all controller instances.
It Calls the clean_up() method for each instance, since it iterates through the list of controllers to realize any needed cleanup which can fail so an error will be raised. Then, the remaining instances will continue processing.
- Returns:
bool: True indicating that all the controllers are successfully cleaned up, otherwise False when an error occurred during the operation of the cleanup.
- get_queue() Queue[BusEvent]
This method returns the queue that stores the frames received by the FrameListener.
- Returns:
Queue: The queue that holds the frames received by the FrameListener.
- register_callback(callback_fnc)
- Parameters:
callback_fnc – callback function with parameter of type BusEvent
Setting a callback# ... from mtf.mtf_types import BusEvent # ... def my_callback(msg: BusEvent): # do things # ... creating listener # register our callback listener.register_callback(my_callback)
Warning
The callback function should be lightweight without logs. Otherwise, it will reduce the performance dramatically. The object that is passed to callback functions is mutable. So the user must be careful. In case of silent mode, the callback functions will be invoked only when getting the queue.
- reset()
This method clears the listener’s event queue.
- Returns:
This method does not return anything.
- start_listening(keep_cache: bool = False, silent_mode: bool = True, direction: Direction = Direction.Rx, mode: PublishingMode = PublishingMode.Always, include_null_frames: bool = False, callback: Callable[[MtfDataFrameEvent], None] | None = None)
This method starts listening for bus events and uses an optional callback function to handle the captured events.
- Args:
- silent_mode(bool): A flag that sets whether the listener is in silent mode.
Defaults to False. When silent_mode is False, both the MTF-Pyapi and MTF-Core callbacks are active. When silent_mode is True, only the MTF-Core callback is triggered.
- direction(Direction): The Frames direction (either receive: Rx or
transmit: Tx). In this case, the frames are received.
- mode(PublishingMode): An enumeration indicating that
“OnChange” is always occurring.
- include_null_frames(bool): A flag that determines whether null frames are included.
This option is only applicable to flexray channels. Defaults to False.
callback(Union[FrameCallback, None]): An optional callback function.
- Returns:
Union[None, bool]: Returns None if no callback is provided, or True if listening started successfully.
- stop_listening()
This method stops the listening process (captured events remain and the queue is not cleared).
- Returns:
bool: True if the listener was successfully stopped.
- unregister_callback(callback_fnc)
- Parameters:
callback_fnc – callback function with parameter of type BusEvent, which has been registered
:Example def frame_listener_callabck(vent :BusEvent)
- class mtf.network_port._frame_listener.CanFrameListener
This class extends the FrameListerner class to manage CAN frames.
- get_payloads()
This method gathers payloads from captured events in the listener queue.
- Returns:
list: A list containing the payloads extracted from all captured BusEvent objects in the queue.
- __init__(channel_name: str, frame_id: str)
- static __new__(cls, *args, **kwargs)
Initializes a new instance of the ControllerBase.
The instance will be automatically added to the list of controllers to be cleaned up later. It guarantees that all the controller instances are followed up and cleaned up when the associate method ‘controllers_cleanup(cls)’ is called.
- Note:
Do not override this method in subclasses to maintain this functionality.
- Args:
*args: Suitable arguments passed to the constructor of the ControllerBase class. **kwargs: keywords passed to the constructor of the ControllerBase class.
- Returns:
instance(ControllerBase): The new instance of the class that has been created.
- clean_up()
This method cleans up resources used by the listener by stopping any ongoing operations and resetting the listener’s internal state to ensure it is in a clean and ready state for future use.
- Returns:
bool: Returns True if the cleanup is successfully done. False if an exception occurs.
- classmethod controllers_cleanup()
Cleans up all controller instances.
It Calls the clean_up() method for each instance, since it iterates through the list of controllers to realize any needed cleanup which can fail so an error will be raised. Then, the remaining instances will continue processing.
- Returns:
bool: True indicating that all the controllers are successfully cleaned up, otherwise False when an error occurred during the operation of the cleanup.
- get_queue() Queue[BusEvent]
This method returns the queue that stores the frames received by the FrameListener.
- Returns:
Queue: The queue that holds the frames received by the FrameListener.
- register_callback(callback_fnc)
- Parameters:
callback_fnc – callback function with parameter of type BusEvent
Setting a callback# ... from mtf.mtf_types import BusEvent # ... def my_callback(msg: BusEvent): # do things # ... creating listener # register our callback listener.register_callback(my_callback)
Warning
The callback function should be lightweight without logs. Otherwise, it will reduce the performance dramatically. The object that is passed to callback functions is mutable. So the user must be careful. In case of silent mode, the callback functions will be invoked only when getting the queue.
- reset()
This method clears the listener’s event queue.
- Returns:
This method does not return anything.
- start_listening(keep_cache: bool = False, silent_mode: bool = True, direction: Direction = Direction.Rx, mode: PublishingMode = PublishingMode.Always, include_null_frames: bool = False, callback: Callable[[MtfDataFrameEvent], None] | None = None)
This method starts listening for bus events and uses an optional callback function to handle the captured events.
- Args:
- silent_mode(bool): A flag that sets whether the listener is in silent mode.
Defaults to False. When silent_mode is False, both the MTF-Pyapi and MTF-Core callbacks are active. When silent_mode is True, only the MTF-Core callback is triggered.
- direction(Direction): The Frames direction (either receive: Rx or
transmit: Tx). In this case, the frames are received.
- mode(PublishingMode): An enumeration indicating that
“OnChange” is always occurring.
- include_null_frames(bool): A flag that determines whether null frames are included.
This option is only applicable to flexray channels. Defaults to False.
callback(Union[FrameCallback, None]): An optional callback function.
- Returns:
Union[None, bool]: Returns None if no callback is provided, or True if listening started successfully.
- stop_listening()
This method stops the listening process (captured events remain and the queue is not cleared).
- Returns:
bool: True if the listener was successfully stopped.
- unregister_callback(callback_fnc)
- Parameters:
callback_fnc – callback function with parameter of type BusEvent, which has been registered
:Example def frame_listener_callabck(vent :BusEvent)
- class mtf.network_port._frame_listener.FrameListerner
- __init__(channel_name: str, frame_id: str)
- static __new__(cls, *args, **kwargs)
Initializes a new instance of the ControllerBase.
The instance will be automatically added to the list of controllers to be cleaned up later. It guarantees that all the controller instances are followed up and cleaned up when the associate method ‘controllers_cleanup(cls)’ is called.
- Note:
Do not override this method in subclasses to maintain this functionality.
- Args:
*args: Suitable arguments passed to the constructor of the ControllerBase class. **kwargs: keywords passed to the constructor of the ControllerBase class.
- Returns:
instance(ControllerBase): The new instance of the class that has been created.
- clean_up()
This method cleans up resources used by the listener by stopping any ongoing operations and resetting the listener’s internal state to ensure it is in a clean and ready state for future use.
- Returns:
bool: Returns True if the cleanup is successfully done. False if an exception occurs.
- classmethod controllers_cleanup()
Cleans up all controller instances.
It Calls the clean_up() method for each instance, since it iterates through the list of controllers to realize any needed cleanup which can fail so an error will be raised. Then, the remaining instances will continue processing.
- Returns:
bool: True indicating that all the controllers are successfully cleaned up, otherwise False when an error occurred during the operation of the cleanup.
- get_queue() Queue[BusEvent]
This method returns the queue that stores the frames received by the FrameListener.
- Returns:
Queue: The queue that holds the frames received by the FrameListener.
- register_callback(callback_fnc)
- Parameters:
callback_fnc – callback function with parameter of type BusEvent
Setting a callback# ... from mtf.mtf_types import BusEvent # ... def my_callback(msg: BusEvent): # do things # ... creating listener # register our callback listener.register_callback(my_callback)
Warning
The callback function should be lightweight without logs. Otherwise, it will reduce the performance dramatically. The object that is passed to callback functions is mutable. So the user must be careful. In case of silent mode, the callback functions will be invoked only when getting the queue.
- reset()
This method clears the listener’s event queue.
- Returns:
This method does not return anything.
- start_listening(keep_cache: bool = False, silent_mode: bool = True, direction: Direction = Direction.Rx, mode: PublishingMode = PublishingMode.Always, include_null_frames: bool = False, callback: Callable[[MtfDataFrameEvent], None] | None = None)
This method starts listening for bus events and uses an optional callback function to handle the captured events.
- Args:
- silent_mode(bool): A flag that sets whether the listener is in silent mode.
Defaults to False. When silent_mode is False, both the MTF-Pyapi and MTF-Core callbacks are active. When silent_mode is True, only the MTF-Core callback is triggered.
- direction(Direction): The Frames direction (either receive: Rx or
transmit: Tx). In this case, the frames are received.
- mode(PublishingMode): An enumeration indicating that
“OnChange” is always occurring.
- include_null_frames(bool): A flag that determines whether null frames are included.
This option is only applicable to flexray channels. Defaults to False.
callback(Union[FrameCallback, None]): An optional callback function.
- Returns:
Union[None, bool]: Returns None if no callback is provided, or True if listening started successfully.
- stop_listening()
This method stops the listening process (captured events remain and the queue is not cleared).
- Returns:
bool: True if the listener was successfully stopped.
- unregister_callback(callback_fnc)
- Parameters:
callback_fnc – callback function with parameter of type BusEvent, which has been registered
:Example def frame_listener_callabck(vent :BusEvent)