motion-master-client 0.0.421 → 0.0.422

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3367,7 +3367,7 @@ class MotionMasterReqResClient {
3367
3367
  // @ts-ignore
3368
3368
  return this.runOsCommandAndWriteFsBuffer(deviceRef, command, content, commandTimeout, responsePollingInterval).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => {
3369
3369
  if (response.request !== 'succeeded') {
3370
- throw new Error('Login to SMM for parameter download failed.');
3370
+ throw new Error(`Login to SMM for parameter download failed: ${(0, os_command_1.describeOsCommandFailure)(response)}.`);
3371
3371
  }
3372
3372
  }));
3373
3373
  }
@@ -3395,7 +3395,7 @@ class MotionMasterReqResClient {
3395
3395
  // @ts-ignore
3396
3396
  return this.runOsCommandAndWriteFsBuffer(deviceRef, command, content, commandTimeout, responsePollingInterval).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => {
3397
3397
  if (response.request !== 'succeeded') {
3398
- throw new Error('Login to SMM for software update failed.');
3398
+ throw new Error(`Login to SMM for software update failed: ${(0, os_command_1.describeOsCommandFailure)(response)}.`);
3399
3399
  }
3400
3400
  }));
3401
3401
  }
@@ -3415,7 +3415,7 @@ class MotionMasterReqResClient {
3415
3415
  const command = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.LOGOUT);
3416
3416
  return this.runOsCommand(deviceRef, command, commandTimeout, responsePollingInterval).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => {
3417
3417
  if (response.request !== 'succeeded') {
3418
- throw new Error('Logout from SMM failed.');
3418
+ throw new Error(`Logout from SMM failed: ${(0, os_command_1.describeOsCommandFailure)(response)}.`);
3419
3419
  }
3420
3420
  }));
3421
3421
  }
@@ -3440,25 +3440,84 @@ class MotionMasterReqResClient {
3440
3440
  /**
3441
3441
  * Changes the SMM password for the specified device.
3442
3442
  *
3443
+ * The sequence is: write `<newPassword><oldPassword>` to the fs-buffer and run CHANGE_PASSWORD. If, and only if, the
3444
+ * SMM accepts the change, log out from the SMM, trigger an SMM restart (unless `triggerRestart` is false) and then
3445
+ * wait `rebootDelay` milliseconds before completing, so the next SMM command a caller issues does not land in the
3446
+ * reboot.
3447
+ *
3448
+ * The logout has to come before the restart. When the SMM is restarted while the session is still open, it stores
3449
+ * neither the new nor the old password, although it accepted the change, and only the master password gets in again.
3450
+ * After an accepted change the session is therefore closed; log in again with the new password to continue.
3451
+ *
3443
3452
  * @param deviceRef - A reference to the target device.
3444
3453
  * @param oldPassword - The current SMM password.
3445
- * @param newPassword - The new password to set for the SMM.
3446
- * @param commandTimeout - The timeout in milliseconds for the command to complete.
3454
+ * @param newPassword - The new password to set for the SMM, 4 to 24 printable ASCII characters.
3455
+ * @param commandTimeout - The timeout in milliseconds for the CHANGE_PASSWORD command. On firmware below 5.2.0 it also
3456
+ * covers the FoE write of the fs-buffer, because the buffer is written before the command is issued. If it runs out
3457
+ * while the SMM is still storing the password, the client gives up, the SMM is not restarted, and the result of the
3458
+ * change is unknown. Defaults to 12000: the drive gives up on the SMM after 10 s, so do not set it lower, and do not
3459
+ * retry after a timeout, the SMM may still be running the change.
3447
3460
  * @param responsePollingInterval - The interval in milliseconds between polling for the response.
3448
- *
3449
- * @throws {Error} If the password change attempt fails.
3461
+ * @param triggerRestart - Whether to restart the SMM after an accepted change and the logout. Defaults to true. The
3462
+ * firmware requires a restart after a password change, so pass false only if you restart the SMM yourself (with
3463
+ * {@link triggerSmmRestart}) before issuing any other SMM command. The logout happens either way, so your restart
3464
+ * comes after it.
3465
+ * @param rebootDelay - How long to wait after the restart command completes, in milliseconds, before the observable
3466
+ * completes. Defaults to 3000, the `SMM_REBOOT_DELAY` the firmware test reference uses. Ignored when
3467
+ * `triggerRestart` is false.
3468
+ *
3469
+ * @throws {Error} If a password is not 1 (old) or 4 (new) to 24 printable ASCII characters, if the SMM rejects the
3470
+ * change (the SMM is then not restarted and the session stays open), if the logout after an accepted change fails
3471
+ * (the SMM is then not restarted), or if the restart fails.
3450
3472
  *
3451
3473
  * @remarks
3452
- * A prior successful login is required before changing the password.
3453
- * The new password must be at least 4 characters long.
3474
+ * Completion means the SMM accepted the change. It does not prove that the SMM stored the intended password; only a
3475
+ * login with the new password does.
3454
3476
  *
3455
- * This function sends an acyclic command to update the password. If successful, it triggers an SMM restart.
3477
+ * Rules a caller has to follow, because the SMM and the drive do not enforce them for you:
3478
+ *
3479
+ * - A login for parameter download must be open. A login fails while a session is already open, so log out first:
3480
+ * use {@link reloginToSmmForParameterDownload}. The SMM closes a session after 5 minutes.
3481
+ * - The OS command object (0x1023) and the fs-buffer are a single slot per device. Nothing else may issue OS commands
3482
+ * to the same device during the sequence: no second script, no Motion Master Console on the OS Commands page, no
3483
+ * other tool. Issue SMM functions one at a time and wait for each to complete.
3484
+ * - When the SMM rejects the change, the response does not say why: a wrong old password, a missing or expired
3485
+ * session and an SMM that is still booting all produce the same "the SMM rejected the request (status 2)".
3456
3486
  */
3457
- changeSmmPassword(deviceRef, oldPassword, newPassword, commandTimeout = 10000, responsePollingInterval = 500) {
3458
- const command = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.CHANGE_PASSWORD);
3459
- const content = (0, smm_1.packSmmChangePassword)(newPassword, oldPassword);
3460
- // @ts-ignore
3461
- return this.runOsCommandAndWriteFsBuffer(deviceRef, command, content, commandTimeout, responsePollingInterval).pipe((0, operators_1.last)(), (0, operators_1.mergeMap)(() => this.triggerSmmRestart(deviceRef)));
3487
+ changeSmmPassword(deviceRef, oldPassword, newPassword, commandTimeout = 12000, responsePollingInterval = 500, triggerRestart = true, rebootDelay = 3000) {
3488
+ return (0, rxjs_1.defer)(() => {
3489
+ (0, smm_1.assertValidSmmPassword)(oldPassword, 'Old password');
3490
+ (0, smm_1.assertValidSmmPassword)(newPassword, 'New password', smm_1.SMM_PASSWORD_MIN_LENGTH);
3491
+ const command = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.CHANGE_PASSWORD);
3492
+ const content = (0, smm_1.packSmmChangePassword)(newPassword, oldPassword);
3493
+ // @ts-ignore
3494
+ return this.runOsCommandAndWriteFsBuffer(deviceRef, command, content, commandTimeout, responsePollingInterval);
3495
+ }).pipe((0, operators_1.last)(), (0, operators_1.concatMap)((response) => {
3496
+ if (response.request !== 'succeeded') {
3497
+ throw new Error(`Changing SMM password failed: ${(0, os_command_1.describeOsCommandFailure)(response)}. The password was not changed and the SMM was not restarted.`);
3498
+ }
3499
+ // Log out before the restart. A restart while the session is still open makes the SMM store neither the new
3500
+ // nor the old password, although it accepted the change (reproduced on firmware v5.6.6, issue #185).
3501
+ const logout$ = this.logoutFromSmm(deviceRef).pipe((0, operators_1.catchError)((err) => (0, rxjs_1.throwError)(() => {
3502
+ var _a;
3503
+ return new Error(`The SMM accepted the password change, but the logout failed, so the SMM was not restarted. Log out and restart the SMM before using the new password. ${(_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : err}`);
3504
+ })), (0, operators_1.last)(null, undefined));
3505
+ if (!triggerRestart) {
3506
+ return logout$;
3507
+ }
3508
+ return logout$.pipe((0, operators_1.concatMap)(() => this.triggerSmmRestart(deviceRef).pipe((0, operators_1.catchError)((err) => (0, rxjs_1.throwError)(() => { var _a; return new Error(`The SMM accepted the password change, but the restart failed. ${(_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : err}`); })), (0, operators_1.last)(null, undefined))), (0, operators_1.concatMap)(() => (0, rxjs_1.timer)(rebootDelay)));
3509
+ }), (0, operators_1.last)(null, undefined), (0, operators_1.map)(() => undefined));
3510
+ }
3511
+ /**
3512
+ * Runs an SMM sequence and then logs out from the SMM, on completion and on error alike.
3513
+ *
3514
+ * Unlike a `finalize(() => logout.subscribe())`, the logout is part of the returned observable: the result is
3515
+ * delivered only after the logout has finished, so a caller's next SMM command cannot run alongside it on the
3516
+ * device's single OS command slot. A failing logout does not replace the sequence's own result or error.
3517
+ */
3518
+ logoutFromSmmAfter(deviceRef, sequence$) {
3519
+ const logout$ = (0, rxjs_1.defer)(() => this.logoutFromSmm(deviceRef)).pipe((0, operators_1.catchError)(() => rxjs_1.EMPTY), (0, operators_1.filter)(() => false));
3520
+ return (0, rxjs_1.concat)(sequence$.pipe((0, operators_1.catchError)((err) => (0, rxjs_1.concat)(logout$, (0, rxjs_1.throwError)(() => err)))), logout$);
3462
3521
  }
3463
3522
  /**
3464
3523
  * Triggers an SMM restart for the specified device.
@@ -3479,7 +3538,7 @@ class MotionMasterReqResClient {
3479
3538
  const command = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.TRIGGER_RESTART);
3480
3539
  return this.runOsCommand(deviceRef, command, commandTimeout, responsePollingInterval).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => {
3481
3540
  if (response.request !== 'succeeded') {
3482
- throw new Error('Triggering SMM restart failed.');
3541
+ throw new Error(`Triggering SMM restart failed: ${(0, os_command_1.describeOsCommandFailure)(response)}.`);
3483
3542
  }
3484
3543
  }));
3485
3544
  }
@@ -3499,7 +3558,7 @@ class MotionMasterReqResClient {
3499
3558
  const command = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.IO_FAILURE_ACKNOWLEDGE);
3500
3559
  return this.runOsCommand(deviceRef, command, commandTimeout, responsePollingInterval).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => {
3501
3560
  if (response.request !== 'succeeded') {
3502
- throw new Error('Acknowledging I/O failure on SMM failed.');
3561
+ throw new Error(`Acknowledging I/O failure on SMM failed: ${(0, os_command_1.describeOsCommandFailure)(response)}.`);
3503
3562
  }
3504
3563
  }));
3505
3564
  }
@@ -3516,7 +3575,7 @@ class MotionMasterReqResClient {
3516
3575
  const command = (0, os_command_1.createSmmAcyclicHandlerConfigureSoftwareUpdateOsCommand)(fileSize);
3517
3576
  return this.runOsCommand(deviceRef, command, 10000, 100).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => {
3518
3577
  if (response.request !== 'succeeded') {
3519
- throw new Error('Configuring SMM software update failed.');
3578
+ throw new Error(`Configuring SMM software update failed: ${(0, os_command_1.describeOsCommandFailure)(response)}.`);
3520
3579
  }
3521
3580
  }));
3522
3581
  }
@@ -3571,7 +3630,7 @@ class MotionMasterReqResClient {
3571
3630
  observables.push((0, rxjs_1.defer)(() => this.runOsCommandAndWriteFsBuffer(deviceRef, transmitSoftwareCommand, fsBufferContent, commandTimeout, responsePollingInterval, false, fsBufferReadWriteTimeout).pipe((0, operators_1.last)(), // Only consider the final response of the command.
3572
3631
  (0, operators_1.map)((response) => {
3573
3632
  if (response.request !== 'succeeded') {
3574
- throw new Error(`Transmitting SMM software chunk ${i + 1}/${n} failed.`);
3633
+ throw new Error(`Transmitting SMM software chunk ${i + 1}/${n} failed: ${(0, os_command_1.describeOsCommandFailure)(response)}.`);
3575
3634
  }
3576
3635
  }) // Interpret the response success.
3577
3636
  )));
@@ -3584,7 +3643,7 @@ class MotionMasterReqResClient {
3584
3643
  // @ts-ignore
3585
3644
  this.runOsCommandAndWriteFsBuffer(deviceRef, finalizeSoftwareUpdateCommand, packedCrc).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => {
3586
3645
  if (response.request !== 'succeeded') {
3587
- throw new Error('Finalizing SMM software update failed.');
3646
+ throw new Error(`Finalizing SMM software update failed: ${(0, os_command_1.describeOsCommandFailure)(response)}.`);
3588
3647
  }
3589
3648
  }))),
3590
3649
  // Step 7: Trigger a restart so the new software takes effect.
@@ -3862,7 +3921,7 @@ class MotionMasterReqResClient {
3862
3921
  // @ts-ignore
3863
3922
  content, commandTimeout, responsePollingInterval).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => {
3864
3923
  if (response.request !== 'succeeded') {
3865
- throw new Error('Transmitting SMM parameters failed.');
3924
+ throw new Error(`Transmitting SMM parameters failed: ${(0, os_command_1.describeOsCommandFailure)(response)}.`);
3866
3925
  }
3867
3926
  }));
3868
3927
  }));
@@ -3925,7 +3984,7 @@ class MotionMasterReqResClient {
3925
3984
  const command = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.VERIFY_PARAMETERS);
3926
3985
  return this.runOsCommandAndWriteFsBuffer(deviceRef, command, content, commandTimeout, responsePollingInterval).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => {
3927
3986
  if (response.request !== 'succeeded') {
3928
- throw new Error('Verifying SMM parameters failed.');
3987
+ throw new Error(`Verifying SMM parameters failed: ${(0, os_command_1.describeOsCommandFailure)(response)}.`);
3929
3988
  }
3930
3989
  }));
3931
3990
  }));
@@ -3990,7 +4049,7 @@ class MotionMasterReqResClient {
3990
4049
  const command = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.VALIDATE_CONFIGURATION);
3991
4050
  return this.runOsCommandAndWriteFsBuffer(deviceRef, command, content, commandTimeout, responsePollingInterval).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => {
3992
4051
  if (response.request !== 'succeeded') {
3993
- throw new Error('Validating SMM configuration failed.');
4052
+ throw new Error(`Validating SMM configuration failed: ${(0, os_command_1.describeOsCommandFailure)(response)}.`);
3994
4053
  }
3995
4054
  }));
3996
4055
  }
@@ -4454,7 +4513,7 @@ class MotionMasterReqResClient {
4454
4513
  // Fail lambda to handle errors in a consistent way.
4455
4514
  const fail = (message) => (0, rxjs_1.throwError)(() => new Error(message));
4456
4515
  // Resolve the SMM parameter structure version for getting the correct SMM OD.
4457
- return this.resolveSmmParameterStructureVersion(deviceRef).pipe((0, operators_1.concatMap)((parameterStructureVersion) => {
4516
+ const sequence$ = this.resolveSmmParameterStructureVersion(deviceRef).pipe((0, operators_1.concatMap)((parameterStructureVersion) => {
4458
4517
  const smmOd = (0, smm_1.resolveSmmOd)(parameterStructureVersion);
4459
4518
  // Group SMM safety parameters by their 'group' property,
4460
4519
  // then for each group, map the SMM OD parameters to the matching
@@ -4509,9 +4568,9 @@ class MotionMasterReqResClient {
4509
4568
  }));
4510
4569
  }));
4511
4570
  }));
4512
- }), (0, operators_1.finalize)(() => {
4513
- this.logoutFromSmm(deviceRef).subscribe();
4514
4571
  }));
4572
+ // Log out at the end, on success and on failure, before the result is delivered.
4573
+ return this.logoutFromSmmAfter(deviceRef, sequence$);
4515
4574
  }
4516
4575
  /**
4517
4576
  * Executes a forward call by sending the provided data, then parses the JSON response.