1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-23 16:25:22 +03:00

Auto merged - #2561 at Sun, 26 Sep 2021 00:17:14 GMT

Fix reconnection issue in cli
This commit is contained in:
J Blackman 2021-09-26 10:17:14 +10:00 committed by GitHub
commit b93805154c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 24 deletions

View file

@ -265,7 +265,7 @@ function startProcess() {
if (GUI.connected_to || GUI.connecting_to) { if (GUI.connected_to || GUI.connecting_to) {
$('a.connect').click(); $('a.connect').click();
} else { } else {
self.disconnect(); serial.disconnect();
} }
$('div.open_firmware_flasher a.flash').click(); $('div.open_firmware_flasher a.flash').click();
} else if (GUI.allowedTabs.indexOf(tab) < 0) { } else if (GUI.allowedTabs.indexOf(tab) < 0) {

View file

@ -344,7 +344,7 @@ const MSP = {
if (!requestExists) { if (!requestExists) {
obj.timer = setInterval(function () { obj.timer = setInterval(function () {
console.log(`MSP data request timed-out: ${code} direction: ${MSP.message_direction} tab: ${GUI.active_tab}`); console.warn(`MSP: data request timed-out: ${code} ID: ${serial.connectionId} TAB: ${GUI.active_tab}`);
serial.send(bufferOut, false); serial.send(bufferOut, false);
}, 1000); // we should be able to define timeout in the future }, 1000); // we should be able to define timeout in the future

View file

@ -209,6 +209,7 @@ const serial = {
}, },
disconnect: function (callback) { disconnect: function (callback) {
const self = this; const self = this;
const id = self.connectionId;
self.connected = false; self.connected = false;
self.emptyOutputBuffer(); self.emptyOutputBuffer();
@ -221,6 +222,8 @@ const serial = {
for (let i = (self.onReceiveError.listeners.length - 1); i >= 0; i--) { for (let i = (self.onReceiveError.listeners.length - 1); i >= 0; i--) {
self.onReceiveError.removeListener(self.onReceiveError.listeners[i]); self.onReceiveError.removeListener(self.onReceiveError.listeners[i]);
} }
let status = true;
if (self.connectionType !== 'virtual') { if (self.connectionType !== 'virtual') {
if (self.connectionType === 'tcp') { if (self.connectionType === 'tcp') {
chrome.sockets.tcp.disconnect(self.connectionId, function () { chrome.sockets.tcp.disconnect(self.connectionId, function () {
@ -231,23 +234,22 @@ const serial = {
const disconnectFn = (self.connectionType === 'serial') ? chrome.serial.disconnect : chrome.sockets.tcp.close; const disconnectFn = (self.connectionType === 'serial') ? chrome.serial.disconnect : chrome.sockets.tcp.close;
disconnectFn(self.connectionId, function (result) { disconnectFn(self.connectionId, function (result) {
checkChromeRuntimeError(); if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError.message);
}
result = result || self.connectionType === 'tcp'; result = result || self.connectionType === 'tcp';
console.log(`${self.connectionType}: ${result ? 'closed' : 'failed to close'} connection with ID: ${self.connectionId}, Sent: ${self.bytesSent} bytes, Received: ${self.bytesReceived} bytes`); console.log(`${self.connectionType}: ${result ? 'closed' : 'failed to close'} connection with ID: ${id}, Sent: ${self.bytesSent} bytes, Received: ${self.bytesReceived} bytes`);
status = result;
});
} else {
CONFIGURATOR.virtualMode = false;
self.connectionType = false;
}
self.connectionId = false; self.connectionId = false;
self.bitrate = 0; self.bitrate = 0;
if (callback) callback(result);
});
} else {
self.connectionId = false;
CONFIGURATOR.virtualMode = false;
self.connectionType = false;
if (callback) { if (callback) {
callback(true); callback(status);
}
} }
} else { } else {
// connection wasn't opened, so we won't try to close anything // connection wasn't opened, so we won't try to close anything
@ -282,7 +284,8 @@ const serial = {
const _callback = self.outputBuffer[0].callback; const _callback = self.outputBuffer[0].callback;
if (!self.connected) { if (!self.connected) {
console.log(`${self.connectionType}: attempting to send when disconnected`); console.log(`${self.connectionType}: attempting to send when disconnected. ID: ${self.connectionId}`);
if (_callback) { if (_callback) {
_callback({ _callback({
bytesSent: 0, bytesSent: 0,
@ -294,7 +297,9 @@ const serial = {
const sendFn = (self.connectionType === 'serial') ? chrome.serial.send : chrome.sockets.tcp.send; const sendFn = (self.connectionType === 'serial') ? chrome.serial.send : chrome.sockets.tcp.send;
sendFn(self.connectionId, _data, function (sendInfo) { sendFn(self.connectionId, _data, function (sendInfo) {
checkChromeRuntimeError(); if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError.message);
}
if (sendInfo === undefined) { if (sendInfo === undefined) {
console.log('undefined send error'); console.log('undefined send error');
@ -334,7 +339,7 @@ const serial = {
counter++; counter++;
} }
console.log(`${self.connectionType}: send buffer overflowing, dropped: ${counter} ${entries}`); console.log(`${self.connectionType}: send buffer overflowing, dropped: ${counter}`);
} }
_send(); _send();
@ -344,7 +349,7 @@ const serial = {
}); });
} }
if (!self.transmitting) { if (!self.transmitting && self.connected) {
self.transmitting = true; self.transmitting = true;
_send(); _send();
} }
@ -400,7 +405,7 @@ const serial = {
FC.CONFIG.armingDisabled = false; FC.CONFIG.armingDisabled = false;
FC.CONFIG.runawayTakeoffPreventionDisabled = false; FC.CONFIG.runawayTakeoffPreventionDisabled = false;
let message = 'error: UNDEFINED'; let message;
if (self.connectionType === 'tcp') { if (self.connectionType === 'tcp') {
switch (result){ switch (result){
case -15: case -15:
@ -429,10 +434,11 @@ const serial = {
break; break;
} }
} }
console.log(`${self.connectionType}: ${direction} ${message}: ${result}`); const resultMessage = message ? `${message} ${result}` : result;
console.warn(`${self.connectionType}: ${resultMessage} ID: ${self.connectionId} (${direction})`);
if (GUI.connected_to || GUI.connecting_to) { if (GUI.connected_to || GUI.connecting_to) {
$('a.connect').click(); $('a.connect').trigger('click');
} else { } else {
self.disconnect(); self.disconnect();
} }

View file

@ -66,7 +66,7 @@ function initializeSerialBackend() {
$('select#baud').hide(); $('select#baud').hide();
} else if (portName !== '0') { } else if (portName !== '0') {
if (!clicks) { if (!clicks) {
console.log(`${serial.connectionType}: connecting to: ${portName}`); console.log(`Connecting to: ${portName}`);
GUI.connecting_to = portName; GUI.connecting_to = portName;
// lock port select & baud while we are connecting / connected // lock port select & baud while we are connecting / connected
@ -90,8 +90,7 @@ function initializeSerialBackend() {
} }
GUI.timeout_kill_all(); GUI.timeout_kill_all();
GUI.interval_kill_all(); GUI.interval_kill_all();
GUI.tab_switch_cleanup(); GUI.tab_switch_cleanup(() => GUI.tab_switch_in_progress = false);
GUI.tab_switch_in_progress = false;
function onFinishCallback() { function onFinishCallback() {
finishClose(toggleStatus); finishClose(toggleStatus);