@@ -120,6 +120,9 @@ function loadPropeller(sock, portName, action, payload, debug) {
120
120
let connect ;
121
121
let originalBaudrate ;
122
122
123
+ // Halt timed events that may interfere with download
124
+ haltTimedEvents ( ) ;
125
+
123
126
if ( port . isWired ) {
124
127
if ( port . connId ) {
125
128
// Connection exists, prep to reuse it
@@ -140,34 +143,37 @@ function loadPropeller(sock, portName, action, payload, debug) {
140
143
// Use connection to download application to the Propeller
141
144
connect ( )
142
145
. then ( function ( ) { listen ( port , true ) } ) //Enable listener
143
- . then ( function ( ) { log ( notice ( 000 , [ "Scanning port " + portName ] ) , mUser , sock ) } ) //Notify what port we're using
146
+ . then ( function ( ) { log ( notice ( 000 , [ "Scanning port " + portName ] ) , mUser , sock , - 1 ) } ) //Notify what port we're using
144
147
. then ( function ( ) { return talkToProp ( sock , port , binImage , action === 'EEPROM' ) } ) //Download user application to RAM or EEPROM
145
148
. then ( function ( ) { return changeBaudrate ( port , originalBaudrate ) } ) //Restore original baudrate
146
149
. then ( function ( ) { //Success! Open terminal or graph if necessary
147
150
listen ( port , false ) ; //Disable listener
148
151
port . mode = ( debug !== "none" ) ? "debug" : "programming" ;
149
- log ( notice ( nsDownloadSuccessful ) , mAll , sock ) ;
152
+ log ( notice ( nsDownloadSuccessful ) , mAll , sock , - 1 ) ;
150
153
if ( sock && debug !== "none" ) { //If debug needed, open terminal/graph
151
154
sock . send ( JSON . stringify ( { type :"ui-command" , action :( debug === "term" ) ? "open-terminal" : "open-graph" } ) ) ;
152
155
sock . send ( JSON . stringify ( { type :"ui-command" , action :"close-compile" } ) ) ;
153
156
} else { //Else
154
157
updatePort ( port , { mode : "none" } ) ; // Clear port mode
155
- if ( port . isWireless ) closePort ( port , false ) . catch ( function ( e ) { log ( e . message , mAll , sock ) ; } ) // Close Telnet port (if wireless)
158
+ if ( port . isWireless ) closePort ( port , false ) . catch ( function ( e ) { log ( e . message , mAll , sock , - 1 ) ; } ) // Close Telnet port (if wireless)
156
159
}
157
160
} ) //Error? Disable listener and display error
158
161
. catch ( function ( e ) {
159
162
listen ( port , false ) ;
160
- log ( e . message , mAll , sock ) ;
161
- log ( notice ( neDownloadFailed ) , mAll , sock ) ;
163
+ log ( e . message , mAll , sock , - 1 ) ;
164
+ log ( notice ( neDownloadFailed ) , mAll , sock , - 1 ) ;
162
165
updatePort ( port , { mode : "none" } ) ;
163
166
if ( ( port . isWired && port . connId ) || port . isWireless ) { return changeBaudrate ( port , originalBaudrate ) }
164
167
} )
165
- . catch ( function ( e ) { log ( e . message , mAll , sock ) } )
168
+ . catch ( function ( e ) { log ( e . message , mAll , sock , - 1 ) } )
166
169
. then ( function ( ) { if ( port . isWireless ) return closePort ( port , false ) } )
167
- . catch ( function ( e ) { log ( e . message , mAll , sock ) ; } ) ;
170
+ . catch ( function ( e ) { log ( e . message , mAll , sock , - 1 ) } )
171
+ . then ( function ( ) { resumeTimedEvents ( ) } ) // Resume timed events that were halted earlier
172
+ . catch ( function ( ) { resumeTimedEvents ( ) } ) ;
168
173
} else {
169
174
// Port not found
170
- log ( notice ( neCanNotFindPort , [ portName ] ) , mAll , sock ) ;
175
+ log ( notice ( neCanNotFindPort , [ portName ] ) , mAll , sock , - 1 ) ;
176
+ log ( notice ( neDownloadFailed ) , mAll , sock , - 1 ) ;
171
177
}
172
178
}
173
179
@@ -274,15 +280,15 @@ function talkToProp(sock, port, binImage, toEEPROM) {
274
280
}
275
281
//Prep for expected packetID:transmissionId response (Micro-Boot-Loader's "Ready" signal)
276
282
propComm . mblEPacketId [ 0 ] = packetId ;
277
- propComm . mblETransId [ 0 ] = 0 ; //MBL transmission's Id is always 0
283
+ propComm . mblETransId [ 0 ] = 0 ; //MBL transmission's Id is always 0
278
284
//Send Micro Boot Loader package and get response; if wired port, unpause (may be auto-paused by incoming data error); wireless ports, carry on immediately
279
285
log ( "Transmitting Micro Boot Loader package" , mDeep ) ;
280
286
send ( port , txData , true )
281
- . then ( function ( ) { if ( port . isWired ) { return unPause ( port ) } } ) //Unpause port (if wired)
282
- . then ( function ( ) { return propComm . response } ) //Wait for response (may timeout with rejection)
283
- . then ( function ( ) { log ( notice ( 000 , [ "Found Propeller" ] ) , mUser + mDbug , sock ) } ) //Succeeded!
287
+ . then ( function ( ) { if ( port . isWired ) { return unPause ( port ) } } ) //Unpause port (if wired)
288
+ . then ( function ( ) { return propComm . response } ) //Wait for response (may timeout with rejection)
289
+ . then ( function ( ) { log ( notice ( 000 , [ "Found Propeller" ] ) , mUser + mDbug , sock , - 1 ) } ) //Succeeded!
284
290
. then ( function ( ) { return resolve ( ) } )
285
- . catch ( function ( e ) { return reject ( e ) } ) ; //Failed!
291
+ . catch ( function ( e ) { return reject ( e ) } ) ; //Failed!
286
292
} ) ;
287
293
}
288
294
@@ -320,16 +326,17 @@ function talkToProp(sock, port, binImage, toEEPROM) {
320
326
321
327
return new Promise ( function ( resolve , reject ) {
322
328
log ( ( totalPackets - packetId + 1 ) + " of " + totalPackets , mDbug ) ;
323
- log ( notice ( nsDownloading ) , mUser , sock ) ;
329
+ log ( notice ( nsDownloading ) , mUser , sock , - 1 ) ;
324
330
prepForMBLResponse ( userDeliveryTime , notice ( neCommunicationLost ) ) ;
325
331
var txPacketLength = 2 + //Determine packet length (in longs); header + packet limit or remaining data length
326
332
Math . min ( Math . trunc ( maxDataSize / 4 ) - 2 , Math . trunc ( binImage . byteLength / 4 ) - pIdx ) ;
327
- txData = new ArrayBuffer ( txPacketLength * 4 ) ; //Set packet length (in longs) }
333
+ txData = new ArrayBuffer ( txPacketLength * 4 ) ; //Set packet length (in longs) }
328
334
txView = new Uint8Array ( txData ) ;
329
335
propComm . mblEPacketId [ 0 ] = packetId - 1 ; //Set next expected packetId
330
- propComm . mblETransId [ 0 ] = Math . floor ( Math . random ( ) * 4294967296 ) ; //Set next random Transmission ID
336
+ propComm . mblETransId [ 0 ] = Math . floor ( Math . random ( ) * 4294967296 ) ; //Set next random Transmission ID
331
337
( new DataView ( txData , 0 , 4 ) ) . setUint32 ( 0 , packetId , true ) ; //Store Packet ID
332
338
( new DataView ( txData , 4 , 4 ) ) . setUint32 ( 0 , propComm . mblETransId [ 0 ] , true ) ; //Store random Transmission ID
339
+ //log('Sending PID/TID: '+txView.subarray(0, 4)+'/'+txView.subarray(4, 8), mDeep);
333
340
txView . set ( ( new Uint8Array ( binImage ) ) . slice ( pIdx * 4 , pIdx * 4 + ( txPacketLength - 2 ) * 4 ) , 8 ) ; //Store section of binary image
334
341
send ( port , txData , false ) //Transmit packet
335
342
. then ( function ( ) { pIdx += txPacketLength - 2 ; packetId -- ; resolve ( ) ; } ) ; //Increment image index, decrement Packet ID (to next packet), resolve
@@ -361,7 +368,7 @@ function talkToProp(sock, port, binImage, toEEPROM) {
361
368
function sendInstructionPacket ( ) {
362
369
return new Promise ( function ( resolve , reject ) {
363
370
next = instPacket . next ( ) ;
364
- log ( next . value . sendLog , mAll , sock ) ;
371
+ log ( next . value . sendLog , mAll , sock , - 1 ) ;
365
372
366
373
generateLoaderPacket ( next . value . type , packetId ) ; //Generate next executable packet
367
374
@@ -390,7 +397,7 @@ function talkToProp(sock, port, binImage, toEEPROM) {
390
397
}
391
398
392
399
//Set up continuous progress indicator during this phase
393
- progress = setInterval ( function ( ) { log ( notice ( nsDownloading ) , mUser , sock ) } , 1000 ) ;
400
+ progress = setInterval ( log , 1000 , notice ( nsDownloading ) , mUser , sock ) ;
394
401
395
402
sendInstructionPacket ( )
396
403
. then ( function ( ) { clearInterval ( progress ) ; return resolve ( ) ; } )
@@ -454,8 +461,7 @@ function hearFromProp(info) {
454
461
455
462
// Parse HTTP-command responses into proper object, or treat wired and Telnet-wireless streams as an unformatted array
456
463
let stream = ( dataSource === dsHTTP ) ? parseHTTP ( info . data ) : new Uint8Array ( info . data )
457
- log ( "Received " + info . data . byteLength + " bytes" , mDeep ) ;
458
- // console.log(stream);
464
+ //log("Received " + info.data.byteLength + " bytes:" + ((info.data.byteLength < 9) ? " " : "\n") + stream.toString(), mDeep);
459
465
460
466
var sIdx = 0 ;
461
467
@@ -819,7 +825,7 @@ function generateLoaderPacket(loaderType, packetId, clockSpeed, clockMode) {
819
825
fBitTime . setUint32 ( 0 , Math . round ( clockSpeed / finalBaudrate ) , true ) ; //Final Bit Time (baudrate in clock cycles)
820
826
bitTime1_5 . setUint32 ( 0 , Math . round ( ( ( 1.5 * clockSpeed ) / finalBaudrate ) - maxRxSenseError ) , true ) ; //1.5x Final Bit Time minus maximum start bit sense error
821
827
failsafe . setUint32 ( 0 , 2 * Math . trunc ( clockSpeed / ( 3 * 4 ) ) , true ) ; //Failsafe Timeout (seconds-worth of Loader's Receive loop iterations)
822
- endOfPacket . setUint32 ( 0 , Math . round ( 2 * clockSpeed / finalBaudrate * 10 / 12 ) , true ) ; //EndOfPacket Timeout (2 bytes worth of Loader's Receive loop iterations)
828
+ endOfPacket . setUint32 ( 0 , Math . round ( 500 * clockSpeed / finalBaudrate * 10 / 12 ) , true ) ; //EndOfPacket Timeout (500 bytes worth of Loader's Receive loop iterations)
823
829
sTime . setUint32 ( 0 , Math . max ( Math . round ( clockSpeed * 0.0000006 ) , 14 ) , true ) ; //Minimum EEPROM Start/Stop Condition setup/hold time (400 KHz = 1/0.6 µS); Minimum 14 cycles }
824
830
sclHighTime . setUint32 ( 0 , Math . max ( Math . round ( clockSpeed * 0.0000006 ) , 14 ) , true ) ; //Minimum EEPROM SCL high time (400 KHz = 1/0.6 µS); Minimum 14 cycles
825
831
sclLowTime . setUint32 ( 0 , Math . max ( Math . round ( clockSpeed * 0.0000013 ) , 14 ) , true ) ; //Minimum EEPROM SCL low time (400 KHz = 1/1.3 µS); Minimum 26 cycles
0 commit comments