SfaManager
- class mtf.diag_port.sfa.sfa_manager.SfaManager
(SFA) Manager implementation.
This class implements a manager to handle token parsing, use all functionality related to sfa coming from TDFNext.
Note:
Important
In order for the SFA Manager to work properly the diag manager must already have been started and all needed controllers must have been added as well.
- __init__()
Create a new instance.
- set_up(token_path: str)
Parse all tokens from the given path and set up the environment.
- Args:
token_path (str): The path to parse tokens from.
Note:
Important
This method must be called before any other token-related method may be executed.
- add_ecu(connection_name: str, ecu_id: str = None, vin_id: str = None)
Add an ECU defined by the given parameters.
- Args:
connection_name (str): The name of the connection. ecu_id (str): The ID of the ECU to be added. vin_id (str): The Vehicle Identification Number of the ECU.
- Returns:
bool: True if the operation was successful, False otherwise.
Note:
Note
This function adds an ECU to the list with all its tokens, checks if the tokens are available in the ECU by sending corresponding diagnosis jobs.
- update_ecu(connection_name)
Update the ECU state defined by the given connection.
- Args:
connection_name (str): The name of the connection / ECU to be updated.
- Returns:
bool: True on success, False otherwise.
- clean_ecu_list()
Clean the ECU list.
- handle_engineering_token_status(engineering_token_status)
Check the given Engineering token status.
- Args:
engineering_token_status (int): The engineering token status.
Note:
Note
If Engineering token is Disabled (status == 2) or Expired (status == 03) we need to generate new tokens.
- handle_plant_token_status(result, plant_token_status, connection_name, switch_mode_retries)
Check the plant token status of the given connection.
- Args:
result (int): The result code of the operation. plant_token_status (int): The plant token status value. connection_name (str): The name of the connection to chck on. switch_mode_retries (int): The number of retries before giving up.
- Returns:
bool: True on success, False otherwise.
Note:
Note
On status codes 0x01 (Enabled), 0x02 (Disabled), and 0x03 (Expired) the token will be recovered, if possible.
- switch_mode(connection_name: str, target_mode: EcuModes, switch_mode_retries: int = 5)
Switch an ECU on the given connection to the given mode.
- Args:
connection_name (str): The of the connection /ECU. target_mode (EcuModes): The ECU modeto switch to. switch_mode_retries (int): The number of retries before giving up (default: 5).
- Returns:
bool: True on success, False otherwise.
- handle_engineering_mode_switch(connection_name, current_mode, target_mode, switch_mode_retries)
Handle the switching process to Engineering Mode.
- Args:
connection_name (str): The name of the connection / ECU. current_mode (EcuModes): The current ECU mode. target_mode (EcuModes): UNUSED. TODO: Remove this parameter. switch_mode_retries (int): The number of retries before giving up.
- Returns:
bool: True on success, False otherwise.
- handle_field_mode_switch(connection_name, current_mode, target_mode, switch_mode_retries)
Handle the switching process to FieldMode.
- Args:
connection_name (str): The name of the connection / ECU. current_mode (EcuModes): The current ECU mode. target_mode (EcuModes): UNUSED. TODO: Remove this parameter. switch_mode_retries (int): The number of retries before giving up.
- Returns:
bool: True on success, False otherwise.
- handle_plant_mode_switch(connection_name, current_mode, target_mode, switch_mode_retries)
Handle the switching process to PlantMode.
- Args:
connection_name (str): The name of the connection / ECU. current_mode (EcuModes): The current ECU mode. target_mode (EcuModes): UNUSED. TODO: Remove this parameter. switch_mode_retries (int): The number of retries before giving up.
- Returns:
bool: True on success, False otherwise.
- read_mode(connection_name: str)
Read the current ECU mode of the given connection.
- Args:
connection_name (str): The name of the connection / ECU.
- Returns:
EcuModes or None: The current ECU mode or None.
- write_token(connection_name: str, feature_id: hex, retries=1)
Enable the given feature in ghe gven ECU.
- Args:
connection_name (str): The name of the connetcion / ECU. feature_id (hex): The hexadecimal feature ID to enable. retries (int): The number of retries before giving up (default: 1).
- Returns:
bool: True on success, False otherwise.
Note:
Note
The manager will start from the oldest token within that retry window until the newest token available in the list.
- write_specific_token(connection_name: str, feature_id: hex, token_index: int) bool
Enable the given feature in the given ECU using the given token.
- Args:
connection_name (str): The name of the connection / ECU. feature_id (hex): The hexadecimal feature ID to enable. token_index (int): The index of the token to use.
- Returns:
bool: True on sucess, False otherwise.
- set_feature_status(connection_name: str, feature_id: hex, status: int) bool
Enable or disable an ECU feature according to the given parameters.
- Args:
connection_name (str): The name of the connection / ECU. feature_id (hex): The hexadecimal feature ID. status (int): Set to 1 to enable or 0 to disable the feature.
- Returns:
bool: True on success, False otherwise.
- read_status(connection_name: str, feature_id: hex)
Read the status of the given feature.
- Args:
connection_name (str): The name of the connection / ECU. feature_id (hex): The hexadecimal feature ID.
- Returns:
int or None: 1 if the feature is enabled, 0 if it is disabled, and None otherwise.
- read_sensitive_feature_status(connection_name: str, feature_id: hex)
Read the status of the given feature.
- Args:
connection_name (str): The name of the connection / ECU. feature_id (hex): The hexadecimal feature ID.
- Returns:
int or None: 1 if the feature is enabled, 0 if it is disabled, and None otherwise.
- write_sensitive_token(connection_name: str, feature_id: hex, retries=1)
Enable the given feature in ghe gven ECU.
- Args:
connection_name (str): The name of the connetcion / ECU. feature_id (hex): The hexadecimal feature ID to enable. retries (int): The number of retries before giving up (default: 1).
- Returns:
bool: True on success, False otherwise.
Note:
Note
The manager will start from the oldest token within that retry window until the newest token available in the list.
- clear_feature(connection_name: str, feature_id: hex)
Clear the given featurein the given ECU.
- Args:
connection_name (str): The name of te connection / ECU. feature_id (hex): The hexadecimal feature ID.
- Returns:
bool: True on success, False otherwise.
Note:
Important
In order to clear a feature the ECU must be in Engineering Mode.
- clear_all_features(connection_name: str)
Clear all features eabled previously in this session.
- Args:
connection_name (str): The name of the connection / ECU.
- Returns:
bool: True on success, False otherwise.
Note:
Important
In order to clear features the ECU must be in Engineering Mode, thus the Engineering Mode enabling token must not have been cleared in advance.
- clear_all_features_mode(connection_name: str, original_mode)
Clear all session features.
- Args:
connection_name (str): The name of the connection / ECU. original_mode (str): The current ECU mode.
- Returns:
bool: True on success, False otherwise.
Note:
Important
In order to clear features the ECU must be in Engineering Mode, thus the Engineering Mode enabling token must not have been cleared in advance.
- fallback_field_mode(connection_name: str, safe_mode=True)
Fall back to field mode.
- Args:
connection_name (str): The name of the connection / ECU. safe_mode (bool): Whether or not to check for ENG tokens before falling back (default: True).
- Returns:
bool: True on success, False otherwise
Note:
Note
This function sets the ecu back to FIELD mode from ENGINEERING or PLANT mode. If the safe_mode parameter is set to False, the function will skip checking whether there is at least, one ENG token available to go back to engineering mode if needed for token clearing.
- property vin_id
Get the VIN (Vehicle Identification Number).
- get_vin_id(connection_name: str)
Retrieve the VIN (Vehicle Identification Number).
- Args:
connection_name (str): The name of the target ECU.
- Returns:
str: The entire VIN or None if an error occurred.
- property token_list
Get the tokens list.
- get_ecu_id(connection_name)
Get the ECU ID.
- Args:
connection_name (str): The name of the connection.
- Returns:
string: The ECU ID.