|
17 | 17 |
|
18 | 18 | // Programming metrics
|
19 | 19 | let postResetDelay = null; //Delay after reset and before serial stream; Post-Reset Delay is set by loadPropeller()
|
20 |
| -let autoAdjust = 20; //Amount to adjust postResetDelay upon each failure |
| 20 | +let autoAdjust = 30; //Amount to adjust postResetDelay upon each failure |
21 | 21 | let txData; //Data to transmit to the Propeller (size/contents created later)
|
22 | 22 |
|
23 | 23 | const defaultClockSpeed = 80000000;
|
@@ -140,17 +140,21 @@ function loadPropeller(sock, portPath, action, payload, debug) {
|
140 | 140 | //Set postResetDelay based on platform; ideal Post-Reset Delay = 100 ms; adjust downward according to typically-busy operating systems
|
141 | 141 | postResetDelay = (platform === pfWin) ? 60 : 100;
|
142 | 142 | if (port.connId) {
|
143 |
| - // Connection exists, prep to reuse it |
144 |
| - originalBaudrate = port.baud; |
145 |
| - updatePort(port, {mode: "programming", bSocket: sock}); |
146 |
| - connect = function() {return changeBaudrate(port, initialBaudrate)} |
| 143 | + // Connection exists, prep to close it first (to reset it), then open it (fresh) |
| 144 | + originalBaudrate = initialBaudrate; |
| 145 | + connect = function() {return closePort(port).then(function() {return openPort(sock, portPath, initialBaudrate, "programming")}).catch(function(e) {return Promise.reject(e)})} |
| 146 | +// The following temporarily removed (and replaced above) to intentionally close and reopen port in hopes it eliminates the CrOS v67+ failed download problem |
| 147 | +// // Connection exists, prep to reuse it |
| 148 | +// originalBaudrate = port.baud; |
| 149 | +// updatePort(port, {mode: "programming", bSocket: sock}); |
| 150 | +// connect = function() {return changeBaudrate(port, initialBaudrate)} |
147 | 151 | } else {
|
148 | 152 | // No connection yet, prep to create one
|
149 | 153 | originalBaudrate = initialBaudrate;
|
150 | 154 | connect = function() {return openPort(sock, portPath, initialBaudrate, "programming")}
|
151 | 155 | }
|
152 | 156 | } else {
|
153 |
| - //Virtually-clear postResetDelay (it's controlled by wireless device) |
| 157 | + //Nearly-clear the postResetDelay (it's controlled by wireless device) |
154 | 158 | postResetDelay = 1;
|
155 | 159 | //TODO Retrieve actual current baudrate
|
156 | 160 | originalBaudrate = initialBaudrate;
|
@@ -180,9 +184,11 @@ function loadPropeller(sock, portPath, action, payload, debug) {
|
180 | 184 | log(e.message, mAll, sock);
|
181 | 185 | log(notice(neDownloadFailed), mAll, sock);
|
182 | 186 | updatePort(port, {mode: "none"});
|
183 |
| - if ((port.isWired && port.connId) || port.isWireless) {changeBaudrate(port, originalBaudrate)} |
184 |
| - if (port.isWireless) {closePort(port, false)} |
185 |
| - }); |
| 187 | + if ((port.isWired && port.connId) || port.isWireless) {return changeBaudrate(port, originalBaudrate)} |
| 188 | + }) |
| 189 | + .catch(function(e) {log(e.message, mAll, sock)}) |
| 190 | + .then(function() {if (port.isWireless) return closePort(port, false)}) |
| 191 | + .catch(function(e) {log(e.message, mAll, sock);}); |
186 | 192 | } else {
|
187 | 193 | // Port not found
|
188 | 194 | log(notice(neCanNotFindPort, [portPath]), mAll, sock);
|
@@ -304,7 +310,9 @@ function talkToProp(sock, port, binImage, toEEPROM) {
|
304 | 310 | .catch(function(e) { //Error!
|
305 | 311 | if (noticeCode(e.message) === nePropellerNotFound && --attempts) { // Retry (if "Propeller not found" and more attempts available)
|
306 | 312 | log("Propeller not found: retrying...", mDeep);
|
307 |
| - postResetDelay = Math.max(postResetDelay - autoAdjust, 1); // Shorten Post Reset Delay upon every attempt (min 1) |
| 313 | + if (platform === pfWin) { // If Windows platform, |
| 314 | + postResetDelay = Math.max(postResetDelay - autoAdjust, 1); // Shorten Post Reset Delay upon every attempt (min 1) |
| 315 | + } |
308 | 316 | return sendLoader(); // note: sendLoader does not return execution below (promises continue at next .then/.catch)
|
309 | 317 | }
|
310 | 318 | return reject(e); // Or if other error (or out of retry attempts), reject with message
|
@@ -429,15 +437,15 @@ function talkToProp(sock, port, binImage, toEEPROM) {
|
429 | 437 | var next;
|
430 | 438 |
|
431 | 439 | /* Calculate expected Micro Boot Loader and User Application delivery times
|
432 |
| - = 300 [>max post-reset-delay] + ((10 [bits per byte] * (data bytes [transmitting] + 20 silence bytes [MBL waiting] + 8 MBL "ready" bytes [MBL responding])) / |
433 |
| - initial baud rate) * 1,000 [to scale ms to integer] + 1 [to always round up] + 500 [Rx hardware to OS slack time] */ |
434 |
| - var mblDeliveryTime = 300+((10*(txData.byteLength+20+8))/initialBaudrate)*1000+1 + (port.isWireless) ? 1500 : 250; |
| 440 | + = 210 [max post-reset-delay] + ((10 [bits per byte] * (data bytes [transmitting] + 20 silence bytes [MBL waiting] + 8 MBL "ready" bytes [MBL responding])) / |
| 441 | + initial baud rate) * 1,000 [to scale ms to integer] + 1 [to always round up] + 250 or 1500 [Rx hardware or Network to OS slack time] */ |
| 442 | + var mblDeliveryTime = Math.trunc(210+((10*(txData.byteLength+20+8))/initialBaudrate)*1000+1 + ((port.isWired) ? 250 : 1500)); |
435 | 443 |
|
436 | 444 | //=((10 [bits per byte] * [max packet size]) / final baud rate) * 1,000 [to scale ms to integer] + 1 [to always round up] + 1500 or 250 [Network or Rx hardware to OS slack time]
|
437 |
| - var userDeliveryTime = ((10*maxDataSize)/finalBaudrate)*1000+1 + (port.isWireless) ? 1500 : 250; |
| 445 | + var userDeliveryTime = Math.trunc(((10*maxDataSize)/finalBaudrate)*1000+1 + ((port.isWired) ? 250 : 1500)); |
438 | 446 |
|
439 |
| - //Set for limited retry attempts (multiple when wired to try various post-reset timing) |
440 |
| - var attempts = (port.isWired) ? Math.trunc(postResetDelay / autoAdjust) + 1 : 1; |
| 447 | + //Set for limited retry attempts (multiple when wired; potentially trying various post-reset timing) |
| 448 | + var attempts = (port.isWired) ? ((platform === pfWin) ? Math.max(Math.trunc(postResetDelay / autoAdjust), 1) : 1) : 1; |
441 | 449 |
|
442 | 450 | Promise.resolve()
|
443 | 451 | .then(function() {return sendLoader();}) //Get Propeller's attention and send initial application (Micro Boot Loader)
|
|
0 commit comments