processing hex file in different thread

pull/3/head
cTn 11 years ago
parent 2cc056e2a1
commit f490f99596

@ -16,7 +16,6 @@
<script type="text/javascript" src="./js/msp.js"></script>
<script type="text/javascript" src="./main.js"></script>
<script type="text/javascript" src="./js/backup_restore.js"></script>
<script type="text/javascript" src="./js/hex_reader.js"></script>
<script type="text/javascript" src="./js/stm32.js"></script>
<!-- Various tabs are divided into separate files (for clarity) -->

@ -28,13 +28,21 @@ function tab_initialize_firmware_flasher() {
reader.onloadend = function(e) {
console.log('File loaded');
STM32.GUI_status('<span style="color: green">Firmware loaded, ready for flashing</span>');
intel_hex = e.target.result;
parsed_hex = read_hex_file(intel_hex);
$('span.size').html((parsed_hex.bytes / 1000) + ' kB');
$('a.flash_firmware').removeClass('locked');
parse_hex(intel_hex, function(data) {
parsed_hex = data;
if (parsed_hex) {
STM32.GUI_status('<span style="color: green">Firmware loaded, ready for flashing</span>');
$('a.flash_firmware').removeClass('locked');
$('span.size').html((parsed_hex.bytes / 1000) + ' kB');
} else {
STM32.GUI_status('<span style="color: red">HEX file appears to be corrupted</span>');
}
});
};
reader.readAsText(file);
@ -52,13 +60,20 @@ function tab_initialize_firmware_flasher() {
$.get('https://raw.github.com/multiwii/baseflight/master/obj/baseflight.hex', function(data) {
intel_hex = data;
parsed_hex = read_hex_file(intel_hex);
$('span.path').html('Using remote Firmware');
$('span.size').html((parsed_hex.bytes / 1000) + ' kB');
$('a.flash_firmware').removeClass('locked');
STM32.GUI_status('<span style="color: green">Remote Firmware loaded, ready for flashing</span>');
parse_hex(intel_hex, function(data) {
parsed_hex = data;
if (parsed_hex) {
STM32.GUI_status('<span style="color: green">Remote Firmware loaded, ready for flashing</span>');
$('a.flash_firmware').removeClass('locked');
$('span.path').html('Using remote Firmware');
$('span.size').html((parsed_hex.bytes / 1000) + ' kB');
} else {
STM32.GUI_status('<span style="color: red">HEX file appears to be corrupted</span>');
}
});
}).fail(function() {
STM32.GUI_status('<span style="color: red">Failed to load remote firmware</span>');
$('a.flash_firmware').addClass('locked');
@ -87,4 +102,17 @@ function tab_initialize_firmware_flasher() {
}
});
});
}
function parse_hex(str, callback) {
// parsing hex in different thread
var worker = new Worker('./workers/hex_parser.js');
// "callback"
worker.onmessage = function (event) {
callback(event.data);
};
// send data/string over for processing
worker.postMessage(str);
}

@ -69,13 +69,16 @@ function read_hex_file(data) {
}
}
if (hexfile_valid) {
console.log('HEX file parsed: ' + result.bytes + ' bytes');
return result;
if (result.end_of_file && hexfile_valid) {
postMessage(result);
} else {
console.log('HEX file parsed, CRC check failed: ' + result.bytes + ' bytes');
return false;
postMessage(false);
}
}
onmessage = function(event) {
read_hex_file(event.data);
// terminate worker
close();
}
Loading…
Cancel
Save