Fix reconnection issue in cli
parent
2d268ee115
commit
7f9e15878c
|
@ -262,7 +262,7 @@ function startProcess() {
|
|||
if (GUI.connected_to || GUI.connecting_to) {
|
||||
$('a.connect').click();
|
||||
} else {
|
||||
self.disconnect();
|
||||
serial.disconnect();
|
||||
}
|
||||
$('div.open_firmware_flasher a.flash').click();
|
||||
} else if (GUI.allowedTabs.indexOf(tab) < 0) {
|
||||
|
|
|
@ -344,7 +344,7 @@ const MSP = {
|
|||
|
||||
if (!requestExists) {
|
||||
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);
|
||||
}, 1000); // we should be able to define timeout in the future
|
||||
|
|
|
@ -209,6 +209,7 @@ const serial = {
|
|||
},
|
||||
disconnect: function (callback) {
|
||||
const self = this;
|
||||
const id = self.connectionId;
|
||||
self.connected = false;
|
||||
self.emptyOutputBuffer();
|
||||
|
||||
|
@ -221,6 +222,8 @@ const serial = {
|
|||
for (let i = (self.onReceiveError.listeners.length - 1); i >= 0; i--) {
|
||||
self.onReceiveError.removeListener(self.onReceiveError.listeners[i]);
|
||||
}
|
||||
|
||||
let status = true;
|
||||
if (self.connectionType !== 'virtual') {
|
||||
if (self.connectionType === 'tcp') {
|
||||
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;
|
||||
disconnectFn(self.connectionId, function (result) {
|
||||
checkChromeRuntimeError();
|
||||
|
||||
if (chrome.runtime.lastError) {
|
||||
console.log(chrome.runtime.lastError.message);
|
||||
}
|
||||
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`);
|
||||
|
||||
self.connectionId = false;
|
||||
self.bitrate = 0;
|
||||
|
||||
if (callback) callback(result);
|
||||
console.log(`${self.connectionType}: ${result ? 'closed' : 'failed to close'} connection with ID: ${id}, Sent: ${self.bytesSent} bytes, Received: ${self.bytesReceived} bytes`);
|
||||
status = result;
|
||||
});
|
||||
} else {
|
||||
self.connectionId = false;
|
||||
CONFIGURATOR.virtualMode = false;
|
||||
self.connectionType = false;
|
||||
if (callback) {
|
||||
callback(true);
|
||||
}
|
||||
}
|
||||
self.connectionId = false;
|
||||
self.bitrate = 0;
|
||||
|
||||
if (callback) {
|
||||
callback(status);
|
||||
}
|
||||
} else {
|
||||
// connection wasn't opened, so we won't try to close anything
|
||||
|
@ -282,7 +284,8 @@ const serial = {
|
|||
const _callback = self.outputBuffer[0].callback;
|
||||
|
||||
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) {
|
||||
_callback({
|
||||
bytesSent: 0,
|
||||
|
@ -294,7 +297,9 @@ const serial = {
|
|||
|
||||
const sendFn = (self.connectionType === 'serial') ? chrome.serial.send : chrome.sockets.tcp.send;
|
||||
sendFn(self.connectionId, _data, function (sendInfo) {
|
||||
checkChromeRuntimeError();
|
||||
if (chrome.runtime.lastError) {
|
||||
console.log(chrome.runtime.lastError.message);
|
||||
}
|
||||
|
||||
if (sendInfo === undefined) {
|
||||
console.log('undefined send error');
|
||||
|
@ -334,7 +339,7 @@ const serial = {
|
|||
counter++;
|
||||
}
|
||||
|
||||
console.log(`${self.connectionType}: send buffer overflowing, dropped: ${counter} ${entries}`);
|
||||
console.log(`${self.connectionType}: send buffer overflowing, dropped: ${counter}`);
|
||||
}
|
||||
|
||||
_send();
|
||||
|
@ -344,7 +349,7 @@ const serial = {
|
|||
});
|
||||
}
|
||||
|
||||
if (!self.transmitting) {
|
||||
if (!self.transmitting && self.connected) {
|
||||
self.transmitting = true;
|
||||
_send();
|
||||
}
|
||||
|
@ -400,7 +405,7 @@ const serial = {
|
|||
FC.CONFIG.armingDisabled = false;
|
||||
FC.CONFIG.runawayTakeoffPreventionDisabled = false;
|
||||
|
||||
let message = 'error: UNDEFINED';
|
||||
let message;
|
||||
if (self.connectionType === 'tcp') {
|
||||
switch (result){
|
||||
case -15:
|
||||
|
@ -429,10 +434,11 @@ const serial = {
|
|||
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) {
|
||||
$('a.connect').click();
|
||||
$('a.connect').trigger('click');
|
||||
} else {
|
||||
self.disconnect();
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ function initializeSerialBackend() {
|
|||
$('select#baud').hide();
|
||||
} else if (portName !== '0') {
|
||||
if (!clicks) {
|
||||
console.log(`${serial.connectionType}: connecting to: ${portName}`);
|
||||
console.log(`Connecting to: ${portName}`);
|
||||
GUI.connecting_to = portName;
|
||||
|
||||
// lock port select & baud while we are connecting / connected
|
||||
|
@ -90,8 +90,7 @@ function initializeSerialBackend() {
|
|||
}
|
||||
GUI.timeout_kill_all();
|
||||
GUI.interval_kill_all();
|
||||
GUI.tab_switch_cleanup();
|
||||
GUI.tab_switch_in_progress = false;
|
||||
GUI.tab_switch_cleanup(() => GUI.tab_switch_in_progress = false);
|
||||
|
||||
function onFinishCallback() {
|
||||
finishClose(toggleStatus);
|
||||
|
|
Loading…
Reference in New Issue