@ -2,6 +2,7 @@
TABS . cli = {
TABS . cli = {
'validateText' : "" ,
'validateText' : "" ,
'currentLine' : "" ,
'sequenceElements' : 0
'sequenceElements' : 0
} ;
} ;
@ -19,14 +20,6 @@ TABS.cli.initialize = function (callback) {
CONFIGURATOR . cliActive = true ;
CONFIGURATOR . cliActive = true ;
// Enter CLI mode
var bufferOut = new ArrayBuffer ( 1 ) ;
var bufView = new Uint8Array ( bufferOut ) ;
bufView [ 0 ] = 0x23 ; // #
serial . send ( bufferOut ) ;
var textarea = $ ( '.tab-cli textarea' ) ;
var textarea = $ ( '.tab-cli textarea' ) ;
textarea . keypress ( function ( event ) {
textarea . keypress ( function ( event ) {
@ -62,6 +55,16 @@ TABS.cli.initialize = function (callback) {
// give input element user focus
// give input element user focus
textarea . focus ( ) ;
textarea . focus ( ) ;
GUI . timeout _add ( 'enter_cli' , function enter _cli ( ) {
// Enter CLI mode
var bufferOut = new ArrayBuffer ( 1 ) ;
var bufView = new Uint8Array ( bufferOut ) ;
bufView [ 0 ] = 0x23 ; // #
serial . send ( bufferOut ) ;
} , 250 ) ;
GUI . content _ready ( callback ) ;
GUI . content _ready ( callback ) ;
} ) ;
} ) ;
} ;
} ;
@ -135,11 +138,13 @@ TABS.cli.read = function (readInfo) {
if ( GUI . operating _system != "MacOS" ) {
if ( GUI . operating _system != "MacOS" ) {
text += "<br />" ;
text += "<br />" ;
}
}
this . currentLine = "" ;
break ;
break ;
case 13 : // carriage return
case 13 : // carriage return
if ( GUI . operating _system == "MacOS" ) {
if ( GUI . operating _system == "MacOS" ) {
text += "<br />" ;
text += "<br />" ;
}
}
this . currentLine = "" ;
break ;
break ;
case 60 :
case 60 :
text += '<' ;
text += '<' ;
@ -150,19 +155,41 @@ TABS.cli.read = function (readInfo) {
default :
default :
text += String . fromCharCode ( data [ i ] ) ;
text += String . fromCharCode ( data [ i ] ) ;
this . currentLine += String . fromCharCode ( data [ i ] ) ;
}
}
if ( this . currentLine == 'Rebooting' ) {
CONFIGURATOR . cliActive = false ;
CONFIGURATOR . cliValid = false ;
GUI . log ( chrome . i18n . getMessage ( 'cliReboot' ) ) ;
GUI . log ( chrome . i18n . getMessage ( 'deviceRebooting' ) ) ;
if ( BOARD . find _board _definition ( CONFIG . boardIdentifier ) . vcp ) { // VCP-based flight controls may crash old drivers, we catch and reconnect
$ ( 'a.connect' ) . click ( ) ;
GUI . timeout _add ( 'start_connection' , function start _connection ( ) {
$ ( 'a.connect' ) . click ( ) ;
} , 2000 ) ;
} else {
GUI . timeout _add ( 'waiting_for_bootup' , function waiting _for _bootup ( ) {
MSP . send _message ( MSP _codes . MSP _IDENT , false , false , function ( ) {
GUI . log ( chrome . i18n . getMessage ( 'deviceReady' ) ) ;
$ ( '#tabs ul.mode-connected .tab_setup a' ) . click ( ) ;
} ) ;
} , 1500 ) ; // 1500 ms seems to be just the right amount of delay to prevent data request timeouts
}
}
}
}
} else {
} else {
// try to catch part of valid CLI enter message
// try to catch part of valid CLI enter message
this . validateText += String . fromCharCode ( data [ i ] ) ;
this . validateText += String . fromCharCode ( data [ i ] ) ;
text += String . fromCharCode ( data [ i ] ) ;
}
}
}
}
if ( ! CONFIGURATOR . cliValid && this . validateText . indexOf ( 'CLI' ) != - 1 ) {
if ( ! CONFIGURATOR . cliValid && this . validateText . indexOf ( 'CLI' ) != - 1 ) {
GUI . log ( chrome . i18n . getMessage ( 'cliEnter' ) ) ;
CONFIGURATOR . cliValid = true ;
CONFIGURATOR . cliValid = true ;
this . validateText = "" ;
this . validateText = "" ;
text = "Entering CLI Mode, type 'exit' to return, or 'help'<br /><br /># " ;
}
}
$ ( '.tab-cli .window .wrapper' ) . append ( text ) ;
$ ( '.tab-cli .window .wrapper' ) . append ( text ) ;
@ -170,7 +197,7 @@ TABS.cli.read = function (readInfo) {
} ;
} ;
TABS . cli . cleanup = function ( callback ) {
TABS . cli . cleanup = function ( callback ) {
if ( ! CONFIGURATOR . connectionValid ) {
if ( ! CONFIGURATOR . connectionValid || ! CONFIGURATOR . cliValid ) {
if ( callback ) callback ( ) ;
if ( callback ) callback ( ) ;
return ;
return ;
}
}
@ -190,10 +217,7 @@ TABS.cli.cleanup = function (callback) {
// we can setup an interval asking for data lets say every 200ms, when data arrives, callback will be triggered and tab switched
// we can setup an interval asking for data lets say every 200ms, when data arrives, callback will be triggered and tab switched
// we could probably implement this someday
// we could probably implement this someday
GUI . timeout _add ( 'waiting_for_bootup' , function waiting _for _bootup ( ) {
GUI . timeout _add ( 'waiting_for_bootup' , function waiting _for _bootup ( ) {
CONFIGURATOR . cliActive = false ;
CONFIGURATOR . cliValid = false ;
if ( callback ) callback ( ) ;
if ( callback ) callback ( ) ;
} , 5 000) ; // if we dont allow enough time to reboot, CRC of "first" command sent will fail, keep an eye for this one
} , 1000 ) ; // if we dont allow enough time to reboot, CRC of "first" command sent will fail, keep an eye for this one
} ) ;
} ) ;
} ;
} ;