Ver código fonte

Added timeout code to handle portscanning not to overload the system. added multipliers

Andrew Chalkley 8 anos atrás
pai
commit
15e65074c6
3 arquivos alterados com 14 adições e 8 exclusões
  1. 2 1
      back-end/flash.js
  2. 0 1
      back-end/ipcHandlers.js
  3. 12 6
      ui/src/App.js

+ 2 - 1
back-end/flash.js

@@ -4,6 +4,7 @@ const nodeFetch = require('node-fetch');
 const RomComm = require('rom-comm');
 
 function handleBinaryPreparer(binaryPreparer, port, onError, onProgress, onComplete) {
+    const flashSpeedMultiplier = process.platform === 'win32' ? 2 : 4;
     binaryPreparer
         .on("error", onError)
         .on("progress", progress => {
@@ -11,7 +12,7 @@ function handleBinaryPreparer(binaryPreparer, port, onError, onProgress, onCompl
             onProgress(progress.details.downloadedBytes / progress.details.downloadSize, progress.display);
         })
         .on("complete", flashSpec => {
-            const device = RomComm.serial(port, { baudRate: 115200 }, {
+            const device = RomComm.serial(port, { baudRate: 115200 * flashSpeedMultiplier }, {
                 onProgress: progress => onProgress(progress.flashedBytes / progress.totalBytes, 'Flashing')
             });
             device.open(err => {

+ 0 - 1
back-end/ipcHandlers.js

@@ -3,7 +3,6 @@ const scanForPorts = require('./scanForPorts');
 const flash = require('./flash');
 const {ipcMain} = require('electron');
 
-
 function onPortScanComplete(err, ports, event) {
     if (err) {
         event.sender.send('portError', { message: err.message });

+ 12 - 6
ui/src/App.js

@@ -45,6 +45,7 @@ class App extends Component {
       readyToFlash: false,
       isFlashing: false,
       firstRun: true,
+      isScanningForPorts: false,
       percent: 100,
       status: 'Finding ports and manifests...'
     };
@@ -72,8 +73,6 @@ class App extends Component {
     }
   }
 
-
-
   prepareEventHandlers() {
     ipcRenderer.on('portsFound', (event, ports) => this.portsFound(ports));
     ipcRenderer.on('noPortError', (event, error) => {
@@ -108,12 +107,20 @@ class App extends Component {
   }
 
   componentWillMount() {
+    this.scanForPortsInterval = setInterval(() => {
+      if (!this.state.isFlashing && !this.state.isScanningForPorts) {
+        this.setState({isScanningForPorts: true});
+        this.scanForPorts();
+      }
+    }, CONSTANTS.pollTime);
     this.prepareEventHandlers();
-
-    this.scanForPorts();
     this.fetchManifests();
   }
 
+  componentWillUnmount() {
+    clearInterval(this.scanForPortsInterval);
+  }
+
   scanForPorts() {
     ipcRenderer.send('scanForPorts');
   }
@@ -125,14 +132,13 @@ class App extends Component {
     const isFirstSerialPortAdded = this.state.ports.length === 0 && portValues.length > 0;
     const isLastSerialPort = portValues.length === 1;
 
-    const newState = { ports: portValues };
+    const newState = { ports: portValues, isScanningForPorts: false };
 
     if (isFirstSerialPortAdded || isLastSerialPort) {
       Object.assign(newState, { selectedPort: portValues[0].value });
     }
 
     this.setState(newState);
-    if (!this.state.isFlashing) this.scanForPorts()
     this.prepareUI();
   }