Skip to content

Commit 407b843

Browse files
committed
Add Save and Erase button for onboard logging
1 parent b7805d7 commit 407b843

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

locales/en/messages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3558,6 +3558,10 @@
35583558
"dataflashSaveFileDepreciationHint": {
35593559
"message": "This method is slow and inherently prone to error / file corruption, because the MSP connection itself has intrinsic, fundamental limitations that make it unsuitable for file transfers. It may work for small log files only. Do not create support requests if file transfers fail when saved using this method. The recommended method is to use '<b>$t(onboardLoggingRebootMscText.message)</b>' (below) to activate the Mass Storage Mode, and access your flight controller as a storage device to download the log files."
35603560
},
3561+
"dataflashButtonSaveAndErase": {
3562+
"message": "Save & Erase",
3563+
"description": "Button text to save blackbox logs to file and then erase the flash"
3564+
},
35613565
"dataflashButtonErase": {
35623566
"message": "Erase flash"
35633567
},

src/js/tabs/onboard_logging.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,19 @@ onboard_logging.initialize = function (callback) {
478478
});
479479
}
480480

481-
function flash_save_begin() {
481+
function conditionallyEraseFlash(maxBytes, nextAddress) {
482+
if (!isNaN(maxBytes) && nextAddress >= maxBytes) {
483+
$(".dataflash-confirm-erase").addClass("erasing");
484+
MSP.send_message(MSPCodes.MSP_DATAFLASH_ERASE, false, false, poll_for_erase_completion);
485+
} else {
486+
gui_log(
487+
i18n.getMessage("dataflashSaveIncompleteWarning") ||
488+
"Downloaded size did not match expected size - not erasing flash.",
489+
);
490+
}
491+
}
492+
493+
function flash_save_begin(alsoErase = false) {
482494
if (GUI.connected_to) {
483495
self.blockSize = self.BLOCK_SIZE;
484496

@@ -515,6 +527,10 @@ onboard_logging.initialize = function (callback) {
515527
mark_saving_dialog_done(startTime, nextAddress, totalBytesCompressed);
516528
}
517529
FileSystem.closeFile(openedFile);
530+
// Optionally erase after successful full download
531+
if (!saveCancelled && alsoErase) {
532+
conditionallyEraseFlash(maxBytes, nextAddress);
533+
}
518534
} else {
519535
if (!self.writeError) {
520536
mspHelper.dataflashRead(nextAddress, self.blockSize, onChunkRead);
@@ -528,6 +544,9 @@ onboard_logging.initialize = function (callback) {
528544
// A zero-byte block indicates end-of-file, so we're done
529545
mark_saving_dialog_done(startTime, nextAddress, totalBytesCompressed);
530546
FileSystem.closeFile(openedFile);
547+
if (alsoErase) {
548+
conditionallyEraseFlash(maxBytes, nextAddress);
549+
}
531550
}
532551
} else {
533552
// There was an error with the received block (address didn't match the one we asked for), retry

src/tabs/onboard_logging.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ <h3 i18n="dataflashSavingTitle"></h3>
110110

111111
<div class="dataflash-buttons">
112112
<a class="regular-button erase-flash" href="#" i18n="dataflashButtonErase"></a>
113+
<a class="regular-button require-msc-not-supported save-flash-erase" href="#" i18n="dataflashButtonSaveAndErase"></a>
113114
<a class="regular-button require-msc-not-supported save-flash" href="#" i18n="dataflashButtonSaveFile"></a>
115+
<a class="regular-button require-msc-supported save-flash-erase" href="#" i18n="dataflashButtonSaveAndErase"></a>
114116
<a class="regular-button require-msc-supported save-flash" href="#"><span i18n="dataflashButtonSaveFileDeprecated"></span><span class="helpicon cf_tip" i18n_title="dataflashSaveFileDepreciationHint"></span></a>
115117
<p i18n="dataflashSavetoFileNote"></p>
116118
</div>

0 commit comments

Comments
 (0)