1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-15 04:15:28 +03:00

processing hex file in different thread

This commit is contained in:
cTn 2013-11-16 10:01:29 +01:00
parent 2cc056e2a1
commit f490f99596
3 changed files with 48 additions and 18 deletions

View file

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

View file

@ -28,13 +28,21 @@ function tab_initialize_firmware_flasher() {
reader.onloadend = function(e) { reader.onloadend = function(e) {
console.log('File loaded'); console.log('File loaded');
STM32.GUI_status('<span style="color: green">Firmware loaded, ready for flashing</span>');
intel_hex = e.target.result; intel_hex = e.target.result;
parsed_hex = read_hex_file(intel_hex);
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'); $('span.size').html((parsed_hex.bytes / 1000) + ' kB');
$('a.flash_firmware').removeClass('locked'); } else {
STM32.GUI_status('<span style="color: red">HEX file appears to be corrupted</span>');
}
});
}; };
reader.readAsText(file); 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) { $.get('https://raw.github.com/multiwii/baseflight/master/obj/baseflight.hex', function(data) {
intel_hex = data; intel_hex = data;
parsed_hex = read_hex_file(intel_hex);
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.path').html('Using remote Firmware');
$('span.size').html((parsed_hex.bytes / 1000) + ' kB'); $('span.size').html((parsed_hex.bytes / 1000) + ' kB');
$('a.flash_firmware').removeClass('locked'); } else {
STM32.GUI_status('<span style="color: red">HEX file appears to be corrupted</span>');
STM32.GUI_status('<span style="color: green">Remote Firmware loaded, ready for flashing</span>'); }
});
}).fail(function() { }).fail(function() {
STM32.GUI_status('<span style="color: red">Failed to load remote firmware</span>'); STM32.GUI_status('<span style="color: red">Failed to load remote firmware</span>');
$('a.flash_firmware').addClass('locked'); $('a.flash_firmware').addClass('locked');
@ -88,3 +103,16 @@ 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);
}

View file

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