Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add console logs to bootloader #369

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions cflib/bootloader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def start_bootloader(self, warm_boot=False, cf=None):
def get_target(self, target_id):
return self._cload.request_info_update(target_id)

def flash(self, filename: str, targets: List[Target], cf=None):
def flash(self, filename: str, targets: List[Target], cf=None, enable_console_log: Optional[bool] = False):
# Separate flash targets from decks
platform = self._get_platform_id()
flash_targets = [t for t in targets if t.platform == platform]
Expand Down Expand Up @@ -170,7 +170,8 @@ def flash(self, filename: str, targets: List[Target], cf=None):
# Flash all decks and reboot after each deck
current_index = 0
while current_index != -1:
current_index = self._flash_deck_incrementally(deck_artifacts, deck_targets, current_index)
current_index = self._flash_deck_incrementally(deck_artifacts, deck_targets, current_index,
enable_console_log=enable_console_log)
if self.progress_cb:
self.progress_cb('Deck updated! Restarting...', int(100))
if current_index != -1:
Expand Down Expand Up @@ -198,7 +199,8 @@ def flash_full(self, cf: Optional[Crazyflie] = None,
targets: Optional[Tuple[str, ...]] = None,
info_cb: Optional[Callable[[int, TargetTypes], NoReturn]] = None,
progress_cb: Optional[Callable[[str, int], NoReturn]] = None,
terminate_flash_cb: Optional[Callable[[], bool]] = None):
terminate_flash_cb: Optional[Callable[[], bool]] = None,
enable_console_log: Optional[bool] = False):
"""
Flash .zip or bin .file to list of targets.
Reset to firmware when done.
Expand All @@ -218,7 +220,7 @@ def flash_full(self, cf: Optional[Crazyflie] = None,
info_cb(self.protocol_version, connected)

if filename is not None:
self.flash(filename, targets, cf)
self.flash(filename, targets, cf, enable_console_log=enable_console_log)
self.reset_to_firmware()

def _get_flash_artifacts_from_zip(self, filename):
Expand Down Expand Up @@ -396,14 +398,15 @@ def console_callback(self, text: str):
# Crazyflie at appropriate places.
print(text, end='')

def _flash_deck_incrementally(self, artifacts: List[FlashArtifact], targets: List[Target], start_index: int):
def _flash_deck_incrementally(self, artifacts: List[FlashArtifact], targets: List[Target], start_index: int,
enable_console_log: Optional[bool] = False):
flash_all_targets = len(targets) == 0
if self.progress_cb:
self.progress_cb('Identifying deck to be updated', 0)

with SyncCrazyflie(self.clink, cf=Crazyflie()) as scf:
# Uncomment to enable console logs from the CF.
# scf.cf.console.receivedChar.add_callback(self.console_callback)
if enable_console_log:
scf.cf.console.receivedChar.add_callback(self.console_callback)

deck_mems = scf.cf.mem.get_mems(MemoryElement.TYPE_DECK_MEMORY)
deck_mems_count = len(deck_mems)
Expand Down Expand Up @@ -499,6 +502,10 @@ def progress_cb(msg: str, percent: int):
self.progress_cb(f'Failed to update deck {deck.name}', int(0))
raise RuntimeError(f'Failed to update deck {deck.name}')

if enable_console_log:
# Wait a bit to let the console log print
time.sleep(4)

# We flashed a deck, return for re-boot
next_index = deck_index + 1
if next_index >= len(decks):
Expand Down