mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-17 05:15:20 +03:00
traffic tracking inside serial backend
This commit is contained in:
parent
b0c4b1cf1b
commit
c98bdd9f54
3 changed files with 16 additions and 20 deletions
26
js/serial.js
26
js/serial.js
|
@ -1,5 +1,7 @@
|
||||||
var serial = {
|
var serial = {
|
||||||
connectionId: -1,
|
connectionId: -1,
|
||||||
|
bytes_received: 0,
|
||||||
|
bytes_sent: 0,
|
||||||
|
|
||||||
transmitting: false,
|
transmitting: false,
|
||||||
output_buffer: [],
|
output_buffer: [],
|
||||||
|
@ -12,6 +14,12 @@ var serial = {
|
||||||
|
|
||||||
chrome.serial.connect(path, options, function(connectionInfo) {
|
chrome.serial.connect(path, options, function(connectionInfo) {
|
||||||
self.connectionId = connectionInfo.connectionId;
|
self.connectionId = connectionInfo.connectionId;
|
||||||
|
self.bytes_received = 0;
|
||||||
|
self.bytes_sent = 0;
|
||||||
|
|
||||||
|
self.onReceive.addListener(function(info) {
|
||||||
|
self.bytes_received += info.data.byteLength;
|
||||||
|
});
|
||||||
|
|
||||||
if (connectionInfo.connectionId > 0) {
|
if (connectionInfo.connectionId > 0) {
|
||||||
console.log('SERIAL: Connection opened with ID: ' + connectionInfo.connectionId + ', Baud: ' + connectionInfo.bitrate);
|
console.log('SERIAL: Connection opened with ID: ' + connectionInfo.connectionId + ', Baud: ' + connectionInfo.bitrate);
|
||||||
|
@ -25,6 +33,11 @@ var serial = {
|
||||||
|
|
||||||
self.empty_output_buffer();
|
self.empty_output_buffer();
|
||||||
|
|
||||||
|
// remove listeners
|
||||||
|
for (var i = (self.onReceive.listeners_.length - 1); i >= 0; i--) {
|
||||||
|
self.onReceive.removeListener(self.onReceive.listeners_[i].callback);
|
||||||
|
}
|
||||||
|
|
||||||
chrome.serial.disconnect(this.connectionId, function(result) {
|
chrome.serial.disconnect(this.connectionId, function(result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
console.log('SERIAL: Connection with ID: ' + self.connectionId + ' closed');
|
console.log('SERIAL: Connection with ID: ' + self.connectionId + ' closed');
|
||||||
|
@ -66,6 +79,8 @@ var serial = {
|
||||||
callback(sendInfo);
|
callback(sendInfo);
|
||||||
self.output_buffer.shift();
|
self.output_buffer.shift();
|
||||||
|
|
||||||
|
self.bytes_sent += sendInfo.bytesSent;
|
||||||
|
|
||||||
if (self.output_buffer.length) {
|
if (self.output_buffer.length) {
|
||||||
// keep the buffer withing reasonable limits
|
// keep the buffer withing reasonable limits
|
||||||
while (self.output_buffer.length > 500) {
|
while (self.output_buffer.length > 500) {
|
||||||
|
@ -82,16 +97,7 @@ var serial = {
|
||||||
sending();
|
sending();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onReceive: {
|
onReceive: chrome.serial.onReceive,
|
||||||
listeners_: chrome.serial.onReceive.listeners_,
|
|
||||||
|
|
||||||
addListener: function(function_reference) {
|
|
||||||
chrome.serial.onReceive.addListener(function_reference);
|
|
||||||
},
|
|
||||||
removeListener: function(function_reference) {
|
|
||||||
chrome.serial.onReceive.removeListener(function_reference);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
empty_output_buffer: function() {
|
empty_output_buffer: function() {
|
||||||
this.output_buffer = [];
|
this.output_buffer = [];
|
||||||
this.transmitting = false;
|
this.transmitting = false;
|
||||||
|
|
|
@ -129,11 +129,6 @@ $(document).ready(function() {
|
||||||
GUI.tab_switch_cleanup();
|
GUI.tab_switch_cleanup();
|
||||||
GUI.timeout_remove('connecting');
|
GUI.timeout_remove('connecting');
|
||||||
|
|
||||||
// remove listeners
|
|
||||||
serial.onReceive.listeners_.forEach(function(listener) {
|
|
||||||
serial.onReceive.removeListener(listener.callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
serial.disconnect(onClosed);
|
serial.disconnect(onClosed);
|
||||||
|
|
||||||
GUI.connected_to = false;
|
GUI.connected_to = false;
|
||||||
|
|
|
@ -569,11 +569,6 @@ STM32_protocol.prototype.upload_procedure = function(step) {
|
||||||
case 99:
|
case 99:
|
||||||
// disconnect
|
// disconnect
|
||||||
|
|
||||||
// remove listeners
|
|
||||||
serial.onReceive.listeners_.forEach(function(listener) {
|
|
||||||
serial.onReceive.removeListener(listener.callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
GUI.interval_remove('STM32_timeout'); // stop STM32 timeout timer (everything is finished now)
|
GUI.interval_remove('STM32_timeout'); // stop STM32 timeout timer (everything is finished now)
|
||||||
|
|
||||||
console.log('Transfered: ' + self.serial_bytes_send + ' bytes, Received: ' + self.serial_bytes_received + ' bytes');
|
console.log('Transfered: ' + self.serial_bytes_send + ' bytes, Received: ' + self.serial_bytes_received + ' bytes');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue