Skip to content

Instantly share code, notes, and snippets.

@taylor224
Last active September 16, 2015 05:53
Show Gist options
  • Select an option

  • Save taylor224/f69b895f7fe01fe3f354 to your computer and use it in GitHub Desktop.

Select an option

Save taylor224/f69b895f7fe01fe3f354 to your computer and use it in GitHub Desktop.

Revisions

  1. taylor224 revised this gist Sep 16, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion edrs.py
    Original file line number Diff line number Diff line change
    @@ -109,7 +109,7 @@ def speed(_hex):
    #runtimedata = connection.query(obd.commands.RUN_TIME).value
    #accelposdata = connection.query(obd.commands.RELATIVE_ACCEL_POS).value

    if speeddata == prevspeed or rpmdata == prevrpm:
    if speeddata == prevspeed and rpmdata == prevrpm:
    continue

    print speeddata
  2. taylor224 revised this gist Sep 16, 2015. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions edrs.py
    Original file line number Diff line number Diff line change
    @@ -94,6 +94,8 @@ def speed(_hex):
    time.sleep(7)

    starttime = time.time()
    prevspeed = 0
    prevrpm = 0

    print 'Recording Start'

    @@ -106,10 +108,15 @@ def speed(_hex):
    rpmdata = connection.query(commFastRPM).value
    #runtimedata = connection.query(obd.commands.RUN_TIME).value
    #accelposdata = connection.query(obd.commands.RELATIVE_ACCEL_POS).value

    if speeddata == prevspeed or rpmdata == prevrpm:
    continue

    print speeddata
    f.write(str(difftime) + '=' + str(speeddata) + '=' + str(rpmdata) + '\n')
    print 'time : ' + str(difftime) + '\nSpeed : ' + str(speeddata) + '\nRPM : ' + str(rpmdata) + '\n'
    prevspeed = speeddata
    prevrpm = rpmdata
    time.sleep(0.001)

    except (KeyboardInterrupt, SystemExit):
  3. taylor224 revised this gist Sep 14, 2015. 1 changed file with 54 additions and 16 deletions.
    70 changes: 54 additions & 16 deletions edrs.py
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,21 @@
    import time
    import os
    import sys
    from obd import OBDCommand
    from obd.utils import unhex

    def rpm(_hex):
    v = unhex(_hex) # helper function to convert hex to int
    v = v / 4.0
    return (v, obd.Unit.RPM)

    def speed(_hex):
    v = unhex(_hex)
    return (v, obd.Unit.KPH)


    commFastRPM = OBDCommand("RPM", "Engine RPM", "01", "0C1", 2, rpm)
    commFastSpeed = OBDCommand("SPEED", "Speed", "01", "0D1", 1, speed)

    print '============================================='
    print 'OBD Vehicle ECU Data Recording System'
    @@ -12,6 +27,7 @@

    print 'System Initializing...'

    obd.debug.console = False
    dataindex = 0

    for i in range(100):
    @@ -28,10 +44,17 @@

    print 'Connecting to Vehicle ECU'

    connection = obd.OBD()
    #connection = obd.OBD()
    #ports = obd.scanSerial()
    #print ports
    #connection = obd.OBD('/dev/tty.OBDII-SPP')
    #connection = obd.OBD('/dev/rfcomm0')

    # For Async Connection
    connection = obd.Async('/dev/rfcomm0')
    connection.watch(commFastSpeed, force=True)
    connection.watch(commFastRPM, force=True)
    #connection.watch(obd.commands.RUN_TIME)
    connection.start()

    if connection.is_connected():
    print 'Link SUCCESSED with Vehicle ECU'
    @@ -45,20 +68,29 @@
    time.sleep(1)

    print ''
    print '=================================================='
    print 'Data from ECU'
    print 'Engine - '
    print 'RPM : ' + str(obd.commands.RPM)
    print 'Throttle Position : ' + str(obd.commands.THROTTLE_POS)
    print 'Uptime : ' + str(obd.commands.RUN_TIME)
    print 'Fuel Type : ' + str(obd.commands.FUEL_TYPE)
    print 'Device - '
    print 'Accel Pedal Position : ' + str(obd.commands.RELATIVE_ACCEL_POS)
    print 'Fuel System Status : ' + str(obd.commands.FUEL_STATUS)
    print 'Status : ' + str(obd.commands.STATUS)
    print ''
    print '- Engine -'
    print 'RPM : ' + str(connection.query(obd.commands.RPM).value)
    print 'Throttle Position : ' + str(connection.query(obd.commands.THROTTLE_POS).value)
    print 'Uptime : ' + str(connection.query(obd.commands.RUN_TIME).value)
    print 'Fuel Type : ' + str(connection.query(obd.commands.FUEL_TYPE).value)
    print '- Device -'
    print 'Accel Pedal Position : ' + str(connection.query(obd.commands.RELATIVE_ACCEL_POS).value)
    print 'Fuel System Status : ' + str(connection.query(obd.commands.FUEL_STATUS).value)
    print 'Status : ' + str(connection.query(obd.commands.STATUS).value)
    print '=================================================='
    print ''
    print ''
    print 'Recording Start in 7 Second'

    print 'test'
    print connection.query(commFastRPM).value
    print 'test2'
    print connection.query(commFastRPM).value
    print 'test3'
    print connection.query(commFastRPM).value
    time.sleep(7)

    starttime = time.time()
    @@ -69,10 +101,16 @@
    while(True):
    nowtime = time.time()
    difftime = nowtime - starttime
    print obd.commands.SPEED
    f.write(str(difftime) + '=' + str(obd.commands.SPEED) + '=' + str(obd.commands.RPM) + '=' + str(obd.commands.RUN_TIME) + '=' + str(obd.commands.RELATIVE_ACCEL_POS))
    print str(difftime) + '=' + str(obd.commands.SPEED) + '=' + str(obd.commands.RPM) + '=' + str(obd.commands.RUN_TIME) + '=' + str(obd.commands.RELATIVE_ACCEL_POS)
    time.sleep(0.1)

    speeddata = connection.query(commFastSpeed).value
    rpmdata = connection.query(commFastRPM).value
    #runtimedata = connection.query(obd.commands.RUN_TIME).value
    #accelposdata = connection.query(obd.commands.RELATIVE_ACCEL_POS).value

    print speeddata
    f.write(str(difftime) + '=' + str(speeddata) + '=' + str(rpmdata) + '\n')
    print 'time : ' + str(difftime) + '\nSpeed : ' + str(speeddata) + '\nRPM : ' + str(rpmdata) + '\n'
    time.sleep(0.001)

    except (KeyboardInterrupt, SystemExit):
    print 'System Shutdown Requested'
    @@ -88,4 +126,4 @@
    f.close()
    print 'Data File Saved'
    print 'System Halt'
    sys.exit(0)
    sys.exit(0)
  4. taylor224 revised this gist Sep 14, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions edrs.py
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    import json
    import time
    import os
    import sys

    print '============================================='
    print 'OBD Vehicle ECU Data Recording System'
  5. taylor224 revised this gist Sep 14, 2015. 1 changed file with 11 additions and 11 deletions.
    22 changes: 11 additions & 11 deletions edrs.py
    Original file line number Diff line number Diff line change
    @@ -32,7 +32,7 @@
    #print ports
    #connection = obd.OBD('/dev/tty.OBDII-SPP')

    if obd.is_connected():
    if connection.is_connected():
    print 'Link SUCCESSED with Vehicle ECU'
    else:
    print 'Link FAIL with Vehicle ECU'
    @@ -46,14 +46,14 @@
    print ''
    print 'Data from ECU'
    print 'Engine - '
    print 'RPM : ' + str(obd.command.RPM)
    print 'Throttle Position : ' + str(obd.command.THROTTLE_POS)
    print 'Uptime : ' + str(obd.command.RUN_TIME)
    print 'Fuel Type : ' + str(obd.command.FUEL_TYPE)
    print 'RPM : ' + str(obd.commands.RPM)
    print 'Throttle Position : ' + str(obd.commands.THROTTLE_POS)
    print 'Uptime : ' + str(obd.commands.RUN_TIME)
    print 'Fuel Type : ' + str(obd.commands.FUEL_TYPE)
    print 'Device - '
    print 'Accel Pedal Position : ' + str(obd.command.RELATIVE_ACCEL_POS)
    print 'Fuel System Status : ' + str(obd.command.FUEL_STATUS)
    print 'Status : ' + str(obd.command.STATUS)
    print 'Accel Pedal Position : ' + str(obd.commands.RELATIVE_ACCEL_POS)
    print 'Fuel System Status : ' + str(obd.commands.FUEL_STATUS)
    print 'Status : ' + str(obd.commands.STATUS)
    print ''
    print ''
    print 'Recording Start in 7 Second'
    @@ -68,9 +68,9 @@
    while(True):
    nowtime = time.time()
    difftime = nowtime - starttime
    print obd.command.SPEED
    f.write(str(difftime) + '=' + str(obd.command.SPEED) + '=' + str(obd.command.RPM) + '=' + str(obd.command.RUN_TIME) + '=' + str(obd.command.RELATIVE_ACCEL_POS))
    print str(difftime) + '=' + str(obd.command.SPEED) + '=' + str(obd.command.RPM) + '=' + str(obd.command.RUN_TIME) + '=' + str(obd.command.RELATIVE_ACCEL_POS)
    print obd.commands.SPEED
    f.write(str(difftime) + '=' + str(obd.commands.SPEED) + '=' + str(obd.commands.RPM) + '=' + str(obd.commands.RUN_TIME) + '=' + str(obd.commands.RELATIVE_ACCEL_POS))
    print str(difftime) + '=' + str(obd.commands.SPEED) + '=' + str(obd.commands.RPM) + '=' + str(obd.commands.RUN_TIME) + '=' + str(obd.commands.RELATIVE_ACCEL_POS)
    time.sleep(0.1)

    except (KeyboardInterrupt, SystemExit):
  6. taylor224 revised this gist Sep 14, 2015. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions edrs.py
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@
    if i is 100:
    print 'Data File is FULL. Please Back up and Delete Data Files'
    print 'System Halt'
    os.exit(1)
    sys.exit(1)

    f = open('data' + str(dataindex) + '.json', 'w')

    @@ -38,7 +38,7 @@
    print 'Link FAIL with Vehicle ECU'
    print 'FATAL ERROR'
    print 'System Halt'
    os.exit(1)
    sys.exit(1)

    print 'ECU Connection Initializing...'
    time.sleep(1)
    @@ -79,12 +79,12 @@
    f.close()
    print 'Data File Saved'
    print 'System Halt'
    os.exit(0)
    sys.exit(0)

    except Exception, e:
    print 'FATAL ERROR OCCURRED - ' + str(e)
    print 'Saving Data File'
    f.close()
    print 'Data File Saved'
    print 'System Halt'
    os.exit(0)
    sys.exit(0)
  7. taylor224 revised this gist Sep 14, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions edrs.py
    Original file line number Diff line number Diff line change
    @@ -28,6 +28,9 @@
    print 'Connecting to Vehicle ECU'

    connection = obd.OBD()
    #ports = obd.scanSerial()
    #print ports
    #connection = obd.OBD('/dev/tty.OBDII-SPP')

    if obd.is_connected():
    print 'Link SUCCESSED with Vehicle ECU'
  8. taylor224 revised this gist Sep 13, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion edrs.py
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@
    dataindex = 0

    for i in range(100):
    if not os.exists('data' + str(i) + '.json'):
    if not os.path.exists('data' + str(i) + '.json'):
    print 'Data File Location : data' + str(i) + '.json'
    dataindex = i
    break
  9. taylor224 created this gist Sep 13, 2015.
    87 changes: 87 additions & 0 deletions edrs.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,87 @@
    import obd
    import json
    import time
    import os

    print '============================================='
    print 'OBD Vehicle ECU Data Recording System'
    print ''
    print 'version 0.0.1'
    print '============================================='

    print 'System Initializing...'

    dataindex = 0

    for i in range(100):
    if not os.exists('data' + str(i) + '.json'):
    print 'Data File Location : data' + str(i) + '.json'
    dataindex = i
    break
    if i is 100:
    print 'Data File is FULL. Please Back up and Delete Data Files'
    print 'System Halt'
    os.exit(1)

    f = open('data' + str(dataindex) + '.json', 'w')

    print 'Connecting to Vehicle ECU'

    connection = obd.OBD()

    if obd.is_connected():
    print 'Link SUCCESSED with Vehicle ECU'
    else:
    print 'Link FAIL with Vehicle ECU'
    print 'FATAL ERROR'
    print 'System Halt'
    os.exit(1)

    print 'ECU Connection Initializing...'
    time.sleep(1)

    print ''
    print 'Data from ECU'
    print 'Engine - '
    print 'RPM : ' + str(obd.command.RPM)
    print 'Throttle Position : ' + str(obd.command.THROTTLE_POS)
    print 'Uptime : ' + str(obd.command.RUN_TIME)
    print 'Fuel Type : ' + str(obd.command.FUEL_TYPE)
    print 'Device - '
    print 'Accel Pedal Position : ' + str(obd.command.RELATIVE_ACCEL_POS)
    print 'Fuel System Status : ' + str(obd.command.FUEL_STATUS)
    print 'Status : ' + str(obd.command.STATUS)
    print ''
    print ''
    print 'Recording Start in 7 Second'

    time.sleep(7)

    starttime = time.time()

    print 'Recording Start'

    try:
    while(True):
    nowtime = time.time()
    difftime = nowtime - starttime
    print obd.command.SPEED
    f.write(str(difftime) + '=' + str(obd.command.SPEED) + '=' + str(obd.command.RPM) + '=' + str(obd.command.RUN_TIME) + '=' + str(obd.command.RELATIVE_ACCEL_POS))
    print str(difftime) + '=' + str(obd.command.SPEED) + '=' + str(obd.command.RPM) + '=' + str(obd.command.RUN_TIME) + '=' + str(obd.command.RELATIVE_ACCEL_POS)
    time.sleep(0.1)

    except (KeyboardInterrupt, SystemExit):
    print 'System Shutdown Requested'
    print 'Saving Data File'
    f.close()
    print 'Data File Saved'
    print 'System Halt'
    os.exit(0)

    except Exception, e:
    print 'FATAL ERROR OCCURRED - ' + str(e)
    print 'Saving Data File'
    f.close()
    print 'Data File Saved'
    print 'System Halt'
    os.exit(0)