@@ -124,7 +124,7 @@ const Comms = {
124
124
}
125
125
// Actually write the command with a 'print OK' at the end, and use responseHandler
126
126
// to deal with the response. If OK we call uploadCmd to upload the next block
127
- Puck . write ( `${ cmd } ;${ Comms . getProgressCmd ( currentBytes / maxBytes ) } Bluetooth .println("OK")\n` , responseHandler , true /* wait for a newline*/ ) ;
127
+ Puck . write ( `${ cmd } ;${ Comms . getProgressCmd ( currentBytes / maxBytes ) } ${ Const . CONNECTION_DEVICE } .println("OK")\n` , responseHandler , true /* wait for a newline*/ ) ;
128
128
}
129
129
130
130
uploadCmd ( )
@@ -240,18 +240,20 @@ const Comms = {
240
240
return ;
241
241
}
242
242
243
- let cmd , finalJS = `JSON.stringify(require("Storage").getStats?require("Storage").getStats():{})+","+E.toJS([process.env.BOARD,process.env.VERSION,process.env.EXPTR,process.env.MODULES,0|getTime(),E.CRC32(getSerial()+NRF.getAddress())]).substr(1)` ;
243
+ let cmd , finalJS = `JSON.stringify(require("Storage").getStats?require("Storage").getStats():{})+","+E.toJS([process.env.BOARD,process.env.VERSION,process.env.EXPTR,process.env.MODULES,0|getTime(),E.CRC32(getSerial()+(global.NRF?NRF.getAddress():0))]).substr(1)` ;
244
+ let device = Const . CONNECTION_DEVICE ;
244
245
if ( Const . SINGLE_APP_ONLY ) // only one app on device, info file is in app.info
245
- cmd = `\x10Bluetooth .println("["+(require("Storage").read("app.info")||"null")+","+${ finalJS } )\n` ;
246
+ cmd = `\x10 ${ device } .println("["+(require("Storage").read("app.info")||"null")+","+${ finalJS } )\n` ;
246
247
else
247
- cmd = `\x10Bluetooth .print("[");require("Storage").list(/\\.info$/).forEach(f=>{var j=require("Storage").readJSON(f,1)||{};Bluetooth .print(JSON.stringify({id:f.slice(0,-5),version:j.version,files:j.files,data:j.data,type:j.type})+",")});Bluetooth .println(${ finalJS } )\n` ;
248
+ cmd = `\x10 ${ device } .print("[");require("Storage").list(/\\.info$/).forEach(f=>{var j=require("Storage").readJSON(f,1)||{};${ device } .print(JSON.stringify({id:f.slice(0,-5),version:j.version,files:j.files,data:j.data,type:j.type})+",")});${ device } .println(${ finalJS } )\n` ;
248
249
Puck . write ( cmd , ( appListStr , err ) => {
249
250
Progress . hide ( { sticky :true } ) ;
250
251
// we may have received more than one line - we're looking for an array (starting with '[')
251
252
var lines = appListStr ? appListStr . split ( "\n" ) . map ( l => l . trim ( ) ) : [ ] ;
252
253
var appListJSON = lines . find ( l => l [ 0 ] == "[" ) ;
253
254
// check to see if we got our data
254
255
if ( ! appListJSON ) {
256
+ console . log ( "No JSON, just got: " + JSON . stringify ( appListStr ) ) ;
255
257
return reject ( "No response from device. Is 'Programmable' set to 'Off'?" ) ;
256
258
}
257
259
// now try and parse
@@ -285,7 +287,7 @@ const Comms = {
285
287
} ,
286
288
// Get an app's info file from Bangle.js
287
289
getAppInfo : app => {
288
- return Comms . write ( `\x10Bluetooth .println(require("Storage").read(${ JSON . stringify ( AppInfo . getAppInfoFilename ( app ) ) } )||"null")\n` ) .
290
+ return Comms . write ( `\x10 ${ Const . CONNECTION_DEVICE } .println(require("Storage").read(${ JSON . stringify ( AppInfo . getAppInfoFilename ( app ) ) } )||"null")\n` ) .
289
291
then ( appJSON => {
290
292
let app ;
291
293
try {
@@ -371,7 +373,7 @@ const Comms = {
371
373
}
372
374
}
373
375
// Use write with newline here so we wait for it to finish
374
- let cmd = ' \x10E.showMessage("Erasing...");require("Storage").eraseAll();Bluetooth. println("OK");reset()\n' ;
376
+ let cmd = ` \x10E.showMessage("Erasing...");require("Storage").eraseAll();${ Const . CONNECTION_DEVICE } . println("OK");reset()\n` ;
375
377
Puck . write ( cmd , handleResult , true /* wait for newline */ ) ;
376
378
} ) . then ( ( ) => new Promise ( resolve => {
377
379
console . log ( "<COMMS> removeAllApps: Erase complete, waiting 500ms for 'reset()'" ) ;
@@ -489,9 +491,9 @@ const Comms = {
489
491
return Comms . readTextBlock ( `\x03\x10(function() {
490
492
var s = require("Storage").read(${ JSON . stringify ( filename ) } );
491
493
if (s===undefined) s="";
492
- Bluetooth .println(((s.length+2)/3)<<2);
493
- for (var i=0;i<s.length;i+=${ CHUNKSIZE } ) Bluetooth .print(btoa(s.substr(i,${ CHUNKSIZE } )));
494
- Bluetooth .print("\\xFF");
494
+ ${ Const . CONNECTION_DEVICE } .println(((s.length+2)/3)<<2);
495
+ for (var i=0;i<s.length;i+=${ CHUNKSIZE } ) ${ Const . CONNECTION_DEVICE } .print(btoa(s.substr(i,${ CHUNKSIZE } )));
496
+ ${ Const . CONNECTION_DEVICE } .print("\\xFF");
495
497
})()\n` ) . then ( text => {
496
498
return atobSafe ( text ) ;
497
499
} ) ;
@@ -502,10 +504,10 @@ Bluetooth.print("\\xFF");
502
504
console . log ( `<COMMS> readStorageFile ${ JSON . stringify ( filename ) } ` ) ;
503
505
return Comms . readTextBlock ( `\x03\x10(function() {
504
506
var f = require("Storage").open(${ JSON . stringify ( filename ) } ,"r");
505
- Bluetooth .println(f.getLength());
507
+ ${ Const . CONNECTION_DEVICE } .println(f.getLength());
506
508
var l = f.readLine();
507
- while (l!==undefined) { Bluetooth .print(l); l = f.readLine(); }
508
- Bluetooth .print("\\xFF");
509
+ while (l!==undefined) { ${ Const . CONNECTION_DEVICE } .print(l); l = f.readLine(); }
510
+ ${ Const . CONNECTION_DEVICE } .print("\\xFF");
509
511
})()\n` ) ;
510
512
} ,
511
513
// Read a non-storagefile file
0 commit comments