@@ -68,24 +68,15 @@ module.exports = class eSimCommands extends CLICommandBase {
68
68
69
69
async doProvision ( device ) {
70
70
let provisionOutputLogs = [ ] ;
71
- const logAndPush = ( message ) => {
72
- const messages = Array . isArray ( message ) ? message : [ message ] ;
73
- messages . forEach ( msg => {
74
- provisionOutputLogs . push ( msg ) ;
75
- if ( this . verbose ) {
76
- console . log ( msg ) ;
77
- }
78
- } ) ;
79
- } ;
80
71
const timestamp = new Date ( ) . toISOString ( ) ;
81
72
const platform = platformForId ( device . specs . productId ) . name ;
82
73
const port = device . port ;
83
74
84
- logAndPush ( `${ os . EOL } Provisioning device ${ device . deviceId } with platform ${ platform } ` ) ;
75
+ provisionOutputLogs . push ( `${ os . EOL } Provisioning device ${ device . deviceId } with platform ${ platform } ` ) ;
85
76
86
- // Flash firmware and retrieve EID
77
+ // Flash firmware and wait for AT to work
87
78
const flashResp = await this . _flashATPassThroughFirmware ( device , platform ) ;
88
- logAndPush ( ...flashResp . output ) ;
79
+ provisionOutputLogs . push ( ...flashResp . output ) ;
89
80
if ( ! flashResp . success ) {
90
81
await this . _changeLed ( device , PROVISIONING_FAILURE ) ;
91
82
this . _addToJson ( this . outputJson , {
@@ -98,8 +89,9 @@ module.exports = class eSimCommands extends CLICommandBase {
98
89
return ;
99
90
}
100
91
92
+ // Get the EID
101
93
const eidResp = await this . _getEid ( port ) ;
102
- logAndPush ( ...eidResp . output ) ;
94
+ provisionOutputLogs . push ( ...eidResp . output ) ;
103
95
if ( ! eidResp . success ) {
104
96
await this . _changeLed ( device , PROVISIONING_FAILURE ) ;
105
97
this . _addToJson ( this . outputJson , {
@@ -112,14 +104,15 @@ module.exports = class eSimCommands extends CLICommandBase {
112
104
return ;
113
105
}
114
106
const eid = eidResp . eid ;
115
- logAndPush ( `EID: ${ eid } ` ) ;
107
+ provisionOutputLogs . push ( `EID: ${ eid } ` ) ;
116
108
109
+ // Get the profiles for this EID and compare them against the list in the input JSON under the same EID
117
110
const matchingEsim = this . inputJsonData . provisioning_data . find ( item => item . esim_id === eid ) ;
118
111
const iccidFromJson = matchingEsim . profiles . map ( ( profile ) => profile . iccid ) ;
119
112
const expectedProfilesArray = matchingEsim . profiles ;
120
113
121
114
const profileCmdResp = await this . _checkForExistingProfiles ( port ) ;
122
- logAndPush ( ...profileCmdResp . output ) ;
115
+ provisionOutputLogs . push ( ...profileCmdResp . output ) ;
123
116
if ( ! profileCmdResp . success ) {
124
117
await this . _changeLed ( device , PROVISIONING_FAILURE ) ;
125
118
this . _addToJson ( this . outputJson , {
@@ -144,7 +137,7 @@ module.exports = class eSimCommands extends CLICommandBase {
144
137
// extract the iccids that belong to this EID
145
138
const matchingEsim = this . inputJsonData . provisioning_data . find ( item => item . esim_id === eid ) ;
146
139
if ( ! matchingEsim ) {
147
- logAndPush ( 'No profiles found for the given EID in the input JSON' ) ;
140
+ provisionOutputLogs . push ( 'No profiles found for the given EID in the input JSON' ) ;
148
141
this . _addToJson ( this . outputJson , {
149
142
esim_id : eid ,
150
143
device_id : device . deviceId ,
@@ -160,7 +153,7 @@ module.exports = class eSimCommands extends CLICommandBase {
160
153
const equal = _ . isEqual ( _ . sortBy ( existingIccids ) , _ . sortBy ( iccidFromJson ) ) ;
161
154
if ( equal ) {
162
155
this . _changeLed ( device , PROVISIONING_SUCCESS ) ;
163
- logAndPush ( 'Profiles already provisioned correctly on the device for the given EID' ) ;
156
+ provisionOutputLogs . push ( 'Profiles already provisioned correctly on the device for the given EID' ) ;
164
157
this . _addToJson ( this . outputJson , {
165
158
esim_id : eid ,
166
159
device_id : device . deviceId ,
@@ -171,7 +164,7 @@ module.exports = class eSimCommands extends CLICommandBase {
171
164
} ) ;
172
165
return ;
173
166
} else {
174
- logAndPush ( 'Profiles exist on the device but do not match the profiles in the input JSON' ) ;
167
+ provisionOutputLogs . push ( 'Profiles exist on the device but do not match the profiles in the input JSON' ) ;
175
168
await this . _changeLed ( device , PROVISIONING_FAILURE ) ;
176
169
this . _addToJson ( this . outputJson , {
177
170
esim_id : eid ,
@@ -186,7 +179,7 @@ module.exports = class eSimCommands extends CLICommandBase {
186
179
187
180
// Get profiles for this EID from the input JSON
188
181
const profileResp = this . _getProfiles ( eid ) ;
189
- logAndPush ( ...profileResp . output ) ;
182
+ provisionOutputLogs . push ( ...profileResp . output ) ;
190
183
if ( ! profileResp . success ) {
191
184
await this . _changeLed ( device , PROVISIONING_FAILURE ) ;
192
185
this . _addToJson ( this . outputJson , {
@@ -199,17 +192,17 @@ module.exports = class eSimCommands extends CLICommandBase {
199
192
return ;
200
193
}
201
194
202
- logAndPush ( `${ os . EOL } Provisioning the following profiles to EID ${ eid } :` ) ;
195
+ provisionOutputLogs . push ( `${ os . EOL } Provisioning the following profiles to EID ${ eid } :` ) ;
203
196
204
197
const profiles = profileResp . profiles ;
205
198
profiles . forEach ( ( profile , index ) => {
206
199
const rspUrl = `1\$${ profile . smdp } \$${ profile . matching_id } ` ;
207
- logAndPush ( `\t${ index + 1 } . ${ profile . provider } (${ rspUrl } )` ) ;
200
+ provisionOutputLogs . push ( `\t${ index + 1 } . ${ profile . provider } (${ rspUrl } )` ) ;
208
201
} ) ;
209
202
203
+ // Download each profile and update the JSON output
210
204
await this . _changeLed ( device , PROVISIONING_PROGRESS ) ;
211
205
212
- // Download each profile and update the JSON output
213
206
const downloadResp = await this . _doDownload ( profiles , port ) ;
214
207
const downloadedProfiles = downloadResp . downloadedProfiles ;
215
208
const downloadedProfilesArray = downloadedProfiles . map ( ( profile ) => {
@@ -220,7 +213,7 @@ module.exports = class eSimCommands extends CLICommandBase {
220
213
duration : profile . duration
221
214
} ;
222
215
} ) ;
223
- logAndPush ( ...downloadResp . output ) ;
216
+ provisionOutputLogs . push ( ...downloadResp . output ) ;
224
217
225
218
if ( ! downloadResp . success ) {
226
219
await this . _changeLed ( device , PROVISIONING_FAILURE ) ;
@@ -241,7 +234,7 @@ module.exports = class eSimCommands extends CLICommandBase {
241
234
const iccidsOnDeviceAfterDownload = profilesOnDeviceAfterDownload . map ( ( line ) => line . split ( '[' ) [ 1 ] . split ( ',' ) [ 0 ] . trim ( ) ) ;
242
235
const equal = _ . isEqual ( _ . sortBy ( iccidsOnDeviceAfterDownload ) , _ . sortBy ( iccidFromJson ) ) ;
243
236
if ( ! equal ) {
244
- logAndPush ( 'Profiles did not match after download' ) ;
237
+ provisionOutputLogs . push ( 'Profiles did not match after download' ) ;
245
238
await this . _changeLed ( device , PROVISIONING_FAILURE ) ;
246
239
this . _addToJson ( this . outputJson , {
247
240
esim_id : eid ,
@@ -268,6 +261,7 @@ module.exports = class eSimCommands extends CLICommandBase {
268
261
} ) ;
269
262
270
263
console . log ( `${ os . EOL } Provisioning complete for EID ${ eid } ` ) ;
264
+ provisionOutputLogs . push ( `${ os . EOL } Provisioning complete for EID ${ eid } ` ) ;
271
265
}
272
266
273
267
_validateArgs ( args ) {
@@ -331,7 +325,7 @@ module.exports = class eSimCommands extends CLICommandBase {
331
325
logAndPush ( 'Waiting for the device to reboot...' ) ;
332
326
await utilities . delay ( 5000 ) ;
333
327
334
- // Handle initial logs (temporary workaround)
328
+ // Handle initial logs
335
329
logAndPush ( `${ os . EOL } Checking for the AT-OK to work...` ) ;
336
330
let atOkReceived = false ;
337
331
const start = Date . now ( ) ;
@@ -400,6 +394,7 @@ module.exports = class eSimCommands extends CLICommandBase {
400
394
}
401
395
}
402
396
397
+ // Check for profiles that are exsting on the device
403
398
async _checkForExistingProfiles ( port ) {
404
399
let outputLogs = [ ] ;
405
400
const logAndPush = ( message ) => {
@@ -428,11 +423,11 @@ module.exports = class eSimCommands extends CLICommandBase {
428
423
}
429
424
}
430
425
426
+ // Use lpa tool's listProfiles command to get the profiles on the device
431
427
async _listProfiles ( port ) {
432
428
try {
433
429
const resProfiles = await execa ( this . lpa , [ 'listProfiles' , `--serial=${ port } ` ] ) ;
434
430
const profilesOutput = resProfiles . stdout ;
435
- console . log ( '[dbg] profilesOutput: ' , profilesOutput ) ;
436
431
437
432
// Extract lines matching the profile format
438
433
const profilesList = profilesOutput
@@ -446,6 +441,7 @@ module.exports = class eSimCommands extends CLICommandBase {
446
441
}
447
442
}
448
443
444
+ // Get the profiles that match the EID from the input JSON
449
445
_getProfiles ( eid ) {
450
446
// Get the profile list that matches the EID that is given by the field eid
451
447
let outputLogs = [ ] ;
@@ -468,6 +464,9 @@ module.exports = class eSimCommands extends CLICommandBase {
468
464
return { success : true , profiles : eidBlock ?. profiles , output : outputLogs } ;
469
465
}
470
466
467
+ // Download profiles to the device
468
+ // Profiles are flashed one after another.
469
+ // If any profile download fails, the process stops and the device is marked as failed
471
470
async _doDownload ( profiles , port ) {
472
471
const outputLogs = [ ] ;
473
472
const downloadedProfiles = [ ] ;
@@ -538,6 +537,8 @@ module.exports = class eSimCommands extends CLICommandBase {
538
537
} ;
539
538
}
540
539
540
+ // Add the output logs to the output JSON file
541
+ // If previous data exists, append to it
541
542
_addToJson ( jsonFile , data ) {
542
543
try {
543
544
// Read and parse existing JSON data
@@ -560,6 +561,7 @@ module.exports = class eSimCommands extends CLICommandBase {
560
561
}
561
562
}
562
563
564
+ // Sends a control request to change the LED state
563
565
async _changeLed ( device , state ) {
564
566
let outputLogs = [ ] ;
565
567
let usbDevice ;
@@ -575,20 +577,4 @@ module.exports = class eSimCommands extends CLICommandBase {
575
577
await usbDevice . close ( ) ;
576
578
}
577
579
}
578
-
579
- async _getImei ( device ) {
580
- let outputLogs = [ ] ;
581
- let usbDevice ;
582
- try {
583
- usbDevice = await usbUtils . getOneUsbDevice ( { idOrName : device . deviceId } ) ;
584
- const cellInfo = await usbDevice . getCellularInfo ( { timeout : 5000 } ) ;
585
- outputLogs . push ( `IMEI: ${ cellInfo ?. imei } ` ) ;
586
- return { success : true , imei : cellInfo ?. imei , output : outputLogs } ;
587
- } catch ( err ) {
588
- outputLogs . push ( `Failed to get IMEI: ${ err . message } ` ) ;
589
- return { success : false , output : outputLogs } ;
590
- } finally {
591
- await usbDevice . close ( ) ;
592
- }
593
- }
594
580
} ;
0 commit comments