def restore_board_eeprom(boards, p3):
    for k in boards.keys():
        cmd = "sudo ethercat -f -p " + str(boards[k]["slave_id"]) + " sii_write " + boards[k]["eeprom"]
        print "Executing: ", cmd
        os.system(cmd)
    print "Power cycle and hit return"
    raw_input()
    time.sleep(4.0)
    if p3:
        m3rt.ethercat_bus_init(verbose=True)
    list_slaves()
def restore_board_eeprom(boards, p3):
    for k in boards.keys():
        cmd = 'sudo ethercat -f -p ' + str(
            boards[k]['slave_id']) + ' sii_write ' + boards[k]['eeprom']
        print 'Executing: ', cmd
        os.system(cmd)
    print 'Power cycle and hit return'
    raw_input()
    time.sleep(4.0)
    if p3:
        m3rt.ethercat_bus_init(verbose=True)
    list_slaves()
def set_bootloader_eeprom(boards, p3):
    # Check if eeprom files are available
    filename = m3t.get_m3_config_path() + "eeprom/eeprom_bld_sn_0.hex"
    eepf = glob.glob(filename)
    if len(eepf) != 1:
        print "BLD EEPROM file not found", filename
        return
    else:
        bld_eeprom = eepf[0]
    for k in boards.keys():
        cmd = "sudo ethercat -f -p " + str(boards[k]["slave_id"]) + " sii_write " + bld_eeprom
        print "Executing: ", cmd
        os.system(cmd)
    print "Power cycle now. Hit return when ready"
    raw_input()
    time.sleep(4.0)
    if p3:
        m3rt.ethercat_bus_init(verbose=True)
    list_slaves()
def set_bootloader_eeprom(boards, p3):
    #Check if eeprom files are available
    filename = m3t.get_m3_config_path() + 'eeprom/eeprom_bld_sn_0.hex'
    eepf = glob.glob(filename)
    if len(eepf) != 1:
        print 'BLD EEPROM file not found', filename
        return
    else:
        bld_eeprom = eepf[0]
    for k in boards.keys():
        cmd = 'sudo ethercat -f -p ' + str(
            boards[k]['slave_id']) + ' sii_write ' + bld_eeprom
        print 'Executing: ', cmd
        os.system(cmd)
    print 'Power cycle now. Hit return when ready'
    raw_input()
    time.sleep(4.0)
    if p3:
        m3rt.ethercat_bus_init(verbose=True)
    list_slaves()