Doip Server Module
- class mtf.diag_port.diag_servers.doip_server.DoipRequest
The Doip responses generator.
- __init__(payload: bytes, logical_add: bytes | None = None)
DoipRequest constructor.
- Parameters:
payload – Doip response payload.
logical_add – server/ target logical address.
- generate_negative_response(nrc: int = 17, data: bytes = b'') bytes
- This function generates a UDS message encapsulated in a DoIP header, representing
a negative response to a DoIP request.
- Args:
param nrc (int): Negative response Code. Defaults to 0x11. param data (bytes): response data.
- Returns:
bytes: doip negative response composed of the Doip header and the uds packet.
- generate_ack()
Generate the tcp acknowledgement.
- Args:
This function does not take any parameter.
- Returns:
bytes: The acknowledgement packet.
- generate_routing_activation_response() bytes
This function generates a DoIP routing activation response packet.
- Args:
This function does not take any parameter.
- Returns:
bytes: The routing activation response.
- generate_positive_response(data: bytes = b'') bytes
- This function generates a UDS message encapsulated in a DoIP header
, representing a positive response to a DoIP request.
- Args:
data (bytes): response data.
- Returns:
bytes: The doip positive response composed of the Doip header and the uds packet.
- class mtf.diag_port.diag_servers.doip_server.DoipServer
Doip server
- __init__(ip: str, logical_address: int, port: int = 13400, buffer_size: int = 1024, sock_opts: dict | None = None)
Doip server constructor.
- Parameters:
ip – Doip server ip address.
logical_address – Doip server logical address.
port – Doip port number. Defaults to 13400.
buffer_size – buffer size.
sock_opts – Socket options defined in a dictionary. Keys can be either strings (option names, defaulting to SOL_SOCKET level) or tuples (level, option name). 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')
- 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).
- Args:
ip (str): The IP address of the receiver (To whom the announcement will be sent). occurrence (int): The number of attempts to send the vehicle announcement.Defaults: 1. cycle (int): The Waiting time after each send of the vehicle announcement.Defaults: 0. port (Optional[int]): The port number if given. Defaults to None. further_action (bytes): Data bytes to be added for the packet. Defaults to b’'.
- Returns:
This method does not return a value.
- 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)
- The DoipServer callback function orchestrates
the Doip communication: It handles the incoming Doip requests, processes them based on their contents and then sends appropriate responses back to the client.
- Args:
data (bytes): Doip request’s data that will be processed. connection (socket): Doip server socket. adrr (str): Doip server address.
- Returns:
This method does not return a value.