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.

This function is used to configure the CANTP connection by specifying the connection parameters.

Note

:caption:”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

:caption:”Note:”

CAN-FD is supported.

Note

:caption:”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

:caption:”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)

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.