Example #1
0
def handle_modprobe_ehcihcd(insert=True):
    if insert:
        command = 'modprobe'
    else:
        command = 'rmmod'
    
    # launch modprobe timeout of 30 seconds
    v = OSTools.polling_popen([command, 'ehci_hcd'], timeout=30.0)
    
    # polling_popen returns False upon failure
    if v:
        (ret, err) = v
    else:
        ret, err = '', ''
    
    # rety 5 times while there is an error
    retry_count = 5
    while err and (retry_count > 0):
        v = OSTools.polling_popen([command, 'ehci_hcd'], timeout=30.0)
        if v:
            ret, err = v
        if ret:
            logger.info("Process %s returned without error" % command)
            break
        retry_count -= 1
        if err:
            logger.error("Unable to excecute %s successfuly (%d left)." % (command, retry_count))
    return (ret, err)
Example #2
0
def goto_known_state():
    # kill pppd
    pid = OSTools.pppd_pid()
    if pid != 0:
        OSTools.pppd_terminate(pid)
    
    # call rmmod
    logger.warn("Cleaning up, removed ehci_hcd.")
    OSTools.polling_popen(['rmmod', '-f', 'ehci_hcd'], timeout=30.0)
    
    # remove power from usb hub
    set_gpio_usbhub_power(on=False)
Example #3
0
 def _send_i2cget_read(self, port, chipadr, register):
     i2c_chip = '0x%02x' % int(chipadr)
     i2c_register = '0x%02x' % int(register)
     args = ['i2cget', '-y', str(port), i2c_chip, i2c_register]
     
     # process open
     return OSTools.polling_popen(args, 5.0)
Example #4
0
def turn_on_usbhub():
    # two stages, first enable GPIO210 then modprobe usb_ehci
    logger.info("Applying power to USB hub controller.")
    
    # set gpio. wait to get a lock if need be.
    set_gpio_usbhub_power(on=True)
            
    handle_modprobe_ehcihcd(insert=True)
    
    # check /dev/ttyUSB0
    time.sleep(5)
    
    ## Check to see if we have a mf112 connected
    try:
        (ret, err) = OSTools.polling_popen(['lsusb'], 2.0)
        lines = ret.strip().split('\n')
        for line in lines:
            sects = line.split(' ')
            if len(sects) > 6:
                if sects[5] == "19d2:0103":
                    os.popen('usb_modeswitch -v 0x19d2 -p 0x0103 -V 19d2 -P 0x0031 -M 5553424312345679000000000000061b000000020000000000000000000000')
                    logger.info("MF112 detected, running modeswitch")
                    time.sleep(10)
    except:
        logger.exception("Unable to check usb devices")
    
    #### REMOVE!
    #time.sleep(5)
    #os.popen('usb_modeswitch -v 0x19d2 -p 0x0103 -V 19d2 -P 0x0031 -M 5553424312345679000000000000061b000000020000000000000000000000')
    #time.sleep(5)
    
    retry_count = 5
    while retry_count > 0:
        if exists('/dev/ttyUSB0'):
            logger.info("Modem detected on ttyUSB0!")
            break
        else:
            logger.error("Modem still not detected, %d retry attempts left." % retry_count)
            time.sleep(4)
        retry_count -= 1
    
    return exists('/dev/ttyUSB0')
Example #5
0
 def _send_i2cset_write(self, port, chipadr, register, byte, mask=0):
     """Converts parameters to strings, and invokes i2cset"""
     i2c_chip = "0x%02x" % int(chipadr)
     i2c_register = "0x%02x" % int(register)
     i2c_byte = "0x%02x" % int(byte)
     
     # the default arguments passed to the function
     #   -y : no confirmation prompt
     #   PORT : the /dev/i2c-? port number to use
     #   CHIP : chip address
     #   REG : the register to write to
     #   BYTE : the byte of data to write
     args = ['i2cset', '-y', str(port), i2c_chip, i2c_register, i2c_byte]
     
     # A mask is used to select individual leds
     #   the register is read from the chip, and masked by MASK
     if mask:
         i2c_mask = "0x%02x" % int(mask)
     if mask:
         # arm linux i2cset requires the mask as a positional argument
         args.insert(2, '-m')
         args.insert(3, i2c_mask)
     
     return OSTools.polling_popen(args, 5.0)