Exemple #1
0
def stop_user_code(port, ctx=proscli.utils.State()):
    click.echo('Stopping user code... ', nl=False)
    stopbits = [0x0f, 0x0f, 0x21, 0xde, 0x08, 0x00, 0x00, 0x00, 0x08, 0xf1, 0x04]
    debug(bytes_to_str(stopbits), ctx)
    if not port.is_open:
        port.open()
    port.flush()
    port.read(port.in_waiting)
    for stopbit in stopbits:
        port.write([stopbit])
    port.flush()
    response = port.read_all()
    debug(bytes_to_str(response), ctx)
    port.parity = serial.PARITY_NONE
    click.echo('complete')
def stop_user_code(port, ctx=proscli.utils.State()):
    click.echo('Stopping user code... ', nl=False)
    stopbits = [0x0f, 0x0f, 0x21, 0xde, 0x08, 0x00, 0x00, 0x00, 0x08, 0xf1, 0x04]
    debug(bytes_to_str(stopbits), ctx)
    if not port.is_open:
        port.open()
    port.flush()
    port.read(port.in_waiting)
    for stopbit in stopbits:
        port.write([stopbit])
    port.flush()
    response = port.read_all()
    debug(bytes_to_str(response), ctx)
    port.parity = serial.PARITY_NONE
    click.echo('complete')
Exemple #3
0
def send_to_download_channel(port, ctx=proscli.utils.State()):
    click.echo('Sending to download channel... ', nl=False)
    download_ch_bits = [0xc9, 0x36, 0xb8, 0x47, 0x35]
    configure_port(port, serial.PARITY_EVEN)
    debug('DL CH BITS: {}  PORT CFG: {}'.format(bytes_to_str(download_ch_bits), repr(port)), ctx)
    for _ in itertools.repeat(None, 5):
        port.read(port.in_waiting)
        port.write(download_ch_bits)
        port.flush()
        time.sleep(0.25)
        response = port.read_all()
        debug('DB CH RESPONSE: {}'.format(bytes_to_str(response)), ctx)
        response = response[-1:]
        if response is not None and len(response) > 0 and response[0] == ACK:
            click.echo('complete')
            return True
    click.echo('failed')
    return False
def send_to_download_channel(port, ctx=proscli.utils.State()):
    click.echo('Sending to download channel... ', nl=False)
    download_ch_bits = [0xc9, 0x36, 0xb8, 0x47, 0x35]
    configure_port(port, serial.PARITY_EVEN)
    debug('DL CH BITS: {}  PORT CFG: {}'.format(bytes_to_str(download_ch_bits), repr(port)), ctx)
    for _ in itertools.repeat(None, 5):
        port.read(port.in_waiting)
        port.write(download_ch_bits)
        port.flush()
        time.sleep(0.25)
        response = port.read_all()
        debug('DB CH RESPONSE: {}'.format(bytes_to_str(response)), ctx)
        response = response[-1:]
        if response is not None and len(response) > 0 and response[0] == ACK:
            click.echo('complete')
            return True
    click.echo('failed')
    return False
Exemple #5
0
def send_to_download_channel(port, ctx=proscli.utils.State()):
    click.echo('Sending to download channel (this may take a while)... ', nl=False)
    download_ch_bits = [0xc9, 0x36, 0xb8, 0x47, 0x35]
    debug('DL CH BITS: {}  PORT CFG: {}'.format(bytes_to_str(download_ch_bits), repr(port)), ctx)
    for _ in itertools.repeat(None, 5):
        port.read_all()
        time.sleep(0.1)
        port.write(download_ch_bits)
        port.flush()
        time.sleep(3)
        response = port.read_all()
        debug('DB CH RESPONSE: {}'.format(bytes_to_str(response)), ctx)
        response = response[-1:]
        sys_info = ask_sys_info(port, ctx, silent=True)
        if (sys_info is not None and sys_info.connection_type == ConnectionType.serial_vexnet2_dl) or (response is not None and len(response) > 0 and response[0] == ACK):
            click.echo('complete')
            return True
    click.echo('failed')
    return False
Exemple #6
0
def ask_sys_info(port, ctx=proscli.utils.State(), silent=False):
    if not silent:
        click.echo('Asking for system information... ', nl=False)
    sys_info_bits = [0xc9, 0x36, 0xb8, 0x47, 0x21]
    if not port.is_open:
        port.open()
    debug('SYS INFO BITS: {}  PORT CFG: {}'.format(bytes_to_str(sys_info_bits), repr(port)), ctx)
    for _ in itertools.repeat(None, 10):
        port.read_all()
        port.write(sys_info_bits)
        port.flush()
        time.sleep(0.1)
        response = port.read_all()
        debug('SYS INFO RESPONSE: {}'.format(bytes_to_str(response)), ctx)
        if len(response) > 14:
            response = response[:14]
        if len(response) == 14 and response[0] == 0xaa and response[1] == 0x55\
                and response[2] == 0x21 and response[3] == 0xa:  # synchronization matched
            sys_info = SystemInfo()
            sys_info.device = port.name
            sys_info.joystick_firmware = '{}.{}'.format(response[4], response[5])
            sys_info.cortex_firmware = '{}.{}'.format(response[6], response[7])
            if response[8] > 5:  # anything smaller than 5 is probably garbage from ADC
                sys_info.joystick_battery = response[8] * 0.059
            if response[9] > 5:  # anything smaller than 5 is probably garbage from ADC
                sys_info.cortex_battery = response[9] * 0.059
            if response[10] > 5:  # anything smaller than 5 is probably garbage from ADC
                sys_info.backup_battery = response[10] * 0.059
            try:
                # Mask FCS bits out of response[11]
                sys_info.connection_type = ConnectionType(response[11] & 0b00110111)
            except ValueError:
                sys_info.connection_type = ConnectionType.unknown
            sys_info.previous_polls = response[13]
            sys_info.byte_representation = response
            if not silent:
                click.echo('complete')
            return sys_info
        time.sleep(0.15)
    return None
Exemple #7
0
def expose_bootloader(port, ctx=proscli.utils.State()):
    click.echo('Exposing bootloader... ', nl=False)
    bootloader_bits = [0xc9, 0x36, 0xb8, 0x47, 0x25]
    port.flush()
    debug('EXPOSE BL BITS: {}  PORT CFG: {}'.format(bytes_to_str(bootloader_bits), repr(port)), ctx)
    port.read_all()
    time.sleep(0.1)
    for _ in itertools.repeat(None, 5):
        port.write(bootloader_bits)
        time.sleep(0.1)
    time.sleep(0.3)  # time delay to allow shift to download mode
    click.echo('complete')
    return True
def ask_sys_info(port, ctx=proscli.utils.State()):
    click.echo('Asking for system information... ', nl=False)
    sys_info_bits = [0xc9, 0x36, 0xb8, 0x47, 0x21]
    if not port.is_open:
        port.open()
    configure_port(port, serial.PARITY_NONE)
    debug('SYS INFO BITS: {}  PORT CFG: {}'.format(bytes_to_str(sys_info_bits), repr(port)), ctx)
    for _ in itertools.repeat(None, 10):
        port.read(port.in_waiting)
        port.write(sys_info_bits)
        port.flush()
        time.sleep(0.1)
        response = port.read_all()
        debug('SYS INFO RESPONSE: {}'.format(bytes_to_str(response)), ctx)
        if len(response) > 14:
            response = response[:14]
        if len(response) == 14 and response[0] == 0xaa and response[1] == 0x55\
                and response[2] == 0x21 and response[3] == 0xa:  # synchronization matched
            sys_info = SystemInfo()
            sys_info.device = port.name
            sys_info.joystick_firmware = '{}.{}'.format(response[4], response[5])
            sys_info.cortex_firmware = '{}.{}'.format(response[6], response[7])
            if response[8] > 5:  # anything smaller than 5 is probably garbage from ADC
                sys_info.joystick_battery = response[8] * 0.059
            if response[9] > 5:  # anything smaller than 5 is probably garbage from ADC
                sys_info.cortex_battery = response[9] * 0.059
            if response[10] > 5:  # anything smaller than 5 is probably garbage from ADC
                sys_info.backup_battery = response[10] * 0.059
            try:
                sys_info.connection_type = ConnectionType(response[11])
            except ValueError:
                sys_info.connection_type = ConnectionType.unknown
            sys_info.previous_polls = response[13]
            sys_info.byte_representation = response
            click.echo('complete')
            return sys_info
        time.sleep(0.15)
    return None
def expose_bootloader(port, ctx=proscli.utils.State()):
    click.echo('Exposing bootloader... ', nl=False)
    bootloader_bits = [0xc9, 0x36, 0xb8, 0x47, 0x25]
    configure_port(port, serial.PARITY_NONE)
    port.flush()
    debug('EXPOSE BL BITS: {}  PORT CFG: {}'.format(bytes_to_str(bootloader_bits), repr(port)), ctx)
    port.read(port.in_waiting)
    for _ in itertools.repeat(None, 5):
        port.write(bootloader_bits)
        port.flush()
    configure_port(port, serial.PARITY_NONE)
    time.sleep(0.3)  # time delay to allow shift to download mode
    click.echo('complete')
    return True
def debug_response(command, response, fmt="STM BL RESPONSE TO 0x{}: {}"):
    if not isinstance(command, str):
        command = bytes_to_str(command)
    if not isinstance(response, str):
        response = bytes_to_str(response)
    debug(fmt.format(command, response))
Exemple #11
0
def debug_response(command, response, fmt='STM BL RESPONSE TO 0x{}: {}'):
    if not isinstance(command, str):
        command = bytes_to_str(command)
    if not isinstance(response, str):
        response = bytes_to_str(response)
    debug(fmt.format(command, response))