Signal Module
- class mtf.network_port.signals.signal.SignalListener
- __init__(channel_name: str, frame_id: int, pdu_name: str, signal_name: str)
- get_queue() Queue
Get the queue
- start_listening(keep_cache: bool = False, silent_mode: bool = True, on_change: bool = False)
Starts listening for the signal.
- Args:
- on_change (bool, optional): A flag indicating if the listener should only trigger on signal changes.
Defaults to False.
- Returns:
bool: True if the listener was started successfully, False otherwise.
- stop_listening() bool
Stops listening for the signal.
- Returns:
bool: True if the listener was stopped successfully, False otherwise.
- register_callback(callback_fnc: Callable[[BaseEvent], None])
- Parameters:
callback_fnc – callback function with parameter of type BaseEvent
Setting a callback# ... from mtf.network_port.listeners.listener_base import BaseEvent # ... def my_callback(msg: BaseEvent): # 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: Callable[[BaseEvent], None])
- Parameters:
callback_fnc – callback function with parameter of type BaseEvent, which has been registered
:Example def frame_listener_callabck(event :BaseEvent)
- 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.
- reset()
cleanup the queue
- class mtf.network_port.signals.signal.Signal
- static __new__(cls, channel_name: str, frame_id: str, pdu_name: str, signal_name: str)
Overrides the __new__ method to ensure only one instance of Signal class is created for each tuple (channel_name, frame_id, pdu_name, signal_name).
- Args:
channel_name (str): The name of the channel. frame_id (str): The ID of the frame. pdu_name (str): The name of the pdu. signal_name (str): The name of the signal.
- Returns:
Signal: The signal instance associated with the tuple (channel_name, frame_id, pdu_name, signal_name).
- __init__(channel_name: str, frame_id: str, pdu_name: str, signal_name: str)
Initializes a Signal instance with the given tuple (channel_name, frame_id, pdu_name, signal_name).
- Args:
channel_name (str): The name of the channel. frame_id (str): The ID of the frame. pdu_name (str): The name of the pdu. signal_name (str): The name of the signal.
- property channel_name: str
Retrieves the name of the channel.
- Returns:
str: The name of the channel.
- property frame_id: str
Retrieves the ID of the frame.
- Returns:
str: The ID of the frame.
- property pdu_name: str
Retrieves the name of the pdu.
- Returns:
str: The name of the pdu.
- property signal_name: str
Retrieves the name of the signal.
- Returns:
str: The name of the signal.
- property listener
Retrieves a SignalListener instance associated with the signal.
- Returns:
SignalListener: The SignalListener instance associated with the signal.
- property frame_id_int
Retrieves the integer representation of the frame ID.
- Returns:
int: The integer representation of the frame ID.
- set_signal_raw_value(signal_value: int | list[int], update_and_send: bool = True) bool
Sets the raw value of the signal with the given value.
- Args:
signal_value (Union[int, list[int]]): The raw value of the signal. update_and_send (bool, optional): A flag indicating if the update and send operation should be performed.
Defaults to True.
- Returns:
bool: True if the raw value was set successfully, False otherwise.
- set_signal_physical_value(signal_value: float, update_and_send: bool = True) bool
Sets the physical value of the signal with the given value.
- Args:
signal_value (float): The physical value of the signal. update_and_send (bool, optional): A flag indicating if the update and send operation should be performed.
Defaults to True.
- Returns:
bool: True if the physical value was set successfully, False otherwise.
- get_signal_last_value() int | list[int]
Retrieves the last value of the signal.
- Returns:
Union[int, list[int]]: The last value of the signal.
- get_signal_last_physical_value() int | list[int]
Retrieves the last physical value of the signal.
- Returns:
Union[int, list[int]]: The last physical value of the signal.
- last_signal_value_retrieved() bool
Checks if the last value of the signal has been retrieved.
- Returns:
bool: True if the last value has been retrieved, False otherwise.
- get_signal_path() str
Retrieves the path of the signal.
- Returns:
str: The path of the signal.
- is_from_dynamic_pdu_signal() bool
Checks if the signal is from a dynamic PDU.
- Returns:
bool: True if the signal is from a dynamic PDU, False otherwise.
- classmethod clear_registered_signals()
Clears the instances dictionary of registered signals.