add a default handler for serial errors (disconnect) (#1522)
add a default handler for serial errors (disconnect)10.7.0-preview
commit
e1af1fbd52
|
@ -306,6 +306,13 @@
|
||||||
"message": "Show Log"
|
"message": "Show Log"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"serialErrorFrameError": {
|
||||||
|
"message": "Serial connection error: bad framing"
|
||||||
|
},
|
||||||
|
"serialErrorParityError": {
|
||||||
|
"message": "Serial connection error: bad parity"
|
||||||
|
},
|
||||||
|
|
||||||
"serialPortOpened": {
|
"serialPortOpened": {
|
||||||
"message": "Serial port <span class=\"message-positive\">successfully</span> opened with ID: $1"
|
"message": "Serial port <span class=\"message-positive\">successfully</span> opened with ID: $1"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var serial = {
|
var serial = {
|
||||||
connected: false,
|
connected: false,
|
||||||
connectionId: false,
|
connectionId: false,
|
||||||
openRequested: false,
|
openRequested: false,
|
||||||
openCanceled: false,
|
openCanceled: false,
|
||||||
|
@ -39,7 +39,7 @@ var serial = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connectionInfo && !self.openCanceled) {
|
if (connectionInfo && !self.openCanceled) {
|
||||||
self.connected = true;
|
self.connected = true;
|
||||||
self.connectionId = connectionInfo.connectionId;
|
self.connectionId = connectionInfo.connectionId;
|
||||||
self.bitrate = connectionInfo.bitrate;
|
self.bitrate = connectionInfo.bitrate;
|
||||||
self.bytesReceived = 0;
|
self.bytesReceived = 0;
|
||||||
|
@ -52,8 +52,6 @@ var serial = {
|
||||||
});
|
});
|
||||||
|
|
||||||
self.onReceiveError.addListener(function watch_for_on_receive_errors(info) {
|
self.onReceiveError.addListener(function watch_for_on_receive_errors(info) {
|
||||||
console.error(info);
|
|
||||||
|
|
||||||
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
|
||||||
if (!self.failed++) {
|
if (!self.failed++) {
|
||||||
|
@ -84,8 +82,6 @@ var serial = {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//case 'break':
|
|
||||||
// This occurs on F1 boards with old firmware during reboot
|
|
||||||
case 'overrun':
|
case 'overrun':
|
||||||
// wait 50 ms and attempt recovery
|
// wait 50 ms and attempt recovery
|
||||||
self.error = info.error;
|
self.error = info.error;
|
||||||
|
@ -112,13 +108,20 @@ var serial = {
|
||||||
});
|
});
|
||||||
}, 50);
|
}, 50);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'timeout':
|
case 'timeout':
|
||||||
// TODO
|
// No data has been received for receiveTimeout milliseconds.
|
||||||
|
// We will do nothing.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'frame_error':
|
||||||
|
case 'parity_error':
|
||||||
|
GUI.log(i18n.getMessage('serialError' + inflection.camelize(info.error)));
|
||||||
case 'break': // This seems to be the error that is thrown under NW.js in Windows when the device reboots after typing 'exit' in CLI
|
case 'break': // This seems to be the error that is thrown under NW.js in Windows when the device reboots after typing 'exit' in CLI
|
||||||
|
case 'disconnected':
|
||||||
case 'device_lost':
|
case 'device_lost':
|
||||||
|
default:
|
||||||
|
console.log("serial disconnecting: " + info.error);
|
||||||
CONFIG.armingDisabled = false;
|
CONFIG.armingDisabled = false;
|
||||||
CONFIG.runawayTakeoffPreventionDisabled = false;
|
CONFIG.runawayTakeoffPreventionDisabled = false;
|
||||||
|
|
||||||
|
@ -128,10 +131,6 @@ var serial = {
|
||||||
self.disconnect();
|
self.disconnect();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'disconnected':
|
|
||||||
// TODO
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -307,7 +306,7 @@ var serial = {
|
||||||
// store inside separate variables in case array gets destroyed
|
// store inside separate variables in case array gets destroyed
|
||||||
var data = self.outputBuffer[0].data,
|
var data = self.outputBuffer[0].data,
|
||||||
callback = self.outputBuffer[0].callback;
|
callback = self.outputBuffer[0].callback;
|
||||||
|
|
||||||
if (!self.connected) {
|
if (!self.connected) {
|
||||||
console.log('attempting to send when disconnected');
|
console.log('attempting to send when disconnected');
|
||||||
if (callback) callback({
|
if (callback) callback({
|
||||||
|
@ -327,7 +326,7 @@ var serial = {
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// tcp send error
|
// tcp send error
|
||||||
if (self.connectionType == 'tcp' && sendInfo.resultCode < 0) {
|
if (self.connectionType == 'tcp' && sendInfo.resultCode < 0) {
|
||||||
var error = 'system_error';
|
var error = 'system_error';
|
||||||
|
|
Loading…
Reference in New Issue