semi working logging, missing poll rate

pull/3/head
cTn 10 years ago
parent c40c783ddc
commit 0c95e94cd5

@ -25,6 +25,23 @@
line-height: 20px;
color: silver;
}
.tab-logging .info {
margin-top: 10px;
}
.tab-logging .info dt {
float: left;
width: 120px;
height: 20px;
line-height: 20px;
font-weight: bold;
}
.tab-logging .info dd {
display: block;
margin-left: 130px;
height: 20px;
line-height: 20px;
}
.tab-logging .buttons {
margin-top: 10px;
}

@ -1,13 +1,23 @@
<div class="tab-logging">
<div class="note">
Data will be logged in this tab <span style="color: red">only</span>, leaving this tab will <span style="color: red">cancel</span> logging and application will return to its normal <strong>"configurator"</strong> operation.<br />
You are free to select the global update period, data will be written into the log file every <strong>1</strong> second.
Data will be logged in this tab <span style="color: red">only</span>, leaving the tab will <span style="color: red">cancel</span>
logging and application will return to its normal <strong>"configurator"</strong> state.<br />
You are free to select the global update period, data will be written into the log file every <strong>1</strong> second for performance reasons.
</div>
<div class="properties">
<dl>
<dt><label><input type="checkbox" name="MSP_RAW_IMU" /> MSP_RAW_IMU</label></dt><dd>9 columns (accel[x, y, z], gyro[x, y, z], mag[x, y, z])</dd>
<dt><label><input type="checkbox" name="MSP_ATTITUDE" /> MSP_ATTITUDE</label></dt><dd>3 columns (x, y, z)</dd>
<dt><label><input type="checkbox" name="MSP_ALTITUDE" /> MSP_ALTITUDE</label></dt><dd>one column</dd>
<dt><label><input type="checkbox" name="MSP_RC" /> MSP_RC</label></dt><dd>8 columns by default</dd>
<dt><label><input type="checkbox" name="MSP_MOTOR" /> MSP_MOTOR</label></dt><dd>8 columns by default</dd>
<dt><label><input type="checkbox" name="MSP_DEBUG" /> MSP_DEBUG</label></dt><dd>4 columns</dd>
</dl>
</div>
<div class="info">
<dl>
<dt>Samples Saved:</dt><dd class="samples">0</dd>
<dt>Log Size:</dt><dd class="size">0 kB</dd>
</dl>
</div>
<div class="buttons">

@ -2,6 +2,8 @@ function tab_initialize_logging() {
ga_tracker.sendAppView('Logging');
GUI.active_tab = 'logging';
var requested_properties = [];
$('#content').load("./tabs/logging.html", process_html);
function process_html() {
@ -13,15 +15,106 @@ function tab_initialize_logging() {
$('a.logging').click(function() {
if (fileEntry.isFile) {
// TODO:
// grab enabled properties
// grab refresh rate
// start data polling timer
// start buffer flushing sequence & timer (keep fileWriter.readyState in mind)
var clicks = $(this).data('clicks');
if (!clicks) {
// reset some variables before start
samples = 0;
log_buffer = [];
requested_properties = [];
$('.properties input:checked').each(function() {
requested_properties.push($(this).prop('name'));
});
if (requested_properties.length) {
function poll_data() {
// save current
crunch_data();
// request new
for (var i = 0; i < requested_properties.length; i++) {
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) {
send_message(requested_properties[i]);
} else {
send_message(requested_properties[i], false, false, poll_data);
}
*/
}
}
GUI.interval_add('log_data_pull', poll_data, 1000, true); // refresh rate goes here
GUI.interval_add('flush_data', function() {
if (fileWriter.readyState == 0 || fileWriter.readyState == 2) {
append_to_file(log_buffer.join('\n'));
$('.samples').text(samples += log_buffer.length);
$('.size').text((fileWriter.length / 1024).toFixed(2) + ' kB');
log_buffer = [];
} else {
console.log('IO having trouble keeping up with the data flow');
}
}, 1000);
$(this).text('Stop Logging');
$(this).data("clicks", !clicks);
} else {
GUI.log('Please select at least one property to log');
}
} else {
GUI.interval_remove('log_data_pull');
GUI.interval_remove('flush_data');
$(this).text('Start Logging');
$(this).data("clicks", !clicks);
}
} else {
GUI.log('Please select log file');
}
});
}
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.kinematicsX;
sample += ',' + SENSOR_DATA.kinematicsY;
sample += ',' + SENSOR_DATA.kinematicsZ;
break;
case 'MSP_ALTITUDE':
sample += ',' + SENSOR_DATA.altitude;
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
var fileEntry = null;
var fileWriter = null;

Loading…
Cancel
Save