
from time import sleep

from proto9x.usb import usb
from proto9x.tls import tls
from proto9x.flash import read_flash
from proto9x.init_flash import init_flash
from proto9x.upload_fwext import upload_fwext
from proto9x.calibrate import calibrate
from proto9x.init_db import init_db

#usb.trace_enabled=True
#tls.trace_enabled=True

def restart():
    print('Sleeping...')
    sleep(3)
    tls.reset()
    usb.open()
    usb.send_init()
    tls.parseTlsFlash(read_flash(1, 0, 0x1000))
    tls.open()

usb.open()
print('Initializing flash...')
init_flash()

restart()
print('Uploading firmware...')
upload_fwext()

restart()
print('Calibrating...')
calibrate()

print('Init database...')
init_db()

print('That\'s it, pairing\'s finished')

[((24, 0, 24, 10), 'proto9x.usb.usb.open', 'usb.open', ({}, {}), '()', False, 'from proto9x.usb import usb\n'), ((26, 0, 26, 12), 'proto9x.init_flash.init_flash', 'init_flash', ({}, {}), '()', False, 'from proto9x.init_flash import init_flash\n'), ((30, 0, 30, 14), 'proto9x.upload_fwext.upload_fwext', 'upload_fwext', ({}, {}), '()', False, 'from proto9x.upload_fwext import upload_fwext\n'), ((34, 0, 34, 11), 'proto9x.calibrate.calibrate', 'calibrate', ({}, {}), '()', False, 'from proto9x.calibrate import calibrate\n'), ((37, 0, 37, 9), 'proto9x.init_db.init_db', 'init_db', ({}, {}), '()', False, 'from proto9x.init_db import init_db\n'), ((17, 4, 17, 12), 'time.sleep', 'sleep', ({(17, 10, 17, 11): '(3)'}, {}), '(3)', False, 'from time import sleep\n'), ((18, 4, 18, 15), 'proto9x.tls.tls.reset', 'tls.reset', ({}, {}), '()', False, 'from proto9x.tls import tls\n'), ((19, 4, 19, 14), 'proto9x.usb.usb.open', 'usb.open', ({}, {}), '()', False, 'from proto9x.usb import usb\n'), ((20, 4, 20, 19), 'proto9x.usb.usb.send_init', 'usb.send_init', ({}, {}), '()', False, 'from proto9x.usb import usb\n'), ((22, 4, 22, 14), 'proto9x.tls.tls.open', 'tls.open', ({}, {}), '()', False, 'from proto9x.tls import tls\n'), ((21, 22, 21, 46), 'proto9x.flash.read_flash', 'read_flash', ({(21, 33, 21, 34): '(1)', (21, 36, 21, 37): '(0)', (21, 39, 21, 45): '(4096)'}, {}), '(1, 0, 4096)', False, 'from proto9x.flash import read_flash\n')]