1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-21 23:35:22 +03:00

Implemented switchable compression for MSP_DATAFLASH_READ

This commit is contained in:
DieHertz 2017-07-25 01:40:58 +03:00
parent ac0049db19
commit 0bf02e5398
2 changed files with 25 additions and 6 deletions

View file

@ -1488,7 +1488,18 @@ MspHelper.prototype.dataflashRead = function(address, blockSize, onDataCallback)
/* Strip that address off the front of the reply and deliver it separately so the caller doesn't have to
* figure out the reply format:
*/
onDataCallback(address, new DataView(response.data.buffer, response.data.byteOffset + headerSize, dataSize));
if (dataCompressionType == 0) {
onDataCallback(address, new DataView(response.data.buffer, response.data.byteOffset + headerSize, dataSize), dataSize);
} else if (dataCompressionType == 1) {
// Read compressed char count to avoid decoding stray bit sequences as bytes
var compressedCharCount = response.data.readU16();
// Compressed format uses 2 additional bytes as a pseudo-header to denote the number of uncompressed bytes
var compressedArray = new Uint8Array(response.data.buffer, response.data.byteOffset + headerSize + 2, dataSize - 2);
var decompressedArray = huffmanDecodeBuf(compressedArray, compressedCharCount, defaultHuffmanTree, defaultHuffmanLenIndex);
onDataCallback(address, new DataView(decompressedArray.buffer), dataSize);
}
} else {
// Report address error
console.log('Expected address ' + address + ' but received ' + chunkAddress + ' - retrying');

View file

@ -310,10 +310,13 @@ TABS.onboard_logging.initialize = function (callback) {
$(".dataflash-saving")[0].close();
}
function mark_saving_dialog_done(startTime, totalBytes) {
function mark_saving_dialog_done(startTime, totalBytes, totalBytesCompressed) {
var totalTime = (new Date().getTime() - startTime) / 1000;
console.log('Received ' + totalBytes + ' bytes in ' + totalTime.toFixed(2) + 's ('
+ (totalBytes / totalTime / 1024).toFixed(2) + 'kB / s) with block size ' + self.blockSize + '.');
if (totalBytesCompressed) {
console.log('Compressed into', totalBytesCompressed, 'bytes with mean compression factor of', totalBytes / totalBytesCompressed);
}
$(".dataflash-saving").addClass("done");
@ -331,7 +334,10 @@ TABS.onboard_logging.initialize = function (callback) {
function flash_save_begin() {
if (GUI.connected_to) {
if (BOARD.find_board_definition(CONFIG.boardIdentifier).vcp) {
if (GUI.operating_system == "MacOS") {
// Address Chrome for macOS issue with large serial reads
self.blockSize = self.VCP_BLOCK_SIZE_3_0;
} else if (BOARD.find_board_definition(CONFIG.boardIdentifier).vcp) {
if (semver.gte(CONFIG.apiVersion, "1.31.0")) {
self.blockSize = self.VCP_BLOCK_SIZE;
} else {
@ -347,14 +353,16 @@ TABS.onboard_logging.initialize = function (callback) {
prepare_file(function(fileWriter) {
var nextAddress = 0;
var totalBytesCompressed = 0;
show_saving_dialog();
function onChunkRead(chunkAddress, chunkDataView) {
function onChunkRead(chunkAddress, chunkDataView, bytesCompressed) {
if (chunkDataView !== null) {
// Did we receive any data?
if (chunkDataView.byteLength > 0) {
nextAddress += chunkDataView.byteLength;
totalBytesCompressed += bytesCompressed;
$(".dataflash-saving progress").attr("value", nextAddress / maxBytes * 100);
@ -365,7 +373,7 @@ TABS.onboard_logging.initialize = function (callback) {
if (saveCancelled) {
dismiss_saving_dialog();
} else {
mark_saving_dialog_done(startTime, nextAddress);
mark_saving_dialog_done(startTime, nextAddress, totalBytesCompressed);
}
} else {
mspHelper.dataflashRead(nextAddress, self.blockSize, onChunkRead);
@ -375,7 +383,7 @@ TABS.onboard_logging.initialize = function (callback) {
fileWriter.write(blob);
} else {
// A zero-byte block indicates end-of-file, so we're done
mark_saving_dialog_done(startTime, nextAddress);
mark_saving_dialog_done(startTime, nextAddress, totalBytesCompressed);
}
} else {
// There was an error with the received block (address didn't match the one we asked for), retry