@@ -67,7 +67,7 @@ module.exports = class ESimCommands extends CLICommandBase {
67
67
provisionedDevices . add ( deviceId ) ;
68
68
console . log ( `Device ${ deviceId } connected` ) ;
69
69
// Do not await here, so that the next device can be processed
70
- await this . doProvision ( device ) ;
70
+ this . doProvision ( device ) ;
71
71
}
72
72
}
73
73
} , 1000 ) ;
@@ -119,7 +119,7 @@ module.exports = class ESimCommands extends CLICommandBase {
119
119
provisionOutputLogs . push ( {
120
120
step : 'final_step' ,
121
121
timestamp : new Date ( ) . toISOString ( ) . replace ( / : / g, '-' ) ,
122
- success : success ,
122
+ success : success ? 'success' : 'failed' ,
123
123
details : {
124
124
rawLogs : success ? [ 'Provisioning successful' ] : [ 'Provisioning failed' , ...logs ] ,
125
125
}
@@ -287,8 +287,8 @@ module.exports = class ESimCommands extends CLICommandBase {
287
287
const stepOutput = ( ) => ( {
288
288
step : 'flash_at_firmware' ,
289
289
timestamp,
290
+ status,
290
291
details : {
291
- status : status ,
292
292
fwPath : fwPath ,
293
293
rawLogs : logs
294
294
}
@@ -336,28 +336,36 @@ module.exports = class ESimCommands extends CLICommandBase {
336
336
}
337
337
338
338
async _verifyAtOk ( device ) {
339
- const usbDevice = await usbUtils . getOneUsbDevice ( { idOrName : device . deviceId } ) ;
339
+ let usbDevice ;
340
340
let atOkReceived = false ;
341
- const timeout = Date . now ( ) + 30000 ;
342
-
341
+ const timeout = Date . now ( ) + 30000 ; // Set a 30-second timeout
342
+
343
343
while ( Date . now ( ) < timeout && ! atOkReceived ) {
344
344
try {
345
+ if ( ! usbDevice ?. isOpen ) {
346
+ usbDevice = await usbUtils . reopenDevice ( device ) ;
347
+ }
348
+
345
349
const resp = await usbDevice . sendControlRequest ( CTRL_REQUEST_APP_CUSTOM , JSON . stringify ( GET_AT_COMMAND_STATUS ) ) ;
350
+
351
+ // Check response for AT-OK
346
352
if ( resp ?. result === 0 && resp . data ?. [ 0 ] === '1' ) {
347
353
atOkReceived = true ;
348
354
}
349
355
} catch ( error ) {
350
- // Ignore
356
+ //
351
357
}
352
358
353
359
if ( ! atOkReceived ) {
354
360
await utilities . delay ( 1000 ) ;
355
361
}
356
362
}
357
- await usbDevice . close ( ) ;
363
+ if ( usbDevice ?. isOpen ) {
364
+ await usbDevice . close ( ) ;
365
+ }
358
366
return atOkReceived ;
359
367
}
360
-
368
+
361
369
async _runFlashCommand ( device , fwPath ) {
362
370
const flashCmdInstance = new FlashCommand ( ) ;
363
371
await flashCmdInstance . flashLocal ( {
@@ -385,9 +393,9 @@ module.exports = class ESimCommands extends CLICommandBase {
385
393
const stepOutput = ( ) => ( {
386
394
step : 'get_eid' ,
387
395
timestamp : timestamp ,
396
+ status : status ,
388
397
details : {
389
398
eid : eid ,
390
- status : status ,
391
399
command : command ,
392
400
rawLogs : logs
393
401
}
@@ -544,7 +552,6 @@ module.exports = class ESimCommands extends CLICommandBase {
544
552
command = `${ this . lpa } download ${ rspUrl } --serial=${ port } ` ;
545
553
result = await execa ( this . lpa , [ 'download' , rspUrl , `--serial=${ port } ` ] ) ;
546
554
const timeTaken = ( ( Date . now ( ) - startTime ) / 1000 ) . toFixed ( 2 ) ;
547
-
548
555
if ( result ?. stdout . includes ( 'Profile successfully downloaded' ) ) {
549
556
logAndPush ( `\n\tProfile ${ provider } successfully downloaded in ${ timeTaken } sec` ) ;
550
557
logAndPush ( '\n\t LPA command result: ' + result ?. stdout ) ;
@@ -571,7 +578,6 @@ module.exports = class ESimCommands extends CLICommandBase {
571
578
} catch ( error ) {
572
579
const timeTaken = ( ( Date . now ( ) - startTime ) / 1000 ) . toFixed ( 2 ) ;
573
580
logAndPush ( `\n\tProfile download failed for ${ provider } with error: ${ error . message } ` ) ;
574
- logAndPush ( '\n\t LPA command result: ' + result ?. stdout ) ;
575
581
downloadedProfiles . push ( {
576
582
status : 'failed' ,
577
583
iccid : iccid ,
@@ -623,7 +629,9 @@ module.exports = class ESimCommands extends CLICommandBase {
623
629
outputLogs . push ( `Failed to change LED state: ${ err . message } ` ) ;
624
630
return { success : false , output : outputLogs } ;
625
631
} finally {
626
- await usbDevice . close ( ) ;
632
+ if ( usbDevice ?. isOpen ) {
633
+ await usbDevice . close ( ) ;
634
+ }
627
635
}
628
636
}
629
637
} ;
0 commit comments