Bus Listener Module
- class mtf.network_port.bus_listener.BusListener
Listening to frames on a specific communication bus
- __init__(bus_name: str, *args, **kwargs)
- get_queue() Queue[BusEvent]
Return the queue containing the events or messages related to the communication bus Return:
Queue[BusEvent]
- reset()
Reset the state of the bus listener by clearing its history and emptying the event queue
- start_listening(silent_mode: bool = False) bool
Start listening for events on a communication bus Args:
silent_mode (bool): Specify whether the listening should be done in silent mode or not
- Return:
bool
- stop_listening() bool
Stop listening for events on a communication bus Return:
bool
- register_callback(callback_fnc: Callable[[BusEvent], None])
- Parameters:
callback_fnc – callback function with parameter of type
BusEvent
Setting a callback# ... from mtf.mtf_types import BusEvent # ... def my_bus_event_callback(msg: BusEvent): # do things # ... creating listener # register our callback listener.register_callback(my_bus_event_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
Setting a callback# ... from mtf.mtf_types import BusEvent # ... def my_bus_event_callback(msg: BusEvent): # do things # ... creating listener, register callback, do work # register our callback listener.register_callback(my_bus_event_callback)
- callback_(data_frame: BusEvent)
used as a callback function when an event or frame is received on the communication bus Args:
data_frame (BusEvent): The data frame
- clean_up()
Clean up all controller instances. This method should be overridden to precise the specific cleanup logic. If an instance does not override it, a default message will appear to inform that there are no cleanup logic is implemented.
- Return:
bool: True when the cleanup was successful, otherwise False if cleanup failed. By default, it returns True, yet this method should be overridden to present the actual cleanup status.
- 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.
- 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.bus_listener.CanBusListener
Manage event listening on a CAN bus
- __init__(bus_name: 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.
- callback_(data_frame: BusEvent)
used as a callback function when an event or frame is received on the communication bus Args:
data_frame (BusEvent): The data frame
- clean_up()
Clean up all controller instances. This method should be overridden to precise the specific cleanup logic. If an instance does not override it, a default message will appear to inform that there are no cleanup logic is implemented.
- Return:
bool: True when the cleanup was successful, otherwise False if cleanup failed. By default, it returns True, yet this method should be overridden to present the actual cleanup status.
- 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]
Return the queue containing the events or messages related to the communication bus Return:
Queue[BusEvent]
- register_callback(callback_fnc: Callable[[BusEvent], None])
- Parameters:
callback_fnc – callback function with parameter of type
BusEvent
Setting a callback# ... from mtf.mtf_types import BusEvent # ... def my_bus_event_callback(msg: BusEvent): # do things # ... creating listener # register our callback listener.register_callback(my_bus_event_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()
Reset the state of the bus listener by clearing its history and emptying the event queue
- start_listening(silent_mode: bool = False) bool
Start listening for events on a communication bus Args:
silent_mode (bool): Specify whether the listening should be done in silent mode or not
- Return:
bool
- stop_listening() bool
Stop listening for events on a communication bus Return:
bool
- unregister_callback(callback_fnc)
- Parameters:
callback_fnc – callback function with parameter of type
BusEvent
Setting a callback# ... from mtf.mtf_types import BusEvent # ... def my_bus_event_callback(msg: BusEvent): # do things # ... creating listener, register callback, do work # register our callback listener.register_callback(my_bus_event_callback)
- class mtf.network_port.bus_listener.LinBusListener
Manage event listening on a LIN bus
- __init__(bus_name: 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.
- callback_(data_frame: BusEvent)
used as a callback function when an event or frame is received on the communication bus Args:
data_frame (BusEvent): The data frame
- clean_up()
Clean up all controller instances. This method should be overridden to precise the specific cleanup logic. If an instance does not override it, a default message will appear to inform that there are no cleanup logic is implemented.
- Return:
bool: True when the cleanup was successful, otherwise False if cleanup failed. By default, it returns True, yet this method should be overridden to present the actual cleanup status.
- 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]
Return the queue containing the events or messages related to the communication bus Return:
Queue[BusEvent]
- register_callback(callback_fnc: Callable[[BusEvent], None])
- Parameters:
callback_fnc – callback function with parameter of type
BusEvent
Setting a callback# ... from mtf.mtf_types import BusEvent # ... def my_bus_event_callback(msg: BusEvent): # do things # ... creating listener # register our callback listener.register_callback(my_bus_event_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()
Reset the state of the bus listener by clearing its history and emptying the event queue
- start_listening(silent_mode: bool = False) bool
Start listening for events on a communication bus Args:
silent_mode (bool): Specify whether the listening should be done in silent mode or not
- Return:
bool
- stop_listening() bool
Stop listening for events on a communication bus Return:
bool
- unregister_callback(callback_fnc)
- Parameters:
callback_fnc – callback function with parameter of type
BusEvent
Setting a callback# ... from mtf.mtf_types import BusEvent # ... def my_bus_event_callback(msg: BusEvent): # do things # ... creating listener, register callback, do work # register our callback listener.register_callback(my_bus_event_callback)
- class mtf.network_port.bus_listener.IoListener
Manage event listening on a IO bus
- __init__(bus_name: str)
- property last_value
Returns a deep copy of the last value in a queue
- get_queue() Queue[IoEvent]
Return the queue containing the events or messages related to the IO communication bus Return:
Queue[IoEvent]
- register_callback(callback_fnc)
- Parameters:
callback_fnc – callback function with parameter of type IoEvent
Setting a callback# ... from mtf.mtf_types import IoEvent # ... def my_callback(msg: IoEvent): # 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 io_listener_callabck(io_event :IoEvent)
- callback_(io_event: IoEvent)
used as a callback function when an event or frame is received on the communication bus Args:
data_frame (BusEvent): The data frame
- 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()
Clean up all controller instances. This method should be overridden to precise the specific cleanup logic. If an instance does not override it, a default message will appear to inform that there are no cleanup logic is implemented.
- Return:
bool: True when the cleanup was successful, otherwise False if cleanup failed. By default, it returns True, yet this method should be overridden to present the actual cleanup status.
- 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.
- reset()
Reset the state of the bus listener by clearing its history and emptying the event queue
- start_listening(silent_mode: bool = False) bool
Start listening for events on a communication bus Args:
silent_mode (bool): Specify whether the listening should be done in silent mode or not
- Return:
bool
- stop_listening() bool
Stop listening for events on a communication bus Return:
bool
- class mtf.network_port.bus_listener.FlexrayBusListener
Manage event listening on a Flexray bus
- __init__(bus_name: str)
- get_queue() Queue[FlexrayBusEvent]
Return the queue containing the events or messages related to the Flexray communication bus Return:
Queue[FlexrayBusEvent]
- register_callback(callback_fnc: Callable[[FlexrayBusEvent], None])
- Parameters:
callback_fnc – callback function with parameter of type FlexrayBusEvent
Setting a callback# ... from mtf.mtf_types import FlexrayBusEvent # ... def my_callback(msg: FlexrayBusEvent): # 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 FlexrayBusEvent, which has been registered
:Example def flexray_bus_listener_callabck(data_frame :FlexrayBusEvent)
- callback_(data_frame: BusEvent)
used as a callback function when an event or frame is received on the communication bus Args:
data_frame (BusEvent): The data frame
- 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()
Clean up all controller instances. This method should be overridden to precise the specific cleanup logic. If an instance does not override it, a default message will appear to inform that there are no cleanup logic is implemented.
- Return:
bool: True when the cleanup was successful, otherwise False if cleanup failed. By default, it returns True, yet this method should be overridden to present the actual cleanup status.
- 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.
- reset()
Reset the state of the bus listener by clearing its history and emptying the event queue
- start_listening(silent_mode: bool = False) bool
Start listening for events on a communication bus Args:
silent_mode (bool): Specify whether the listening should be done in silent mode or not
- Return:
bool
- stop_listening() bool
Stop listening for events on a communication bus Return:
bool
- class mtf.network_port.bus_listener.LegacyBusesListener
- __init__(channels_name: set[str])
- start_listening(direction: ~mtf.libs.mtf_pybinder.ListenerDirection = <ListenerDirection.Any: 2>, silent_mode: bool = False) bool
- stop_listening() bool
- register_callback(callback_fnc: Callable[[BusEvent], None])
- Parameters:
callback_fnc – callback function with parameter of type
BusEvent
Setting a callback# ... from mtf.mtf_types import BusEvent # ... def my_bus_event_callback(msg: BusEvent): # do things # ... creating listener # register our callback listener.register_callback(my_bus_event_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
Setting a callback# ... from mtf.mtf_types import BusEvent # ... def my_bus_event_callback(msg: BusEvent): # do things # ... creating listener, register callback, do work # register our callback listener.register_callback(my_bus_event_callback)
- 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() bool
Clean up all controller instances. This method should be overridden to precise the specific cleanup logic. If an instance does not override it, a default message will appear to inform that there are no cleanup logic is implemented.
- Return:
bool: True when the cleanup was successful, otherwise False if cleanup failed. By default, it returns True, yet this method should be overridden to present the actual cleanup status.
- 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.