SfaManager

class mtf.diag_port.sfa.sfa_manager.SfaManager

This class implements a manager to handle token parsing, use and all the functionality related with sfa coming from TDFNext. this module run correctly only if diag manager was already started and all needed controllers already added.

__init__()
set_up(token_path: str)

Prepare environment for sfa manager, parse tokens under token_path This method must be called before calling any token related methods :param token_path: path to folder containing tokens :type token_path: str :return: :rtype:

add_ecu(connection_name: str, ecu_id: str | None = None, vin_id: str | None = None)

This function adds an ECU to the list with all its tokens, checks if the tokens are available int the ECU by sending corresponding diagnosis jobs.

:param
  • connection_name * (str): string with the name of the connection as configured in the diag manager config

  • ecu_id * (str): ECU identifier

  • vin_id * (str): Vehicule Identification Number

Returns:

True if process was successful, False otherwise

update_ecu(connection_name)

Updates all the features status for an ECU, performing a discovery job

Parameters:

connection_name – string containing the name of the target ecu

Returns:

clean_ecu_list()

This function cleans the ecu list completely

Returns:

switch_mode(connection_name: str, target_mode: EcuModes, switch_mode_retries: int = 5)

This function set the mode of a target ecu

Parameters:
  • switch_mode_retries (int) – retries to switch ecu mode

  • connection_name – string containing the name of the target ecu

  • target_mode – target EcuModes enum

Returns:

handle_engineering_mode_switch(connection_name, current_mode, target_mode, switch_mode_retries)
handle_field_mode_switch(connection_name, current_mode, target_mode, switch_mode_retries)
handle_plant_mode_switch(connection_name, current_mode, target_mode, switch_mode_retries)
read_mode(connection_name: str)

This function reads the current mode of the target ecu.

Parameters:

connection_name – string containing the target ecu name

Returns:

EcuModes value if success, None otherwise

write_token(connection_name: str, feature_id: hex, retries=1)

This function enables a specified feature in the target ECU, using the parsed token available.

Parameters:
  • connection_name – string with the name of the target ecu

  • feature_id – hex number with the desired feature id

  • retries – int value with the number of retries to perform. The manager will start from the oldest

token within that retry window until the newest token available in the list. :return: True if writing process succeeded, False otherwise. Num of tries performed.

write_specific_token(connection_name: str, feature_id: hex, token_index: int) bool

This function enables a specified feature in the target ECU, using the specified token that is selected by the tc

Parameters:
  • connection_name – string with the name of the target ecu

  • feature_id – hex number with the desired feature id

  • token_index – The index of the token in the sfa manager token list that should be used

Returns:

True if writing process succeeded, False otherwise.

set_feature_status(connection_name: str, feature_id: hex, status: int) bool

This function enable or disable a specific feature based on the status value

Parameters:
  • connection_name – string with the name of the target ecu

  • feature_id – hex number with the desired feature id

  • status – 0 in order to disable the provided feature, 1 in order ro enable it.

Returns:

True if writing process succeeded, False otherwise.

read_status(connection_name: str, feature_id: hex)

This function reads the current status of a feature in the target ecu.

Parameters:
  • connection_name – string with the name of the target ecu

  • feature_id – hex number with the desired feature id

Returns:

int in hex format with the status value for the feature, None if process failed

read_sensitive_feature_status(connection_name: str, feature_id: hex)

This function reads the current status of a feature in the target ecu.

Parameters:
  • connection_name – string with the name of the target ecu

  • feature_id – hex number with the desired feature id

Returns:

int in hex format with the status value for the sensitive feature, None if process failed

write_sensitive_token(connection_name: str, feature_id: hex, retries=1)

This function enables a specified feature in the target ECU, using the parsed token available.

Parameters:
  • connection_name – string with the name of the target ecu

  • feature_id – hex number with the desired feature id

  • retries – int value with the number of retries to perform. The manager will start from the oldest

token within that retry window until the newest token available in the list. :return: True if writing process succeeded, False otherwise. Num of tries performed.

clear_feature(connection_name: str, feature_id: hex)

This function clears a specified feature in the target ECU. Keep in mind that ENGINEERING mode is needed to clear features.

Parameters:
  • connection_name – string with the name of the target ecu

  • feature_id – hex number with the desired feature id

Returns:

True if process success, False otherwise

clear_all_features(connection_name: str)

This function clears all the features that have been enabled during the current session for an ecu. Last token to clear is the Engineering mode one, as is needed to set the device in that mode to perform these operations.

Parameters:

connection_name – string with the name of the target ecu

Returns:

True if process success, False otherwise

clear_all_features_mode(connection_name: str, original_mode)

This function clears all the features that have been enabled during the current session for an ecu. Last token to clear is the Engineering mode one, as is needed to set the device in that mode to perform these operations.

Parameters:
  • connection_name – string with the name of the target ecu

  • original_mode – current Ecu mode

Returns:

True if process success, False otherwise

fallback_field_mode(connection_name: str, safe_mode=True)

This function sets the ecu back to FIELD mode from ENGINEERING or PLANT mode. If safe_mode parameter is set to False, the function will skip checking if there is at least, one ENG token available to go back to engineering mode if needed for token clearing.

Parameters:
  • connection_name – string with the name of the target ecu

  • safe_mode – boolean to skip ward’s check for ENG tokens

Returns:

True if process success, False otherwise

property vin_id
get_vin_id(connection_name: str)

This function retrieves the VIN (Vehicle Identification Number) id

Parameters:

connection_name – string containing the name of the target ECU

Returns:

The entire VIN ID as a string. Returns None if an error occurs or if attempting to retrieve the VIN ID of the Device Under Test.

property token_list
get_ecu_id(connection_name)