示例#1
0
async def post_serial_update(
        serial: str = Path(...,
                           description="Serial number of the module"),
        hardware: ThreadManager = Depends(get_hardware))\
        -> V1BasicResponse:
    """Update module firmware"""
    attached_modules = hardware.attached_modules     # type: ignore
    matching_module = find_matching_module(serial, attached_modules)

    if not matching_module:
        raise V1HandlerError(message=f'Module {serial} not found',
                             status_code=status.HTTP_404_NOT_FOUND)

    try:
        if matching_module.bundled_fw:
            await asyncio.wait_for(
                modules.update_firmware(
                    matching_module,
                    matching_module.bundled_fw.path,
                    asyncio.get_event_loop()),
                100)
            return V1BasicResponse(
                message=f'Successfully updated module {serial}'
            )
        else:
            res = (f'Bundled fw file not found for module of '
                   f'type: {matching_module.name()}')
            status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
    except modules.UpdateError as e:
        res = f'Update error: {e}'
        status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
    except asyncio.TimeoutError:
        res = 'Module not responding'
        status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
    raise V1HandlerError(message=res, status_code=status_code)
示例#2
0
async def update_module_firmware(request):
    """
    This handler accepts a POST request and initiates a firmware
    update on the attached module specified by its serial number in the
    query string. The update process attempts to bootload the firmware
    file for the matching module type that is present in the file system
    onto the specified attached module.

    On update success:
    # status 200

    On bundled firmware file not found:
    On bootloader error:
    On bootloader not responding:
    # status 500

    On module not found:
    # status 404
    """
    log.debug('Update Module Firmware request received')
    serial = request.match_info['serial']

    matching_module = None
    for module in request.app['com.opentrons.hardware'].attached_modules:
        if module.device_info.get('serial') == serial:
            matching_module = module
            break

    if not matching_module:
        return json_response({'message': f'Module {serial} not found'},
                             status=404)

    try:
        if matching_module.bundled_fw:
            await asyncio.wait_for(
                modules.update_firmware(matching_module,
                                        matching_module.bundled_fw.path,
                                        request.loop), UPDATE_TIMEOUT)
            res = f'Successfully updated module {serial}'
            status = 200
        else:
            res = (f'Bundled fw file not found for module of '
                   f'type: {matching_module.name()}')
            status = 500
    except modules.UpdateError as e:
        res = f'Update error: {e}'
        status = 500
    except asyncio.TimeoutError:
        res = 'Module not responding'
        status = 500
    return json_response({'message': res}, status=status)
示例#3
0
async def _upload_to_module(hw, serialnum, fw_filename, loop):
    hw_mods = hw.attached_modules
    for module in hw_mods:
        if module.device_info.get('serial') == serialnum:
            log.info("Module with serial {} found".format(serialnum))
            try:
                await asyncio.wait_for(
                    modules.update_firmware(module, fw_filename, loop),
                    UPDATE_TIMEOUT)
                return f'Successully updated module {serialnum}', 200
            except modules.UpdateError as e:
                return f'Bootloader error: {e}', 400
            except asyncio.TimeoutError:
                return 'Bootloader not responding', 500
            break
    return f'Module {serialnum} not found', 404