Esempio n. 1
0
def flash(ctx, save_file_system, y, port, binary, no_poll, retry):
    """Upload binaries to the microcontroller. A serial port and binary file need to be specified.

    By default, the port is automatically selected (if you want to be pedantic, 'auto').
    Otherwise, a system COM port descriptor needs to be used. In Windows/NT, this takes the form of COM1.
    In *nx systems, this takes the form of /dev/tty1 or /dev/acm1 or similar.
    \b
    Specifying 'all' as the COM port will automatically upload to all available microcontrollers.

    By default, the CLI will look around for a proper binary to upload to the microcontroller. If one was not found, or
    if you want to change the default binary, you can specify it.
    """
    click.echo(' ====:: PROS Flasher v{} ::===='.format(get_version()))
    if port == 'auto':
        ports = prosflasher.ports.list_com_ports()
        if len(ports) == 0:
            click.echo(
                'No microcontrollers were found. Please plug in a cortex or manually specify a serial port.\n',
                err=True)
            click.get_current_context().abort()
            sys.exit(1)
        port = ports[0].device
        if len(ports) > 1 and port is not None and y is False:
            port = None
            for p in ports:
                if click.confirm('Download to ' + p.device, default=True):
                    port = p.device
                    break
            if port is None:
                click.echo('No additional ports found.')
                click.get_current_context().abort()
                sys.exit(1)
    if port == 'all':
        port = [p.device for p in prosflasher.ports.list_com_ports()]
        if len(port) == 0:
            click.echo(
                'No microcontrollers were found. Please plug in a cortex or manually specify a serial port.\n',
                err=True)
            click.get_current_context().abort()
            sys.exit(1)
        if y is False:
            click.confirm('Download to ' + ', '.join(port),
                          default=True,
                          abort=True,
                          prompt_suffix='?')
    else:
        port = [port]

    if binary == 'default':
        binary = os.getcwd()
        if ctx.verbosity > 3:
            click.echo(
                'Default binary selected, new directory is {}'.format(binary))

    binary = find_binary(binary)

    if binary is None:
        click.echo(
            'No binary was found! Ensure you are in a built PROS project (run make) '
            'or specify the file with the -f flag',
            err=True)
        click.get_current_context().exit()

    if ctx.verbosity > 3:
        click.echo('Final binary is {}'.format(binary))

    click.echo('Flashing ' + binary + ' to ' + ', '.join(port))
    for p in port:
        tries = 1
        code = prosflasher.upload.upload(p, y, binary, no_poll, ctx)
        while tries <= retry and (not code or code == -1000):
            click.echo('Retrying...')
            code = prosflasher.upload.upload(p, y, binary, no_poll, ctx)
            tries += 1
Esempio n. 2
0
import click
#from pkg_resources import get_distribution
import proscli
from proscli.utils import default_options, get_version


def main():
    # the program name should always be pros. don't care if it's not...
    try:
        cli.main(prog_name='pros')
    except KeyboardInterrupt:
        click.echo('Aborted!')


@click.command('pros',
               cls=click.CommandCollection,
               context_settings=dict(help_option_names=['-h', '--help']),
               sources=[
                   proscli.terminal_cli, proscli.build_cli,
                   proscli.flasher_cli, proscli.conductor_cli,
                   proscli.upgrade_cli
               ])
@click.version_option(version=get_version(), prog_name='pros')
@default_options
def cli():
    pass


if __name__ == '__main__':
    main()