def GMLAN_InitDiagnostics(sock, broadcast_socket=None, timeout=None, verbose=None, retry=0): # noqa: E501 # type: (ISOTPSocket, Optional[ISOTPSocket], Optional[int], Optional[bool], int) -> bool # noqa: E501 """ Send messages to put an ECU into diagnostic/programming state. :param sock: socket for communication. :param broadcast_socket: socket for broadcasting. If provided some message will be sent as broadcast. Recommended when used on a network with several ECUs. :param timeout: timeout for sending, receiving or sniffing packages. :param verbose: set verbosity level :param retry: number of retries in case of failure. :return: True on success else False """ # Helper function def _send_and_check_response(sock, req, timeout, verbose): # type: (ISOTPSocket, Packet, Optional[int], Optional[bool]) -> bool if verbose: print("Sending %s" % repr(req)) resp = sock.sr1(req, timeout=timeout, verbose=False) return _check_response(resp, verbose) if verbose is None: verbose = conf.verb > 0 retry = abs(retry) while retry >= 0: retry -= 1 # DisableNormalCommunication p = GMLAN(service="DisableNormalCommunication") if broadcast_socket is None: if not _send_and_check_response(sock, p, timeout, verbose): continue else: if verbose: print("Sending %s as broadcast" % repr(p)) broadcast_socket.send(p) time.sleep(0.05) # ReportProgrammedState p = GMLAN(service="ReportProgrammingState") if not _send_and_check_response(sock, p, timeout, verbose): continue # ProgrammingMode requestProgramming p = GMLAN() / GMLAN_PM(subfunction="requestProgrammingMode") if not _send_and_check_response(sock, p, timeout, verbose): continue time.sleep(0.05) # InitiateProgramming enableProgramming # No response expected p = GMLAN() / GMLAN_PM(subfunction="enableProgrammingMode") if verbose: print("Sending %s" % repr(p)) sock.send(p) time.sleep(0.05) return True return False
def GMLAN_InitDiagnostics(sock, broadcastsocket=None, timeout=None, verbose=None, retry=0): """Send messages to put an ECU into an diagnostic/programming state. Args: sock: socket to send the message on. broadcast: socket for broadcasting. If provided some message will be sent as broadcast. Recommended when used on a network with several ECUs. timeout: timeout for sending, receiving or sniffing packages. verbose: set verbosity level retry: number of retries in case of failure. Returns true on success. """ if verbose is None: verbose = conf.verb retry = abs(retry) while retry >= 0: retry -= 1 # DisableNormalCommunication p = GMLAN(service="DisableNormalCommunication") if broadcastsocket is None: if not _send_and_check_response(sock, p, timeout, verbose): continue else: if verbose: print("Sending %s as broadcast" % repr(p)) broadcastsocket.send(p) time.sleep(0.05) # ReportProgrammedState p = GMLAN(service="ReportProgrammingState") if not _send_and_check_response(sock, p, timeout, verbose): continue # ProgrammingMode requestProgramming p = GMLAN() / GMLAN_PM(subfunction="requestProgrammingMode") if not _send_and_check_response(sock, p, timeout, verbose): continue time.sleep(0.05) # InitiateProgramming enableProgramming # No response expected p = GMLAN() / GMLAN_PM(subfunction="enableProgrammingMode") if verbose: print("Sending %s" % repr(p)) sock.send(p) time.sleep(0.05) return True return False
def execute(self, socket, state, timeout=1, execution_time=1200, **kwargs): # type: (_SocketUnion, EcuState, int, int, Any) -> None supported = GMLAN_InitDiagnostics(cast(SuperSocket, socket), timeout=20, verbose=kwargs.get("debug", False)) # TODO: Refactor result storage if supported: self._store_result(state, GMLAN() / GMLAN_PM(), GMLAN(service=0xE5)) else: self._store_result( state, GMLAN() / GMLAN_PM(), GMLAN() / GMLAN_NR(returnCode=0x11, requestServiceId=0xA5)) self._state_completed[state] = True