Bus Transmitter Module

This module provides functionality to simulate and perform bus transmissions.

class mtf.network_port.bus_transmitter.BusTransmitter

This abstract class provides the base functionality for performing bus transmissions.

abstract classmethod transmit_frame(*args, **kwargs)

Abstract method that transmits a frame.

Raises:

NotImplementedError: If this method is not implemented by a subclass.

class mtf.network_port.bus_transmitter.CanTransmitter

This class implements functionality for CAN frames transmissions.

transmitter
classmethod transmit_frame(channel_name: str, frame_id: int, payload: List, bit_rate_switch=True, error_flags: int = 0)

Transmits the given CAN frame on the specific channel.

Args:

channel_name (str): The name of the CAN channel to transmit the frame on. frame_id (int): The ID of the CAN frame to transmit. payload (FramePayload): The payload of the CAN frame to transmit. bit_rate_switch (bool, optional): Whether to use the bit rate switch (BRS) feature.

True -> BRS.ON False -> BRS.OFF Defaults to True.

error_flags (int): Whether to set a CRC error.

Defaults to 0.

Returns:

bool: True on success; False otherwise.

classmethod start_transmit_cyclic_frame(channel_name: str, frame_id: int, payload: List, cycle: int)

Transmits the given frame cyclically on a specific channel.

Args:

channel_name (str): The channel name to transmit over. frame_id (int): The ID of the CAN frame to transmit. payload (FramePayload): The payload of the CAN frame to transmit. cycle (int): The cycle duration (in ms).

Returns:
bool: True if the cyclic transmission was started successfully;

otherwise, False.

classmethod stop_transmit_cyclic_frame(channel_name: str, frame_id: int)

Stops the cyclic transmission of the given frame on the given channel.

Args:

channel_name (str): The channel name. frame_id (int): The ID of the CAN frame.

Returns:
bool: True if the cyclic transmission was successfully stopped;

otherwise, False.

class mtf.network_port.bus_transmitter.CanFdTransmitter

This class implements CAN-FD frames transmission.

classmethod transmit_frame(channel_name: str, frame_id: int, payload: List, bit_rate_switch=True, error_flags: int = 0)

Transmits the given frame on the given channel.

Args:

channel_name (str): The name of the CANFD channel to transmit the frame over. frame_id (int): The ID of the CANFD frame to transmit. payload (FramePayload): The payload of the CANFD frame to transmit. bit_rate_switch (bool, optional): Whether to use the bit rate switch (BRS) feature.

True -> BRS.ON False -> BRS.OFF Defaults to True.

error_flags (int): Whether to set a CRC error. Defaults to 0.

Returns:

bool: True on success; False otherwise.

classmethod start_transmit_cyclic_frame(channel_name: str, frame_id: int, payload: List, cycle: int)

Starts cyclic transmission of a CANFD frame on a specific channel.

Args:

channel_name (str): The channel name to start transmitting over. frame_id (int): The ID of the CANFD frame. payload (FramePayload): The payload of the CANFD frame to transmit. cycle (int): The cycle duration (in µs).

Returns:

bool: True if the cyclic transmission was started successfully; False otherwise.

classmethod stop_transmit_cyclic_frame(channel_name: str, frame_id: int)

Stops the cyclic transmission of a CANFD frame on a specific channel.

Args:

channel_name (str): The channel name to stop transmitting over. frame_id (int): The ID of the CANFD frame.

Returns:

bool: True if the cyclic transmission was successfully stopped; False otherwise.

transmitter
class mtf.network_port.bus_transmitter.LinTransmitter

This class implements functionality for frames transmission over a LIN bus.

transmitter
classmethod transmit_frame(channel_name: str, frame_id: int, payload: List)

Transmits the given LIN frame on a specific channel.

Args:

channel_name (str): The name of the LIN channel to transmit the frame over. frame_id (int): The ID of the LIN frame to transmit. payload (FramePayload): The payload of the LIN frame to transmit.

Returns:

bool: True on success; False otherwise.

classmethod wake_up_lin_bus(channel_name: str)

Wakes up the given LIN bus on the associated channel (Async Wake up sending).

Args:

channel_name (str): The LIN bus to wake up.

Returns:

bool: True if the LIN bus wakes up successfully; False otherwise.

classmethod get_state(channel_name: str)

Gets the current LIN bus state on the associated channel.

Args:

channel_name (str): The LIN bus to check.

Returns:

LinBusState: The current LIN bus state.

Note:

Note

Possible LIN bus states are:

  • Init : node is initiated.

  • Operational : node is awake.

  • Sleep : node in sleep mode.

class mtf.network_port.bus_transmitter.FlexrayTransmitter

This class implements functionality for frames transmission over a FlexRay bus.

transmitter
classmethod transmit_frame(channel_name: str, frame_id: str, payload: ~typing.List, communication_channel: ~mtf.enum_types.FRCommunicationChannel = <FRCommunicationChannel.A: 0>, transmission_mode: ~mtf.enum_types.TransmissionMode = TransmissionMode.SingleShot)

Transmits the given FlexRay frame.

Args:

channel_name (str): The name of the Flexray channel to transmit the frame over. frame_id (str): The ID of the Flexray frame to transmit. payload (FramePayload): The payload of the FlexRay frame to transmit. communication_channel (FRCommunicationChannel): The specific FlexRay communication channel (A or B).

Defaults to FRCommunicationChannel.ChannelA.

transmission_mode (TransmissionMode): Continuous or SingleShot.

Returns:

bool: True on success; False otherwise.

classmethod stop_transmit(channel_name: str, frame_id: str | int, communication_channel: ~mtf.enum_types.FRCommunicationChannel = <FRCommunicationChannel.A: 0>)

Stops the continuous transmission of the given frame on a specific communication channel.

Args:

channel_name (str): The name of the Flexray channel to stop transmitting the frame over. frame_id (Union[str, int]): The ID of the Flexray frame. communication_channel (FRCommunicationChannel): The specific FlexRay communication channel (A or B).

Defaults to FRCommunicationChannel.ChannelA.

Returns:

bool: True if the transmission was successfully stopped; False otherwise.

classmethod activate_wake_up(channel_name: str, do_wake_up: bool)

Activates wake up for the given channel.

Args:

channel_name (str): The channel name. do_wake_up (bool): Whether to automatically wake the FLEXRAY bus up when sleeping.

Returns:

bool: True on success; False otherwise.

classmethod start_fr_communication(channel_name: str, do_wake_up: bool)

Starts the FlexRay communication for the given channel.

Args:

channel_name (str): The channel name. do_wake_up (bool): Whether to automatically wake the bus up when sleeping.

Returns:

bool: True if the FlexRay communication started successfully; False otherwise.

classmethod stop_fr_communication(channel_name: str)

Stops communication for the given FlexRay bus.

Args:

channel_name (str): The name of the FlexRay bus to stop.

Returns:

bool: True on success; False otherwise.

Note:

Note

This method stops the sync messages from being transmitted.

class mtf.network_port.bus_transmitter.EthernetTransmitter

This class implements functionality to transmit Ethernet payloads.

transmitter
lock
classmethod transmit_frame(channel_name: str, payload: List)

Transmits the given payload over the given Ethernet channel.

Args:

channel_name (str): The name of the Ethernet channel to transmit the payload over. payload (FramePayload): The Ethernet packet to transmit.

Returns:

bool: True on success; False otherwise.

classmethod transmit_frame_queue(channel_name: str, timestamped_queue: List[tuple[int, List[int]]])

Transmits queue of packets with respect to the delays between successive message.

Args:

channel_name (str): The name of the Ethernet channel to transmit the frame over. timestamped_queue (List[tuple[int, List[int]]]): Each tuple contains:

  • First element: The delay between the previous message and the current message in nanoseconds.

  • Second element: The payload to be sent.

Examples:

transmit_frame_queue
from mtf.mtf_base import MtfBase

# Here the delta time between the first message and the second one is 4seconds 
# and the delta time between the second frame and the third one is 1second.
MtfBase.bus_manager.bus_transmitter(BusType.ETHERNET).transmit_frame_queue("ethernet_channel_name", [(0,[1,2,3]), (4000000000,[3,2,1]), ,(1000000000,payload)])

Note:

Warning

This method is deprecated. Please use configure_frame_queue and start_frame_queue instead.

classmethod configure_frame_queue(channel_name: str, timestamped_queue: List[tuple[int, List[int]]])

Configures a packet queue on the given Ethernet channel.

Args:

channel_name (str): The name of the Ethernet channel to be configured. timestamped_queue (list[tuple(int,list[int])]): Each tuple contains:

  • First element: The delay between the previous message and the current message in nanoseconds.

  • Second element: The payload to be sent.

Returns:

bool: True if the queue transmission is configured; False otherwise.

Examples:

configure_frame_queue
from mtf.mtf_base import MtfBase

MtfBase.bus_manager.bus_transmitter(BusType.ETHERNET).configure_frame_queue("ethernet_channel_name", [(0,[1,2,3]), (2,[1,2,3]) .....])
classmethod start_frame_queue(channel_name: str)

Starts transmitting the packet queue on the given Ethernet channel.

Args:

channel_name (str): The channel name to start the transmission over.

Returns:

bool: True on success; False otherwise.

Note:

Important

The packet queue to be transmitted must have been configured in advance.

classmethod send_ethernet_packet(channel_name: str, packet: Packet)

Transmits the given PCPP packet.

Args:

channel_name (str): The channel name to transmit over. packet (pcpp.Packet): The PCPP packet to transmit.

Returns:

bool: True on success; False otherwise.

Examples:

send_ethernet_packet
from mtf.libs.mtf_pybinder.pcpp import RawPacket, Packet
import numpy as np
from mtf.mtf_base import MtfBase

payload = [
    0x04, 0xEC, 0xD8, 0xCC, 0xA0, 0x92, 0xAC, 0x71, 0x2E, 0x41, 0x6F, 0x03,
    0x08, 0x00, 0x45, 0x00, 0x00, 0x43, 0xF7, 0x56, 0x40, 0x00, 0x6C, 0x11,
    0x58, 0x6B, 0x28, 0x63, 0xDC, 0xA2, 0xAC, 0x10, 0x0D, 0xD2, 0x01, 0xBB,
    0xFF, 0xA1, 0x00, 0x2F, 0xF2, 0x40, 0x4A, 0xA8, 0x26, 0x18, 0xAF, 0xFF,
    0x3D, 0xF4, 0x09, 0xAA, 0x5B, 0x16, 0xD9, 0xE1, 0xC7, 0xF5, 0x09, 0x2A,
    0xE8, 0xA9, 0x93, 0xD5, 0xE9, 0x44, 0x7A, 0xED, 0xC7, 0xDB, 0x37, 0x9E,
    0xEC, 0x97, 0xC3, 0x81, 0xA3, 0x61, 0xA6, 0xEC, 0x04,
]
udp_packet = np.array(payload,dtype=np.uint8)
rp = RawPacket(udp_packet)
my_packet = Packet(rp)
MtfBase.bus_manager.bus_transmitter(BusType.ETHERNET).send_ethernet_packet("ethernet_channel_name", my_packet)