Can Tp Module

This module provides the CANTP protocol APIs.

class mtf.diag_port.can_tp.CanTp

This class povides all API functionality for the CANTP protocol.

__init__()

Create a new instance.

Returns:

CanTp: The newly created instance.

send(payload: list)

Send the given payload (supports CAN and CAN-FD).

Args:

payload (list): The payload to be sent.

Returns:
None or bool: Returns None if the controller is not configured or

the result of the controller’s transmit method.

close()

Close the CanTp instance and clean up the controller.

Returns:

bool: True if successfully closed, False otherwise.

recv()

Receive a frame from the configured controller.

Returns:

None or received_frame: The received frame or None if no frame was received.

bind(interface, address: Address, *args, **kwargs)

Bind to the given interface and ISOTP address.

Args:

interface (str): Name of the interface(channel name). address (isotp.Address): isotp.Address instance that will take the Receiver frame ID (rxid),

Transmitter frame ID (txid), source address, and target address.

Returns:

bool: True if successful, False otherwise.

Note:

Note

This method doesn’t support CAN-FD.

This method supports normal addressing in case both source_address and target_address equal 0.

Configure(interface, rxid, txid, protocol: CanProtocol = CanProtocol.CAN, pdu_length=8, padding_value=255, flow_timeout=200, *args, **kwargs)

Configure the CANTP communication using the given parameters.

Args:

interface (str): Name of the interface (channel name). rxid (int): Receiver frame ID. txid (int): Transmitter frame ID. protocol (CanProtocol): CAN protocol type (default: CAN). pdu_length (int): PDU length (default: 8). padding_value (int): Padding value (default: 255). flow_timeout (int): Flow timeout in ms (default: 200).

Returns:

bool: True if successful, False otherwise.

Note:

Note

CAN-FD is supported.

Important

In order to properly configure the client, the ‘source_address’ and ‘target_address’ along with their respective values must be specified within the kwargs parameter.

configure_flow_control(block_size: int, separation_time: int)

Configure the flow control using the given parameters.

Args:

block_size (int): Block size for flow control in bytes. separation_time (int): Separation time for flow control in ms.

Returns:

bool: True if successful, False otherwise.

update_transmission_timeout(tx_timeout: int)

Update the transmission timeout.

Args:

tx_timeout (int): Transmission timeout in milliseconds.

Returns:

bool: True if successful, False otherwise.

Note:

Note

When tx_timeout is set to 0, it will disable the transmission check.

get_can_tp_queue()

Get the CANTP queue.

Returns:

list: The CanTp queue.

reset_can_tp_queue()

Reset the CANTP queue.

clean_up()

Cleanup and close the instance.

Returns:

bool: True if successful, False otherwise.

static __new__(cls, *args, **kwargs)

Creates a new instance.

Args:

*args: The variable arguments list. **wargs: The keyword arguments list.

Returns:

ControllersBase: The newly created instance.

Note:

Note

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.

Important

Do not override this method in subclasses to maintain this functionality.

classmethod controllers_cleanup()

Cleans up all controller instances.

It calls clean_up() for each controller in the list. If a cleanup fails, an error is raised, but the method continues processing the remaining controllers.

Returns:
bool: True indicating that all controllers were cleaned up successfully.

Otherwise, False is returned when an error occurs during the cleanup process.