mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-21 07:15:18 +03:00
only fire recovery routine once if bus is not recoverable
This commit is contained in:
parent
619f9032be
commit
e20806c7a8
1 changed files with 30 additions and 26 deletions
56
js/serial.js
56
js/serial.js
|
@ -1,10 +1,11 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var serial = {
|
var serial = {
|
||||||
connectionId: -1,
|
connectionId: -1,
|
||||||
bitrate: 0,
|
bitrate: 0,
|
||||||
bytes_received: 0,
|
bytes_received: 0,
|
||||||
bytes_sent: 0,
|
bytes_sent: 0,
|
||||||
|
failed: 0,
|
||||||
|
|
||||||
transmitting: false,
|
transmitting: false,
|
||||||
output_buffer: [],
|
output_buffer: [],
|
||||||
|
@ -18,6 +19,7 @@ var serial = {
|
||||||
self.bitrate = connectionInfo.bitrate;
|
self.bitrate = connectionInfo.bitrate;
|
||||||
self.bytes_received = 0;
|
self.bytes_received = 0;
|
||||||
self.bytes_sent = 0;
|
self.bytes_sent = 0;
|
||||||
|
self.failed = 0;
|
||||||
|
|
||||||
self.onReceive.addListener(function log_bytes_received(info) {
|
self.onReceive.addListener(function log_bytes_received(info) {
|
||||||
self.bytes_received += info.data.byteLength;
|
self.bytes_received += info.data.byteLength;
|
||||||
|
@ -29,32 +31,34 @@ var serial = {
|
||||||
|
|
||||||
switch (info.error) {
|
switch (info.error) {
|
||||||
case 'system_error': // we might be able to recover from this one
|
case 'system_error': // we might be able to recover from this one
|
||||||
var crunch_status = function (info) {
|
if (!self.failed++) {
|
||||||
if (info) {
|
chrome.serial.setPaused(self.connectionId, false, function () {
|
||||||
if (!info.paused) {
|
self.getInfo(function (info) {
|
||||||
console.log('SERIAL: Connection recovered from last onReceiveError');
|
if (info) {
|
||||||
googleAnalytics.sendException('Serial: onReceiveError - recovered', false);
|
if (!info.paused) {
|
||||||
} else {
|
console.log('SERIAL: Connection recovered from last onReceiveError');
|
||||||
console.log('SERIAL: Connection did not recover from last onReceiveError, disconnecting');
|
googleAnalytics.sendException('Serial: onReceiveError - recovered', false);
|
||||||
GUI.log('Unrecoverable <span style="color: red">failure</span> of serial connection, disconnecting...');
|
|
||||||
googleAnalytics.sendException('Serial: onReceiveError - unrecoverable', false);
|
|
||||||
|
|
||||||
if (GUI.connected_to || GUI.connecting_to) {
|
self.failed = 0;
|
||||||
$('a.connect').click();
|
} else {
|
||||||
|
console.log('SERIAL: Connection did not recover from last onReceiveError, disconnecting');
|
||||||
|
GUI.log('Unrecoverable <span style="color: red">failure</span> of serial connection, disconnecting...');
|
||||||
|
googleAnalytics.sendException('Serial: onReceiveError - unrecoverable', false);
|
||||||
|
|
||||||
|
if (GUI.connected_to || GUI.connecting_to) {
|
||||||
|
$('a.connect').click();
|
||||||
|
} else {
|
||||||
|
self.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
self.disconnect();
|
if (chrome.runtime.lastError) {
|
||||||
|
console.error(chrome.runtime.lastError.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
} else {
|
});
|
||||||
if (chrome.runtime.lastError) {
|
|
||||||
console.error(chrome.runtime.lastError.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.serial.setPaused(self.connectionId, false, function () {
|
|
||||||
self.getInfo(crunch_status);
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case 'timeout':
|
case 'timeout':
|
||||||
// TODO
|
// TODO
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue