示例#1
0
def main():
    """ Decode a tracefile """

    if len(sys.argv) < 2:
        sys.exit('Usage: %s tracefile' % sys.argv[0])
    
    if not os.path.exists(sys.argv[1]):
        sys.exit('ERROR: Tracefile %s was not found!' % sys.argv[1])
    
    tracefile = sys.argv[1]
    
    
    print "=================================================================="
    print ""
    print "OBD2 trace decode"
    print "----------------------"
    print ""
    print "Date: ", time.ctime()
    print ""
    print "Trace: ", tracefile
    
    
    print ""
    print "Loading default PID definitions from CSV file..."
    obd2.load_pids_from_csv( 'obd2_std_PIDs.csv' )
    # Global: obd2.PIDs[]
    
    print ""
    print "Loading default DTC definitions from CSV file..."
    obd2.load_dtcs_from_csv( 'obd2_std_DTCs.csv' )
    # Global: obd2.DTCs[]
    

    print ""
    with open(tracefile, 'rb') as f:
      while 1:
        print "code:"
        #l = obd2.decode_obd2_reply( read_result_from_trace(f) )
        eof, reply = read_result_from_trace(f) 
        if eof == 1:
          break
        if reply != []:
          pprint.pprint(reply)
          print "decoded:"
          pprint.pprint(obd2.decode_obd2_reply( reply[1:] ) )
def main():
    """ Decode a tracefile """

    if len(sys.argv) < 2:
        sys.exit('Usage: %s tracefile' % sys.argv[0])
    
    if not os.path.exists(sys.argv[1]):
        sys.exit('ERROR: Tracefile %s was not found!' % sys.argv[1])
    
    tracefile = sys.argv[1]
    
    
    print "=================================================================="
    print ""
    print "OBD2 trace decode"
    print "----------------------"
    print ""
    print "Date: ", time.ctime()
    print ""
    print "Trace: ", tracefile
    
    
    print ""
    print "Loading default PID definitions from CSV file..."
    obd2.load_pids_from_csv( 'obd2_std_PIDs.csv' )
    # Global: obd2.PIDs[]
    
    print ""
    print "Loading default DTC definitions from CSV file..."
    obd2.load_dtcs_from_csv( 'obd2_std_DTCs.csv' )
    # Global: obd2.DTCs[]
    

    # create OBD2_READER object 
    TYPE   = 'FILE'
    READER = 'ELM327'
    
    # create reader object (disconnected)
    reader = obd2_reader.OBD2reader( TYPE, READER )
    
    reader.debug = debug

    # open tracefile
    reader.open_trace(tracefile)

    # manually set since we can't query the tracefile
    #reader.Style   = 'can'
    #reader.Headers = 1
    #reader.Style   = 'old'
    #reader.Headers = 0
    reader.Style   = style
    reader.Headers = headers


    vehicle = obd2.OBD2( reader )


    print ""
    print "Reading from tracefile..."
    print ""

    while 1:
        record = reader.RTRV_record()
        if debug > 0:
            print "-----------------------------------"
            print "Raw Record: ",
            pprint.pprint(record)

        obd2_record = reader.triage_record( record )
        if obd2_record == []:
            # then this must have been something other than an obd2_record, nothing to do
            pass
        else:
            if debug > 1:
                print "--"
                print "Triaged Record: ",
                pprint.pprint(obd2_record)
                print "--"

            dec_rec =  obd2.decode_obd2_record( obd2_record )
            if debug > 0 :
                print "--"
                print "Decoded Record: ",
                pprint.pprint( dec_rec )
                print " "
                print "=================================="
                print " "

            # do something with the decoded obd2_record
            vehicle.store_info( dec_rec )

        if reader.eof == 1:
            break


    print "-----------------------------------"
    print ""
    print ""
    print "Reader Attributes:"
    print "------------------"
    pprint.pprint( reader.attr )
    print ""

    #
    print "Reader State:"
    print "-------------"
    print "      Type:", reader.Type         
    print "    Device:", reader.Device       
    print "     debug:", reader.debug        
    print "     State:", reader.State        
    #print "recwaiting", reader.recwaiting   
    print "     Style:", reader.Style        
    print "   Headers:", reader.Headers      
    #reader.attr         
    #print reader.attr_cmds 
    print "    Trace?:", reader.RecordTrace  
    print "Trace file:", reader.tf_out
    #



    print ""
    print "Vehicle Basic Info:"
    print "-------------------"
    pprint.pprint( vehicle.info )
    print ""
    vehicle.show_basic_info()
    print ""
    print ""
    print "Vehicle OBD2 Status:"
    print "--------------------"
    pprint.pprint( vehicle.obd2status )
    print ""
    print "-----------------------------------"
    print ""
    print "Vehicle supported PIDs:"
    print "-----------------------"
    pprint.pprint( vehicle.suppPIDs )
    print ""
    print "-----------------------------------"
    print ""
    print "Vehicle Sensor readings:"
    print "--------------------"
    pprint.pprint( vehicle.sensor_readings )
    print ""
    print "-----------------------------------"
    print "END"
        print k.rjust(16), ": ", reader.attr[k]

    # TODO
    #   notice that ELM327 is not connected and throw exception
    
    
    
    #print ""
    #print "OBD2 initialization"
    #print "-------------------"
    
    vehicle = obd2.OBD2( reader )
    
    #print ""
    #print "Loading default PID definitions from CSV file..."
    obd2.load_pids_from_csv( 'obd2_std_PIDs.csv' )
    #print ""
    #print "Loading default DTC definitions from CSV file..."
    obd2.load_dtcs_from_csv( 'obd2_std_DTCs.csv' )


    
    
    print ""
    print "=================================================================="
    # debug
    #reader.RTRV_record()
    print ""
    print "Scanning vehicle for supported features..."
    vehicle.scan_features()
    
示例#4
0
def main():
    
    
    print "=================================================================="
    print ""
    print "OBD2 vehicle demo scan"
    print "----------------------"
    print ""
    print "Scan date: ", time.ctime()
    
    
    
    print ""
    print "=================================================================="
    print ""
    print "Serial port attributes"
    print "----------------------"
    
    #ser_device = '/dev/pts/7'
    ser_device = '/dev/ttyUSB0'
    
    ser_settings = {
     'baudrate': 38400,
     'bytesize': serial.EIGHTBITS,
     'parity'  : serial.PARITY_NONE,
     'stopbits': serial.STOPBITS_ONE,
     'xonxoff' : False,
     'rtscts'  : False,
     'dsrdtr'  : False,
     'timeout' : None,
     'interCharTimeout': None,
     'writeTimeout'    : None
    }
    
    # create serial port (closed)
    port = serial.Serial(None)
    port.port = ser_device
    port.applySettingsDict(ser_settings)
    
    print "Device".rjust(16), ": ",  port.name
    #pprint.pprint( port.getSettingsDict() )
    #print ""
    
    settings = port.getSettingsDict()
    for k in sorted(settings.keys()):
        print k.rjust(16), ": ", settings[k]
    
    
    
    print ""
    print "=================================================================="
    print ""
    print "OBD2 reader device"
    print "------------------"
    
    TYPE   = 'SERIAL'
    READER = 'ELM327'
    
    # create reader object (disconnected)
    reader = obd2_reader.OBD2reader( TYPE, READER )
    reader.Port = port
    reader.Headers = 1

    # we want a record of what we pulled
    reader.record_trace()

    try:
        reader.connect()   # this also opens the serial port

        print "Device".rjust(16), ": ", str(reader.Device)
        print "State".rjust(16), ": ", str(reader.State)
        print "Style".rjust(16), ": ", str(reader.Style)
        print "Headers".rjust(16), ": ", str(reader.Headers)

        #pprint.pprint( reader.attr )

        for k in sorted(reader.attr.keys()):
            print k.rjust(16), ": ", reader.attr[k]

    except:
        print("\n\nConnection Error\n\n")
        return

    # TODO
    #   notice that ELM327 is not connected and throw exception
    
    
    
    print ""
    print "=================================================================="
    print ""
    print "OBD2 initialization"
    print "-------------------"
    
    vehicle = obd2.OBD2( reader )
    
    print ""
    print "Loading default PID definitions from CSV file..."
    obd2.load_pids_from_csv( 'obd2_std_PIDs.csv' )
    
    print ""
    print "Loading default DTC definitions from CSV file..."
    obd2.load_dtcs_from_csv( 'obd2_std_DTCs.csv' )


    
    
    # debug
    #reader.RTRV_record()
    print ""
    print "Scanning vehicle for supported features..."
    vehicle.scan_features()
    
    #print ""
    #print "Supported PIDs - DEBUG"
    #print "----------------------"
    #pprint.pprint(vehicle.suppPIDs)
    
    
    
    print ""
    print "=================================================================="
    print " "
    print "General vehicle info"
    print "--------------------"
    vehicle.scan_basic_info()
    vehicle.show_basic_info()
    print " "
    # I should fix the inconsistent use of "scan"
    
    
    
    print ""
    print "=================================================================="
    print " "
    print "Scan for Diagnostic and Emmissions Monitor info"
    print "-----------------------------------------------"
    print " "
    #print "OBD2 Status BEFORE scan:"
    #pprint.pprint(vehicle.obd2status)
    #print " "
    #print "Scanning for OBD2 status... "
    vehicle.scan_obd2_status()
    print " "
    #print "OBD2 Status AFTER scan:"
    pprint.pprint(vehicle.obd2status)
    print " "
    
    
    
    print ""
    print "=================================================================="
    print " "
    print "Scan for Current Sensor Readings"
    print "--------------------------------"
    print " "
    #vehicle.scan_curr_sensors()
    sensors = vehicle.curr_sensors()
    for pid in sensors:
        vehicle.scan_pid( pid )
        vehicle.show_last_reading( pid )
    print " "
    for pid in sensors:
        vehicle.scan_pid( pid )
        vehicle.show_last_reading( pid )
    print " "
    print " RAW Data structure:"
    pprint.pprint( vehicle.sensor_readings )
    

    print " "
    print " "
    print " DTCs:"
    vehicle.scan_pid( '03' )
    vehicle.show_last_reading( '03' )
    
    
    
    print ""
    print "=================================================================="
    print "=================================================================="
示例#5
0
def main():
    
    
    print "=================================================================="
    print ""
    print "OBD2 vehicle demo scan"
    print "----------------------"
    print ""
    print "Scan date: ", time.ctime()
    
    
    
    print ""
    print "=================================================================="
    print ""
    print "Serial port attributes"
    print "----------------------"
    
    #ser_device = '/dev/pts/7'
    ser_device = '/dev/ttyUSB0'
    
    ser_settings = {
     'baudrate': 38400,
     'bytesize': serial.EIGHTBITS,
     'parity'  : serial.PARITY_NONE,
     'stopbits': serial.STOPBITS_ONE,
     'xonxoff' : False,
     'rtscts'  : False,
     'dsrdtr'  : False,
     'timeout' : None,
     'interCharTimeout': None,
     'writeTimeout'    : None
    }
    
    # create serial port (closed)
    port = serial.Serial(None)
    port.port = ser_device
    port.applySettingsDict(ser_settings)
    
    print "Device".rjust(16), ": ",  port.name
    #pprint.pprint( port.getSettingsDict() )
    #print ""
    
    settings = port.getSettingsDict()
    for k in sorted(settings.keys()):
        print k.rjust(16), ": ", settings[k]
    
    
    
    print ""
    print "=================================================================="
    print ""
    print "OBD2 reader device"
    print "------------------"
    
    TYPE   = 'SERIAL'
    READER = 'ELM327'
    
    # create reader object (disconnected)
    reader = obd2_reader.OBD2reader( TYPE, READER )
    reader.Port = port
    reader.Headers = 1

    # we want a record of what we pulled
    reader.record_trace()

    reader.connect()   # this also opens the serial port
    
    print "Device".rjust(16), ": ", str(reader.Device)
    print "State".rjust(16), ": ", str(reader.State)
    print "Style".rjust(16), ": ", str(reader.Style)
    print "Headers".rjust(16), ": ", str(reader.Headers)

    #pprint.pprint( reader.attr )
    
    for k in sorted(reader.attr.keys()):
        print k.rjust(16), ": ", reader.attr[k]

    # TODO
    #   notice that ELM327 is not connected and throw exception
    
    
    
    print ""
    print "=================================================================="
    print ""
    print "OBD2 initialization"
    print "-------------------"
    
    vehicle = obd2.OBD2( reader )
    
    print ""
    print "Loading default PID definitions from CSV file..."
    obd2.load_pids_from_csv( 'obd2_std_PIDs.csv' )
    
    print ""
    print "Loading default DTC definitions from CSV file..."
    obd2.load_dtcs_from_csv( 'obd2_std_DTCs.csv' )


    
    
    # debug
    #reader.RTRV_record()
    print ""
    print "Scanning vehicle for supported features..."
    vehicle.scan_features()
    
    #print ""
    #print "Supported PIDs - DEBUG"
    #print "----------------------"
    #pprint.pprint(vehicle.suppPIDs)
    
    
    
    print ""
    print "=================================================================="
    print " "
    print "General vehicle info"
    print "--------------------"
    vehicle.scan_basic_info()
    vehicle.show_basic_info()
    print " "
    # I should fix the inconsistent use of "scan"
    
    
    
    print ""
    print "=================================================================="
    print " "
    print "Scan for Diagnostic and Emmissions Monitor info"
    print "-----------------------------------------------"
    print " "
    #print "OBD2 Status BEFORE scan:"
    #pprint.pprint(vehicle.obd2status)
    #print " "
    #print "Scanning for OBD2 status... "
    vehicle.scan_obd2_status()
    print " "
    #print "OBD2 Status AFTER scan:"
    pprint.pprint(vehicle.obd2status)
    print " "
    
    
    
    print ""
    print "=================================================================="
    print " "
    print "Scan for Current Sensor Readings"
    print "--------------------------------"
    print " "
    #vehicle.scan_curr_sensors()
    sensors = vehicle.curr_sensors()
    for pid in sensors:
        vehicle.scan_pid( pid )
        vehicle.show_last_reading( pid )
    print " "
    for pid in sensors:
        vehicle.scan_pid( pid )
        vehicle.show_last_reading( pid )
    print " "
    print " RAW Data structure:"
    pprint.pprint( vehicle.sensor_readings )
    

    print " "
    print " "
    print " DTCs:"
    vehicle.scan_pid( '03' )
    vehicle.show_last_reading( '03' )
    
    
    
    print ""
    print "=================================================================="
    print "=================================================================="
示例#6
0
def main():
    
    
    print "=================================================================="
    print ""
    print "OBD2 vehicle demo scan"
    print "----------------------"
    print ""
    print "Scan date: ", time.ctime()
    
    
    
    print ""
    print "=================================================================="
    print ""
    print "Serial port attributes"
    print "----------------------"
    
    #ser_device = '/dev/pts/7'
    ser_device = '/dev/ttyUSB0'
    
    ser_settings = {
     'baudrate': 38400,
     'bytesize': serial.EIGHTBITS,
     'parity'  : serial.PARITY_NONE,
     'stopbits': serial.STOPBITS_ONE,
     'xonxoff' : False,
     'rtscts'  : False,
     'dsrdtr'  : False,
     'timeout' : None,
     'interCharTimeout': None,
     'writeTimeout'    : None
    }
    
    # create serial port (closed)
    port = serial.Serial(None)
    port.port = ser_device
    port.applySettingsDict(ser_settings)
    
    print "Device".rjust(16), ": ",  port.name
    #pprint.pprint( port.getSettingsDict() )
    #print ""
    
    settings = port.getSettingsDict()
    for k in sorted(settings.keys()):
        print k.rjust(16), ": ", settings[k]
    
    
    
    print ""
    print "=================================================================="
    print ""
    print "OBD2 reader device"
    print "------------------"
    
    READER = 'ELM327'
    
    # create reader object (disconnected)
    reader = obd2_reader.OBD2reader( READER )
    reader.Port = port
    reader.connect()   # this also opens the serial port
    
    print "Device".rjust(16), ": ", str(reader.Device)
    print "State".rjust(16), ": ", str(reader.State)
    #pprint.pprint( reader.attr )
    
    for k in sorted(reader.attr.keys()):
        print k.rjust(16), ": ", reader.attr[k][1]

    # TODO
    #   notice that ELM327 is not connected and throw exception
    
    
    
    print ""
    print "=================================================================="
    print ""
    print "OBD2 initialization"
    print "-------------------"
    
    vehicle = obd2.OBD2( reader )
    
    print ""
    print "Loading default PID definitions from CSV file..."
    obd2.load_pids_from_csv( 'obd2_std_PIDs.csv' )
    
    print ""
    print "Loading default DTC definitions from CSV file..."
    obd2.load_dtcs_from_csv( 'obd2_std_DTCs.csv' )
    
    print ""
    print "Scanning vehicle for supported features..."
    vehicle.scan_features()
    
    #print ""
    #print "Supported PIDs - DEBUG"
    #print "----------------------"
    #pprint.pprint(vehicle.suppPIDs)
    
    
    
    print ""
    print "=================================================================="
    print " "
    print "General vehicle info"
    print "--------------------"
    vehicle.scan_info()
    vehicle.show_info()
    print " "
    # I should fix the inconsistent use of "scan"
    
    
    
    print ""
    print "=================================================================="
    print " "
    print "Scan for Diagnostic and Emmissions Monitor info"
    print "-----------------------------------------------"
    print " "
    print " OVERALL:"
    print " "
    vehicle.scan_perm_diag_info()
    print " "
    print " THIS DRIVE CYCLE ONLY:"
    print " "
    vehicle.scan_cycle_diag_info()
    print " "
    
    
    
    print ""
    print "=================================================================="
    print " "
    print "Scan for Current Sensor Readings"
    print "--------------------------------"
    print " "
    vehicle.scan_curr_sensors()
    print " "
    
    
    
    print ""
    print "=================================================================="
    print "=================================================================="