Ejemplo n.º 1
0
def time():
    """Sets the device date/time to now."""

    dev = evic.HIDTransfer()

    # Connect the device
    connect(dev)

    # Read the data flash
    dataflash = read_dataflash(dev, 1)

    # Get the device info
    device_info = dev.devices.get(dataflash.product_id,
                                  DeviceInfo("Unknown device", None, None))

    # Print the device information
    print_device_info(device_info, dataflash)

    # Write data flash to the device
    with handle_exceptions(IOError):
        click.echo("Writing data flash...", nl=False)
        sleep(0.1)
        dt = datetime.now()
        dataflash.df_year = dt.year
        dataflash.df_month = dt.month
        dataflash.df_day = dt.day
        dataflash.df_hour = dt.hour
        dataflash.df_minute = dt.minute
        dataflash.df_second = dt.second
        dev.write_dataflash(dataflash)
        click.secho("OK", fg='green', bold=True)
Ejemplo n.º 2
0
def dumpdataflash(output, noverify):
    """Write device data flash to a file."""

    dev = evic.HIDTransfer()

    # Connect the device
    connect(dev)

    # Print the USB info of the device
    print_usb_info(dev)

    # Read the data flash
    dataflash = read_dataflash(dev, noverify)

    # Get the device info
    device_info = dev.devices.get(dataflash.product_id,
                                  DeviceInfo("Unknown device", None, None))

    # Print the device information
    print_device_info(device_info, dataflash)

    # Write the data flash to the file
    with handle_exceptions(IOError):
        click.echo("Writing data flash to the file...", nl=False)
        output.write(dataflash.array)
Ejemplo n.º 3
0
def upload_ldrom(inputfile):
    """Upload an LDROM image to the device."""

    dev = evic.HIDTransfer()

    # Connect the device
    connect(dev)

    # Print the USB info of the device
    print_usb_info(dev)

    # Read the data flash
    dataflash = read_dataflash(dev, False)

    # Get the device info
    device_info = dev.devices.get(dataflash.product_id,
                                  DeviceInfo("Unknown device", None, None))

    # Print the device information
    print_device_info(device_info, dataflash)

    # Read the LDROM image
    ldrom = evic.APROM(inputfile.read())

    # Write data flash to the device
    with handle_exceptions(IOError):
        # Write LDROM to the device
        click.echo("Writing LDROM...", nl=False)
        dev.write_ldrom(ldrom)
Ejemplo n.º 4
0
def uploadlogo(inputfile, invert, noverify):
    """Upload a logo to the device."""

    dev = evic.HIDTransfer()

    # Connect the device
    connect(dev)

    # Print the USB info of the device
    print_usb_info(dev)

    # Read the data flash
    dataflash = read_dataflash(dev, noverify)
    dataflash_original = copy.deepcopy(dataflash)

    # Print the device information
    print_device_info(dev, dataflash)

    # Convert the image
    with handle_exceptions(evic.LogoConversionError):
        click.echo("Converting logo...", nl=False)
        # Check supported logo size
        try:
            logosize = dev.supported_logo_size[dataflash.product_id]
        except KeyError:
            raise evic.LogoConversionError("Device doesn't support logos.")
        # Perform the actual conversion
        logo = evic.logo.fromimage(inputfile, invert)
        if (logo.width, logo.height) != logosize:
            raise evic.LogoConversionError(
                "Device only supports {}x{} logos.".format(*logosize))

    # We want to boot to LDROM on restart
    if not dev.ldrom:
        dataflash.bootflag = 1

    # Write data flash to the device
    with handle_exceptions(IOError):
        if dataflash.array != dataflash_original.array:
            click.echo("Writing data flash...", nl=False)
            sleep(0.1)
            dev.write_dataflash(dataflash)
            click.secho("OK", fg='green', bold=True)

        # We should only restart if we're not in LDROM
        if not dev.ldrom:
            # Restart
            click.echo("Restarting the device...", nl=False)
            dev.reset()
            sleep(2)
            click.secho("OK", fg='green', nl=False, bold=True)
            # Reconnect
            connect(dev)

        # Write logo to the device
        click.echo("Writing logo...", nl=False)
        dev.write_logo(logo)
Ejemplo n.º 5
0
def reset():
    """Resets the device."""

    dev = evic.HIDTransfer()

    # Connect the device
    connect(dev)

    # Restart
    click.echo("Restarting the device...", nl=False)
    dev.reset()
    sleep(2)
    click.secho("OK", fg='green', nl=False, bold=True)
Ejemplo n.º 6
0
def resetdataflash():
    """Reset device data flash."""

    dev = evic.HIDTransfer()

    # Connect the device
    connect(dev)

    # Print the USB info of the device
    print_usb_info(dev)

    # Reset data flash
    with handle_exceptions(IOError):
        click.echo("Resetting data flash...", nl=False)
        dev.reset_dataflash()
Ejemplo n.º 7
0
def screenshot(output):
    """Take a screenshot."""

    dev = evic.HIDTransfer()

    # Connect the device
    connect(dev)

    # Read the screen data
    data = dev.read_screen()

    # create the image from screen data
    im = Image.fromstring("1", (64, 128), bytes(data))

    # Write the image to the file
    with handle_exceptions(IOError):
        click.echo("Writing image to the file...", nl=False)
        im.save(output, "PNG")
Ejemplo n.º 8
0
def hidcmd(command, output, start, length):
    """Send a HID command to the device."""

    dev = evic.HIDTransfer()

    # Connect the device
    connect(dev)

    # Print the USB info of the device
    print_usb_info(dev)

    # Send the command
    response = hid_command(dev, command, start, length)

    # Write the data flash to the file
    with handle_exceptions(IOError):
        click.echo("Writing command response to the file...", nl=False)
        output.write(response)
Ejemplo n.º 9
0
def fmcread(output, start, length):
    """Write device flash memory to a file."""

    dev = evic.HIDTransfer()

    # Connect the device
    connect(dev)

    # Print the USB info of the device
    print_usb_info(dev)

    # Read the data flash
    fmemory = fmc_read(dev, start, length)

    # Write the data flash to the file
    with handle_exceptions(IOError):
        click.echo("Writing flash memory to the file...", nl=False)
        output.write(fmemory)
Ejemplo n.º 10
0
def upload(inputfile, encrypted, dataflashfile, noverify):
    """Upload an APROM image to the device."""

    dev = evic.HIDTransfer()

    # Connect the device
    connect(dev)

    # Print the USB info of the device
    print_usb_info(dev)

    # Read the data flash
    verify = 'dataflash' not in noverify
    dataflash = read_dataflash(dev, verify)
    dataflash_original = copy.deepcopy(dataflash)

    # Print the device information
    print_device_info(dev, dataflash)

    # Read the APROM image
    aprom = evic.APROM(inputfile.read())
    if encrypted:
        aprom = evic.APROM(aprom.convert())

    # Verify the APROM image
    if 'aprom' not in noverify:
        with handle_exceptions(evic.APROMError):
            click.echo("Verifying APROM...", nl=False)
            aprom.verify(dev.supported_product_ids[dataflash.product_id],
                         dataflash.hw_version)

    # Are we using a data flash file?
    if dataflashfile:
        buf = bytearray(dataflashfile.read())
        # We used to store the checksum inside the file
        if len(buf) == 2048:
            checksum = struct.unpack("=I", bytes(buf[0:4]))[0]
            dataflash = evic.DataFlash(buf[4:], 0)
        else:
            checksum = sum(buf)
            dataflash = evic.DataFlash(buf, 0)
        if 'dataflash' not in noverify:
            verify_dataflash(dataflash, checksum)

    # We want to boot to LDROM on restart
    if not dev.ldrom:
        dataflash.bootflag = 1

    # Flashing Presa firmware requires HW version <=1.03 on type A devices
    if b'W007' in aprom.data and dataflash.product_id == 'E052' \
            and dataflash.hw_version in [106, 108, 109, 111]:
        click.echo("Changing HW version to 1.03...", nl=False)
        dataflash.hw_version = 103
        click.secho("OK", fg='green', bold=True)

    # Write data flash to the device
    with handle_exceptions(IOError):
        if dataflash.array != dataflash_original.array:
            click.echo("Writing data flash...", nl=False)
            sleep(0.1)
            dev.write_dataflash(dataflash)
            click.secho("OK", fg='green', bold=True)

        # We should only restart if we're not in LDROM
        if not dev.ldrom:
            # Restart
            click.echo("Restarting the device...", nl=False)
            dev.reset()
            sleep(2)
            click.secho("OK", fg='green', nl=False, bold=True)
            # Reconnect
            connect(dev)

        # Write APROM to the device
        click.echo("Writing APROM...", nl=False)
        dev.write_aprom(aprom)