From e20806c7a853f1747dc9a895be1fc341bb864bf2 Mon Sep 17 00:00:00 2001 From: cTn Date: Sun, 14 Sep 2014 14:08:28 +0200 Subject: [PATCH] only fire recovery routine once if bus is not recoverable --- js/serial.js | 56 ++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/js/serial.js b/js/serial.js index 6355800806..faff233899 100644 --- a/js/serial.js +++ b/js/serial.js @@ -1,10 +1,11 @@ 'use strict'; var serial = { - connectionId: -1, - bitrate: 0, - bytes_received: 0, - bytes_sent: 0, + connectionId: -1, + bitrate: 0, + bytes_received: 0, + bytes_sent: 0, + failed: 0, transmitting: false, output_buffer: [], @@ -18,6 +19,7 @@ var serial = { self.bitrate = connectionInfo.bitrate; self.bytes_received = 0; self.bytes_sent = 0; + self.failed = 0; self.onReceive.addListener(function log_bytes_received(info) { self.bytes_received += info.data.byteLength; @@ -29,32 +31,34 @@ var serial = { switch (info.error) { case 'system_error': // we might be able to recover from this one - var crunch_status = function (info) { - if (info) { - if (!info.paused) { - console.log('SERIAL: Connection recovered from last onReceiveError'); - googleAnalytics.sendException('Serial: onReceiveError - recovered', false); - } else { - console.log('SERIAL: Connection did not recover from last onReceiveError, disconnecting'); - GUI.log('Unrecoverable failure of serial connection, disconnecting...'); - googleAnalytics.sendException('Serial: onReceiveError - unrecoverable', false); + if (!self.failed++) { + chrome.serial.setPaused(self.connectionId, false, function () { + self.getInfo(function (info) { + if (info) { + if (!info.paused) { + console.log('SERIAL: Connection recovered from last onReceiveError'); + googleAnalytics.sendException('Serial: onReceiveError - recovered', false); - if (GUI.connected_to || GUI.connecting_to) { - $('a.connect').click(); + self.failed = 0; + } else { + console.log('SERIAL: Connection did not recover from last onReceiveError, disconnecting'); + GUI.log('Unrecoverable failure of serial connection, disconnecting...'); + googleAnalytics.sendException('Serial: onReceiveError - unrecoverable', false); + + if (GUI.connected_to || GUI.connecting_to) { + $('a.connect').click(); + } else { + self.disconnect(); + } + } } 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; case 'timeout': // TODO