Ejemplo n.º 1
0
def send_obd(data):
    conn2 = IsoTPSocketConnection('can0',
                                  rxid=0x7E8,
                                  txid=0x700,
                                  params=params)
    conn2.tpsock.set_opts(txpad=0x55, tx_stmin=2500000)
    conn2.open()
    conn2.send(data)
    conn2.wait_frame()
    conn2.wait_frame()
    conn2.close()
def send_raw(data):
    global params

    conn2 = IsoTPSocketConnection('can0',
                                  rxid=0x7E8,
                                  txid=0x7E0,
                                  params=params)
    conn2.tpsock.set_opts(txpad=0x55, tx_stmin=2500000)

    conn2.open()
    conn2.send(data)
    results = conn2.wait_frame()
    conn2.close()

    if results:
        print(str(results))
        return results
    else:
        return data + b'0x00'
Ejemplo n.º 3
0


if __name__ == '__main__':
    isotp_socket = isotp.socket()
    isotp_socket.set_opts(txpad=CarConfig.TXPADSIZE, rxpad=CarConfig.RXPADSIZE)
    conn = IsoTPSocketConnection('can0', rxid=CarConfig.RXID, txid=CarConfig.TXID, tpsock=isotp_socket)

    with Client(conn, request_timeout=2, config=CarConfig.car_client_config) as client:
        try:
            client.change_session(DiagnosticSessionControl.Session.defaultSession)
            client.unlock_security_access(CarConfig.SECURITY_LEVEL)

            # suppress error
            for i in range(0,3):
                conn.send(b'\x0a\x27')
                time.sleep(0.5)

            client.change_session(DiagnosticSessionControl.Session.programmingSession)   

        except NegativeResponseException as e:
            print('Server refused our request for service %s with code "%s" (0x%02x)' % (e.response.service.get_name(), e.response.code_name, e.response.code))
        except UnexpectedResponseException as e:
            print('Server sent an invalid payload : %s' % e.response.original_payload)
        except TimeoutException as e:
            pass

    isotp_socket2 = isotp.socket()
    isotp_socket2.set_opts(txpad=CarConfig.TXPADSIZE, rxpad=CarConfig.RXPADSIZE)
    conn2 = IsoTPSocketConnection('can0', rxid=0x002, txid=0x001, tpsock=isotp_socket2)