mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-19 14:25:14 +03:00
CF/BF - Prevent exceptions that result in a white content panel occuring
when unplugging USB cable while in CLI mode. Note: Various different exception scenarious were encountered in testing, the main solution seemed to be not trying to send when disconnected (!). Other state related issues were found along the way.
This commit is contained in:
parent
9bf9132772
commit
fb64fa0d61
3 changed files with 24 additions and 2 deletions
23
js/serial.js
23
js/serial.js
|
@ -1,6 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
var serial = {
|
||||
connected: false,
|
||||
connectionId: false,
|
||||
openRequested: false,
|
||||
openCanceled: false,
|
||||
|
@ -38,6 +39,7 @@ var serial = {
|
|||
}
|
||||
|
||||
if (connectionInfo && !self.openCanceled) {
|
||||
self.connected = true;
|
||||
self.connectionId = connectionInfo.connectionId;
|
||||
self.bitrate = connectionInfo.bitrate;
|
||||
self.bytesReceived = 0;
|
||||
|
@ -187,6 +189,7 @@ var serial = {
|
|||
|
||||
console.log('onConnectedCallback', result)
|
||||
if(result == 0) {
|
||||
self.connected = true;
|
||||
chrome.sockets.tcp.setNoDelay(createInfo.socketId, true, function (noDelayResult){
|
||||
if (chrome.runtime.lastError) {
|
||||
console.error('setNoDelay', chrome.runtime.lastError.message);
|
||||
|
@ -221,7 +224,6 @@ var serial = {
|
|||
});
|
||||
|
||||
console.log(self.logHead + 'Connection opened with ID: ' + createInfo.socketId + ', url: ' + self.connectionIP + ':' + self.connectionPort);
|
||||
|
||||
if (callback) callback(createInfo);
|
||||
});
|
||||
} else {
|
||||
|
@ -235,6 +237,7 @@ var serial = {
|
|||
},
|
||||
disconnect: function (callback) {
|
||||
var self = this;
|
||||
self.connected = false;
|
||||
|
||||
if (self.connectionId) {
|
||||
self.emptyOutputBuffer();
|
||||
|
@ -300,9 +303,27 @@ var serial = {
|
|||
// store inside separate variables in case array gets destroyed
|
||||
var data = self.outputBuffer[0].data,
|
||||
callback = self.outputBuffer[0].callback;
|
||||
|
||||
if (!self.connected) {
|
||||
console.log('attempting to send when disconnected');
|
||||
if (callback) callback({
|
||||
bytesSent: 0,
|
||||
error: 'undefined'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var sendFn = (self.connectionType == 'serial') ? chrome.serial.send : chrome.sockets.tcp.send;
|
||||
sendFn(self.connectionId, data, function (sendInfo) {
|
||||
if (sendInfo === undefined) {
|
||||
console.log('undefined send error');
|
||||
if (callback) callback({
|
||||
bytesSent: 0,
|
||||
error: 'undefined'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// tcp send error
|
||||
if (self.connectionType == 'tcp' && sendInfo.resultCode < 0) {
|
||||
var error = 'system_error';
|
||||
|
|
|
@ -340,6 +340,7 @@ function onClosed(result) {
|
|||
MSP.clearListeners();
|
||||
|
||||
CONFIGURATOR.connectionValid = false;
|
||||
CONFIGURATOR.cliValid = false;
|
||||
CONFIGURATOR.cliActive = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -208,7 +208,7 @@ TABS.cli.sendLine = function (line, callback) {
|
|||
}
|
||||
|
||||
TABS.cli.cleanup = function (callback) {
|
||||
if (!CONFIGURATOR.connectionValid || !CONFIGURATOR.cliValid) {
|
||||
if (!(CONFIGURATOR.connectionValid && CONFIGURATOR.cliValid && CONFIGURATOR.cliActive)) {
|
||||
if (callback) callback();
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue