loggin tab, initial work on IO

10.3.x-maintenance
cTn 2014-05-22 12:13:16 +02:00
parent da42cf878d
commit fa90030759
6 changed files with 138 additions and 0 deletions

View File

@ -59,6 +59,9 @@
"tab9": {
"message": "CLI"
},
"tab10": {
"message": "Logging"
},
"serialPortOpened": {
"message": "Serial port <span style=\"color: green\">successfully</span> opened with ID: $1"

View File

@ -16,6 +16,7 @@
<link type="text/css" rel="stylesheet" href="./tabs/motor_outputs.css" media="all" />
<link type="text/css" rel="stylesheet" href="./tabs/sensors.css" media="all" />
<link type="text/css" rel="stylesheet" href="./tabs/cli.css" media="all" />
<link type="text/css" rel="stylesheet" href="./tabs/logging.css" media="all" />
<link type="text/css" rel="stylesheet" href="./tabs/firmware_flasher.css" media="all" />
<script type="text/javascript" src="./js/libraries/google-analytics-bundle.js"></script>
@ -44,6 +45,7 @@
<script type="text/javascript" src="./tabs/motor_outputs.js"></script>
<script type="text/javascript" src="./tabs/sensors.js"></script>
<script type="text/javascript" src="./tabs/cli.js"></script>
<script type="text/javascript" src="./tabs/logging.js"></script>
<script type="text/javascript" src="./tabs/firmware_flasher.js"></script>
</head>
<body>
@ -105,6 +107,7 @@
<li class="tab_motor_outputs"><a href="#" i18n="tab7"></a></li>
<li class="tab_sensors"><a href="#" i18n="tab8"></a></li>
<li class="tab_cli"><a href="#" i18n="tab9"></a></li>
<li class="tab_logging"><a href="#" i18n="tab10"></a></li>
</ul>
<div class="clear-both"></div>
</div>

View File

@ -102,6 +102,9 @@ $(document).ready(function() {
case 'tab_cli':
tab_initialize_cli();
break;
case 'tab_logging':
tab_initialize_logging();
break;
}
});
}

32
tabs/logging.css Normal file
View File

@ -0,0 +1,32 @@
.tab-logging {
}
.tab-logging .note {
padding: 5px;
border: 1px dashed silver;
}
.tab-logging .properties {
margin-top: 10px;
}
.tab-logging .buttons {
margin-top: 10px;
}
.tab-logging .buttons a {
display: block;
float: left;
margin-right: 10px;
height: 28px;
line-height: 28px;
padding: 0 15px 0 15px;
text-align: center;
font-weight: bold;
border: 1px solid silver;
background-color: #ececec;
}
.tab-logging .buttons a:hover {
background-color: #dedcdc;
}

14
tabs/logging.html Normal file
View File

@ -0,0 +1,14 @@
<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 />
Logged <strong>CSV</strong> data will respect properties order below, some of the properties will log more then 1 field, in that case please consult documentation or sourcecode
to find out the order and amount of fields per property.<br />
You are free to select the global update period, data will be written into the log file every 1 second.
</div>
<div class="properties">
</div>
<div class="buttons">
<a href="#" class="log_file">Select Log File</a>
<a href="#" class="logging">Start Logging</a>
</div>
</div>

83
tabs/logging.js Normal file
View File

@ -0,0 +1,83 @@
function tab_initialize_logging() {
ga_tracker.sendAppView('Logging');
GUI.active_tab = 'logging';
$('#content').load("./tabs/logging.html", process_html);
function process_html() {
// translate to user-selected language
localize();
// UI hooks
$('a.log_file').click(prepare_file);
$('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)
}
});
}
// IO related methods
var fileEntry = null;
var fileWriter = null;
function prepare_file() {
// create or load the file
chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: 'bf_data_log', accepts: [{extensions: ['csv']}]}, function(entry) {
if (!entry) {
console.log('No file selected');
return;
}
fileEntry = entry;
// echo/console log path specified
chrome.fileSystem.getDisplayPath(fileEntry, function(path) {
console.log('Log file path: ' + path);
});
// change file entry from read only to read/write
chrome.fileSystem.getWritableEntry(fileEntry, function(fileEntryWritable) {
// check if file is writable
chrome.fileSystem.isWritableEntry(fileEntryWritable, function(isWritable) {
if (isWritable) {
fileEntry = fileEntryWritable;
prepare_writer();
} else {
console.log('File appears to be read only, sorry.');
}
});
});
});
}
function prepare_writer() {
fileEntry.createWriter(function(writer) {
fileWriter = writer;
fileWriter.onerror = function(e) {
console.error(e);
};
fileWriter.onwriteend = function() {
// console.log('Data written');
};
}, function(e) {
console.error(e);
});
}
function append_to_file(data) {
if (fileWriter.position < fileWriter.length) {
fileWriter.seek(fileWriter.length);
}
fileWriter.write(new Blob([data + '\n'], {type: 'text/plain'}));
}
}