Add dataflash tab: Very basic functionality is working
parent
e672dde6e2
commit
0f22b92e35
@ -0,0 +1,81 @@
|
||||
.tab-dataflash {
|
||||
}
|
||||
.tab-dataflash .dataflash-info dd{
|
||||
|
||||
}
|
||||
|
||||
.tab-dataflash .note {
|
||||
padding: 5px;
|
||||
border: 1px dashed silver;
|
||||
}
|
||||
.tab-dataflash .properties {
|
||||
margin-top: 10px;
|
||||
}
|
||||
.tab-dataflash .dataflash-info {
|
||||
overflow:hidden;
|
||||
}
|
||||
.tab-dataflash .dataflash-info dt {
|
||||
float: left;
|
||||
width: 12em;
|
||||
height: 20px;
|
||||
line-height: 20px;
|
||||
|
||||
font-weight: bold;
|
||||
}
|
||||
.tab-dataflash .dataflash-info dd {
|
||||
display: block;
|
||||
height: 20px;
|
||||
line-height: 20px;
|
||||
}
|
||||
.tab-dataflash .speed {
|
||||
margin-top: 5px;
|
||||
width: 80px;
|
||||
|
||||
border: 1px solid silver;
|
||||
}
|
||||
.tab-dataflash .info {
|
||||
margin-top: 10px;
|
||||
}
|
||||
.tab-dataflash .info dt {
|
||||
float: left;
|
||||
width: 120px;
|
||||
height: 20px;
|
||||
line-height: 20px;
|
||||
|
||||
font-weight: bold;
|
||||
}
|
||||
.tab-dataflash .info dd {
|
||||
display: block;
|
||||
margin-left: 130px;
|
||||
height: 20px;
|
||||
line-height: 20px;
|
||||
}
|
||||
.tab-dataflash .buttons {
|
||||
width: calc(100% - 20px);
|
||||
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
}
|
||||
.tab-dataflash .buttons a {
|
||||
display: block;
|
||||
float: right;
|
||||
|
||||
margin-left: 10px;
|
||||
|
||||
height: 28px;
|
||||
line-height: 28px;
|
||||
|
||||
padding: 0 15px 0 15px;
|
||||
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
|
||||
border: 1px solid silver;
|
||||
background-color: #ececec;
|
||||
}
|
||||
.tab-dataflash .buttons a:hover {
|
||||
background-color: #dedcdc;
|
||||
}
|
||||
.tab-dataflash .buttons .back {
|
||||
display: none;
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<div class="tab-dataflash">
|
||||
<h3>Dataflash</h3>
|
||||
<dl class="dataflash-info">
|
||||
<dt>Capacity (bytes)</dt>
|
||||
<dd class="dataflash-capacity"></dd>
|
||||
<dt>Capacity (sectors)</dt>
|
||||
<dd class="dataflash-sectors"></dd>
|
||||
</dl>
|
||||
|
||||
<div class="buttons">
|
||||
<a href="#" class="erase_flash" i18n="dataflashButtonErase"></a>
|
||||
<a href="#" class="save_to_file" i18n="dataflashButtonSaveFile"></a>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,130 @@
|
||||
'use strict';
|
||||
|
||||
TABS.dataflash = {};
|
||||
TABS.dataflash.initialize = function (callback) {
|
||||
var self = this;
|
||||
|
||||
if (GUI.active_tab != 'dataflash') {
|
||||
GUI.active_tab = 'dataflash';
|
||||
googleAnalytics.sendAppView('dataflash');
|
||||
}
|
||||
|
||||
var requested_properties = [],
|
||||
samples = 0,
|
||||
requests = 0,
|
||||
log_buffer = [];
|
||||
|
||||
if (CONFIGURATOR.connectionValid) {
|
||||
MSP.send_message(MSP_codes.MSP_DATAFLASH_SUMMARY, false, false, function() {
|
||||
$('#content').load("./tabs/dataflash.html", process_html);
|
||||
});
|
||||
}
|
||||
|
||||
function process_html() {
|
||||
// translate to user-selected language
|
||||
localize();
|
||||
|
||||
$(".tab-dataflash .dataflash-capacity").text(DATAFLASH.totalSize);
|
||||
$(".tab-dataflash .dataflash-sectors").text(DATAFLASH.sectors);
|
||||
|
||||
// UI hooks
|
||||
$('.tab-dataflash a.erase_flash').click(erase_flash);
|
||||
|
||||
$('.tab-dataflash a.save_to_file').click(stream_flash_to_file);
|
||||
|
||||
if (callback) callback();
|
||||
}
|
||||
|
||||
// IO related methods
|
||||
function zeroPad(value, width) {
|
||||
value = "" + value;
|
||||
|
||||
while (value.length < width) {
|
||||
value = "0" + value;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function stream_flash_to_file() {
|
||||
if (GUI.connected_to) {
|
||||
prepare_file(function(fileWriter) {
|
||||
var
|
||||
nextAddress = 0;
|
||||
|
||||
function onChunkRead(chunkAddress, chunkDataView) {
|
||||
// If we didn't get a zero-byte chunk (indicating end-of-file), request more
|
||||
if (chunkDataView.byteLength > 0) {
|
||||
var blob = new Blob([chunkDataView]);
|
||||
|
||||
fileWriter.write(blob);
|
||||
|
||||
nextAddress += chunkDataView.byteLength;
|
||||
MSP.dataflashRead(nextAddress, onChunkRead);
|
||||
}
|
||||
}
|
||||
|
||||
MSP.dataflashRead(nextAddress, onChunkRead);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function prepare_file(onComplete) {
|
||||
var
|
||||
date = new Date(),
|
||||
filename = 'blackbox_log_' + date.getFullYear() + '-' + zeroPad(date.getMonth() + 1, 2) + '-'
|
||||
+ zeroPad(date.getDate(), 2) + '_' + zeroPad(date.getHours(), 2) + zeroPad(date.getMinutes(), 2)
|
||||
+ zeroPad(date.getSeconds(), 2);
|
||||
|
||||
chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: filename,
|
||||
accepts: [{extensions: ['TXT']}]}, function(fileEntry) {
|
||||
if (!fileEntry) {
|
||||
console.log('No file selected');
|
||||
return;
|
||||
}
|
||||
|
||||
// echo/console log path specified
|
||||
chrome.fileSystem.getDisplayPath(fileEntry, function(path) {
|
||||
console.log('Dataflash dump file path: ' + path);
|
||||
});
|
||||
|
||||
prepare_writer(fileEntry, onComplete);
|
||||
});
|
||||
}
|
||||
|
||||
function prepare_writer(fileEntry, onComplete) {
|
||||
fileEntry.createWriter(function (fileWriter) {
|
||||
fileWriter.onerror = function (e) {
|
||||
console.error(e);
|
||||
|
||||
// stop logging if the procedure was/is still running
|
||||
};
|
||||
|
||||
fileWriter.onwriteend = function () {
|
||||
};
|
||||
|
||||
onComplete(fileWriter);
|
||||
}, function (e) {
|
||||
// File is not readable or does not exist!
|
||||
console.error(e);
|
||||
});
|
||||
}
|
||||
|
||||
function erase_flash() {
|
||||
/* var dialog = $("<dialog>lol</dialog>");
|
||||
|
||||
$("body").append(dialog);
|
||||
|
||||
dialog[0].showModal();
|
||||
|
||||
TODO modal dialog to confirm erase */
|
||||
|
||||
MSP.send_message(MSP_codes.MSP_DATAFLASH_ERASE, false, false, function(data) {
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
TABS.dataflash.cleanup = function (callback) {
|
||||
if (callback) callback();
|
||||
};
|
Loading…
Reference in New Issue