Skip to content

Commit b3a5e40

Browse files
committed
Fix at-ok checks
1 parent 3c25c26 commit b3a5e40

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/cmd/esim.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module.exports = class ESimCommands extends CLICommandBase {
6767
provisionedDevices.add(deviceId);
6868
console.log(`Device ${deviceId} connected`);
6969
// Do not await here, so that the next device can be processed
70-
await this.doProvision(device);
70+
this.doProvision(device);
7171
}
7272
}
7373
}, 1000);
@@ -119,7 +119,7 @@ module.exports = class ESimCommands extends CLICommandBase {
119119
provisionOutputLogs.push({
120120
step: 'final_step',
121121
timestamp: new Date().toISOString().replace(/:/g, '-'),
122-
success: success,
122+
success: success ? 'success' : 'failed',
123123
details: {
124124
rawLogs: success ? ['Provisioning successful'] : ['Provisioning failed', ...logs],
125125
}
@@ -287,8 +287,8 @@ module.exports = class ESimCommands extends CLICommandBase {
287287
const stepOutput = () => ({
288288
step: 'flash_at_firmware',
289289
timestamp,
290+
status,
290291
details: {
291-
status: status,
292292
fwPath: fwPath,
293293
rawLogs: logs
294294
}
@@ -336,28 +336,36 @@ module.exports = class ESimCommands extends CLICommandBase {
336336
}
337337

338338
async _verifyAtOk(device) {
339-
const usbDevice = await usbUtils.getOneUsbDevice({ idOrName: device.deviceId });
339+
let usbDevice;
340340
let atOkReceived = false;
341-
const timeout = Date.now() + 30000;
342-
341+
const timeout = Date.now() + 30000; // Set a 30-second timeout
342+
343343
while (Date.now() < timeout && !atOkReceived) {
344344
try {
345+
if (!usbDevice?.isOpen) {
346+
usbDevice = await usbUtils.reopenDevice(device);
347+
}
348+
345349
const resp = await usbDevice.sendControlRequest(CTRL_REQUEST_APP_CUSTOM, JSON.stringify(GET_AT_COMMAND_STATUS));
350+
351+
// Check response for AT-OK
346352
if (resp?.result === 0 && resp.data?.[0] === '1') {
347353
atOkReceived = true;
348354
}
349355
} catch (error) {
350-
// Ignore
356+
//
351357
}
352358

353359
if (!atOkReceived) {
354360
await utilities.delay(1000);
355361
}
356362
}
357-
await usbDevice.close();
363+
if (usbDevice?.isOpen) {
364+
await usbDevice.close();
365+
}
358366
return atOkReceived;
359367
}
360-
368+
361369
async _runFlashCommand(device, fwPath) {
362370
const flashCmdInstance = new FlashCommand();
363371
await flashCmdInstance.flashLocal({
@@ -385,9 +393,9 @@ module.exports = class ESimCommands extends CLICommandBase {
385393
const stepOutput = () => ({
386394
step: 'get_eid',
387395
timestamp: timestamp,
396+
status: status,
388397
details: {
389398
eid: eid,
390-
status: status,
391399
command: command,
392400
rawLogs: logs
393401
}
@@ -544,7 +552,6 @@ module.exports = class ESimCommands extends CLICommandBase {
544552
command = `${this.lpa} download ${rspUrl} --serial=${port}`;
545553
result = await execa(this.lpa, ['download', rspUrl, `--serial=${port}`]);
546554
const timeTaken = ((Date.now() - startTime) / 1000).toFixed(2);
547-
548555
if (result?.stdout.includes('Profile successfully downloaded')) {
549556
logAndPush(`\n\tProfile ${provider} successfully downloaded in ${timeTaken} sec`);
550557
logAndPush('\n\t LPA command result: ' + result?.stdout);
@@ -571,7 +578,6 @@ module.exports = class ESimCommands extends CLICommandBase {
571578
} catch (error) {
572579
const timeTaken = ((Date.now() - startTime) / 1000).toFixed(2);
573580
logAndPush(`\n\tProfile download failed for ${provider} with error: ${error.message}`);
574-
logAndPush('\n\t LPA command result: ' + result?.stdout);
575581
downloadedProfiles.push({
576582
status: 'failed',
577583
iccid: iccid,
@@ -623,7 +629,9 @@ module.exports = class ESimCommands extends CLICommandBase {
623629
outputLogs.push(`Failed to change LED state: ${err.message}`);
624630
return { success: false, output: outputLogs };
625631
} finally {
626-
await usbDevice.close();
632+
if (usbDevice?.isOpen) {
633+
await usbDevice.close();
634+
}
627635
}
628636
}
629637
};

0 commit comments

Comments
 (0)