DoipServer

class mtf.diag_port.diag_servers.doip_server.DoipServer

Implement a basic DoIP server.

This class implements the functionality to (automatically) handle DoIP packets, prepare and send appropriate responses.

__init__(ip: str, logical_address: int, port: int = 13400, buffer_size: int = 1024, sock_opts: dict = None)

Create a new DoIP server instance using the given parameters.

Args:

ip (str): The IP address of the DoIP server. logical_address (int): The logical address of the DoIP server. port (int): The DoIP server port number (default: 13400). buffer_size (int): The buffer size of the DoIP server (default: 1024). sock_opts (dict): The socket arguments key-value pairs (default: None).

Returns:

DoipServer: The newly created DoIP server instance.

Note:

Note

The IP address may be IPv6 as well as IPv4, though the DoIP specification prefers IPv6.

Socket argument keys can be either option names defaulting to SOL_SOCKET level or tuples explicitly specifying the socket level and the option name. And values represent the corresponding option values.

trigger_vehicle_announcement(ip: str, occurrence: int = 1, cycle: int = 0, port: int | None = None, further_action: bytes = b'\x00')

Trigger the DoIP Vehicle Announcement Message to be sent.

Args:

ip (str): The IP address to send the packet to. occurrence (int): The number of times the packet will be sent (default: 1). cycle (int): The time (in ms) to wait before the next packet is sent (default: 0). port (Optional[int]): The port to send the packet(s) on (default: None). further_action (bytes): Data bytes to be added to the packet (default: b’').

Note:

Note

This function sends the vehicle announcement message (0x0004). It creates the DoIP message payload and sends it at every cycle interval for a specified number of occurrence times to the given (IP, port).

configure_socket_options(sock_opts)

Configure socket options based on the provided sock_opts dictionary.

daemon_start()

Daemon thread that will run in the background of the main program.

property positive_responding: bool

Getter of positive_responding attribute

start()

Start the diagnostic server.

stop()

Stop the diagnostic server and close the socket.

wait_connection()

Wait for tcp connection with the diagnostic server.

call_back(data: bytes, connection: socket, adrr: str)

Process the input data and, if necessary, generate an appropriate response.

Args:

data (bytes): Doip request’s data that will be processed. connection (socket): Doip server socket. adrr (str): Doip server address.

Note:

Note

The DoipServer callback function orchestrates the Doip communication: It handles the incoming Doip requests, processes them based on their content and then sends appropriate responses back to the client.