Ejemplo n.º 1
0
def upgrade_myro(url=None, version=None):
    """
    Takes a url or filename and upgrades Myro.
    """
    if url == None:
        url = "http://myro.roboteducation.org/upgrade/"
    if version != None:
        version = version.split(".")
    install_count = 0
    if not url.startswith("http://"):
        print "Looking for Myro upgrades in file", url, "..."
        install_count += import_file(url) # which is a filename
    else:        
        print "Looking for Myro upgrades at", url, "..."
        myro_ver = myro_version.split(".")
        # go to site, check for latest greater than our version
        infp = urllib.urlopen(url)
        contents = infp.read()
        lines = contents.split("\n")
        infp.close()
        for filename in lines:
            filename = filename.strip()
            if filename != "" and filename[0] != '#':
                print "Considering", filename, "..."
                if filename.startswith("myro-upgrade-"):
                    end = filename.index(".zip")
                    patch_ver = filename[13:end].split(".")
                    if (version != None): # get specific version
                        if map(int, patch_ver) == map(int, version):
                            print "   Downloading..."
                            install_count += import_url(url + filename)
                    elif map(int, patch_ver) > map(int, myro_ver):
                        # download it
                        print "   Downloading..."
                        install_count += import_url(url + filename)
    if install_count > 0:
        print "Done upgrading! Please exit and restart Python and Myro"
    else:
        print "Nothing to upgrade in Myro; it's up-to-date."
    return install_count
Ejemplo n.º 2
0
def upgrade_fluke(url=None):
    #define UF_SUCCESS 42
    #define UF_ERROR 1
    #define UF_SEGMENT_SIZE 132

    if myro.globvars.robot == None:
        # force upgrade
        print "Connecting for firmware installation..."
        myro.globvars.robot = SerialRobot()
            
    s = myro.globvars.robot.ser

    # check to see if we can even upgrade
    info = get_info_timeout(s)

    print info
    
    if "fluke" not in info.keys():
        print "(If you just upgraded Myro, please restart Python.)"
        print "Sorry, I can't upgrade the Fluke over Bluetooth."
        print "It must be upgraded manually over the serial port using lpc21isp."
        print "Please see http://wiki.roboteducation.org/IPRE_Fluke_Setup"
        return

    if url == None:
        url = "http://myro.roboteducation.org/upgrade/fluke/"
    install_count = 0
    filename = None
    if url.startswith("http://"):
        fluke_ver = info["fluke"].split(".")
        print "Looking for Fluke upgrade at", url, "..."
        myro_ver = myro_version.split(".")
        # go to site, check for latest greater than our version
        #infp = urllib.urlopen(url)
        try:
            infp = urllib.urlopen(url)
        except:
            print "ERROR: There was an error connecting to the web to download updates. Please check your internet connection. For example, see if you can access", url, "using a web browser."
            return

        contents = infp.read()
        lines = contents.split("\n")
        infp.close()
        for file in lines:
            file = file.strip()
            if file != "" and file[0] != '#':
                print "Considering", file, "..."
                if file.startswith("/fluke-upgrade-"):
                    end = file.index(".hex")
                    patch_ver = file[15:end].split(".")
                    print patch_ver, fluke_ver
                    if map(int, patch_ver) > map(int, fluke_ver):
                        # download it
                        print "   Downloading..."
                        filename = url_retrieve(url + file)
                        break
    else:
        filename = url

    if filename == None:
        print "Nothing found to upgrade!"
        return
    #info = myro.globvars.robot.getInfo()
    sendMagicKey = True

    version = map(int, info["fluke"].split("."))
    print "Version of fluke", version
    
    if version <= [2, 5, 0]:
        sendMagicKey = False
        print "Older firmware version, Not sending magic key"
    else:
        print "Sending magic key"
        
    from intelhex import IntelHex
    import time
    ih = IntelHex(filename)
    binarray = ih.tobinarray()
    arlen = len(binarray)    
    print "%d bytes of firmware." % arlen
    print "checksumming interrupt vectors"
    sum = check_sum(binarray, arlen)
    #declare a finite sized array to hold eeprom dump. 
    #Dynamic appending of lists always comes with a performance hit
    eepromdump = [0] * 135168
    s.flushOutput()
    s.flushInput()
       
    #print "Getting old EEPROM"
    #s.write(chr(SAVE_EEPROM))
    #uf_saveEEPROMdump()
    print "Sending firmware"
    s.write(chr(UPDATE_FIRMWARE))
    if sendMagicKey:        
        # magic code to ensure we don't enter program by accident    
        s.write(chr(0x01))
        s.write(chr(0x23))
        
    uf_storeinEEPROM(s, arlen, binarray)
    print "Waiting for reboot"
    time.sleep(2)
    s.close()
Ejemplo n.º 3
0
def upgrade_fluke(url=None):
    #define UF_SUCCESS 42
    #define UF_ERROR 1
    #define UF_SEGMENT_SIZE 132

    if myro.globvars.robot == None:
        print "Connecting to Fluke for firmware installation..."
        myro.globvars.robot = SerialRobot()
        s = myro.globvars.robot.ser
        info = get_info_timeout(s)
        if "fluke" in info:
            info = info["fluke"]
        else:
            info = "0.0.0"            
    elif myro.globvars.robot.dongle:
        info = myro.globvars.robot.dongle
        s = myro.globvars.robot.ser

    print info
    version = map(int, info.split("."))
    print "Version of fluke", version
    
    if version <= [2, 4, 0]:
        print "(If you just upgraded Myro, please restart Python.)"
        print "Sorry, I can't upgrade the Fluke over Bluetooth."
        print "It must be upgraded manually over the serial port using lpc21isp."
        print "Please see http://wiki.roboteducation.org/IPRE_Fluke_Setup"
        return

    if url == None:
        #url = "http://myro.roboteducation.org/upgrade/fluke/"
        url = "http://www.betterbots.com/upgrade/fluke/"
    install_count = 0
    filename = None
    if url.startswith("http://"):
        #fluke_ver = info["fluke"].split(".")
        print "Looking for Fluke upgrade at", url, "..."
        myro_ver = myro_version.split(".")
        # go to site, check for latest greater than our version
        #infp = urllib.urlopen(url)
        try:
            infp = urllib.urlopen(url)
        except:
            print "ERROR: There was an error connecting to the web to download updates. Please check your internet connection. For example, see if you can access", url, "using a web browser."
            return

        if version >= [3, 0, 0]:
            upgrade_prefix = "/fluke2-upgrade-"
        else:
            upgrade_prefix = "/fluke-upgrade-"

        contents = infp.read()
        lines = contents.split("\n")
        infp.close()
        for file in lines:
            file = file.strip()
            if file != "" and file[0] != '#':
                print "Considering", file, "..."
                if file.startswith(upgrade_prefix):
                    end = file.index(".hex")
                    #patch_ver = file[15:end].split(".")
                    patch_ver = file[len(upgrade_prefix):end].split(".")
                    print patch_ver, version
                    if map(int, patch_ver) > map(int, version):
                        # download it
                        print "   Downloading..."
                        filename = url_retrieve(url + file)
                        break
    else:
        filename = url

    if filename == None:
        print "Nothing found to upgrade!"
        return
    #info = myro.globvars.robot.getInfo()
    sendMagicKey = True

    if version <= [2, 5, 0]:
        sendMagicKey = False
        print "Older firmware version, Not sending magic key"
    else:
        print "Sending magic key"
        
    if version >= [3, 0, 0]:
        import time
        s.flushOutput()
        s.flushInput()
        print "Sending firmware"

        s.write(chr(UPDATE_FIRMWARE))
        # magic code to ensure we don't enter program by accident
        s.write(chr(0x01))
        s.write(chr(0x23))

        upfp = open(filename, "rb")
        bytes = upfp.read()
        upfp.close()
        size = len(bytes)

        s.write(chr((size >> 24) & 0xFF))
        s.write(chr((size >> 16) & 0xFF))
        s.write(chr((size >> 8) & 0xFF))
        s.write(chr((size) & 0xFF))


        while True:
            ns = s.write(bytes)
            if ns == 0 or ns == None:
                break
            size -= ns
            if size <= 0:
                break
            bytes = bytes[ns:]
            sys.stdout.write('.')

        print "Installing update. Do not turn off the Fluke2 while the red CPU activity LED is flashing brightly."
        for i in range(21):
            time.sleep(3)
            sys.stdout.write('.')
        print ""
        print "Finalizing installation. Please exit and restart Python and Myro."

    else:
        from intelhex import IntelHex
        import time
        ih = IntelHex(filename)
        binarray = ih.tobinarray()
        arlen = len(binarray)
        print "%d bytes of firmware." % arlen
        print "checksumming interrupt vectors"
        sum = check_sum(binarray, arlen)
        #declare a finite sized array to hold eeprom dump.
        #Dynamic appending of lists always comes with a performance hit
        eepromdump = [0] * 135168
        s.flushOutput()
        s.flushInput()

        #print "Getting old EEPROM"
        #s.write(chr(SAVE_EEPROM))
        #uf_saveEEPROMdump()
        print "Sending firmware"
        s.write(chr(UPDATE_FIRMWARE))
        if sendMagicKey:
            # magic code to ensure we don't enter program by accident
            s.write(chr(0x01))
            s.write(chr(0x23))

        uf_storeinEEPROM(s, arlen, binarray)
        print "Waiting for reboot..."
        time.sleep(2)
        print "Done upgrading! Please turn your robot off and then back on, and exit and restart Python and Myro."

    s.close()
Ejemplo n.º 4
0
def upgrade_fluke(url=None):
    #define UF_SUCCESS 42
    #define UF_ERROR 1
    #define UF_SEGMENT_SIZE 132

    if myro.globvars.robot == None:
        print "Connecting to Fluke for firmware installation..."
        myro.globvars.robot = SerialRobot()
        s = myro.globvars.robot.ser
        info = get_info_timeout(s)
        if "fluke" in info:
            info = info["fluke"]
        else:
            info = "0.0.0"
    elif myro.globvars.robot.dongle:
        info = myro.globvars.robot.dongle
        s = myro.globvars.robot.ser

    print info
    version = map(int, info.split("."))
    print "Version of fluke", version

    if version <= [2, 4, 0]:
        print "(If you just upgraded Myro, please restart Python.)"
        print "Sorry, I can't upgrade the Fluke over Bluetooth."
        print "It must be upgraded manually over the serial port using lpc21isp."
        print "Please see http://wiki.roboteducation.org/IPRE_Fluke_Setup"
        return

    if url == None:
        #url = "http://myro.roboteducation.org/upgrade/fluke/"
        url = "http://www.betterbots.com/upgrade/fluke/"
    install_count = 0
    filename = None
    if url.startswith("http://"):
        #fluke_ver = info["fluke"].split(".")
        print "Looking for Fluke upgrade at", url, "..."
        myro_ver = myro_version.split(".")
        # go to site, check for latest greater than our version
        #infp = urllib.urlopen(url)
        try:
            infp = urllib.urlopen(url)
        except:
            print "ERROR: There was an error connecting to the web to download updates. Please check your internet connection. For example, see if you can access", url, "using a web browser."
            return

        if version >= [3, 0, 0]:
            upgrade_prefix = "/fluke2-upgrade-"
        else:
            upgrade_prefix = "/fluke-upgrade-"

        contents = infp.read()
        lines = contents.split("\n")
        infp.close()
        for file in lines:
            file = file.strip()
            if file != "" and file[0] != '#':
                print "Considering", file, "..."
                if file.startswith(upgrade_prefix):
                    end = file.index(".hex")
                    #patch_ver = file[15:end].split(".")
                    patch_ver = file[len(upgrade_prefix):end].split(".")
                    print patch_ver, version
                    if map(int, patch_ver) > map(int, version):
                        # download it
                        print "   Downloading..."
                        filename = url_retrieve(url + file)
                        break
    else:
        filename = url

    if filename == None:
        print "Nothing found to upgrade!"
        return
    #info = myro.globvars.robot.getInfo()
    sendMagicKey = True

    if version <= [2, 5, 0]:
        sendMagicKey = False
        print "Older firmware version, Not sending magic key"
    else:
        print "Sending magic key"

    if version >= [3, 0, 0]:
        import time
        s.flushOutput()
        s.flushInput()
        print "Sending firmware"

        s.write(chr(UPDATE_FIRMWARE))
        # magic code to ensure we don't enter program by accident
        s.write(chr(0x01))
        s.write(chr(0x23))

        upfp = open(filename, "rb")
        bytes = upfp.read()
        upfp.close()
        size = len(bytes)

        s.write(chr((size >> 24) & 0xFF))
        s.write(chr((size >> 16) & 0xFF))
        s.write(chr((size >> 8) & 0xFF))
        s.write(chr((size) & 0xFF))

        while True:
            ns = s.write(bytes)
            if ns == 0 or ns == None:
                break
            size -= ns
            if size <= 0:
                break
            bytes = bytes[ns:]
            sys.stdout.write('.')

        print "Installing update. Do not turn off the Fluke2 while the red CPU activity LED is flashing brightly."
        for i in range(21):
            time.sleep(3)
            sys.stdout.write('.')
        print ""
        print "Finalizing installation. Please exit and restart Python and Myro."

    else:
        from intelhex import IntelHex
        import time
        ih = IntelHex(filename)
        binarray = ih.tobinarray()
        arlen = len(binarray)
        print "%d bytes of firmware." % arlen
        print "checksumming interrupt vectors"
        sum = check_sum(binarray, arlen)
        #declare a finite sized array to hold eeprom dump.
        #Dynamic appending of lists always comes with a performance hit
        eepromdump = [0] * 135168
        s.flushOutput()
        s.flushInput()

        #print "Getting old EEPROM"
        #s.write(chr(SAVE_EEPROM))
        #uf_saveEEPROMdump()
        print "Sending firmware"
        s.write(chr(UPDATE_FIRMWARE))
        if sendMagicKey:
            # magic code to ensure we don't enter program by accident
            s.write(chr(0x01))
            s.write(chr(0x23))

        uf_storeinEEPROM(s, arlen, binarray)
        print "Waiting for reboot..."
        time.sleep(2)
        print "Done upgrading! Please turn your robot off and then back on, and exit and restart Python and Myro."

    s.close()