<filename>src/aceinna/devices/upgrade_workers/jump_application_worker.py
import time
from ..base.upgrade_worker_base import UpgradeWorkerBase
from ...framework.utils import helper
from ..ping.open import ping
from . import (UPGRADE_EVENT, UPGRADE_GROUP)


class JumpApplicationWorker(UpgradeWorkerBase):
    '''Firmware upgrade worker
    '''

    def __init__(self, communicator, bootloader_baudrate=115200):
        super(JumpApplicationWorker, self).__init__()
        self._communicator = communicator
        self.current = 0
        self.total = 0
        self._original_baudrate = communicator.serial_port.baudrate
        self._bootloader_baudrate = bootloader_baudrate
        self._group = UPGRADE_GROUP.FIRMWARE

    def stop(self):
        self._is_stopped = True

    def get_upgrade_content_size(self):
        return self.total

    def work(self):
        '''Send JA and ping device
        '''
        if self._is_stopped:
            return

        # run command JA
        command_line = helper.build_bootloader_input_packet('JA')
        self._communicator.serial_port.baudrate = self._bootloader_baudrate
        self._communicator.reset_buffer()  # clear input and output buffer
        self._communicator.write(command_line, True)
        time.sleep(5)

        # ping device
        can_ping = False
        self._communicator.serial_port.baudrate = self._original_baudrate

        while not can_ping:
            self._communicator.reset_buffer()  # clear input and output buffer
            info = ping(self._communicator, None)
            if info:
                can_ping = True
            time.sleep(0.5)

        self.emit(UPGRADE_EVENT.FINISH, self._key)

<filename>src/aceinna/devices/upgrade_workers/jump_application_worker.py
import time
from ..base.upgrade_worker_base import UpgradeWorkerBase
from ...framework.utils import helper
from ..ping.open import ping
from . import (UPGRADE_EVENT, UPGRADE_GROUP)


class JumpApplicationWorker(UpgradeWorkerBase):
    '''Firmware upgrade worker
    '''

    def __init__(self, communicator, bootloader_baudrate=115200):
        super(JumpApplicationWorker, self).__init__()
        self._communicator = communicator
        self.current = 0
        self.total = 0
        self._original_baudrate = communicator.serial_port.baudrate
        self._bootloader_baudrate = bootloader_baudrate
        self._group = UPGRADE_GROUP.FIRMWARE

    def stop(self):
        self._is_stopped = True

    def get_upgrade_content_size(self):
        return self.total

    def work(self):
        '''Send JA and ping device
        '''
        if self._is_stopped:
            return

        # run command JA
        command_line = helper.build_bootloader_input_packet('JA')
        self._communicator.serial_port.baudrate = self._bootloader_baudrate
        self._communicator.reset_buffer()  # clear input and output buffer
        self._communicator.write(command_line, True)
        time.sleep(5)

        # ping device
        can_ping = False
        self._communicator.serial_port.baudrate = self._original_baudrate

        while not can_ping:
            self._communicator.reset_buffer()  # clear input and output buffer
            info = ping(self._communicator, None)
            if info:
                can_ping = True
            time.sleep(0.5)

        self.emit(UPGRADE_EVENT.FINISH, self._key)

Firmware upgrade worker Send JA and ping device # run command JA # clear input and output buffer # ping device # clear input and output buffer