def GMLAN_TransferData(sock, addr, payload, maxmsglen=None, timeout=None, verbose=None, retry=0): # noqa: E501 # type: (ISOTPSocket, int, bytes, Optional[int], Optional[int], Optional[bool], int) -> bool # noqa: E501 """ Send TransferData message. Usually used after calling RequestDownload. :param sock: socket to send the message on. :param addr: destination memory address on the ECU. :param payload: data to be sent. :param maxmsglen: maximum length of a single iso-tp message. default: maximum length :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. """ if verbose is None: verbose = conf.verb > 0 retry = abs(retry) startretry = retry scheme = conf.contribs['GMLAN']['GMLAN_ECU_AddressingScheme'] if addr < 0 or addr >= 2**(8 * scheme): warning("Error: Invalid address %s for scheme %s", hex(addr), str(scheme)) return False # max size of dataRecord according to gmlan protocol if maxmsglen is None or maxmsglen <= 0 or maxmsglen > (4093 - scheme): maxmsglen = (4093 - scheme) maxmsglen = cast(int, maxmsglen) for i in range(0, len(payload), maxmsglen): retry = startretry while True: if len(payload[i:]) > maxmsglen: transdata = payload[i:i + maxmsglen] else: transdata = payload[i:] pkt = GMLAN() / GMLAN_TD(startingAddress=addr + i, dataRecord=transdata) resp = sock.sr1(pkt, timeout=timeout, verbose=0) if _check_response(resp, verbose): break retry -= 1 if retry >= 0: if verbose: print("Retrying..") else: return False return True
def _get_initial_requests(self, **kwargs): # type: (Any) -> Iterable[Packet] scan_range = kwargs.pop("scan_range", range(0x1ff)) temp = conf.contribs["GMLAN"]['GMLAN_ECU_AddressingScheme'] # Shift operations to eliminate addresses not aligned to 4 max_addr = (2**(temp * 8) - 1) >> 2 addresses = (random.randint(0, max_addr) << 2 for _ in scan_range) return (GMLAN() / GMLAN_TD(subfunction=0, startingAddress=x) for x in addresses)