def do_test(filename=None):
    elm = create_test_elm(filename)
    try:
        elm.open()
        elm.set_protocol(None)
        elm.connect_to_vehicle()
    except Exception as e:
        unexpected_error(e)
        # if the connection fails, everything else will too
        return

    global dtc_count
    dtc_count = 0

    read_all_supported_pids(elm, 0x01)

    if dtc_count:
        try:
            responses = elm.send_request(OBDRequest(sid=0x03))
            for r in responses:
                print "%s: %s" % (r.bus_message.header, str(r))
        except obd.exception.DataError:
            pass
        except Exception as e:
            unexpected_error(e)

    read_all_supported_pids(elm, 0x09)

    return
Exemple #2
0
def query_vehicle(interface):
    interface.open()
    interface.set_protocol(None)
    interface.connect_to_vehicle()

    responses = interface.send_request(OBDRequest(sid=0x01, pid=0x01))

    # Find the response(s) for ECUs that support emissions monitors
    ecus = []
    for r in responses:
        supported = [
            m for m in r.non_continuous_monitors
            if m in r.supported_monitors()
        ]
        if len(supported) > 0:
            ecus.append(r)

    # If the engine's off (none support monitors), just pick the first
    if len(ecus) == 0:
        ecus.append(responses[0])

    # Print the readiness status
    for ecu in ecus:
        if len(ecus) > 1:
            untested("multiple ECUs with supported monitors")
            print "ECU 0x%02X:" % response.header.tx_id
        check_readiness(ecu)

    interface.disconnect_from_vehicle()
    interface.close()
    return
Exemple #3
0
def read_all_supported_pids(elm, sid):

    for pid_support in range(0x00, 0x100, 0x20):
        time.sleep(DELAY)
        supported_pids = get_supported_pids(elm, sid, pid_support)

        # issue individual requests
        for pid in supported_pids:
            if pid == pid_support + 0x20:
                # fetched next time through outer loop
                break

            try:
                time.sleep(DELAY)
                responses = elm.send_request(OBDRequest(sid=sid, pid=pid))
                #print "got response for sid=$%02X pid=$%02X" % (sid, pid)
            except obd.exception.DataError:
                print "no response to sid=$%02X pid=$%02X" % (sid, pid)
                continue
            except Exception as e:
                unexpected_error(e)
                continue

            for r in responses:
                print "%s: %s" % (r.bus_message.header, str(r))

        if pid_support + 0x20 not in supported_pids:
            # stop if no higher pid_support queries are supported
            break
    return
Exemple #4
0
def read_dtcs(elm, sid):
    try:
        responses = elm.send_request(OBDRequest(sid=sid))
        for r in responses:
            print "%s: %s" % (r.bus_message.header, str(r))
    except obd.exception.DataError:
        pass
    except Exception as e:
        unexpected_error(e)
    return
Exemple #5
0
def get_supported_pids(elm, sid, start_pid):
    # default to all in case the support query fails for some reason
    supported_pids = range(start_pid + 1, start_pid + 1 + 0x20)

    try:
        responses = elm.send_request(OBDRequest(sid=sid, pid=start_pid))
        support = responses[0]
        supported_pids = support.supported_pids
        pids = ",".join(["$%02X" % pid for pid in supported_pids])
        print "supported pids for sid=$%02X pid=$%02X: [%s]" % (sid, start_pid, pids)
        obd.util.debug(supported_pids)
    except obd.exception.DataError as e:
        print "unable to determine PID support for sid=$%02X pid=$%02X, assuming none supported" % (sid, start_pid)
        supported_pids = []
        obd.util.debug(supported_pids)
    except Exception as e:
        unexpected_error(e)

    return supported_pids