Skip to content

Commit ccbbd68

Browse files
committed
Add a hard delay after flashing Fix logging
1 parent c538706 commit ccbbd68

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

src/cmd/esim.js

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module.exports = class eSimCommands extends CLICommandBase {
4545
: 'No devices found.';
4646
throw new Error(errorMessage);
4747
}
48-
await this.doProvision(devices[0], { verbose: true });
48+
await this.doProvision(devices[0]);
4949
}
5050

5151
async bulkProvisionCommand(args) {
@@ -66,17 +66,26 @@ module.exports = class eSimCommands extends CLICommandBase {
6666
console.log('Ready to bulk provision. Connect devices to start. Press Ctrl-C to exit.');
6767
}
6868

69-
async doProvision(device, { verbose = false } = {}) {
69+
async doProvision(device) {
7070
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+
};
7180
const timestamp = new Date().toISOString();
7281
const platform = platformForId(device.specs.productId).name;
7382
const port = device.port;
7483

75-
provisionOutputLogs.push(`${os.EOL}Provisioning device ${device.deviceId} with platform ${platform}`);
84+
logAndPush(`${os.EOL}Provisioning device ${device.deviceId} with platform ${platform}`);
7685

7786
// 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);
8089
if (!flashResp.success) {
8190
await this._changeLed(device, PROVISIONING_FAILURE);
8291
this._addToJson(this.outputJson, {
@@ -90,7 +99,7 @@ module.exports = class eSimCommands extends CLICommandBase {
9099
}
91100

92101
const eidResp = await this._getEid(port);
93-
provisionOutputLogs.push(...eidResp.output);
102+
logAndPush(...eidResp.output);
94103
if (!eidResp.success) {
95104
await this._changeLed(device, PROVISIONING_FAILURE);
96105
this._addToJson(this.outputJson, {
@@ -103,14 +112,14 @@ module.exports = class eSimCommands extends CLICommandBase {
103112
return;
104113
}
105114
const eid = eidResp.eid;
106-
provisionOutputLogs.push(`EID: ${eid}`);
115+
logAndPush(`EID: ${eid}`);
107116

108117
const matchingEsim = this.inputJsonData.provisioning_data.find(item => item.esim_id === eid);
109118
const iccidFromJson = matchingEsim.profiles.map((profile) => profile.iccid);
110119
const expectedProfilesArray = matchingEsim.profiles;
111120

112121
const profileCmdResp = await this._checkForExistingProfiles(port);
113-
provisionOutputLogs.push(...profileCmdResp.output);
122+
logAndPush(...profileCmdResp.output);
114123
if (!profileCmdResp.success) {
115124
await this._changeLed(device, PROVISIONING_FAILURE);
116125
this._addToJson(this.outputJson, {
@@ -135,7 +144,7 @@ module.exports = class eSimCommands extends CLICommandBase {
135144
// extract the iccids that belong to this EID
136145
const matchingEsim = this.inputJsonData.provisioning_data.find(item => item.esim_id === eid);
137146
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');
139148
this._addToJson(this.outputJson, {
140149
esim_id: eid,
141150
device_id: device.deviceId,
@@ -151,7 +160,7 @@ module.exports = class eSimCommands extends CLICommandBase {
151160
const equal = _.isEqual(_.sortBy(existingIccids), _.sortBy(iccidFromJson));
152161
if (equal) {
153162
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');
155164
this._addToJson(this.outputJson, {
156165
esim_id: eid,
157166
device_id: device.deviceId,
@@ -162,7 +171,7 @@ module.exports = class eSimCommands extends CLICommandBase {
162171
});
163172
return;
164173
} 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');
166175
await this._changeLed(device, PROVISIONING_FAILURE);
167176
this._addToJson(this.outputJson, {
168177
esim_id: eid,
@@ -177,7 +186,7 @@ module.exports = class eSimCommands extends CLICommandBase {
177186

178187
// Get profiles for this EID from the input JSON
179188
const profileResp = this._getProfiles(eid);
180-
provisionOutputLogs.push(...profileResp.output);
189+
logAndPush(...profileResp.output);
181190
if (!profileResp.success) {
182191
await this._changeLed(device, PROVISIONING_FAILURE);
183192
this._addToJson(this.outputJson, {
@@ -190,12 +199,12 @@ module.exports = class eSimCommands extends CLICommandBase {
190199
return;
191200
}
192201

193-
provisionOutputLogs.push(`${os.EOL}Provisioning the following profiles to EID ${eid}:`);
202+
logAndPush(`${os.EOL}Provisioning the following profiles to EID ${eid}:`);
194203

195204
const profiles = profileResp.profiles;
196205
profiles.forEach((profile, index) => {
197206
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})`);
199208
});
200209

201210
await this._changeLed(device, PROVISIONING_PROGRESS);
@@ -211,7 +220,7 @@ module.exports = class eSimCommands extends CLICommandBase {
211220
duration: profile.duration
212221
};
213222
});
214-
provisionOutputLogs.push(...downloadResp.output);
223+
logAndPush(...downloadResp.output);
215224

216225
if (!downloadResp.success) {
217226
await this._changeLed(device, PROVISIONING_FAILURE);
@@ -232,7 +241,7 @@ module.exports = class eSimCommands extends CLICommandBase {
232241
const iccidsOnDeviceAfterDownload = profilesOnDeviceAfterDownload.map((line) => line.split('[')[1].split(',')[0].trim());
233242
const equal = _.isEqual(_.sortBy(iccidsOnDeviceAfterDownload), _.sortBy(iccidFromJson));
234243
if (!equal) {
235-
provisionOutputLogs.push('Profiles did not match after download');
244+
logAndPush('Profiles did not match after download');
236245
await this._changeLed(device, PROVISIONING_FAILURE);
237246
this._addToJson(this.outputJson, {
238247
esim_id: eid,
@@ -282,7 +291,7 @@ module.exports = class eSimCommands extends CLICommandBase {
282291
this.lpa = args.lpa;
283292
}
284293

285-
async _flashATPassThroughFirmware(device, platform, port) {
294+
async _flashATPassThroughFirmware(device, platform) {
286295
let outputLogs = [];
287296
const logAndPush = (message) => {
288297
const messages = Array.isArray(message) ? message : [message];
@@ -317,17 +326,10 @@ module.exports = class eSimCommands extends CLICommandBase {
317326
verbose: true,
318327
});
319328
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);
331333

332334
// Handle initial logs (temporary workaround)
333335
logAndPush(`${os.EOL}Checking for the AT-OK to work...`);

0 commit comments

Comments
 (0)