@@ -138,16 +138,12 @@ function loadPropeller(sock, portPath, action, payload, debug) {
138
138
139
139
if ( port . isWired ) {
140
140
//Set postResetDelay based on platform; ideal Post-Reset Delay = 100 ms; adjust downward according to typically-busy operating systems
141
- postResetDelay = ( platform === pfWin ) ? 60 : 100 ;
141
+ postResetDelay = ( ( platform === pfWin ) && ( ! experimentalTiming ) ) ? 60 : 100 ;
142
142
if ( port . connId ) {
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)}
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 ) }
151
147
} else {
152
148
// No connection yet, prep to create one
153
149
originalBaudrate = initialBaudrate ;
@@ -261,6 +257,14 @@ function clearPropCommTimer() {
261
257
}
262
258
}
263
259
260
+ function wait ( ms ) {
261
+ /* Actively delay for ms milliseconds.
262
+ This should only be used for time-critical delays as it doesn't release to the task queue but instead consumes CPU time until finished.
263
+ */
264
+ let Done = Date . now ( ) + ms ;
265
+ while ( Date . now ( ) < Done ) { }
266
+ }
267
+
264
268
function talkToProp ( sock , port , binImage , toEEPROM ) {
265
269
/* Return promise to deliver Propeller Application (binImage) to Propeller
266
270
sock is the websocket to direct mUser messages at
@@ -283,7 +287,8 @@ function talkToProp(sock, port, binImage, toEEPROM) {
283
287
284
288
function sendMBL ( ) {
285
289
return new Promise ( function ( resolve , reject ) {
286
- setTimeout ( function ( ) {
290
+
291
+ function txmit ( ) {
287
292
//Prep for expected packetID:transmissionId response (Micro-Boot-Loader's "Ready" signal)
288
293
propComm . mblEPacketId [ 0 ] = packetId ;
289
294
propComm . mblETransId [ 0 ] = 0 ; //MBL transmission's Id is always 0
@@ -295,9 +300,16 @@ function talkToProp(sock, port, binImage, toEEPROM) {
295
300
. then ( function ( ) { log ( notice ( 000 , [ "Found Propeller" ] ) , mUser + mDbug , sock ) } ) //Succeeded!
296
301
. then ( function ( ) { return resolve ( ) } )
297
302
. catch ( function ( e ) { return reject ( e ) } ) ; //Failed!
298
- } , postResetDelay ) ;
303
+ }
304
+
305
+ if ( ! experimentalTiming ) {
306
+ setTimeout ( txmit , postResetDelay ) ;
307
+ } else {
308
+ wait ( postResetDelay ) ;
309
+ txmit ( ) ;
310
+ }
299
311
} ) ;
300
- } ;
312
+ }
301
313
302
314
Promise . resolve ( )
303
315
. then ( function ( ) { resetPropComm ( port , mblDeliveryTime , null , null , true ) ; } ) //Reset propComm object
0 commit comments