10.3.x-maintenance
cTn 2013-04-12 19:17:27 +02:00
parent e1c1522da5
commit ac1090b4a4
6 changed files with 207 additions and 73 deletions

View File

@ -730,7 +730,36 @@ a:hover {
} }
.tab-sensors #baro { .tab-sensors #baro {
height: 120px; height: 120px;
} }
.tab-cli {
}
.tab-cli p {
padding: 5px;
border: 1px dotted silver;
}
.tab-cli .window {
margin-top: 10px;
height: 400px;
padding: 5px;
overflow-y: scroll;
overflow-x: hidden;
color: white;
border: 1px solid silver;
background-color: black;
}
.tab-cli input {
margin-top: 10px;
display: block;
width: 911px;
padding-left: 5px;
border: 1px solid silver;
}
/* Flotr related styles */ /* Flotr related styles */
.flotr-legend { .flotr-legend {

View File

@ -1,7 +1,7 @@
var timers = new Array(); var timers = new Array();
$(document).ready(function() { $(document).ready(function() {
var tabs = $('#tabs > ul'); tabs = $('#tabs > ul');
$('a', tabs).click(function() { $('a', tabs).click(function() {
if ($(this).parent().hasClass('active') == false) { // only initialize when the tab isn't already active if ($(this).parent().hasClass('active') == false) { // only initialize when the tab isn't already active
if (connectionId < 1) { // if there is no active connection, return if (connectionId < 1) { // if there is no active connection, return
@ -11,6 +11,11 @@ $(document).ready(function() {
// Disable any active "data pulling" timer // Disable any active "data pulling" timer
disable_timers(); disable_timers();
// Disable CLI (there is no "nicer way of doing so right now)
if (CLI_active == true) {
leave_CLI();
}
// Disable previous active button // Disable previous active button
$('li', tabs).removeClass('active'); $('li', tabs).removeClass('active');
@ -29,12 +34,15 @@ $(document).ready(function() {
$('#content').load("./tabs/motor_outputs.html", tab_initialize_motor_outputs); $('#content').load("./tabs/motor_outputs.html", tab_initialize_motor_outputs);
} else if ($(this).parent().hasClass('tab_sensors')) { } else if ($(this).parent().hasClass('tab_sensors')) {
$('#content').load("./tabs/sensors.html", tab_initialize_sensors); $('#content').load("./tabs/sensors.html", tab_initialize_sensors);
} else if ($(this).parent().hasClass('tab_cli')) {
$('#content').load("./tabs/cli.html", tab_initialize_cli);
} }
} }
}); });
// temporary // temporary
//$('#content').load("./tabs/initial_setup.html", tab_initialize_initial_setup); //$('#content').load("./tabs/cli.html", tab_initialize_cli);
}); });
function disable_timers() { function disable_timers() {

View File

@ -103,6 +103,8 @@ var GPS_DATA = {
update: 0 update: 0
}; };
var CLI_active = false;
$(document).ready(function() { $(document).ready(function() {
port_picker = $('div#port-picker .port select'); port_picker = $('div#port-picker .port select');
baud_picker = $('div#port-picker #baud'); baud_picker = $('div#port-picker #baud');
@ -146,20 +148,30 @@ $(document).ready(function() {
if (selected_port != '0') { if (selected_port != '0') {
if (clicks) { // odd number of clicks if (clicks) { // odd number of clicks
// Disable any active "data pulling" timer // Disable any active "data pulling" timer
disable_timers(); disable_timers();
chrome.serial.close(connectionId, onClosed); // Disable CLI (there is no "nicer way of doing so right now)
if (CLI_active == true) {
clearTimeout(connection_delay); leave_CLI(function() {
clearInterval(serial_poll); chrome.serial.close(connectionId, onClosed);
clearInterval(port_usage_poll);
clearTimeout(connection_delay);
clearInterval(serial_poll);
clearInterval(port_usage_poll);
});
} else {
chrome.serial.close(connectionId, onClosed);
clearTimeout(connection_delay);
clearInterval(serial_poll);
clearInterval(port_usage_poll);
}
// Change port utilization to 0 // Change port utilization to 0
$('span.port-usage').html('0%'); $('span.port-usage').html('0%');
$(this).text('Connect'); $(this).text('Connect');
$(this).removeClass('active'); $(this).removeClass('active');
} else { // even number of clicks } else { // even number of clicks
console.log('Connecting to: ' + selected_port); console.log('Connecting to: ' + selected_port);
@ -234,68 +246,74 @@ function onCharRead(readInfo) {
var data = new Uint8Array(readInfo.data); var data = new Uint8Array(readInfo.data);
for (var i = 0; i < data.length; i++) { for (var i = 0; i < data.length; i++) {
switch (message_state) { if (CLI_active != true) {
case 0: // sync char 1 // Standard "GUI" MSP handling
if (data[i] == 36) { // $ switch (message_state) {
case 0: // sync char 1
if (data[i] == 36) { // $
message_state++;
}
break;
case 1: // sync char 2
if (data[i] == 77) { // M
message_state++;
} else { // restart and try again
message_state = 0;
}
break;
case 2: // direction (should be >)
if (data[i] == 62) { // >
message_status = 1;
} else { // unknown
message_status = 0;
}
message_state++; message_state++;
} break;
break; case 3:
case 1: // sync char 2 message_length_expected = data[i]; // data length
if (data[i] == 77) { // M
message_checksum = data[i];
// setup arraybuffer
message_buffer = new ArrayBuffer(message_length_expected);
message_buffer_uint8_view = new Uint8Array(message_buffer);
message_state++; message_state++;
} else { // restart and try again break;
message_state = 0; case 4:
} message_code = data[i]; // code
break; message_checksum ^= data[i];
case 2: // direction (should be >)
if (data[i] == 62) { // > if (message_length_expected != 0) { // standard message
message_status = 1; message_state++;
} else { // unknown } else { // MSP_ACC_CALIBRATION, etc...
message_status = 0; message_state += 2;
} }
break;
message_state++; case 5: // data / payload
break; message_buffer_uint8_view[message_length_received] = data[i];
case 3: message_checksum ^= data[i];
message_length_expected = data[i]; // data length message_length_received++;
message_checksum = data[i]; if (message_length_received >= message_length_expected) {
message_state++;
// setup arraybuffer }
message_buffer = new ArrayBuffer(message_length_expected); break;
message_buffer_uint8_view = new Uint8Array(message_buffer); case 6: // CRC
if (message_checksum == data[i]) {
message_state++; // process data
break; process_message(message_code, message_buffer);
case 4: }
message_code = data[i]; // code
message_checksum ^= data[i]; // Reset variables
message_length_received = 0;
if (message_length_expected != 0) { // standard message message_state = 0;
message_state++; break;
} else { // MSP_ACC_CALIBRATION, etc... }
message_state += 2; } else {
} // CLI Enabled (Terminal "style" handling)
break; handle_CLI(data[i]);
case 5: // data / payload
message_buffer_uint8_view[message_length_received] = data[i];
message_checksum ^= data[i];
message_length_received++;
if (message_length_received >= message_length_expected) {
message_state++;
}
break;
case 6: // CRC
if (message_checksum == data[i]) {
// process data
process_message(message_code, message_buffer);
}
// Reset variables
message_length_received = 0;
message_state = 0;
break;
} }
char_counter++; char_counter++;

View File

@ -17,6 +17,7 @@
<script type="text/javascript" src="./tabs/auxiliary_configuration.js"></script> <script type="text/javascript" src="./tabs/auxiliary_configuration.js"></script>
<script type="text/javascript" src="./tabs/motor_outputs.js"></script> <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/sensors.js"></script>
<script type="text/javascript" src="./tabs/cli.js"></script>
</head> </head>
<body> <body>
<div id="main-wrapper"> <div id="main-wrapper">
@ -82,6 +83,7 @@
<li class="tab_auxiliary_configuration"><a href="#">Auxiliary Configuration</a></li> <li class="tab_auxiliary_configuration"><a href="#">Auxiliary Configuration</a></li>
<li class="tab_motor_outputs"><a href="#">Motor/Servo Outputs</a></li> <li class="tab_motor_outputs"><a href="#">Motor/Servo Outputs</a></li>
<li class="tab_sensors"><a href="#">Raw Sensor Data</a></li> <li class="tab_sensors"><a href="#">Raw Sensor Data</a></li>
<li class="tab_cli"><a href="#">CLI</a></li>
</ul> </ul>
<div class="clear-both"></div> <div class="clear-both"></div>
</div> </div>

9
tabs/cli.html Normal file
View File

@ -0,0 +1,9 @@
<div class="tab-cli">
<p>
<span style="color: red;">Note</span>: Leaving CLI tab or pressing Disconnect will <strong>automatically</strong>
send "<strong>exit</strong>" to the board, which will make the controller save all the changes and <span style="color: red">restart</span>.
</p>
<div class="window">
</div>
<input type="text" name="commands" value="" />
</div>

68
tabs/cli.js Normal file
View File

@ -0,0 +1,68 @@
function tab_initialize_cli() {
CLI_active = true;
// Enter CLI mode
var bufferOut = new ArrayBuffer(1);
var bufView = new Uint8Array(bufferOut);
bufView[0] = 0x23; // #
chrome.serial.write(connectionId, bufferOut, function(writeInfo) {
// used for debugging purposes (should be disabled in "stable" builds
console.log("Wrote: " + writeInfo.bytesWritten + " bytes");
});
$('.tab-cli input').keypress(function(event) {
if (event.which == 13) { // enter
var out_string = $('.tab-cli input').val();
var bufferOut = new ArrayBuffer(out_string.length + 1); // +1 for enter character
var bufView = new Uint8Array(bufferOut);
for (var i = 0; i < out_string.length; i++) {
bufView[i] = out_string.charCodeAt(i);
}
bufView[out_string.length] = 0x0D; // enter
chrome.serial.write(connectionId, bufferOut, function(writeInfo) {
$('.tab-cli input').val('');
});
}
});
// give input element user focus
$('.tab-cli input').focus();
}
function leave_CLI(callback) {
var bufferOut = new ArrayBuffer(5);
var bufView = new Uint8Array(bufferOut);
bufView[0] = 0x65; // e
bufView[1] = 0x78; // x
bufView[2] = 0x69; // i
bufView[3] = 0x74; // t
bufView[4] = 0x0D; // enter
chrome.serial.write(connectionId, bufferOut, function(writeInfo) {
if (typeof callback !== 'undefined') {
callback();
}
});
CLI_active = false;
}
function handle_CLI(data) {
switch (data) {
case 10: // line feed
break;
case 13: // carriage return
$('.tab-cli .window').append("<br />");
break;
default:
$('.tab-cli .window').append(String.fromCharCode(data));
$('.tab-cli .window').scrollTop($('.tab-cli .window').height());
}
}