@@ -45,7 +45,7 @@ module.exports = class eSimCommands extends CLICommandBase {
45
45
: 'No devices found.' ;
46
46
throw new Error ( errorMessage ) ;
47
47
}
48
- await this . doProvision ( devices [ 0 ] , { verbose : true } ) ;
48
+ await this . doProvision ( devices [ 0 ] ) ;
49
49
}
50
50
51
51
async bulkProvisionCommand ( args ) {
@@ -66,17 +66,26 @@ module.exports = class eSimCommands extends CLICommandBase {
66
66
console . log ( 'Ready to bulk provision. Connect devices to start. Press Ctrl-C to exit.' ) ;
67
67
}
68
68
69
- async doProvision ( device , { verbose = false } = { } ) {
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
+ } ;
71
80
const timestamp = new Date ( ) . toISOString ( ) ;
72
81
const platform = platformForId ( device . specs . productId ) . name ;
73
82
const port = device . port ;
74
83
75
- provisionOutputLogs . push ( `${ os . EOL } Provisioning device ${ device . deviceId } with platform ${ platform } ` ) ;
84
+ logAndPush ( `${ os . EOL } Provisioning device ${ device . deviceId } with platform ${ platform } ` ) ;
76
85
77
86
// Flash firmware and retrieve EID
78
- const flashResp = await this . _flashATPassThroughFirmware ( device , platform , port ) ;
79
- provisionOutputLogs . push ( ...flashResp . output ) ;
87
+ const flashResp = await this . _flashATPassThroughFirmware ( device , platform ) ;
88
+ logAndPush ( ...flashResp . output ) ;
80
89
if ( ! flashResp . success ) {
81
90
await this . _changeLed ( device , PROVISIONING_FAILURE ) ;
82
91
this . _addToJson ( this . outputJson , {
@@ -90,7 +99,7 @@ module.exports = class eSimCommands extends CLICommandBase {
90
99
}
91
100
92
101
const eidResp = await this . _getEid ( port ) ;
93
- provisionOutputLogs . push ( ...eidResp . output ) ;
102
+ logAndPush ( ...eidResp . output ) ;
94
103
if ( ! eidResp . success ) {
95
104
await this . _changeLed ( device , PROVISIONING_FAILURE ) ;
96
105
this . _addToJson ( this . outputJson , {
@@ -103,14 +112,14 @@ module.exports = class eSimCommands extends CLICommandBase {
103
112
return ;
104
113
}
105
114
const eid = eidResp . eid ;
106
- provisionOutputLogs . push ( `EID: ${ eid } ` ) ;
115
+ logAndPush ( `EID: ${ eid } ` ) ;
107
116
108
117
const matchingEsim = this . inputJsonData . provisioning_data . find ( item => item . esim_id === eid ) ;
109
118
const iccidFromJson = matchingEsim . profiles . map ( ( profile ) => profile . iccid ) ;
110
119
const expectedProfilesArray = matchingEsim . profiles ;
111
120
112
121
const profileCmdResp = await this . _checkForExistingProfiles ( port ) ;
113
- provisionOutputLogs . push ( ...profileCmdResp . output ) ;
122
+ logAndPush ( ...profileCmdResp . output ) ;
114
123
if ( ! profileCmdResp . success ) {
115
124
await this . _changeLed ( device , PROVISIONING_FAILURE ) ;
116
125
this . _addToJson ( this . outputJson , {
@@ -135,7 +144,7 @@ module.exports = class eSimCommands extends CLICommandBase {
135
144
// extract the iccids that belong to this EID
136
145
const matchingEsim = this . inputJsonData . provisioning_data . find ( item => item . esim_id === eid ) ;
137
146
if ( ! matchingEsim ) {
138
- provisionOutputLogs . push ( 'No profiles found for the given EID in the input JSON' ) ;
147
+ logAndPush ( 'No profiles found for the given EID in the input JSON' ) ;
139
148
this . _addToJson ( this . outputJson , {
140
149
esim_id : eid ,
141
150
device_id : device . deviceId ,
@@ -151,7 +160,7 @@ module.exports = class eSimCommands extends CLICommandBase {
151
160
const equal = _ . isEqual ( _ . sortBy ( existingIccids ) , _ . sortBy ( iccidFromJson ) ) ;
152
161
if ( equal ) {
153
162
this . _changeLed ( device , PROVISIONING_SUCCESS ) ;
154
- provisionOutputLogs . push ( 'Profiles already provisioned correctly on the device for the given EID' ) ;
163
+ logAndPush ( 'Profiles already provisioned correctly on the device for the given EID' ) ;
155
164
this . _addToJson ( this . outputJson , {
156
165
esim_id : eid ,
157
166
device_id : device . deviceId ,
@@ -162,7 +171,7 @@ module.exports = class eSimCommands extends CLICommandBase {
162
171
} ) ;
163
172
return ;
164
173
} else {
165
- provisionOutputLogs . push ( 'Profiles exist on the device but do not match the profiles in the input JSON' ) ;
174
+ logAndPush ( 'Profiles exist on the device but do not match the profiles in the input JSON' ) ;
166
175
await this . _changeLed ( device , PROVISIONING_FAILURE ) ;
167
176
this . _addToJson ( this . outputJson , {
168
177
esim_id : eid ,
@@ -177,7 +186,7 @@ module.exports = class eSimCommands extends CLICommandBase {
177
186
178
187
// Get profiles for this EID from the input JSON
179
188
const profileResp = this . _getProfiles ( eid ) ;
180
- provisionOutputLogs . push ( ...profileResp . output ) ;
189
+ logAndPush ( ...profileResp . output ) ;
181
190
if ( ! profileResp . success ) {
182
191
await this . _changeLed ( device , PROVISIONING_FAILURE ) ;
183
192
this . _addToJson ( this . outputJson , {
@@ -190,12 +199,12 @@ module.exports = class eSimCommands extends CLICommandBase {
190
199
return ;
191
200
}
192
201
193
- provisionOutputLogs . push ( `${ os . EOL } Provisioning the following profiles to EID ${ eid } :` ) ;
202
+ logAndPush ( `${ os . EOL } Provisioning the following profiles to EID ${ eid } :` ) ;
194
203
195
204
const profiles = profileResp . profiles ;
196
205
profiles . forEach ( ( profile , index ) => {
197
206
const rspUrl = `1\$${ profile . smdp } \$${ profile . matching_id } ` ;
198
- provisionOutputLogs . push ( `\t${ index + 1 } . ${ profile . provider } (${ rspUrl } )` ) ;
207
+ logAndPush ( `\t${ index + 1 } . ${ profile . provider } (${ rspUrl } )` ) ;
199
208
} ) ;
200
209
201
210
await this . _changeLed ( device , PROVISIONING_PROGRESS ) ;
@@ -211,7 +220,7 @@ module.exports = class eSimCommands extends CLICommandBase {
211
220
duration : profile . duration
212
221
} ;
213
222
} ) ;
214
- provisionOutputLogs . push ( ...downloadResp . output ) ;
223
+ logAndPush ( ...downloadResp . output ) ;
215
224
216
225
if ( ! downloadResp . success ) {
217
226
await this . _changeLed ( device , PROVISIONING_FAILURE ) ;
@@ -232,7 +241,7 @@ module.exports = class eSimCommands extends CLICommandBase {
232
241
const iccidsOnDeviceAfterDownload = profilesOnDeviceAfterDownload . map ( ( line ) => line . split ( '[' ) [ 1 ] . split ( ',' ) [ 0 ] . trim ( ) ) ;
233
242
const equal = _ . isEqual ( _ . sortBy ( iccidsOnDeviceAfterDownload ) , _ . sortBy ( iccidFromJson ) ) ;
234
243
if ( ! equal ) {
235
- provisionOutputLogs . push ( 'Profiles did not match after download' ) ;
244
+ logAndPush ( 'Profiles did not match after download' ) ;
236
245
await this . _changeLed ( device , PROVISIONING_FAILURE ) ;
237
246
this . _addToJson ( this . outputJson , {
238
247
esim_id : eid ,
@@ -282,7 +291,7 @@ module.exports = class eSimCommands extends CLICommandBase {
282
291
this . lpa = args . lpa ;
283
292
}
284
293
285
- async _flashATPassThroughFirmware ( device , platform , port ) {
294
+ async _flashATPassThroughFirmware ( device , platform ) {
286
295
let outputLogs = [ ] ;
287
296
const logAndPush = ( message ) => {
288
297
const messages = Array . isArray ( message ) ? message : [ message ] ;
@@ -317,17 +326,10 @@ module.exports = class eSimCommands extends CLICommandBase {
317
326
verbose : true ,
318
327
} ) ;
319
328
logAndPush ( `${ os . EOL } Firmware flashed successfully` ) ;
320
-
321
- // Wait for the device to respond
322
- logAndPush ( `${ os . EOL } Waiting for device to respond...` ) ;
323
- const deviceResponded = await usbUtils . waitForDeviceToRespond ( device . deviceId ) ;
324
-
325
- if ( ! deviceResponded ) {
326
- logAndPush ( 'Device did not respond after flashing firmware' ) ;
327
- return { success : false , output : outputLogs } ;
328
- }
329
- logAndPush ( `${ os . EOL } Device responded successfully` ) ;
330
- await deviceResponded . close ( ) ;
329
+
330
+ // FIXME: The control request for the AT-OK check would give 'IN CONTROL transfer failed' without this delay
331
+ logAndPush ( 'Waiting for the device to reboot...' ) ;
332
+ await utilities . delay ( 5000 ) ;
331
333
332
334
// Handle initial logs (temporary workaround)
333
335
logAndPush ( `${ os . EOL } Checking for the AT-OK to work...` ) ;
0 commit comments