splitting MSP and CLI integration, new serial api
parent
834345a80c
commit
c0937ddbd4
134
js/msp.js
134
js/msp.js
|
@ -72,79 +72,73 @@ function MSP_char_read(readInfo) {
|
|||
var data = new Uint8Array(readInfo.data);
|
||||
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
if (CLI_active != true) {
|
||||
// Standard "GUI" MSP handling
|
||||
switch (MSP.state) {
|
||||
case 0: // sync char 1
|
||||
if (data[i] == 36) { // $
|
||||
MSP.state++;
|
||||
}
|
||||
break;
|
||||
case 1: // sync char 2
|
||||
if (data[i] == 77) { // M
|
||||
MSP.state++;
|
||||
} else { // restart and try again
|
||||
MSP.state = 0;
|
||||
}
|
||||
break;
|
||||
case 2: // direction (should be >)
|
||||
if (data[i] == 62) { // >
|
||||
message_status = 1;
|
||||
} else { // unknown
|
||||
message_status = 0;
|
||||
}
|
||||
|
||||
switch (MSP.state) {
|
||||
case 0: // sync char 1
|
||||
if (data[i] == 36) { // $
|
||||
MSP.state++;
|
||||
break;
|
||||
case 3:
|
||||
MSP.message_length_expected = data[i];
|
||||
|
||||
MSP.message_checksum = data[i];
|
||||
|
||||
// setup arraybuffer
|
||||
MSP.message_buffer = new ArrayBuffer(MSP.message_length_expected);
|
||||
MSP.message_buffer_uint8_view = new Uint8Array(MSP.message_buffer);
|
||||
|
||||
}
|
||||
break;
|
||||
case 1: // sync char 2
|
||||
if (data[i] == 77) { // M
|
||||
MSP.state++;
|
||||
break;
|
||||
case 4:
|
||||
MSP.code = data[i];
|
||||
MSP.message_checksum ^= data[i];
|
||||
} else { // restart and try again
|
||||
MSP.state = 0;
|
||||
}
|
||||
break;
|
||||
case 2: // direction (should be >)
|
||||
if (data[i] == 62) { // >
|
||||
message_status = 1;
|
||||
} else { // unknown
|
||||
message_status = 0;
|
||||
}
|
||||
|
||||
MSP.state++;
|
||||
break;
|
||||
case 3:
|
||||
MSP.message_length_expected = data[i];
|
||||
|
||||
MSP.message_checksum = data[i];
|
||||
|
||||
// setup arraybuffer
|
||||
MSP.message_buffer = new ArrayBuffer(MSP.message_length_expected);
|
||||
MSP.message_buffer_uint8_view = new Uint8Array(MSP.message_buffer);
|
||||
|
||||
MSP.state++;
|
||||
break;
|
||||
case 4:
|
||||
MSP.code = data[i];
|
||||
MSP.message_checksum ^= data[i];
|
||||
|
||||
if (MSP.message_length_expected != 0) { // standard message
|
||||
MSP.state++;
|
||||
} else { // MSP_ACC_CALIBRATION, etc...
|
||||
MSP.state += 2;
|
||||
}
|
||||
break;
|
||||
case 5: // payload
|
||||
MSP.message_buffer_uint8_view[MSP.message_length_received] = data[i];
|
||||
MSP.message_checksum ^= data[i];
|
||||
MSP.message_length_received++;
|
||||
|
||||
if (MSP.message_length_received >= MSP.message_length_expected) {
|
||||
MSP.state++;
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
if (MSP.message_checksum == data[i]) {
|
||||
// message received, process
|
||||
process_data(MSP.code, MSP.message_buffer, MSP.message_length_expected);
|
||||
} else {
|
||||
console.log('code: ' + MSP.code + ' - crc failed');
|
||||
|
||||
if (MSP.message_length_expected != 0) { // standard message
|
||||
MSP.state++;
|
||||
} else { // MSP_ACC_CALIBRATION, etc...
|
||||
MSP.state += 2;
|
||||
}
|
||||
break;
|
||||
case 5: // payload
|
||||
MSP.message_buffer_uint8_view[MSP.message_length_received] = data[i];
|
||||
MSP.message_checksum ^= data[i];
|
||||
MSP.message_length_received++;
|
||||
|
||||
if (MSP.message_length_received >= MSP.message_length_expected) {
|
||||
MSP.state++;
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
if (MSP.message_checksum == data[i]) {
|
||||
// message received, process
|
||||
process_data(MSP.code, MSP.message_buffer, MSP.message_length_expected);
|
||||
} else {
|
||||
console.log('code: ' + MSP.code + ' - crc failed');
|
||||
|
||||
MSP.packet_error++;
|
||||
$('span.packet-error').html(MSP.packet_error);
|
||||
}
|
||||
|
||||
// Reset variables
|
||||
MSP.message_length_received = 0;
|
||||
MSP.state = 0;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// CLI Enabled (Terminal "style" handling)
|
||||
handle_CLI(data[i]);
|
||||
MSP.packet_error++;
|
||||
$('span.packet-error').html(MSP.packet_error);
|
||||
}
|
||||
|
||||
// Reset variables
|
||||
MSP.message_length_received = 0;
|
||||
MSP.state = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
char_counter++;
|
||||
|
|
|
@ -288,7 +288,11 @@ function onClosed(result) {
|
|||
}
|
||||
|
||||
function read_serial(info) {
|
||||
MSP_char_read(info);
|
||||
if (!CLI_active) {
|
||||
MSP_char_read(info);
|
||||
} else {
|
||||
handle_CLI(info);
|
||||
}
|
||||
}
|
||||
|
||||
function port_usage() {
|
||||
|
|
66
tabs/cli.js
66
tabs/cli.js
|
@ -118,39 +118,45 @@ function send_slowly(out_arr, i, timeout_needle) {
|
|||
*/
|
||||
|
||||
var sequence_elements = 0;
|
||||
|
||||
function handle_CLI(data) {
|
||||
if (data == 27 || sequence_elements > 0) { // ESC + other
|
||||
sequence_elements++;
|
||||
|
||||
// delete previous space
|
||||
if (sequence_elements == 1) {
|
||||
var content_string = $('.tab-cli .window .wrapper').html();
|
||||
var new_string = content_string.substring(0, content_string.length -1);
|
||||
$('.tab-cli .window .wrapper').html(new_string);
|
||||
function handle_CLI(readInfo) {
|
||||
var data = new Uint8Array(readInfo.data);
|
||||
var text = "";
|
||||
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
if (data[i] == 27 || sequence_elements > 0) { // ESC + other
|
||||
sequence_elements++;
|
||||
|
||||
// delete previous space
|
||||
if (sequence_elements == 1) {
|
||||
text = text.substring(0, text.length -1);
|
||||
}
|
||||
|
||||
// Reset
|
||||
if (sequence_elements >= 5) {
|
||||
sequence_elements = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Reset
|
||||
if (sequence_elements >= 5) {
|
||||
sequence_elements = 0;
|
||||
if (sequence_elements == 0) {
|
||||
switch (data[i]) {
|
||||
case 10: // line feed
|
||||
if (GUI.operating_system == "Windows" || GUI.operating_system == "Linux" || GUI.operating_system == "UNIX") {
|
||||
text += "<br />";
|
||||
}
|
||||
break;
|
||||
case 13: // carriage return
|
||||
if (GUI.operating_system == "MacOS") {
|
||||
text += "<br />";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
text += String.fromCharCode(data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
char_counter++;
|
||||
}
|
||||
|
||||
if (sequence_elements == 0) {
|
||||
switch (data) {
|
||||
case 10: // line feed
|
||||
if (GUI.operating_system == "Windows" || GUI.operating_system == "Linux" || GUI.operating_system == "UNIX") {
|
||||
$('.tab-cli .window .wrapper').append("<br />");
|
||||
}
|
||||
break;
|
||||
case 13: // carriage return
|
||||
if (GUI.operating_system == "MacOS") {
|
||||
$('.tab-cli .window .wrapper').append("<br />");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$('.tab-cli .window .wrapper').append(String.fromCharCode(data));
|
||||
$('.tab-cli .window').scrollTop($('.tab-cli .window .wrapper').height());
|
||||
}
|
||||
}
|
||||
$('.tab-cli .window .wrapper').append(text);
|
||||
$('.tab-cli .window').scrollTop($('.tab-cli .window .wrapper').height()); // there seems to be some sort of initial rendering glitch in 33+, why?
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue