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

loggin polish, sample counter bugfix

This commit is contained in:
cTn 2014-06-25 09:18:01 +02:00
parent c36293000a
commit 1e459d1af8
4 changed files with 71 additions and 67 deletions

View file

@ -478,9 +478,6 @@
"loggingLogSize": { "loggingLogSize": {
"message": "Log Size:" "message": "Log Size:"
}, },
"loggingKB": {
"message": "$1 kB"
},
"loggingButtonLogFile": { "loggingButtonLogFile": {
"message": "Select Log File" "message": "Select Log File"
}, },

10
main.js
View file

@ -236,6 +236,16 @@ function millitime() {
return now; return now;
} }
function bytesToSize(bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
var k = 1024;
if (bytes == 0) return '0 Bytes';
var i = Math.floor(Math.log(bytes) / Math.log(k));
return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
}
/* /*
function add_custom_spinners() { function add_custom_spinners() {
var spinner_element = '<div class="spinner"><div class="up"></div><div class="down"></div></div>'; var spinner_element = '<div class="spinner"><div class="up"></div><div class="down"></div></div>';

View file

@ -29,7 +29,7 @@
<div class="info"> <div class="info">
<dl> <dl>
<dt i18n="loggingSamplesSaved"></dt><dd class="samples">0</dd> <dt i18n="loggingSamplesSaved"></dt><dd class="samples">0</dd>
<dt i18n="loggingLogSize"></dt><dd class="size">0 kB</dd> <dt i18n="loggingLogSize"></dt><dd class="size">0 Bytes</dd>
</dl> </dl>
</div> </div>
<div class="buttons"> <div class="buttons">

View file

@ -66,14 +66,6 @@ function tab_initialize_logging() {
if (!MSP_pass_through) { if (!MSP_pass_through) {
for (var i = 0; i < requested_properties.length; i++) { for (var i = 0; i < requested_properties.length; i++) {
MSP.send_message(MSP_codes[requested_properties[i]]); MSP.send_message(MSP_codes[requested_properties[i]]);
/* this approach could be used if we want to utilize request time compensation
if (i < requested_properties.length -1) {
MSP.send_message(requested_properties[i]);
} else {
MSP.send_message(requested_properties[i], false, false, poll_data);
}
*/
} }
} }
} }
@ -85,7 +77,6 @@ function tab_initialize_logging() {
append_to_file(log_buffer.join('\n')); append_to_file(log_buffer.join('\n'));
$('.samples').text(samples += log_buffer.length); $('.samples').text(samples += log_buffer.length);
$('.size').text(chrome.i18n.getMessage('loggingKB', [(fileWriter.length / 1024).toFixed(2)]));
log_buffer = []; log_buffer = [];
} else { } else {
@ -142,58 +133,6 @@ function tab_initialize_logging() {
}); });
} }
var samples = 0;
var log_buffer = [];
function crunch_data() {
var sample = millitime();
for (var i = 0; i < requested_properties.length; i++) {
switch (requested_properties[i]) {
case 'MSP_RAW_IMU':
sample += ',' + SENSOR_DATA.gyroscope;
sample += ',' + SENSOR_DATA.accelerometer;
sample += ',' + SENSOR_DATA.magnetometer;
break;
case 'MSP_ATTITUDE':
sample += ',' + SENSOR_DATA.kinematics[0];
sample += ',' + SENSOR_DATA.kinematics[1];
sample += ',' + SENSOR_DATA.kinematics[2];
break;
case 'MSP_ALTITUDE':
sample += ',' + SENSOR_DATA.altitude;
break;
case 'MSP_RAW_GPS':
sample += ',' + GPS_DATA.fix;
sample += ',' + GPS_DATA.numSat;
sample += ',' + (GPS_DATA.lat / 10000000);
sample += ',' + (GPS_DATA.lon / 10000000);
sample += ',' + GPS_DATA.alt;
sample += ',' + GPS_DATA.speed;
sample += ',' + GPS_DATA.ground_course;
break;
case 'MSP_ANALOG':
sample += ',' + ANALOG.voltage;
sample += ',' + ANALOG.amperage;
sample += ',' + ANALOG.mAhdrawn;
sample += ',' + ANALOG.rssi;
break;
case 'MSP_RC':
for (var chan = 0; chan < RC.active_channels; chan++) {
sample += ',' + RC.channels[chan];
}
break;
case 'MSP_MOTOR':
sample += ',' + MOTOR_DATA;
break;
case 'MSP_DEBUG':
sample += ',' + SENSOR_DATA.debug;
break;
}
}
log_buffer.push(sample);
}
function print_head() { function print_head() {
var head = "timestamp"; var head = "timestamp";
@ -253,7 +192,59 @@ function tab_initialize_logging() {
} }
} }
log_buffer.push(head); append_to_file(head);
}
var samples = 0;
var log_buffer = [];
function crunch_data() {
var sample = millitime();
for (var i = 0; i < requested_properties.length; i++) {
switch (requested_properties[i]) {
case 'MSP_RAW_IMU':
sample += ',' + SENSOR_DATA.gyroscope;
sample += ',' + SENSOR_DATA.accelerometer;
sample += ',' + SENSOR_DATA.magnetometer;
break;
case 'MSP_ATTITUDE':
sample += ',' + SENSOR_DATA.kinematics[0];
sample += ',' + SENSOR_DATA.kinematics[1];
sample += ',' + SENSOR_DATA.kinematics[2];
break;
case 'MSP_ALTITUDE':
sample += ',' + SENSOR_DATA.altitude;
break;
case 'MSP_RAW_GPS':
sample += ',' + GPS_DATA.fix;
sample += ',' + GPS_DATA.numSat;
sample += ',' + (GPS_DATA.lat / 10000000);
sample += ',' + (GPS_DATA.lon / 10000000);
sample += ',' + GPS_DATA.alt;
sample += ',' + GPS_DATA.speed;
sample += ',' + GPS_DATA.ground_course;
break;
case 'MSP_ANALOG':
sample += ',' + ANALOG.voltage;
sample += ',' + ANALOG.amperage;
sample += ',' + ANALOG.mAhdrawn;
sample += ',' + ANALOG.rssi;
break;
case 'MSP_RC':
for (var chan = 0; chan < RC.active_channels; chan++) {
sample += ',' + RC.channels[chan];
}
break;
case 'MSP_MOTOR':
sample += ',' + MOTOR_DATA;
break;
case 'MSP_DEBUG':
sample += ',' + SENSOR_DATA.debug;
break;
}
}
log_buffer.push(sample);
} }
// IO related methods // IO related methods
@ -285,6 +276,9 @@ function tab_initialize_logging() {
// save entry for next use // save entry for next use
chrome.storage.local.set({'logging_file_entry': chrome.fileSystem.retainEntry(fileEntry)}); chrome.storage.local.set({'logging_file_entry': chrome.fileSystem.retainEntry(fileEntry)});
// reset sample counter in UI
$('.samples').text(0);
prepare_writer(); prepare_writer();
} else { } else {
console.log('File appears to be read only, sorry.'); console.log('File appears to be read only, sorry.');
@ -306,7 +300,7 @@ function tab_initialize_logging() {
}; };
fileWriter.onwriteend = function() { fileWriter.onwriteend = function() {
// console.log('Data written'); $('.size').text(bytesToSize(fileWriter.length));
}; };
if (retaining) { if (retaining) {
@ -314,6 +308,9 @@ function tab_initialize_logging() {
GUI.log(chrome.i18n.getMessage('loggingAutomaticallyRetained', [path])); GUI.log(chrome.i18n.getMessage('loggingAutomaticallyRetained', [path]));
}); });
} }
// update log size in UI on fileWriter creation
$('.size').text(bytesToSize(fileWriter.length));
}, function(e) { }, function(e) {
// File is not readable or does not exist! // File is not readable or does not exist!
console.error(e); console.error(e);